import boto3
import base64
from botocore.exceptions import ClientError


class SecretsManager:
    @staticmethod
    def get(secret_name, region_name='us-west-2'):
        session = boto3.session.Session()
        client = session.client(
            service_name='secretsmanager',
            region_name=region_name
        )

        try:
            get_secret_value_response = client.get_secret_value(
                SecretId=secret_name
            )

        except ClientError as e:
            raise e
        else:
            if 'SecretString' in get_secret_value_response:
                return get_secret_value_response['SecretString']
            else:
                return base64.b64decode(
                    get_secret_value_response['SecretBinary'])
