import boto3
import configparser
import json

class CredentialManager:
    def __init__(self,what, config_file_path='helper/config.ini'):
        #s3 = boto3.client("s3")
        
        #bucket= config_file_path.replace('s3://', '').split('/')[0]
        #key = config_file_path.replace(bucket, '').replace('s3:///', '')

        #s3.download_file(bucket, key, "/tmp/config.ini")
        #config_file_path= '/tmp/config.ini'
        #self.config_file_path = config_file_path
        self.what= what
        self.config = configparser.ConfigParser()
        self.config.read(config_file_path)
        self.secrets_client =boto3.client("secretsmanager", region_name="us-east-1",aws_access_key_id='AKIATBUD4GB6PUTB2TOB',  
                                                              aws_secret_access_key='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')

    def get_credentials(self, source):
        #return self.config.sections()
        #print(self.config)
        # #print(self.config['sources'])
        secret_name = self.config[self.what][source]
        secret = self.secrets_client.get_secret_value(SecretId=secret_name)
        return json.loads(secret['SecretString'])