Skip to content

Shows off using the new credhub features in Pivotal Cloud Foundry

Notifications You must be signed in to change notification settings

Pivotal-Austin/dotnet-credhub-example

Repository files navigation

Dotnet Credhub Example

Getting Started

1. Create a credhub service

cf create-service credhub default credhub-test -c '{"MY_DB_CONNECTION_STRING":"http://user1:[email protected]/super-secret-database"}'

2. Create a dotnet app

Publish first, then push the published directory as an app.

dotnet publish
cf push dotnet-credhub-example

3. Bind the app and credhub service

cf bind-service dotnet-credhub-example credhub-test

4. Restage your app

cf restage dotnet-credhub-example

You should now see the credentials visible on the index page of the application.

Example of getting secrets from vcap

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.

Authors

About

Shows off using the new credhub features in Pivotal Cloud Foundry

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published