Create a ticket
Sign in Sign up
Locker support Locker support
Results

No results found.

Home Locker Secrets Manager Developer tools Secrets - SDK dotNET SDK
Vietnamese English
dotNET SDK

Requirements

  • .NET > 3.+

Installation

Using the .NET Core command-line interface tools

dotnet add package lockerpm
Ā 

Using the NuGet command-line interface

nuget install lockerpm
Ā 

Using the Package Manager Console

Install-Package lockerpm

Usages

Set up the access key

The SDK needs to be configured with your access key which is available in your Locker Secret Dashboard. Initialize the access_key to its value. You also need to set api_base value (default is https://secrets-core.locker.io).

If you need to set your custom headers, you also need to set headers value in the options param:

using Locker;


string accessKeyId = "YOUR_ACCESS_KEY_ID";
string accessKeySecret = "YOUR_ACCESS_KEY_SECRET";
string apiBase = "YOUR_API_BASE";
Dictionary<string, string> headers = new Dictionary<string, string>()
{
    { "CF-Access-Client-Id", "YOUR_CF_ACCESS_CLIENT_ID" },
    { "CF-Access-Client-Secret", "YOUR_CF_ACCESS_CLIENT_SECRET" }
};
LockerConfiguration.Instance.Init(
    accessKeyId: accessKeyId,
    accessKeySecret: accessKeySecret,
    apiBase: apiBase,
    headers: headers
);

// setting by .env file
LockerConfiguration.Instance.Init(
    envPath: "YOUR_ENV_FILE_PATH"
																																																																																																	);

Per-request configuration

All of the service methods accept an optionalĀ RequestOptionsĀ object.Ā This isĀ used if you want to pass the access key,Ā headers on each method,Ā or you want set type of return valueĀ (default type is string,Ā if you want type of object useĀ IsJson=true)

var requestOptions = new RequestOptions();
requestOptions.AccessKeyId = "ACCESS KEY ID";
requestOptions.AccessKeySecret = "ACCESS KEY SECRET";
requestOptions.ApiBase = "API BASE";
requestOptions.IsJson = true;
Ā 

Now, you can use SDK to get or set values:

List secrets

var service = new SecretService();
var secrets = service.List();

Get secret

// Get a secret value by secret key.
// If they Key does not exist, SDK will return the defaultValue
var secretValue = service.GetSecret(
    name: "REDIS_CONNECTION",
    defaultValue: "Default Value"
    )
Console.WriteLine(secretValue);

// Get a secret value by secret key and specific environment name.
// If the Key does not exist, SDK will return the defaultValue
secretValue = service.GetSecret(
    name: "REDIS_CONNECTION",
    environmentName: "staging",
    defaultValue: "Default Value"
    )
Console.WriteLine(secretValue);

// Get a secret value by secret key.
// If they Key does not exist, SDK will throw exception
var options = new SecretRetrieveOptions();
var requestOptions = new RequestOptions();
var secretValue = service.Get(
    name: "REDIS_CONNECTION",
    retrieveOptions: options,
    requestOptions:requestOptions
    )
Console.WriteLine(secretValue);

// Get a secret value by secret key and specific environment name.
// If the Key does not exist, SDK will throw exception
var options = new SecretRetrieveOptions();
var requestOptions = new RequestOptions();
var secretValue = service.Get(
    name: "REDIS_CONNECTION",
    environmentName: "staging",
    retrieveOptions: options,
    requestOptions:requestOptions
    )
Console.WriteLine(secretValue);

Create new secret

var service = new SecretService();
var option = new SecretCreateOptions
   {
       Key = "YOUR_NEW_SECRET_KEY",
       Value = "YOUR_NEW_SECRET_VALUE",
   };
var newSecret = service.Create(option);

Update secret

var service = new SecretService();
var option = new SecretUpdateOptions
   {
       Key = "YOUR_UPDATE_SECRET_KEY",
       Value = "YOUR_UPDATED_SECRET_VALUE",
   };

// Update a secret value by secret key
var updated_secret = service.Modify(
    name: "YOUR_SECRET_KEY",
    updateOptions:option
    );

// Update a secret value by secret key and a specific environment name
var updated_secret = service.Modify(
    name: "YOUR_SECRET_KEY",
    environmentName: "YOUR_ENV_NAME",
    updateOptions:option
    );

List environments

var service = new EnvironmentService();
var environments = service.List();

Get environment by name

var service = new EnvironmentService();
var environment = Service.Get(name: "YOUR_ENV_NAME");
Console.WriteLine(environment);

Create new environment

var service = new EnvironmentService();
var option = new EnvironmentCreateOptions()
   {
       Name = "YOUR_NEW_ENV_NAME",
       ExternalUrl = "YOUR_NEW_ENV_EXTERTAL_URL",
       Description = "YOUR_NEW_ENV_DESCRIPTION"
   };
var newEnv = service.Create(option);

Update environment by name

var service = new EnvironmentService();
var option = new EnvironmentUpdateOptions()
   {
       Name = "YOUR_UPDATE_ENV_NAME",
       ExternalUrl = "YOUR_UPDATE_EXTERNAL_URL"
   };
var updatedEnv = service.Modify(
    name: "YOUR_ENV_NAME,
    updateOptions:opton
    );

Examples

See the examples' folder.

Development

Run tests

Run all test in src/LockerTests

dotnet test
Ā 

Reporting security issues

We take the security and our users' trust very seriously. If you found a security issue in Locker SDK .NET, please report the issue by contacting us at <[email protected]>. Do not file an issue on the tracker.

Ā 

Contributing

Please check CONTRIBUTING.md before making a contribution.

Help and media

License

Was this page helpful?
No
Yes
Join Our Community