airbyte.secrets.env_vars

Secret manager that retrieves secrets from environment variables and .env files.

 1# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
 2"""Secret manager that retrieves secrets from environment variables and `.env` files."""
 3
 4from __future__ import annotations
 5
 6import os
 7
 8from dotenv import dotenv_values
 9
10from airbyte.secrets.base import SecretManager, SecretSourceEnum, SecretString
11
12
13class EnvVarSecretManager(SecretManager):
14    """Secret manager that retrieves secrets from environment variables."""
15
16    name = SecretSourceEnum.ENV.value
17
18    def get_secret(self, secret_name: str) -> SecretString | None:
19        """Get a named secret from the environment."""
20        if secret_name not in os.environ:
21            return None
22
23        return SecretString(os.environ[secret_name])
24
25
26class DotenvSecretManager(SecretManager):
27    """Secret manager that retrieves secrets from a `.env` file."""
28
29    name = SecretSourceEnum.DOTENV.value
30
31    def get_secret(self, secret_name: str) -> SecretString | None:
32        """Get a named secret from the `.env` file."""
33        try:
34            dotenv_vars: dict[str, str | None] = dotenv_values()
35        except Exception:
36            # Can't locate or parse a .env file
37            return None
38
39        if secret_name not in dotenv_vars:
40            # Secret not found
41            return None
42
43        return SecretString(dotenv_vars[secret_name])
class EnvVarSecretManager(airbyte.secrets.base.SecretManager):
14class EnvVarSecretManager(SecretManager):
15    """Secret manager that retrieves secrets from environment variables."""
16
17    name = SecretSourceEnum.ENV.value
18
19    def get_secret(self, secret_name: str) -> SecretString | None:
20        """Get a named secret from the environment."""
21        if secret_name not in os.environ:
22            return None
23
24        return SecretString(os.environ[secret_name])

Secret manager that retrieves secrets from environment variables.

name = 'env'
def get_secret(self, secret_name: str) -> airbyte.secrets.SecretString | None:
19    def get_secret(self, secret_name: str) -> SecretString | None:
20        """Get a named secret from the environment."""
21        if secret_name not in os.environ:
22            return None
23
24        return SecretString(os.environ[secret_name])

Get a named secret from the environment.

class DotenvSecretManager(airbyte.secrets.base.SecretManager):
27class DotenvSecretManager(SecretManager):
28    """Secret manager that retrieves secrets from a `.env` file."""
29
30    name = SecretSourceEnum.DOTENV.value
31
32    def get_secret(self, secret_name: str) -> SecretString | None:
33        """Get a named secret from the `.env` file."""
34        try:
35            dotenv_vars: dict[str, str | None] = dotenv_values()
36        except Exception:
37            # Can't locate or parse a .env file
38            return None
39
40        if secret_name not in dotenv_vars:
41            # Secret not found
42            return None
43
44        return SecretString(dotenv_vars[secret_name])

Secret manager that retrieves secrets from a .env file.

name = 'dotenv'
def get_secret(self, secret_name: str) -> airbyte.secrets.SecretString | None:
32    def get_secret(self, secret_name: str) -> SecretString | None:
33        """Get a named secret from the `.env` file."""
34        try:
35            dotenv_vars: dict[str, str | None] = dotenv_values()
36        except Exception:
37            # Can't locate or parse a .env file
38            return None
39
40        if secret_name not in dotenv_vars:
41            # Secret not found
42            return None
43
44        return SecretString(dotenv_vars[secret_name])

Get a named secret from the .env file.