-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_instance_clid.py
66 lines (54 loc) · 2.23 KB
/
create_instance_clid.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys, os
import argparse
import boto3
import json
from jinja2 import Environment, FileSystemLoader
'''
Create instance.clid file using values from AWS Parameter Store
Also set CLID env var
'''
def main(params):
######################################################################################
# get the CLID related values from AWS Parameter Store
######################################################################################
param_path = f"/nuxeo/{params.version}-{params.env}/instance_cliid"
session = boto3.Session(region_name='us-west-2')
ssm = session.client('ssm')
response = ssm.get_parameters_by_path(
Path=param_path,
WithDecryption=True
)
params = response['Parameters']
param_dict = {}
for p in params:
param_dict[p['Name']] = p['Value']
######################################################################################
# create instance.clid file, which Nuxeo checks to confirm the instance is registered
######################################################################################
environment = Environment(loader=FileSystemLoader("templates/"))
template = environment.get_template('instance.clid.template')
# split clid into 2 parts
clid = param_dict[f'{param_path}/cli_id']
parts = clid.split('--')
part1 = parts[0]
part2 = parts[1]
content = template.render(
CLID=part1,
UUID=part2,
description=param_dict[f'{param_path}/description'],
)
filename = "instance.clid"
with open(filename, "w") as f:
f.write(content)
print(f"Wrote file `{filename}`")
################################################################################################
# create a file containing the value of CLID, which CodeBuild will then use to set CLID env var
################################################################################################
with open('.clid', 'w') as f:
f.write(param_dict[f'{param_path}/cli_id'])
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('env', choices=['prod', 'stg'])
parser.add_argument('version', choices=['2021'])
args = parser.parse_args()
sys.exit(main(args))