- changed env-handler logic
This commit is contained in:
KRAIEM Taha Yassine 2021-05-12 19:05:15 +02:00
parent e28d787aeb
commit 01949660bb
2 changed files with 8 additions and 23 deletions

View file

@ -1,20 +1,11 @@
from os import environ
import json
import os
with open('.chalice/config.json') as json_file:
data = json.load(json_file)
stages = data.get("stages", {})
for s in stages.keys():
target = f'chalicelib/.configs/{stages[s].get("environment_variables", {}).get("stage", s)}.json'
data = {}
try:
with open(target) as stage_vars:
data = json.load(stage_vars)
except IOError:
if not os.path.exists('chalicelib/.configs'):
os.makedirs('chalicelib/.configs')
with open(target, 'w') as outfile:
json.dump({**stages[s].get("environment_variables", {}), **data, **environ},
outfile, indent=2, sort_keys=True)
print(f"injected env-vars to {target}")
data["stages"][s]["environment_variables"] = {**stages[s].get("environment_variables", {}), **environ}
with open('.chalice/config.json', 'w') as outfile:
json.dump(data, outfile, indent=2, sort_keys=True)
print("override config.json")

View file

@ -5,13 +5,7 @@ with open('.chalice/config.json') as json_file:
data = json.load(json_file)
stages = data.get("stages", {})
for s in stages.keys():
target = f'chalicelib/.configs/{stages[s].get("environment_variables", {}).get("stage", s)}.json'
data = {}
try:
with open(target) as stage_vars:
data = json.load(stage_vars)
except IOError:
pass
with open(target, 'w') as outfile:
json.dump({**data, **environ}, outfile, indent=2, sort_keys=True)
print(f"injected env-vars to {target}")
data["stages"][s]["environment_variables"] = {**stages[s].get("environment_variables", {}), **environ}
with open('.chalice/config.json', 'w') as outfile:
json.dump(data, outfile, indent=2, sort_keys=True)
print("override config.json")