Skip to content

Commit

Permalink
Merge pull request #93 from wguanicedew/dev
Browse files Browse the repository at this point in the history
fix env name search
  • Loading branch information
wguanicedew authored Jul 19, 2022
2 parents ede89a9 + 46b928e commit 58791f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
40 changes: 30 additions & 10 deletions main/lib/idds/tests/jsonload_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,30 @@ def is_string(value):


def as_parse_env(dct):
print(dct)
# print(dct)
for key in dct:
value = dct[key]
print(value)
print(type(value))
if is_string(value) and value.startswith('$'):
env_match = re.search('\$\{*([^\}]+)\}*', value) # noqa W605
env_name = env_match.group(1)
if env_name not in os.environ:
print("Error: %s is defined in configmap but is not defined in environments" % env_name)
else:
dct[key] = os.environ[env_name]
# print(value)
# print(type(value))
if is_string(value) and '$' in value:
env_matchs = re.findall('\$\{*([^\}]+)\}*', value) # noqa W605
print("env_matchs")
print(env_matchs)
for env_name in env_matchs:
print(env_name)
if env_name not in os.environ:
print("Error: %s is defined in configmap but is not defined in environments" % env_name)
else:
# dct[key] = os.environ[env_name]
print('${%s}' % env_name)
print(os.environ.get(env_name))
env_name1 = r'${%s}' % env_name
env_name2 = r'$%s' % env_name
print(env_name1)
print(env_name2)
print(value.replace(env_name1, os.environ.get(env_name)))
value = value.replace(env_name1, os.environ.get(env_name)).replace(env_name2, os.environ.get(env_name))
dct[key] = value
return dct


Expand All @@ -49,6 +61,14 @@ def as_parse_env(dct):
"pandacache_url": "${PANDACACHE_URL}",
"panda_verify_host": "${PANDA_VERIFY_HOST}",
"test1": {"test2": "${TEST_ENV}"}
},
"database":
{"default": "postgresql://${IDDS_DATABASE_USER}:${IDDS_DATABASE_PASSWORD}@${IDDS_DATABASE_HOST}/${IDDS_DATABASE_NAME}",
"schema": "${IDDS_DATABASE_SCHEMA}",
"pool_size": 20,
"pool_recycle": 3600,
"echo": 0,
"pool_reset_on_return": "rollback"
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions main/tools/env/merge_configmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ def is_string(value):
def as_parse_env(dct):
for key in dct:
value = dct[key]
if is_string(value) and value.startswith('$'):
env_match = re.search('\$\{*([^\}]+)\}*', value) # noqa W605
env_name = env_match.group(1)
if env_name not in os.environ:
print("Error: %s is defined in configmap but is not defined in environments" % env_name)
else:
dct[key] = os.environ[env_name]
if is_string(value) and '$' in value:
env_matches = re.findall('\$\{*([^\}]+)\}*', value) # noqa W605
for env_name in env_matches:
if env_name not in os.environ:
print("Error: %s is defined in configmap but is not defined in environments" % env_name)
else:
env_name1 = r'${%s}' % env_name
env_name2 = r'$%s' % env_name
value = value.replace(env_name1, os.environ.get(env_name)).replace(env_name2, os.environ.get(env_name))
dct[key] = value
return dct


Expand Down

0 comments on commit 58791f8

Please sign in to comment.