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).| Key | Description | Type | Required |
|---|---|---|---|
accessKeyId | Your access key id | string | ✅ |
accessKeySecret | Your access key secret | string | ✅ |
apiBase | Your server base API URL, default value is https://api.locker.io/locker_secrets | string | ❌ |
headers | Custom headers for API calls | {[header: string]: string} | ❌ |
unsafe | Set TLS to unsafe if you use a server with self-signed certificate, default value is false | boolean | ❌ |
logLevel | Refer to Logging, default value is 1 | number | ❌ |
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
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_valueenvironment_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.
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.
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
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.
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.
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’stry/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:
locker.error.LockerError and its subclasses. Use the documentation for each class for advice about how to respond.
| Code | HTTP Status | Name | Class | Description |
|---|---|---|---|---|
unauthorized | 401 | Authentication Error | locker.error.AuthenticationError | Invalid access_client_id or secret_access_key |
permission_denied | 403 | Permission Denied Error | locker.error.PermissionDeniedError | Your credential does not have enough permission |
rate_limit | 429 | Rate Limit Error | locker.error.RateLimitError | Too many requests |
not_found | 404 | Resource Not Found | locker.error.ResourceNotFoundError | The requested resource is not found |
server_error | 500 | API Server Error | locker.error.APIServerError | Something went wrong on Locker’s end (These are rare) |
http_error | 503 | API Connect Error | locker.error.APIConnectionError | Network error |
cli_error | — | CLI Run Error | locker.error.CliRunError | The encryption/decryption binary runs error by invalid local data, process interruptions |
locker_error | — | General Locker Error | locker.error.LockerError | The general error |
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: