airbyte.secrets.google_colab

Secrets manager for Google Colab user secrets.

 1# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
 2"""Secrets manager for Google Colab user secrets."""
 3
 4from __future__ import annotations
 5
 6from airbyte.secrets.base import SecretManager, SecretSourceEnum, SecretString
 7
 8
 9class ColabSecretManager(SecretManager):
10    """Secret manager that retrieves secrets from Google Colab user secrets."""
11
12    name = SecretSourceEnum.GOOGLE_COLAB.value
13
14    def __init__(self) -> None:
15        """Initialize the Google Colab secret manager."""
16        try:
17            from google.colab import (  # pyright: ignore[reportMissingImports]  # noqa: PLC0415
18                userdata as colab_userdata,
19            )
20
21            self.colab_userdata = colab_userdata
22        except ImportError:
23            self.colab_userdata = None
24
25        super().__init__()
26
27    def get_secret(self, secret_name: str) -> SecretString | None:
28        """Get a named secret from Google Colab user secrets."""
29        if self.colab_userdata is None:
30            # The module doesn't exist. We probably aren't in Colab.
31            return None
32
33        try:
34            return SecretString(self.colab_userdata.get(secret_name))
35        except Exception:
36            # Secret name not found. Continue.
37            return None
class ColabSecretManager(airbyte.secrets.base.SecretManager):
10class ColabSecretManager(SecretManager):
11    """Secret manager that retrieves secrets from Google Colab user secrets."""
12
13    name = SecretSourceEnum.GOOGLE_COLAB.value
14
15    def __init__(self) -> None:
16        """Initialize the Google Colab secret manager."""
17        try:
18            from google.colab import (  # pyright: ignore[reportMissingImports]  # noqa: PLC0415
19                userdata as colab_userdata,
20            )
21
22            self.colab_userdata = colab_userdata
23        except ImportError:
24            self.colab_userdata = None
25
26        super().__init__()
27
28    def get_secret(self, secret_name: str) -> SecretString | None:
29        """Get a named secret from Google Colab user secrets."""
30        if self.colab_userdata is None:
31            # The module doesn't exist. We probably aren't in Colab.
32            return None
33
34        try:
35            return SecretString(self.colab_userdata.get(secret_name))
36        except Exception:
37            # Secret name not found. Continue.
38            return None

Secret manager that retrieves secrets from Google Colab user secrets.

ColabSecretManager()
15    def __init__(self) -> None:
16        """Initialize the Google Colab secret manager."""
17        try:
18            from google.colab import (  # pyright: ignore[reportMissingImports]  # noqa: PLC0415
19                userdata as colab_userdata,
20            )
21
22            self.colab_userdata = colab_userdata
23        except ImportError:
24            self.colab_userdata = None
25
26        super().__init__()

Initialize the Google Colab secret manager.

name = 'google_colab'
def get_secret(self, secret_name: str) -> airbyte.secrets.SecretString | None:
28    def get_secret(self, secret_name: str) -> SecretString | None:
29        """Get a named secret from Google Colab user secrets."""
30        if self.colab_userdata is None:
31            # The module doesn't exist. We probably aren't in Colab.
32            return None
33
34        try:
35            return SecretString(self.colab_userdata.get(secret_name))
36        except Exception:
37            # Secret name not found. Continue.
38            return None

Get a named secret from Google Colab user secrets.