Skip to main content

A simple secrets manager

Project description

A Simple Secrets Manager for python

Installing:

pip3 install simplesecretsmanager

How to use:

Storing

from simplesecretsmanager import manager

secrets_manager = manager.SecretsManager("password", "file.bin")

secrets["MY_SECRET"] = "the_secret"
...

secrets_manager.update_secrets(secrets)
secrets_manager.update_secret("ANOTHER_SECRET", "the_other_secret")
secrets_manager.save()

There are 2 additional options when creating your SecretsManager, you can pass a non-default algorithm (defautls to Pbkdf2Algorithm):

from simplesecretsmanager import manager, utility

algorithm = utility.Argon2Algorithm()

secrets_manager = manager.SecretsManager("password", "file.bin", algorithm=algorithm)

You can also choose to not have the password saved in memory:

from simplesecretsmanager import manager

secrets_manager = manager.SecretsManager("password", "file.bin", save_password=False)

secrets_manager.update_secret("MY_SECRET", "the_secret")
# Must give password when saving if save_password = False, throws SecretsError otherwise
secrets_manager.save("password")

Note: when giving a password to save(), this will be used to encrypt the file, in place of whatever was orinally stored

Retrieving

from simplesecretsmanager import manager

secrets_manager = manager.SecretsManager("password", "file.bin")

try:
    my_secret = secrets_manager.get_secret("MY_SECRET")
except SecretsError as e:
    print("Issue retrieving 'MY_SECRET': {e}")

By default, it will throw an error SecretsError if the secret does not exist. If you instead pass a default value, you'll be able to get that returned no matter what.

You can also use the secret manager with the 'with' clause so that it auto saves after:

with secrets_manager:
    secrets_manager.update_secret("MY_SECRET", "newvalue")

and then upon exiting, newvalue will be saved into "MY_SECRET"

Note: This won't work and will throw an error if used when save_password is false, since we won't be able to save the value when we get there

Provided under MIT License

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

simplesecretsmanager-0.6.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplesecretsmanager-0.6.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file simplesecretsmanager-0.6.2.tar.gz.

File metadata

  • Download URL: simplesecretsmanager-0.6.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/6.2.0-26-generic

File hashes

Hashes for simplesecretsmanager-0.6.2.tar.gz
Algorithm Hash digest
SHA256 1bcf4208ad6954e73798f8e03076bfa825658f6fdbb09f1950c115643c36f3d2
MD5 3984aa1f373d5455b37902e3afca5e31
BLAKE2b-256 41854ad5a148fdc3c7077b4b5f08300c66ef06f4a85f861f8613db1884c2f50f

See more details on using hashes here.

File details

Details for the file simplesecretsmanager-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: simplesecretsmanager-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/6.2.0-26-generic

File hashes

Hashes for simplesecretsmanager-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 33347ac8fc8c42ef5a667d6c113675c6825df0b494346335864105fdc1f82438
MD5 65f8ab989d6f0acb5372bb7e76c74071
BLAKE2b-256 c6d772eec94aedb44ca6f9c69ecb33d8e7a99c7293070290abc033ef019de1a2

See more details on using hashes here.

Supported by

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