Files
deployment-portal-be/scripts/updateConfigsToSecret.py

36 lines
1.2 KiB
Python
Raw Normal View History

import requests
import re
portal_url = "https://gi-deployment-portal.cmd.navi-tech.in"
s = requests.Session()
# tbd: replace it with token
cookie = ""
x_xsrf_token = ""
s.headers.update({'cookie': cookie, 'x-xsrf-token': x_xsrf_token})
list_manifest_path = "/api/manifest/list"
individual_manifest_path = "/api/manifest/"
update_manifest_path = "/api/manifest"
secretFieldsRegex = r'(secret)|(token)|(password)|(key)'
updateFlag = False
r = s.get(portal_url + list_manifest_path)
manifest_list = r.json()
for manifest in manifest_list:
# Get each manifest
r = s.get(portal_url + individual_manifest_path + str(manifest['id']))
manifest = r.json()
envVariables = manifest['environmentVariables']
# Update the required environmentVariables types
for count_e, envVar in enumerate(envVariables):
if envVar['type'] == 'CONFIG' and re.search(secretFieldsRegex, envVar['name'], re.IGNORECASE):
print("Updating type for", envVar['name'])
manifest['environmentVariables'][count_e]['type'] = 'SECRET'
updateFlag = True
if updateFlag:
print("Updating for ", manifest['id'])
r = s.post(portal_url + update_manifest_path, json=manifest)
print(r)
updateFlag = False