Bluemix API to retrieve the service credentials

南楼画角 提交于 2019-12-12 19:06:28

问题


In a previous question, I can get the apiKey for interacting with the MessageHub management api.

I'm not binding to this service to a Bluemix application, so I don't have access to the VCAP_SERVICES environment variable in my application.

I would like to retreive the service credentials programatically. I think this may be a generic Bluemix cf api question rather than a MessageHub question.

How can I retrieve the service credentials using an API call?


回答1:


Sadly because BlueMix runs a version of Cloud Foundry that is 6 months out of date, you can't use the List Service Keys endpoint.

Your only alternative is to bind it to some app (maybe not even a real app) to extract the credentials.

There is an argument that humans needing the credentials for a service is an anti-pattern, but there are plenty of use cases where it is necessary.




回答2:


The https://apidocs.cloudfoundry.org/245/service_instances/list_all_service_keys_for_the_service_instance.html API worked for me.

Using the cf-python-client library:

from cloudfoundry_client.client import CloudFoundryClient
target_endpoint = 'https://api.ng.bluemix.net'

client = CloudFoundryClient(target_endpoint, skip_verification=False)
client.init_with_user_credentials(
    ibm_id,
    ibm_id_password
    )

mh_service_instance = client.service_instances.get_first(name='my_service')
if mh_service_instance:
    mh_service_instance_id = mh_service_instance['metadata']['guid']
    print(mh_service_instance_id)
    print(list(mh_service_instance.service_keys()))


来源:https://stackoverflow.com/questions/40322068/bluemix-api-to-retrieve-the-service-credentials

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!