<gh_stars>1-10
import boto3
import json
from botocore.exceptions import ClientError


class Credentials:
    def __init__(self, cred_type: str, region: str):
        self.creds_type = ['codecommit', 'gitapi']
        if cred_type in self.creds_type:
            self.cred_type = cred_type
        else:
            exit(code='All Bad')
        self.secret_name = "/prd/repo/{}".format(cred_type)
        self.region_name = region

    def get_secret(self) -> dict:
        session = boto3.session.Session()
        client = session.client(
            service_name='secretsmanager',
            region_name=self.region_name
        )

        try:
            get_secret_value_response = client.get_secret_value(
                SecretId=self.secret_name
            )
            return json.loads(get_secret_value_response.get('SecretString'))
        except ClientError as e:
            if e.response['Error']['Code'] == 'DecryptionFailureException':
                # Secrets Manager can't decrypt the protected secret text using the provided KMS key.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'InternalServiceErrorException':
                # An error occurred on the server side.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'InvalidParameterException':
                # You provided an invalid value for a parameter.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'InvalidRequestException':
                # You provided a parameter value that is not valid for the current state of the resource.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'ResourceNotFoundException':
                # We can't find the resource that you asked for.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e

import boto3
import json
from botocore.exceptions import ClientError


class Credentials:
    def __init__(self, cred_type: str, region: str):
        self.creds_type = ['codecommit', 'gitapi']
        if cred_type in self.creds_type:
            self.cred_type = cred_type
        else:
            exit(code='All Bad')
        self.secret_name = "/prd/repo/{}".format(cred_type)
        self.region_name = region

    def get_secret(self) -> dict:
        session = boto3.session.Session()
        client = session.client(
            service_name='secretsmanager',
            region_name=self.region_name
        )

        try:
            get_secret_value_response = client.get_secret_value(
                SecretId=self.secret_name
            )
            return json.loads(get_secret_value_response.get('SecretString'))
        except ClientError as e:
            if e.response['Error']['Code'] == 'DecryptionFailureException':
                # Secrets Manager can't decrypt the protected secret text using the provided KMS key.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'InternalServiceErrorException':
                # An error occurred on the server side.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'InvalidParameterException':
                # You provided an invalid value for a parameter.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'InvalidRequestException':
                # You provided a parameter value that is not valid for the current state of the resource.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
            elif e.response['Error']['Code'] == 'ResourceNotFoundException':
                # We can't find the resource that you asked for.
                # Deal with the exception here, and/or rethrow at your discretion.
                raise e
# Secrets Manager can't decrypt the protected secret text using the provided KMS key. # Deal with the exception here, and/or rethrow at your discretion. # An error occurred on the server side. # Deal with the exception here, and/or rethrow at your discretion. # You provided an invalid value for a parameter. # Deal with the exception here, and/or rethrow at your discretion. # You provided a parameter value that is not valid for the current state of the resource. # Deal with the exception here, and/or rethrow at your discretion. # We can't find the resource that you asked for. # Deal with the exception here, and/or rethrow at your discretion.