cf create-service credhub default credhub-test -c '{"MY_DB_CONNECTION_STRING":"http://user1:[email protected]/super-secret-database"}'
Publish first, then push the published directory as an app.
dotnet publish
cf push dotnet-credhub-example
cf bind-service dotnet-credhub-example credhub-test
cf restage dotnet-credhub-example
You should now see the credentials visible on the index page of the application.
The vcapServicesObject
is a key-value pairing, with the service type as the key and a list of all bound services as the value. The keys represents a service type available in the marketplace (ex: mysql, redis, credhub, etc).
Each bound service object has similar properties such as name, binding_name, and credentials. You can find an up-to-date list of attributes and their descriptions in the CF Documentation.
var vcapServicesJson = Configuration["VCAP_SERVICES"];
dynamic vcapServicesObject = JsonConvert.DeserializeObject(vcapServicesJson);
var credhubServices = vcapServicesObject.credhub;
var myCredential = credhubServices[0].credentials["MY_DB_CONNECTION_STRING"].ToString();
See the Startup.cs file in this repository for a working example.
- Josh Mattila - Project initiator - spinfooser
- Kevin Chow - Contributor - kschow
- Sarah Michaelson - Contributor - skmichaelson