forked from aws-samples/rekognition-identity-verification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default-params.py
69 lines (60 loc) · 1.92 KB
/
default-params.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
67
68
69
#!/usr/bin/env python3
#########################################################
# Modifies a CloudFormation Template to include
# default Stack Parameter values.
#########################################################
from os import environ, path
from json import loads,dumps
from sys import stderr
def get_asset_bucket()->str:
'''
Determines what bucket to use.
'''
bucket = environ.get('S3_ASSET_BUCKET')
if not bucket is None:
return bucket
raise ValueError('Missing env TEMPLATE_ASSET_BUCKET and S3_ASSET_BUCKET')
def get_asset_prefix()->str:
'''
Gets the preferred Asset bucket prefix
'''
prefix = environ.get('S3_ASSET_PREFIX')
if prefix is None:
prefix = ''
return prefix.strip('/')
if __name__ == '__main__':
'''
The program main routine.
'''
#content = stdin.read()
template_file=environ.get('STACK_TEMPLATE_FILE')
if template_file is None:
print("Missing environment variable STACK_TEMPLATE_FILE")
exit(1)
elif not path.isfile(template_file):
print('Unable to find template file %s' % template_file)
exit(1)
else:
with open(template_file,'rt') as f:
content = loads(f.read()) #stdin.read())
parameters:dict = content['Parameters']
for key in parameters.keys():
key:str = key
if not key.startswith('AssetParameters'):
continue
if 'Bucket' in key:
parameters[key]['Default'] = get_asset_bucket()
elif 'ArtifactHash' in key:
start=len('AssetParameters')
end=key.index('ArtifactHash')
parameters[key]['Default'] = key[start:end]
elif 'VersionKey' in key:
start=len('AssetParameters')
end=key.index('S3VersionKey')
sha = key[start:end]
parameters[key]['Default'] = '%s/||asset.%s.zip' % (get_asset_prefix(), sha)
else:
stderr.write('ignoring %s' % key)
#with open('cdk.out/OneClick.template.json', 'w') as f:
# f.write(dumps(content, indent=2))
print(dumps(content, indent=2))