Environ Source - py-bc-configs 0.3.0 documentation

Skip to content
Back to top
View this page

# Environ Source

## About

Module with methods that configure the environment source.

If you wanna use it, please that in your main src __init__.py file.

    from bc_configs import define

    define()

Note

If python-dotenv installed, it will use the dotenv module and call the load_dotenv function.

Note

If hvac installed, it will use the hvac module and put data form storage to os.environ.

Note

If pyyaml is installed, bc_configs will attempt to load environment variables from a YAML file. By default, it looks for .env.yml in the current working directory. You can specify a different YAML file by setting the YAML_CONFIG_FILE environment variable. Variables from the YAML file will be loaded into os.environ, but existing environment variables will not be overwritten.

Example .env.yml file:

    APP_NAME: MyAwesomeApp
    DEBUG_MODE: true
    DATABASE_URL: postgresql://user:password@host:port/dbname

pydantic model bc_configs.environ_source.VaultConfig

  Bases: `BaseConfig`

  Configuration for HashiCorp Vault.

  Show JSON schema

      {
         "title": "VaultConfig",
         "description": "Configuration for HashiCorp Vault.",
         "type": "object",
         "properties": {
            "address": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The address of the Vault server.",
               "title": "Address"
            },
            "mount": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The mount point of the Vault server.",
               "title": "Mount"
            },
            "path": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The path to the secret in the Vault.",
               "title": "Path"
            },
            "token": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The authentication token for accessing the Vault.",
               "title": "Token"
            },
            "username": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The username for authentication (if token is not provided).",
               "title": "Username"
            },
            "password": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The password for authentication (if token is not provided).",
               "title": "Password"
            }
         }
      }

  Fields:

    - `address (str | None)`

    - `mount (str | None)`

    - `password (str | None)`

    - `path (str | None)`

    - `token (str | None)`

    - `username (str | None)`

  Validators:

  field address: str | None = None

    The address of the Vault server.

    Validated by:

      - `_enrich_errors`

      - `_populate_from_env`

  field mount: str | None = None

    The mount point of the Vault server.

    Validated by:

      - `_enrich_errors`

      - `_populate_from_env`

  field password: str | None = None

    The password for authentication (if token is not provided).

    Validated by:

      - `_enrich_errors`

      - `_populate_from_env`

  field path: str | None = None

    The path to the secret in the Vault.

    Validated by:

      - `_enrich_errors`

      - `_populate_from_env`

  field token: str | None = None

    The authentication token for accessing the Vault.

    Validated by:

      - `_enrich_errors`

      - `_populate_from_env`

  field username: str | None = None

    The username for authentication (if token is not provided).

    Validated by:

      - `_enrich_errors`

      - `_populate_from_env`

  has_filled_connect_fields() → bool

    Check if all connect fields are filled.

    Returns:

      True if all fields are filled, False otherwise.

    Return type:

      bool

  need_to_use() → bool

    Check if the token or username and password are provided.

    Returns:

      True if the token or username and password are provided, False otherwise.

    Return type:

      bool

bc_configs.environ_source.define(*, vault_config: VaultConfig | None = None) → None

  Define the configuration for the application.

  Parameters:

    vault_config (VaultConfig | None) – The configuration for accessing secrets from a vault. Defaults to None.