Configure Access Keys
The SDK needs to be configured with your access key id and your secret access key, which is available in your Locker Secrets Dashboard. These keys must not be disclosed. If you reveal these keys, you need to revoke them immediately. Environment variables are a good solution and they are easy to consume in most programming languages.Set up credentials on Linux/MacOS
Set up credentials on Windows
PowerShellapi_base value (default is https://api.locker.io/locker_secrets). If you need to set your custom headers, you also need to set headers value in the options param:
Now, you can use SDK to get or set values:
~/.locker/credentials ), but we do not recommend these ways.
List Secrets
Use.list() method to list all secrets in project
Get Secret Values
Get a secret by key
This function will get the secret value by a key.Get a secret by key and environment name
You could get a secret value by a secret key and specific environment nameCreate Secrets
Use the.create() function to create a new secret:
Update Secrets
List Environments
Use the.list() function to retrieve all environments in your project:
Retrieve an Environment
To retrieve an environment by name, use.retrieve():
Create an Environment
To create a new environment, use.create():
Update an Environment
Error Handling
Locker Secret SDK offers some kinds of errors. They can reflect external events, like invalid credentials, network interruptions, or code problems, like invalid API calls. If an immediate problem prevents a function from continuing, the SDK raises an exception. It’s a best practice to catch and handle exceptions. To catch an exception, use Java’stry/catch syntax. Catch LockerError or its
subclasses to handle Locker-specific exceptions only. Each subclass represents a different kind of exception. When you
catch an exception, you can use its class to choose a response.
Example:
LockerError and its subclasses. Use the documentation for each class for advice about how to respond.
| Name | Class | Description |
|---|---|---|
| Authentication Error | locker.error.AuthenticationError | Invalid access_client_id or invalid secret_access_key |
| Permission Denied Error | locker.error.PermissionDeniedError | Your credential does not have enough permission to execute this operation |
| RateLimit Error | locker.error.RateLimitError | Too many requests |
| API Error | locker.error.APIError | You made an API call with the wrong parameters, in the wrong state, or in an invalid way, or something went wrong on Locker’s end |
| CLI Run Error | locker.error.CliRunError | The encryption/decryption binary runs errors by invalid local data, process interruptions, or invalid secret_access_key |
Logging
The library can be configured to emit logging that will give you better insight into what it’s doing. There are some levels:debug, info, warning, error.
The info logging level is usually most appropriate for production use, but debug is also available for more verbosity.
There are a few options for enabling it:
- Set the environment variable
LOCKER_LOGto the valuedebug,info,warningorerror
- Set
logwhen initializing the Locker object
- Enable it through Python’s logging module: