-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change generate kafka connect properties from env (#10545)
Co-authored-by: david-leifker <114954101+david-leifker@users.noreply.github.com>
- Loading branch information
1 parent
e83550b
commit fc7b685
Showing
2 changed files
with
25 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
import re | ||
import sys | ||
|
||
|
||
def env_to_properties(env_prefix: str, properties_file: str): | ||
pattern = re.compile('(?<=[^_])_(?=[^_])') | ||
props = {} | ||
|
||
for (env_name, val) in os.environ.items(): | ||
if env_name.startswith(env_prefix): | ||
raw_name = env_name[len(env_prefix):].lower() | ||
prop_dot = '.'.join(pattern.split(raw_name)) | ||
props[prop_dot] = val | ||
|
||
with open(properties_file, 'a') as f: | ||
for k, v in props.items(): | ||
f.writelines(f'{k}={v}\n') | ||
|
||
|
||
if __name__ == '__main__': | ||
env_prefix = sys.argv[1] | ||
properties_file = sys.argv[2] | ||
env_to_properties(env_prefix, properties_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters