"""Manages ows secrets_manager client.""" import os from botocore.exceptions import ClientError from owsrequest.constants.environment import DEV_ENVIRONMENT from secrets_manager.lambda_ext import LambdaSecretsManager from . import common_config class AssetTranscoderLambdaSecretsManager(LambdaSecretsManager): """The purpose of this file is to make LambdaSecretsManager work on DEV AWS account.""" def __init__(self, lambda_name, environment=None): """Initialize the class.""" if environment is None: environment = common_config.ENVIRONMENT self.environment = environment super().__init__( environment=environment, service_name=lambda_name, force_remote=True if environment == DEV_ENVIRONMENT else False ) def get_cred(self, env_var): """Hack around LambdaSecretsManager.get_cred. It is required when requesting AWS secrets on DEV AWS account. """ try: return super().get_cred(env_var) except ClientError as e: if self.environment == DEV_ENVIRONMENT: return os.environ.get(env_var) if 'ResourceNotFoundException' in str(e): return None else: raise e