airbyte.secrets.custom
Custom secret manager that retrieves secrets from a custom source.
1# Copyright (c) 2024 Airbyte, Inc., all rights reserved. 2"""Custom secret manager that retrieves secrets from a custom source.""" 3 4from __future__ import annotations 5 6from abc import ABC 7 8from airbyte.secrets.base import SecretManager 9from airbyte.secrets.config import clear_secret_sources, register_secret_manager 10 11 12class CustomSecretManager(SecretManager, ABC): 13 """Custom secret manager that retrieves secrets from a custom source. 14 15 This class is a convenience class that can be used to create custom secret 16 managers. By default, custom secrets managers are auto-registered during 17 creation. 18 """ 19 20 auto_register = True 21 replace_existing = False 22 as_backup = False 23 24 def __init__(self) -> None: 25 """Initialize the custom secret manager.""" 26 super().__init__() 27 if self.auto_register: 28 self.register() 29 30 def register( 31 self, 32 *, 33 replace_existing: bool | None = None, 34 as_backup: bool | None = None, 35 ) -> None: 36 """Register the secret manager as global secret source. 37 38 This makes the secret manager available to the `get_secret` function and 39 allows it to be used automatically as a source for secrets. 40 41 If `replace_existing` is `True`, the secret manager will replace all existing 42 secrets sources, including the default secret managers such as environment 43 variables, dotenv files, and Google Colab secrets. If `replace_existing` is 44 None or not provided, the default behavior will be used from the `replace_existing` 45 of the class (`False` unless overridden by the subclass). 46 """ 47 if replace_existing is None: 48 replace_existing = self.replace_existing 49 50 if as_backup is None: 51 as_backup = self.as_backup 52 53 if replace_existing: 54 clear_secret_sources() 55 56 register_secret_manager( 57 self, 58 as_backup=as_backup, 59 replace_existing=replace_existing, 60 )
13class CustomSecretManager(SecretManager, ABC): 14 """Custom secret manager that retrieves secrets from a custom source. 15 16 This class is a convenience class that can be used to create custom secret 17 managers. By default, custom secrets managers are auto-registered during 18 creation. 19 """ 20 21 auto_register = True 22 replace_existing = False 23 as_backup = False 24 25 def __init__(self) -> None: 26 """Initialize the custom secret manager.""" 27 super().__init__() 28 if self.auto_register: 29 self.register() 30 31 def register( 32 self, 33 *, 34 replace_existing: bool | None = None, 35 as_backup: bool | None = None, 36 ) -> None: 37 """Register the secret manager as global secret source. 38 39 This makes the secret manager available to the `get_secret` function and 40 allows it to be used automatically as a source for secrets. 41 42 If `replace_existing` is `True`, the secret manager will replace all existing 43 secrets sources, including the default secret managers such as environment 44 variables, dotenv files, and Google Colab secrets. If `replace_existing` is 45 None or not provided, the default behavior will be used from the `replace_existing` 46 of the class (`False` unless overridden by the subclass). 47 """ 48 if replace_existing is None: 49 replace_existing = self.replace_existing 50 51 if as_backup is None: 52 as_backup = self.as_backup 53 54 if replace_existing: 55 clear_secret_sources() 56 57 register_secret_manager( 58 self, 59 as_backup=as_backup, 60 replace_existing=replace_existing, 61 )
Custom secret manager that retrieves secrets from a custom source.
This class is a convenience class that can be used to create custom secret managers. By default, custom secrets managers are auto-registered during creation.
25 def __init__(self) -> None: 26 """Initialize the custom secret manager.""" 27 super().__init__() 28 if self.auto_register: 29 self.register()
Initialize the custom secret manager.
31 def register( 32 self, 33 *, 34 replace_existing: bool | None = None, 35 as_backup: bool | None = None, 36 ) -> None: 37 """Register the secret manager as global secret source. 38 39 This makes the secret manager available to the `get_secret` function and 40 allows it to be used automatically as a source for secrets. 41 42 If `replace_existing` is `True`, the secret manager will replace all existing 43 secrets sources, including the default secret managers such as environment 44 variables, dotenv files, and Google Colab secrets. If `replace_existing` is 45 None or not provided, the default behavior will be used from the `replace_existing` 46 of the class (`False` unless overridden by the subclass). 47 """ 48 if replace_existing is None: 49 replace_existing = self.replace_existing 50 51 if as_backup is None: 52 as_backup = self.as_backup 53 54 if replace_existing: 55 clear_secret_sources() 56 57 register_secret_manager( 58 self, 59 as_backup=as_backup, 60 replace_existing=replace_existing, 61 )
Register the secret manager as global secret source.
This makes the secret manager available to the get_secret
function and
allows it to be used automatically as a source for secrets.
If replace_existing
is True
, the secret manager will replace all existing
secrets sources, including the default secret managers such as environment
variables, dotenv files, and Google Colab secrets. If replace_existing
is
None or not provided, the default behavior will be used from the replace_existing
of the class (False
unless overridden by the subclass).