Skip to main content

A small package for handling project secrets

Project description

logo

Downloads PyPI Open Source Code style: black

Azure key vaults

Repository for explaining how to use Azure key vaults in our projects.

Flowdiagram

Index

Usage

This package is designed for easily pulling and creating secrets in Azure key vaults.

pip install this public package

pip install git+ssh://git@github.com/zypp-io/keyvault.git

Secrets to environment

This function sets the keyvault secrets to the runtime environment variables. This function will only work if you have set the required environment variables

from keyvault import secrets_to_environment

secrets_to_environment(keyvault_name="mykeyvault")

Get dotenv secrets

Function for reading the local .env file and capturing the secret_name, secret_value as key value pairs.

from keyvault import get_dotenv_secrets

get_dotenv_secrets(dotenv_file=".env")

Get keyvault secrets

This function can be used to pull secrets from the vault. This function will only work if you have set the required environment variables

from keyvault import get_keyvault_secrets

secrets = get_keyvault_secrets(keyvault_name="mykeyvault")
# Returns a dictionary containing secret_name, secret_value pairs

dotenv to keyvault

This function is designed for making it easy to upload sensitive project secrets to Azure key vault. The function reads the .env file and uploads the names and values to Azure key vault.

from keyvault import dotenv_to_keyvault

dotenv_to_keyvault(keyvault_name="mykeyvault", dotenv_file=".env")
# Uploads your current .env variables to azure key vault

Dict to keyvault

The function lets you upload a dictionary, where the key-value pairs are the secretname-secretvalues in Azure key vault.

from keyvault import dict_to_keyvault

dict_to_keyvault(keyvault_name="mykeyvault", secret_dict={'SECRET_NAME': 'secret value'})

It is also possible to add an expiry date or the content type of the secrets:

from keyvault import dict_to_keyvault
from datetime import datetime, timedelta
expiry_date = datetime.now() + timedelta(days=80)

dict_to_keyvault(
    keyvault_name="mykeyvault",
    secret_dict={'SECRET_NAME': 'secret value'},
    expires_on=expiry_date,
    content_type="text/plain"
)

Delete keyvault secrets

The function lets you delete secrets in the keyvault. Secrets will be deleted with soft_delete enabled.

from keyvault import delete_keyvault_secrets

delete_keyvault_secrets(keyvault_name="mykeyvault", secret_list=["SECRET_NAME"])

mandatory environment variables

There are 3 environment variables that are necessary for authenticating with the azure key vault. These variables always need to be present in the project in order for the secrets to be retrieved.

AZURE_CLIENT_ID=REPLACE-ME
AZURE_CLIENT_SECRET=REPLACE-ME
AZURE_TENANT_ID=REPLACE-ME

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

keyvault-0.2.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

keyvault-0.2.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file keyvault-0.2.1.tar.gz.

File metadata

  • Download URL: keyvault-0.2.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for keyvault-0.2.1.tar.gz
Algorithm Hash digest
SHA256 85a3dc378f1e936b6d623b6355c43e6db25cc28a850073152c419a8199ae49d4
MD5 91410c18bfb56748bf694e0847fd44ca
BLAKE2b-256 9614b0d3dec76b999d04ae98e090e8fcf095aa542d5f82ab145dbb5ce88b6dad

See more details on using hashes here.

File details

Details for the file keyvault-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: keyvault-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for keyvault-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 163e5f4de56bf94a8fcc248628a40a43403c6ecc9b0bc81da5ce1c35757e2aab
MD5 4313807c86c05982fffa0620c744a9be
BLAKE2b-256 d008192067b552de387df578f7e2f0aee0122b92e373b1452139868bc63469f7

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