Results
No results found.
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
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"
);
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:
var service = new SecretService();
var secrets = service.List();
// 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);
var service = new SecretService();
var option = new SecretCreateOptions
{
Key = "YOUR_NEW_SECRET_KEY",
Value = "YOUR_NEW_SECRET_VALUE",
};
var newSecret = service.Create(option);
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
);
var service = new EnvironmentService();
var environments = service.List();
var service = new EnvironmentService();
var environment = Service.Get(name: "YOUR_ENV_NAME");
Console.WriteLine(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);
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
);
See the examples' folder.
Run all test in src/LockerTests
dotnet test
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.
Please check CONTRIBUTING.md before making a contribution.