From 6ca70c53b20780830893dbc57d9903cb40c4917a Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Mon, 3 Apr 2023 23:59:15 +0100 Subject: [PATCH 01/11] TOPS-656 publish to PyPi --- .github/workflows/publish-to-test-pypi.yml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/publish-to-test-pypi.yml diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml new file mode 100644 index 0000000..10f1369 --- /dev/null +++ b/.github/workflows/publish-to-test-pypi.yml @@ -0,0 +1,34 @@ +name: Publish Envars to PyPi + +on: push + +jobs: + build-n-publish: + name: Build and publish to PyPi + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install pypa/build + run: >- + python -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: >- + python -m + build + --sdist + --wheel + --outdir dist/ + . + - name: Publish distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} From 662e725463549b00383c86eba05f47f56f187da0 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Tue, 4 Apr 2023 00:01:00 +0100 Subject: [PATCH 02/11] doit --- .github/workflows/publish-to-test-pypi.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml index 10f1369..a6bbc93 100644 --- a/.github/workflows/publish-to-test-pypi.yml +++ b/.github/workflows/publish-to-test-pypi.yml @@ -28,7 +28,6 @@ jobs: --outdir dist/ . - name: Publish distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }} From fab424ad4545715751f857b20108f1ee12e72728 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Tue, 4 Apr 2023 00:12:31 +0100 Subject: [PATCH 03/11] long_desc --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 055b607..0441f67 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ name='envars', version='0.1', description='A sample Python package', + long_description=open('README.md').read(), author='Keith Harvey', author_email='keith.harvey@timeout.com', packages=['envars'], From 3b8c1b24775df87be8ab245d7940a539941d13e3 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Tue, 4 Apr 2023 00:14:55 +0100 Subject: [PATCH 04/11] simpler --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0441f67..525a2b4 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ name='envars', version='0.1', description='A sample Python package', - long_description=open('README.md').read(), + long_description='my test long description', author='Keith Harvey', author_email='keith.harvey@timeout.com', packages=['envars'], From 8f8b82d6d978e9dd0cb177e5f9600a2430b68047 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Tue, 4 Apr 2023 00:17:00 +0100 Subject: [PATCH 05/11] rename --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 525a2b4..d1b479d 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup setup( - name='envars', + name='timeout-envars', version='0.1', description='A sample Python package', long_description='my test long description', From 710fb286df638d5665c3d2c7022a15282057ffc9 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Tue, 4 Apr 2023 01:11:18 +0100 Subject: [PATCH 06/11] 0.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d1b479d..246c94b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='timeout-envars', - version='0.1', + version='0.2', description='A sample Python package', long_description='my test long description', author='Keith Harvey', From 9013dffd13fb105cdb92da075640aa8116ce7ab2 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Thu, 6 Apr 2023 16:13:59 +0100 Subject: [PATCH 07/11] TOPS-656 - add option to disable templating --- envars/envars.py | 11 ++++++++++- envars/models.py | 7 ++++--- setup.py | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/envars/envars.py b/envars/envars.py index adffbb3..3d84f93 100755 --- a/envars/envars.py +++ b/envars/envars.py @@ -115,6 +115,13 @@ def main(): required=False, action='store_true', ) + parser_print.add_argument( + '-n', + '--no-templating', + required=False, + default=False, + action='store_true', + ) parser_print.add_argument( '-e', '--env', @@ -376,6 +383,7 @@ def process(args): account, decrypt=args.decrypt, template_vars=template_vars, + no_templating=args.no_templating, )}, default_flow_style=False ) @@ -386,7 +394,8 @@ def process(args): args.env, account, decrypt=args.decrypt, - template_vars=template_vars).items(): + template_vars=template_vars, + no_templating=args.no_templating).items(): if args.quote: env_vars.append(f"{name}='{value}'") else: diff --git a/envars/models.py b/envars/models.py index 89cded6..f205073 100755 --- a/envars/models.py +++ b/envars/models.py @@ -210,7 +210,7 @@ def get_var(self, var, env, account): if v.name == var: return {v.name: v.get_value(env, account, fetch_pstore=True)} - def build_env(self, env, account, decrypt=False, template_vars=None): + def build_env(self, env, account, decrypt=False, template_vars=None, no_templating=False): logging.debug(f'build_env({env}, {account})') envars = {} if env != 'default' and env not in self.envs: @@ -228,8 +228,9 @@ def build_env(self, env, account, decrypt=False, template_vars=None): jenv = jinja2.Environment() # process jinja templates - for var in envars: - envars[var] = jenv.from_string(envars[var]).render(template_vars) + if not no_templating: + for var in envars: + envars[var] = jenv.from_string(envars[var]).render(template_vars) # fetch secrets for v in self.envars: diff --git a/setup.py b/setup.py index 246c94b..bba61ca 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='timeout-envars', - version='0.2', + version='0.3', description='A sample Python package', long_description='my test long description', author='Keith Harvey', From a85c4dbf79fafb7a54aaa34bc3125a310bb9be9a Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Thu, 6 Apr 2023 16:21:29 +0100 Subject: [PATCH 08/11] fix tests --- tests/test_cli.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 27ce04e..35ef0e6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -104,7 +104,8 @@ def test_eqauls_in_value(tmp_path): 'template_var': [], 'yaml': False, 'decrypt': True, - 'quote': False + 'quote': False, + 'no_templating': False, }) ret = envars.process(args) @@ -139,7 +140,8 @@ def test_two_env_vars_returned(tmp_path): 'template_var': [], 'yaml': False, 'decrypt': True, - 'quote': False + 'quote': False, + 'no_templating': False, }) ret = envars.process(args) @@ -174,7 +176,8 @@ def test_template_var(tmp_path): 'template_var': [], 'yaml': False, 'decrypt': True, - 'quote': False + 'quote': False, + 'no_templating': False, }) ret = envars.process(args) @@ -200,7 +203,8 @@ def test_extra_template_passing(tmp_path): 'yaml': False, 'decrypt': True, 'template_var': ['RELEASE=12324523523523525234523523'], - 'quote': False + 'quote': False, + 'no_templating': False, }) ret = envars.process(args) @@ -246,7 +250,8 @@ def test_yaml_print_env(tmp_path): 'yaml': True, 'decrypt': True, 'template_var': ['RELEASE=12324523523523525234523523'], - 'quote': False + 'quote': False, + 'no_templating': False, }) ret = envars.process(args) @@ -279,7 +284,8 @@ def test_secret(kms_stub, tmp_path): 'template_var': [], 'yaml': False, 'decrypt': True, - 'quote': False + 'quote': False, + 'no_templating': False, }) ret = envars.process(args) @@ -309,7 +315,8 @@ def test_parameter_store_value(ssm_stub, tmp_path): 'template_var': ['RELEASE=1234'], 'yaml': False, 'decrypt': False, - 'quote': False + 'quote': False, + 'no_templating': False, }) ret = envars.process(args) assert ret == ['PTEST=1234'] @@ -343,7 +350,8 @@ def test_exec_one_var(tmp_path): 'env': 'prod', 'filename': f'{tmp_path}/envars.yml', 'var': 'TEST', - 'quote': False + 'quote': False, + 'no_templating': False, }) envars.os.execlp = MagicMock() envars.execute(args) @@ -381,7 +389,8 @@ def test_exec(tmp_path): 'filename': f'{tmp_path}/envars.yml', 'var': None, 'template_var': [], - 'quote': False + 'quote': False, + 'no_templating': False, }) envars.os.execlp = MagicMock() envars.execute(args) From 6415dae2c44d5f4c7d6411426beb6ac3df9d1d1e Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Wed, 12 Apr 2023 10:25:24 +0200 Subject: [PATCH 09/11] refactor process function --- envars/envars.py | 81 +++++++++++++++++++++-------- envars/models.py | 4 +- tests/test_cli.py | 126 ++++++++++++++++++---------------------------- 3 files changed, 109 insertions(+), 102 deletions(-) diff --git a/envars/envars.py b/envars/envars.py index 3d84f93..fca4040 100755 --- a/envars/envars.py +++ b/envars/envars.py @@ -154,6 +154,13 @@ def main(): default=False, action='store_true', ) + parser_print.add_argument( + '-S', + '--secrets_only', + required=False, + default=False, + action='store_true', + ) parser_print.set_defaults(func=print_env) # @@ -255,7 +262,17 @@ def set_systemd_env(args): if 'RELEASE_SHA' in os.environ: args.template_var = [f'RELEASE={os.environ.get("RELEASE_SHA")}'] args.var = None - ret = process(args) + ret = process( + args.filename, + args.account, + args.env, + args.var, + args.template_var, + args.decrypt, + True if args.no_templating is False else False, + args.yaml, + args.quote, + ) for val in ret: parts = val.split("=", 1) subprocess.run( @@ -284,7 +301,17 @@ def execute(args): vals = envars.get_var(args.var, args.env, args.account) else: args.var = None - ret = process(args) + ret = process( + args.filename, + args.account, + args.env, + args.var, + args.template_var, + args.decrypt, + True if args.no_templating is False else False, + args.yaml, + args.quote, + ) for val in ret: parts = val.split("=", 1) vals[parts[0]] = parts[1] @@ -353,7 +380,17 @@ def add_var(args): def print_env(args): - ret = process(args) + ret = process( + args.filename, + args.account, + args.env, + args.var, + args.template_var, + args.decrypt, + True if args.no_templating is False else False, + args.yaml, + args.quote, + ) if isinstance(ret, list): for var in ret: print(var) @@ -361,29 +398,30 @@ def print_env(args): print(ret) -def process(args): - envars = EnVars(args.filename) +def process(filename, account, env, var=None, template_var=None, decrypt=False, templating=True, as_yaml=False, quote=False): + envars = EnVars(filename) envars.load() - if args.account is None: + if account is None: account = get_account() else: - account = args.account + account = account - if args.env: + if env: template_vars = {} - for tvar in flatten(args.template_var): - template_vars[tvar.split('=')[0]] = tvar.split('=')[1] + if template_var: + for tvar in flatten(template_var): + template_vars[tvar.split('=')[0]] = tvar.split('=')[1] - if args.yaml: + if as_yaml: return ( yaml.dump( {'envars': envars.build_env( - args.env, + env, account, - decrypt=args.decrypt, + decrypt=decrypt, template_vars=template_vars, - no_templating=args.no_templating, + templating=templating, )}, default_flow_style=False ) @@ -391,22 +429,21 @@ def process(args): else: env_vars = [] for name, value in envars.build_env( - args.env, + env, account, - decrypt=args.decrypt, + decrypt=decrypt, template_vars=template_vars, - no_templating=args.no_templating).items(): - if args.quote: + templating=templating).items(): + if quote: env_vars.append(f"{name}='{value}'") else: env_vars.append(f'{name}={value}') return env_vars else: - var = None - if args.var: - var = args.var.upper() - return (envars.print(account, var=var, decrypt=args.decrypt)) + if var: + var = var.upper() + return (envars.print(account, var=var, decrypt=decrypt)) def flatten(lis): diff --git a/envars/models.py b/envars/models.py index f205073..a9d410d 100755 --- a/envars/models.py +++ b/envars/models.py @@ -210,7 +210,7 @@ def get_var(self, var, env, account): if v.name == var: return {v.name: v.get_value(env, account, fetch_pstore=True)} - def build_env(self, env, account, decrypt=False, template_vars=None, no_templating=False): + def build_env(self, env, account, decrypt=False, template_vars=None, templating=True): logging.debug(f'build_env({env}, {account})') envars = {} if env != 'default' and env not in self.envs: @@ -228,7 +228,7 @@ def build_env(self, env, account, decrypt=False, template_vars=None, no_templati jenv = jinja2.Environment() # process jinja templates - if not no_templating: + if templating: for var in envars: envars[var] = jenv.from_string(envars[var]).render(template_vars) diff --git a/tests/test_cli.py b/tests/test_cli.py index 35ef0e6..8c9bf76 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -97,17 +97,12 @@ def test_eqauls_in_value(tmp_path): }) envars.add_var(args) - args = type('Args', (object,), { - 'filename': f'{tmp_path}/envars.yml', - 'env': 'prod', - 'account': None, - 'template_var': [], - 'yaml': False, - 'decrypt': True, - 'quote': False, - 'no_templating': False, - }) - ret = envars.process(args) + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + ) assert ret == ['TEST1=abc='] @@ -133,17 +128,12 @@ def test_two_env_vars_returned(tmp_path): }) envars.add_var(args) - args = type('Args', (object,), { - 'filename': f'{tmp_path}/envars.yml', - 'env': 'prod', - 'account': None, - 'template_var': [], - 'yaml': False, - 'decrypt': True, - 'quote': False, - 'no_templating': False, - }) - ret = envars.process(args) + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + ) assert ret == ['TEST1=A', 'TEST2=B'] @@ -169,17 +159,12 @@ def test_template_var(tmp_path): }) envars.add_var(args) - args = type('Args', (object,), { - 'filename': f'{tmp_path}/envars.yml', - 'env': 'prod', - 'account': None, - 'template_var': [], - 'yaml': False, - 'decrypt': True, - 'quote': False, - 'no_templating': False, - }) - ret = envars.process(args) + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + ) assert ret == ['DOMAIN=timeout.com', 'HOSTNAME=test.timeout.com'] @@ -196,17 +181,13 @@ def test_extra_template_passing(tmp_path): }) envars.add_var(args) - args = type('Args', (object,), { - 'filename': f'{tmp_path}/envars.yml', - 'env': 'prod', - 'account': None, - 'yaml': False, - 'decrypt': True, - 'template_var': ['RELEASE=12324523523523525234523523'], - 'quote': False, - 'no_templating': False, - }) - ret = envars.process(args) + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + template_var=['RELEASE=12324523523523525234523523'], + ) assert ret == ['RELEASE=12324523523523525234523523'] @@ -242,18 +223,14 @@ def test_yaml_print_env(tmp_path): }) envars.add_var(args) - args = type('Args', (object,), { - 'filename': f'{tmp_path}/envars.yml', - 'env': 'prod', - 'var': None, - 'account': None, - 'yaml': True, - 'decrypt': True, - 'template_var': ['RELEASE=12324523523523525234523523'], - 'quote': False, - 'no_templating': False, - }) - ret = envars.process(args) + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + as_yaml=True, + template_var=['RELEASE=12324523523523525234523523'], + ) assert ret == "envars:\n RELEASE: '12324523523523525234523523'\n TEST: test\n" @@ -277,17 +254,13 @@ def test_secret(kms_stub, tmp_path): 'account': None, }) envars.add_var(args) - args = type('Arg', (object,), { - 'filename': f'{tmp_path}/envars.yml', - 'env': 'prod', - 'account': None, - 'template_var': [], - 'yaml': False, - 'decrypt': True, - 'quote': False, - 'no_templating': False, - }) - ret = envars.process(args) + + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + ) assert ret == ['TEST=sssssh'] @@ -308,17 +281,14 @@ def test_parameter_store_value(ssm_stub, tmp_path): }) envars.add_var(args) - args = type('Arg', (object,), { - 'filename': f'{tmp_path}/envars.yml', - 'env': 'prod', - 'account': None, - 'template_var': ['RELEASE=1234'], - 'yaml': False, - 'decrypt': False, - 'quote': False, - 'no_templating': False, - }) - ret = envars.process(args) + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + template_var=['RELEASE=1234'], + ) + assert ret == ['PTEST=1234'] From efcd8483ab77853a224462e14f441bedb6019a24 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Wed, 12 Apr 2023 14:47:49 +0200 Subject: [PATCH 10/11] add print secrets only --- envars/envars.py | 8 ++++- envars/models.py | 49 +++++++++++++++++----------- tests/test_cli.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 20 deletions(-) diff --git a/envars/envars.py b/envars/envars.py index fca4040..a1db5bf 100755 --- a/envars/envars.py +++ b/envars/envars.py @@ -390,6 +390,7 @@ def print_env(args): True if args.no_templating is False else False, args.yaml, args.quote, + args.secrets_only, ) if isinstance(ret, list): for var in ret: @@ -398,7 +399,10 @@ def print_env(args): print(ret) -def process(filename, account, env, var=None, template_var=None, decrypt=False, templating=True, as_yaml=False, quote=False): +def process( + filename, account, env, var=None, template_var=None, + decrypt=False, templating=True, as_yaml=False, quote=False, secrets_only=False): + envars = EnVars(filename) envars.load() @@ -422,6 +426,7 @@ def process(filename, account, env, var=None, template_var=None, decrypt=False, decrypt=decrypt, template_vars=template_vars, templating=templating, + secrets_only=secrets_only, )}, default_flow_style=False ) @@ -433,6 +438,7 @@ def process(filename, account, env, var=None, template_var=None, decrypt=False, account, decrypt=decrypt, template_vars=template_vars, + secrets_only=secrets_only, templating=templating).items(): if quote: env_vars.append(f"{name}='{value}'") diff --git a/envars/models.py b/envars/models.py index a9d410d..c51c625 100755 --- a/envars/models.py +++ b/envars/models.py @@ -210,33 +210,44 @@ def get_var(self, var, env, account): if v.name == var: return {v.name: v.get_value(env, account, fetch_pstore=True)} - def build_env(self, env, account, decrypt=False, template_vars=None, templating=True): + def build_env(self, env, account, decrypt=False, template_vars=None, templating=True, secrets_only=False): logging.debug(f'build_env({env}, {account})') envars = {} if env != 'default' and env not in self.envs: raise (Exception(f'Unknown Env: "{env}"')) - template_vars['STAGE'] = env - # fetch all the non secret values - for v in self.envars: - value = v.get_value(env, account, fetch_pstore=True) - if value and not isinstance(value, Secret): - if v.name not in template_vars.keys(): - template_vars[v.name] = value - envars[v.name] = value + if templating and not secrets_only: + template_vars['STAGE'] = env + # fetch all the non secret values + for v in self.envars: + value = v.get_value(env, account, fetch_pstore=True) + if value and not isinstance(value, Secret): + if v.name not in template_vars.keys(): + template_vars[v.name] = value + envars[v.name] = value - jenv = jinja2.Environment() + jenv = jinja2.Environment() - # process jinja templates - if templating: - for var in envars: - envars[var] = jenv.from_string(envars[var]).render(template_vars) + # process jinja templates + if templating: + for var in envars: + envars[var] = jenv.from_string(envars[var]).render(template_vars) - # fetch secrets - for v in self.envars: - value = v.get_value(env, account, decrypt) - if value: - if v.name not in envars: + # fetch secrets + for v in self.envars: + value = v.get_value(env, account, decrypt) + if value: + if v.name not in envars: + envars[v.name] = value + + elif secrets_only: + for v in self.envars: + if isinstance(v.get_value(env, account), Secret): + envars[v.name] = v.get_value(env, account, decrypt) + else: + for v in self.envars: + value = v.get_value(env, account, decrypt) + if value: envars[v.name] = value return envars diff --git a/tests/test_cli.py b/tests/test_cli.py index 8c9bf76..4316722 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -367,3 +367,84 @@ def test_exec(tmp_path): assert os.environ.get('TEST') == 'test' assert os.environ.get('STEST') == 'stest=' + + +def test_secrets_only(kms_stub, tmp_path): + kms_stub.add_response( + 'encrypt', + service_response={'CiphertextBlob': b'dfghsdghfsd'} + ) + kms_stub.add_response( + 'decrypt', + service_response={'KeyId': 'STEST', 'Plaintext': b'stest', 'EncryptionAlgorithm': 'SYMMETRIC_DEFAULT'} + ) + run_cmd(tmp_path, 'init --app testapp --environments prod,staging --kms-key-arn abc') + args = type('Args', (object,), { + 'variable': 'TEST=test', + 'secret': False, + 'filename': f'{tmp_path}/envars.yml', + 'env': 'default', + 'desc': None, + 'account': None, + }) + envars.add_var(args) + args = type('Args', (object,), { + 'variable': 'STEST=stest', + 'secret': True, + 'filename': f'{tmp_path}/envars.yml', + 'env': 'default', + 'desc': None, + 'account': None, + }) + envars.add_var(args) + + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + secrets_only=True, + ) + + assert ret == ['STEST=stest'] + + +def test_secrets_only_yaml(kms_stub, tmp_path): + kms_stub.add_response( + 'encrypt', + service_response={'CiphertextBlob': b'dfghsdghfsd'} + ) + kms_stub.add_response( + 'decrypt', + service_response={'KeyId': 'STEST', 'Plaintext': b'stest', 'EncryptionAlgorithm': 'SYMMETRIC_DEFAULT'} + ) + run_cmd(tmp_path, 'init --app testapp --environments prod,staging --kms-key-arn abc') + args = type('Args', (object,), { + 'variable': 'TEST=test', + 'secret': False, + 'filename': f'{tmp_path}/envars.yml', + 'env': 'default', + 'desc': None, + 'account': None, + }) + envars.add_var(args) + args = type('Args', (object,), { + 'variable': 'STEST=stest', + 'secret': True, + 'filename': f'{tmp_path}/envars.yml', + 'env': 'default', + 'desc': None, + 'account': None, + }) + envars.add_var(args) + + ret = envars.process( + filename=f'{tmp_path}/envars.yml', + account=None, + env='prod', + decrypt=True, + secrets_only=True, + as_yaml=True, + ) + + assert ret == 'envars:\n STEST: stest\n' From e992e1ae1a0370b897e60ea0bbd26f3e2cc6eff3 Mon Sep 17 00:00:00 2001 From: Keith Harvey Date: Wed, 12 Apr 2023 14:48:33 +0200 Subject: [PATCH 11/11] add print secrets only --- envars/envars.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/envars/envars.py b/envars/envars.py index a1db5bf..d27988c 100755 --- a/envars/envars.py +++ b/envars/envars.py @@ -400,8 +400,9 @@ def print_env(args): def process( - filename, account, env, var=None, template_var=None, - decrypt=False, templating=True, as_yaml=False, quote=False, secrets_only=False): + filename, account, env, + var=None, template_var=None, decrypt=False, + templating=True, as_yaml=False, quote=False, secrets_only=False): envars = EnVars(filename) envars.load()