Format: text/x-python
⬇ Download File (1.2 KB)
   1  import boto3
   2  import configparser
   3  import json
   4  
   5  class CredentialManager:
   6      def __init__(self,what, config_file_path='helper/config.ini'):
   7          #s3 = boto3.client("s3")
   8          
   9          #bucket= config_file_path.replace('s3://', '').split('/')[0]
  10          #key = config_file_path.replace(bucket, '').replace('s3:///', '')
  11  
  12          #s3.download_file(bucket, key, "/tmp/config.ini")
  13          #config_file_path= '/tmp/config.ini'
  14          #self.config_file_path = config_file_path
  15          self.what= what
  16          self.config = configparser.ConfigParser()
  17          self.config.read(config_file_path)
  18          self.secrets_client =boto3.client("secretsmanager", region_name="us-east-1",aws_access_key_id='AKIATBUD4GB6PUTB2TOB',  
  19                                                                aws_secret_access_key='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')
  20  
  21      def get_credentials(self, source):
  22          #return self.config.sections()
  23          #print(self.config)
  24          # #print(self.config['sources'])
  25          secret_name = self.config[self.what][source]
  26          secret = self.secrets_client.get_secret_value(SecretId=secret_name)
  27          return json.loads(secret['SecretString'])