Can I access Cloud Foundry REST API on Bluemix? If yes, how can I access it (cannot find any documentation)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can access the Cloud Foundry REST API on Bluemix as you would normally do with CF. In addition to that, if you need it and you are already familiar with cf curl you can take a look at the bluemix curl command. For example if you want to retrieve the information for all organizations of the current account:
bluemix curl /v2/organizations
Please see the Docs for more information.
回答2:
In order to access CF API you have to get the authentication token. Then add it to each request in the headers.
oauthTokenResponse = requests.post(
f'https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token?grant_type=password&client_id=cf',
data={'username': <your username>, 'password': <your password>, 'client_id': 'cf'},
auth=('cf', '')
)
auth = oauthTokenResponse.json()['token_type'] + ' ' + oauthTokenResponse.json()['access_token']
appsResponse = requests.get(f'{self.api_endpoint}/v2/apps',
headers={'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': auth}
)
apps = json.loads(appsResponse.content)