-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf-test.py
More file actions
47 lines (41 loc) · 1.35 KB
/
cf-test.py
File metadata and controls
47 lines (41 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
#
# stolen from
# http://stackoverflow.com/questions/34717166/how-to-list-all-apps-in-cloudfoundry-using-python
import getpass
import requests
import os
import sys
import json
should_verify = False
if not should_verify:
import urllib3
urllib3.disable_warnings()
url_base = os.getenv('URL_BASE')
if url_base is None or len(url_base) == 0:
print('set URL_BASE to the domain base - e.g. "run.pivotal.io"')
sys.exit(1)
username = input('username:')
password = getpass.getpass('password:')
auth_endpoint = 'https://login.{}/oauth/token'.format(url_base)
oauth_r = requests.post(
auth_endpoint,
data={'username': username,
'password': password,
'grant_type': 'password',
'client_id': 'cf'},
auth=('cf', ''),
verify=should_verify)
print(json.dumps(oauth_r.json(), indent=2, separators={',', ':'}))
authorization = '{} {}'.format(
oauth_r.json()['token_type'],
oauth_r.json()['access_token'])
api_endpoint = 'https://api.{}'.format(url_base)
apps_r = requests.get(
api_endpoint + '/v2/apps',
headers={'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': authorization},
verify=should_verify)
# print oauth_r.json()['token_type'], oauth_r.json()['access_token']
print(json.dumps(apps_r.json(), indent=2, separators={',', ':'}))