Skip to main content

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.

Linux/MacOS

Windows

PowerShell
Command Prompt
You also need to set the api_base value (default is https://api.locker.io/locker_secrets). If you need to set custom headers, also set the headers value in the options parameter. You can now use the SDK to get or set values:
You can also pass parameters in the Locker() method or use the shared credential file (~/.locker/credentials), but we do not recommend these ways.

List Secrets

Use .list() to get all the secrets in your project.

Get Secret Values

This function will get the secret value by a key. If the key does not exist, SDK will return the default_value
You could get a secret value by a secret key and specific environment name by the environment_name parameter. If the key does not exist, SDK will return the default_value

Create Secrets

Use the .create() function to create a new secret:
Create a new secret with a specific environment:

Update Secrets

Use .modify() function to update the value of the secret
Update a secret value by the secret key and the specific environment name

List Environments

Use .list_environments() to get all environments in your project

Retrieve an Environment

To retrieve an environment by name, use .get_environment()

Create an Environment

To create a new environment, use .create_environment()

Update an Environment

To update the external_url of the environment by name, use .update_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 Python’s try/except syntax. Catch locker.error.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:
In the SDK, error objects belong to locker.error.LockerError and its subclasses. Use the documentation for each class for advice about how to respond.

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: 1. Set the environment variable LOCKER_LOG to the value debug, info, warning or error
2. Set log when initializing the Locker object:
3. Enable it through Python’s logging module: