Skip to main content

decorative-secrets

test PyPI version

This library implements decorators for mapping parameters passing sensitive data, such as authentication credentials, to alternate parameters indicating where the same credentials can be retrieved dynamically from a secrets manager and/or environment variables. The use of a decorator pattern to expose multiple authentication mechanisms is intended to facilitate development practices which maintain a semblance of harmony between security hygiene and test-driven development.

Currently, the following secret sources are supported:

  • Databricks Secrets (pip3 install decorative-secrets[databricks])
  • 1Password (pip3 install decorative-secrets[onepassword]): 1Password secrets are retrieved dynamically using the 1Password CLI under the hood. This mechanism can be used with the 1Password desktop client and CLI (including via SSO), in which case a popup window will prompt for authentication during execution, or can use a 1Password service account by setting the OP_SERVICE_ACCOUNT_TOKEN environment variable. The former is recommended for local development and testing, the latter for CI/CD and/or hosted applications.
  • Environment Variables

Future development will target support for AWS Secrets Manager, Google Cloud Secret Manager, and Azure Key Vault.

Installation

You can install decorative-secrets with pip:

pip3 install decorative-secrets

Example Usage

from functools import cache
from my_app_sdk.client import Client
from decorative_secrets.environment import apply_environment_arguments
from decorative_secrets.onepassword import apply_onepassword_arguments
from decorative_secrets.databricks import apply_databricks_secrets_arguments

@cache
@apply_environment_arguments(
  client_id="client_id_environment_variable",
  client_secret="client_secret_environment_variable",
)
@apply_databricks_secrets_arguments(
  client_id="client_id_databricks_secret",
  client_secret="client_secret_databricks_secret",
)
@apply_onepassword_arguments(
  client_id="client_id_onepassword",
  client_secret="client_secret_onepassword",
)
def get_client(
    client_id: str | None = None,
    client_secret: str = None,
    client_id_databricks_secret: tuple[str, str] | None = None,
    client_secret_databricks_secret: tuple[str, str] | None = None,
    client_id_onepassword: str | None = None,
    client_secret_onepassword: str | None = None,
    client_id_environment_variable: str | None = None,
    client_secret_environment_variable: str | None = None,
) -> Client:
    """
    This function is an example use of `decorative-secrets`.
    The returned client will authenticate with explicitly provided
    credentials if a `client_id` and `client_secret` are passed as arguments,
    otherwise, the same function call will first check to see if
    environment variables can be used, then will check to see if databricks
    secrets can be used, and lastly will check to see if 1password
    stored credentials can be obtained. In all cases where
    an argument other than `None` is passed, errors will be caught and
    accumulated for that parameter, but only raised if none of the
    successive mechanisms for retrieving a value for the parameter are
    successful.
    
    Parameters:
        client_id: An eplicitly passed OAuth 2 client ID
        client_secret: An explicitly passed OAuth 2 client secret
        client_id_databricks_secret: A databricks secrets scope and key
        from which to retrieve the client ID, if executed in a Databricks
        Runtime environment
        client_secret_databricks_secret: A databricks secrets scope and key
        from which to retrieve the client secret, if executed in a Databricks
        Runtime environment
        client_id_onepassword: A onepassword reference from which to retrieve
        the client ID. Note: the user will be prompted to login, if they have
        not already done so, unless a `OP_SERVICE_ACCOUNT_TOKEN` environment
        variable has been set, and/or both both an `OP_CONNECT_HOST` and
        `OP_CONNECT_TOKEN` environment variable have been set.
        client_secret_onepassword: A onepassword reference from which to retrieve
        the client secret. Note: the user will be prompted to login, if they have
        not already done so, unless a `OP_SERVICE_ACCOUNT_TOKEN` environment
        variable has been set, and/or both both an `OP_CONNECT_HOST` and
        `OP_CONNECT_TOKEN` environment variable have been set.
        client_id_environment_variable: An environment variable from which
        the client ID may be retrieved
        client_secret_environment_variable: An environment variable from which
        the client secret may be retrieved
    """
    return Client(
        oauth2_client_id=client_id,
        oauth2_client_secret=client_secret
    )


# Initialize an OAuth 2 Client
client: Client = get_client(
  client_id_databricks_secret=("client-scope", "client-id-key"),
  client_secret_databricks_secret=("client-scope", "client-secret-key"),
  client_id_onepassword="op://Vault Name/Client ID Item Name/username",
  client_secret_onepassword="op://Vault Name/Client Secret Item Name/credential",
  client_id_environment_variable="MY_APP_CLIENT_ID",
  client_secret_environment_variable="MY_APP_CLIENT_SECRET",
)

Metadata

Release files for decorative-secrets 0.14.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for decorative-secrets 0.14.1
File Size Uploaded Provenance Actions
decorative_secrets-0.14.1.tar.gz 29.8 kB Without provenance Details for decorative_secrets-0.14.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for decorative-secrets 0.14.1
File Interpreter ABI Platform Actions
decorative_secrets-0.14.1-py3-none-any.whl Python 3 none any Details for decorative_secrets-0.14.1-py3-none-any.whl

Total release size: 65.7 kB

Release files / decorative_secrets-0.14.1.tar.gz

Download URL decorative_secrets-0.14.1.tar.gz
Size 29.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9f54b51248dc02a4233cff63eb31fc2f9895dfeb2b0302e036e449749ae3045f
BLAKE2b-256 checksum
How to use checksums
c667bd6a4726ad2fbb306c85a0d6118846df734c332ca65f018071cbc2145ea0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.2 {"ci":true,"cpu":"x86_64","distro":{"id":"resolute","libc":{"lib":"glibc","version":"2.43"},"name":"Ubuntu","version":"26.04"},"implementation":{"name":"CPython","version":"3.12.3"},"installer":{"name":"hatch","version":"1.18.2"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.3","system":{"name":"Linux","release":"7.0.0-1017-azure"}} HTTPX2/2.16.0

Release files / decorative_secrets-0.14.1-py3-none-any.whl

Download URL decorative_secrets-0.14.1-py3-none-any.whl
Size 35.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d72bcd20801f9a498e2a2345c4fed71bc7d3788bd8ada5101a26bb43e71d967
BLAKE2b-256 checksum
How to use checksums
6afaa6ff22302f29dc2e928514d86a5369da5a0a734e8ab02766aea277021c99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.2 {"ci":true,"cpu":"x86_64","distro":{"id":"resolute","libc":{"lib":"glibc","version":"2.43"},"name":"Ubuntu","version":"26.04"},"implementation":{"name":"CPython","version":"3.12.3"},"installer":{"name":"hatch","version":"1.18.2"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.3","system":{"name":"Linux","release":"7.0.0-1017-azure"}} HTTPX2/2.16.0

Security for decorative-secrets 0.14.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.14.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page