Skip to content

Commit

Permalink
directly handling object instead of text processing
Browse files Browse the repository at this point in the history
  • Loading branch information
PatMyron committed Sep 25, 2020
1 parent 3d796b9 commit 74b5e74
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/cfnlint/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,36 @@ def update_resource_spec(region, url):
spec = patch_spec(spec, 'all')
spec = patch_spec(spec, region)

with open(filename, 'w') as f:
json.dump(spec, f, indent=2, sort_keys=True, separators=(',', ': '))

lines = []
botocore_cache = {}
with open(filename, 'r') as f:
for line in f:
if 'botocore' in line:
service_and_type = line.split('"')[3]
service = '/'.join(service_and_type.split('/')[:-1])
botocore_type = service_and_type.split('/')[-1]
if service not in botocore_cache:
botocore_cache[service] = json.loads(get_url_content('https://raw.githubusercontent.com/boto/botocore/master/botocore/data/' + service + '/service-2.json'))
lines += ' "AllowedValues": [\n'
for value in sorted(botocore_cache[service]['shapes'][botocore_type]['enum']):
lines.append(' "' + value + '",\n')
lines[-1] = lines[-1].replace(',', '')
lines += ' ]\n'
else:
lines += line

def search_and_replace_botocore_types(obj):
if isinstance(obj, dict):
new_obj = {}
for key, value in obj.items():
if key == 'botocore':
service_and_type = value.split('/')
service = '/'.join(service_and_type[:-1])
botocore_type = service_and_type[-1]
if service not in botocore_cache:
botocore_cache[service] = json.loads(get_url_content('https://raw.githubusercontent.com/boto/botocore/master/botocore/data/' + service + '/service-2.json'))
new_obj['AllowedValues'] = sorted(botocore_cache[service]['shapes'][botocore_type]['enum'])
else:
new_obj[key] = search_and_replace_botocore_types(value)
return new_obj

if isinstance(obj, list):
print(obj)
new_list = []
for item in obj:
new_list.append(search_and_replace_botocore_types(item))
return new_list

return obj

spec = search_and_replace_botocore_types(spec)

with open(filename, 'w') as f:
for line in lines:
f.write(line)
json.dump(spec, f, indent=2, sort_keys=True, separators=(',', ': '))

def update_documentation(rules):
"""Generate documentation"""
Expand Down

0 comments on commit 74b5e74

Please sign in to comment.