Skip to content

Commit

Permalink
Expand add env functionality to add variables if not present (apache#…
Browse files Browse the repository at this point in the history
…3827)

* Add config variables if absent

* Took feedback into account
  • Loading branch information
srkukarni authored and merlimat committed Mar 29, 2019
1 parent e88fed4 commit b6c767e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docker/pulsar/scripts/apply-config-from-env.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
# Always apply env config to env scripts as well
conf_files = ['conf/pulsar_env.sh', 'conf/bkenv.sh'] + sys.argv[1:]

PF_ENV_PREFIX = 'PULSAR_'


for conf_filename in conf_files:
lines = [] # List of config file lines
keys = {} # Map a key to its line number in the file
Expand All @@ -56,6 +59,17 @@
idx = keys[k]
lines[idx] = '%s=%s\n' % (k, v)


# Add new keys from Env
for k in sorted(os.environ.keys()):
v = os.environ[k]
if not k.startswith(PF_ENV_PREFIX):
continue
k = k[len(PF_ENV_PREFIX):]
if k not in keys:
print('[%s] Adding config %s = %s' % (conf_filename, k, v))
lines.append('%s=%s\n' % (k, v))

# Store back the updated config in the same file
f = open(conf_filename, 'w')
for line in lines:
Expand Down

0 comments on commit b6c767e

Please sign in to comment.