airbyte.secrets.custom
1# Copyright (c) 2024 Airbyte, Inc., all rights reserved. 2"""___""" 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 super().__init__() 26 if self.auto_register: 27 self.register() 28 29 def register( 30 self, 31 *, 32 replace_existing: bool | None = None, 33 as_backup: bool | None = None, 34 ) -> None: 35 """Register the secret manager as global secret source. 36 37 This makes the secret manager available to the `get_secret` function and 38 allows it to be used automatically as a source for secrets. 39 40 If `replace_existing` is `True`, the secret manager will replace all existing 41 secrets sources, including the default secret managers such as environment 42 variables, dotenv files, and Google Colab secrets. If `replace_existing` is 43 None or not provided, the default behavior will be used from the `replace_existing` 44 of the class (`False` unless overridden by the subclass). 45 """ 46 if replace_existing is None: 47 replace_existing = self.replace_existing 48 49 if as_backup is None: 50 as_backup = self.as_backup 51 52 if replace_existing: 53 clear_secret_sources() 54 55 register_secret_manager( 56 self, 57 as_backup=as_backup, 58 replace_existing=replace_existing, 59 )
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 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 )
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.
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 )
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).