Skip to content

Commit

Permalink
Merge 7e0c9f8 into 7833fc0
Browse files Browse the repository at this point in the history
  • Loading branch information
icgood committed May 8, 2021
2 parents 7833fc0 + 7e0c9f8 commit d32530c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
license = f.read()

setup(name='swim-protocol',
version='0.3.0',
version='0.3.1',
author='Ian Good',
author_email='ian@icgood.net',
description='SWIM protocol implementation for exchanging cluster '
Expand Down
14 changes: 13 additions & 1 deletion swimprotocol/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ def add_arguments(cls, parser: ArgumentParser, *,
help='At least one name or address of '
'a known peer.')

@classmethod
def _get_secret(cls, args: Namespace, env_prefix: str) -> str:
env_secret_file = os.getenv(f'{env_prefix}_SECRET_FILE')
if env_secret_file is not None:
with open(env_secret_file) as secret_file:
return secret_file.read().rstrip('\r\n')
env_secret = os.getenv(f'{env_prefix}_SECRET')
if env_secret is not None:
return env_secret
arg_secret: str = args.swim_secret
return arg_secret

@classmethod
def parse_args(cls, args: Namespace, *, env_prefix: str = 'SWIM') \
-> dict[str, Any]:
Expand All @@ -142,7 +154,7 @@ def parse_args(cls, args: Namespace, *, env_prefix: str = 'SWIM') \
env_prefix: Prefix for the environment variables.
"""
secret = os.getenv(f'{env_prefix}_SECRET', args.swim_secret)
secret = cls._get_secret(args, env_prefix)
local_name = os.getenv(f'{env_prefix}_NAME', args.swim_name)
local_metadata = {key: val.encode('utf-8')
for key, val in args.swim_metadata}
Expand Down

0 comments on commit d32530c

Please sign in to comment.