Skip to main content

Configure Access Keys

The SDK needs to be configured with your access key which is available in your Locker Secrets Dashboard. Initialize the accessKeyId and secretAccessKey to their value. You also need to set apiBase value (default value is https://secrets-core.locker.io).
All initialization options are listed below: You can now use the SDK to get or set values.

Get secrets

Methods:
  • list: list all secrets
  • listSync: get all secrets, but synchronized
  • get: get a secret by key and environment name (optional, defaults to ALL environment), can return a default value if no secret is found
  • getSync: get a secret but synchronized
Example:

Get a secret value

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

Methods:
  • create: create a new secret with a name, value, environment name (optional) and description (optional). You cannot create secrets with the same key in the same environment. Returns the new secret.
Example

Update secrets

Methods:
  • modify: edit the value, environment name or description of a secret. You cannot change the secret’s key. You also cannot change the environment to a new environment that already has a secret with the same name. Returns the updated secret.
Example:

Get environments

Methods:
  • listEnvironments: List all environments
  • listEnvironmentsSync: List all environments but synchronized
  • getEnvironment: get an environment by name
  • getEnvironmentSync: get an environment but synchronized
Example:

Retrieve an environment

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

Create an environment

Methods:
  • createEnvironment: create a new environment with a name, external url and description (optional). You cannot create environments with the same name. Returns the new environment.
Example:

Update an environment

Methods:
  • modifyEnvironment: edit the description and external url of an environment. You cannot change the name of an environment. Returns the updated environment.
Example:

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: NONE (0), ERROR (1), DEBUG (2). Set the logging level when creating a Locker instance to enabling it: