forked from aws-ia/cloudformation-github-resource-providers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_type_configuration.py
39 lines (29 loc) · 982 Bytes
/
get_type_configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"Get the GitHub secret from secrets manager and write it to ~/.cfn-cli/typeConfiguration.json"
import boto3
import base64
import os
import pathlib
from botocore.exceptions import ClientError
def get_secret():
"Get the secret from secrets manager"
secret_name = "cep-github-type-configuration"
region_name = "us-east-1"
session = boto3.session.Session()
client = session.client(
service_name="secretsmanager",
region_name=region_name
)
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
secret = get_secret_value_response["SecretString"]
home_dir = pathlib.Path.home()
config_dir = os.path.join(home_dir, ".cfn-cli")
if not os.path.exists(config_dir):
os.makedirs(config_dir)
full_path = os.path.join(config_dir, "typeConfiguration.json")
with open(full_path, "w") as f:
f.write(secret)
print(full_path)
if __name__ == "__main__":
get_secret()