perf: 优化 vault 配置 (#11313)

Co-authored-by: feng <1304903146@qq.com>
This commit is contained in:
fit2bot
2023-08-17 12:12:58 +08:00
committed by GitHub
parent a084bc9962
commit b20abb494f
9 changed files with 14 additions and 24 deletions

View File

@@ -12,8 +12,9 @@ logger = get_logger(__file__)
def get_vault_client(raise_exception=False, **kwargs):
enabled = kwargs.get('VAULT_ENABLED')
tp = 'hcp' if enabled else 'local'
try:
tp = kwargs.get('VAULT_TYPE')
module_path = f'apps.accounts.backends.{tp}.main'
client = import_module(module_path).Vault(**kwargs)
except Exception as e:
@@ -22,7 +23,6 @@ def get_vault_client(raise_exception=False, **kwargs):
raise
tp = VaultTypeChoices.local
module_path = f'apps.accounts.backends.{tp}.main'
kwargs['VAULT_TYPE'] = tp
client = import_module(module_path).Vault(**kwargs)
return client

View File

@@ -8,10 +8,7 @@ __all__ = ['BaseVault']
class BaseVault(ABC):
def __init__(self, *args, **kwargs):
self.type = kwargs.get('VAULT_TYPE')
def is_type(self, tp):
return self.type == tp
self.enabled = kwargs.get('VAULT_ENABLED')
def get(self, instance):
""" 返回 secret 值 """