Skip to main content

This aims to enable the use of one or more secrets from AWS SecretsManager.

Project description

This package aims to make using AWS SecretsManager more comfortable.

Introduce

This aims to enable the use of one or more secrets from AWS SecretsManager.

If more than one secret is used, the secret specified last takes precedence.

For example, if you use secrets named A and B in that order, overlapping entries from A and B will later use the value of the specified B entry.

>>> A = {"foo": 1, "bar": 2}
>>> B = {"bar": 3}
>>> secrets("bar", casting_type=int)
3

Install

$ python -m pip install aws_chain_secrets

How to use

connect and fetch manually

from aws_chain_secrets import SecretsManager
secrets = SecretsManager('ap-northeast-2', 'secret_name_1', 'secret_name_2', ...)
secrets.connect()
secrets.fetch()
secrets(key="A", default=None, casting_type=int)
secrets.disconnect()

use with context manager

You can omit connect(), fetch() and disconnect() when using context manager.

from aws_chain_secrets import SecretsManager
with SecretsManager('ap-northeast-2', 'secret_name_1', 'secret_name_2', ...) as secrets:
    secrets(key="A", default=None, casting_type=int)

type casting

All secret values ​​retrieved from AWS SecretsManager are string types by default.

You can change it to any type you want.

>>> secrets(key="A", casting_type=int)
1
>>> secrets(key="SOME_ARRAY", casting_type=list)
['1', '2', '3', '4']
>>> secrets(key="SOME_ARRAY", casting_type=list[int])
[1, 2, 3, 4]

default value

You can specify a default value, just like when using Python dict’s get.

# if the key value of A does not exist, 0 specified as default is returned.
>>> secrets(key="A", default=0)
0

change value

You can change (or add) the value of a specified secret by name.

If None is given, the value is set to the highest priority secret (last given as a parameter) with key value.

If there is no secret with the given key, it is registered as a new value in the secret with the highest priority.

>>> secrets.set('secret_name_1', 'key', 'value')

update remote (AWS secrets manager) data from local

You can update (upload) the values of a specified secret by name from local to remote.

If None is given (if the parameter is omitted), the entire secrets are updated.

>>> secrets.update('secret_name_1')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_chain_secrets-1.0.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

aws_chain_secrets-1.0.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file aws_chain_secrets-1.0.3.tar.gz.

File metadata

  • Download URL: aws_chain_secrets-1.0.3.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for aws_chain_secrets-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1cb30d797ddf07c4bcbb06d31d9f9febb305bc3b4b1f546a461abf54e7eb399c
MD5 33a6640a5dc12bc9c6ff5b310602179b
BLAKE2b-256 f4add40f317615dce7de2de4c3505fdd328ddeb46484bbeb07fbb1a97e2bdab2

See more details on using hashes here.

File details

Details for the file aws_chain_secrets-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_chain_secrets-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8f3724b51c2f19076bb592634b93bcd49eab6eedc72d74405e2b42bbce42e9ea
MD5 44f9e9f469e44b0e2d199b5c5dd44896
BLAKE2b-256 845fe6096632605c476d337d9f9caf79f8d2d889fe4282a12b87bf4ae98a4d20

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page