Parse and return service credentials from environment variables that IBM Cloud provides.
$ pip install vcap_services
from vcap_services import load_from_vcap_services
credentials = load_from_vcap_services('personality_insights')
print(credentials);
If VCAP_SERVICES
is:
{
"personality_insights": [{
"credentials": {
"password": "<password>",
"url": "<url>",
"username": "<username>"
},
"label": "personality_insights",
"name": "personality-insights-service",
"plan": "standard"
}]
}
Output:
{
"password": "<password>",
"url": "<url>",
"username": "<username>"
}
Get credentials that match a specific service plan (only for VCAP_SERVICES
).
from vcap_services import load_from_vcap_services
credentials = load_from_vcap_services('personality_insights', 'standard')
print(credentials);
Get credentials that match a specific service instance (replace "YOUR NLC NAME" with the name of your service instance).
from vcap_services import load_from_vcap_services
credentials = load_from_vcap_services('natural_language_classifier', None, 'YOUR NLC NAME')
print(credentials);
Get credentials that match a specific service plan and instance (replace "YOUR NLC NAME" with the name of your service instance).
from vcap_services import load_from_vcap_services
credentials = load_from_vcap_services('natural_language_classifier', 'standard', 'YOUR NLC NAME')
print(credentials);
Running all the tests:
$ pip install -r requirements.txt
$ cp .env.mock .env
$ pytest --cov=vcap_services
MIT.
See CONTRIBUTING.