From e80d0bd9cb76c345218ac3dd648c2a025f31f920 Mon Sep 17 00:00:00 2001 From: Antonia Avramova Date: Tue, 19 Dec 2023 16:11:55 +0200 Subject: [PATCH] Update the python scripts to prioritize arguments over environment variables (#302) [#301] Update the python scripts to prioritize arguments over environment variables Signed-off-by: Antonia Avramova --- quickstart/hono_commands.py | 4 ++-- quickstart/hono_commands_fb.py | 6 +++--- quickstart/hono_commands_fu.py | 4 ++-- quickstart/hono_commands_sb.py | 6 +++--- quickstart/hono_commands_sm.py | 4 ++-- quickstart/hono_commands_su.py | 4 ++-- quickstart/hono_events.py | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/quickstart/hono_commands.py b/quickstart/hono_commands.py index e9e322be..96593346 100644 --- a/quickstart/hono_commands.py +++ b/quickstart/hono_commands.py @@ -105,8 +105,8 @@ def on_sendable(self, event): # Parse command line args options, reminder = getopt.getopt(sys.argv[2:], 't:d:', ["img=", "id="]) opts_dict = dict(options) -tenant_id = os.environ.get("TENANT") or opts_dict['-t'] -device_id = os.environ.get("DEVICE_ID") or opts_dict['-d'] +tenant_id = opts_dict.get('-t') or os.environ["TENANT"] +device_id = opts_dict.get('-d') or os.environ["DEVICE_ID"] command = sys.argv[1] if command == CLI_OPT_RUN_CMD: container_img_ref = opts_dict['--img'] diff --git a/quickstart/hono_commands_fb.py b/quickstart/hono_commands_fb.py index 01279963..11e4be60 100644 --- a/quickstart/hono_commands_fb.py +++ b/quickstart/hono_commands_fb.py @@ -162,9 +162,9 @@ def on_connection_closed(self, event): # Parse command line args options, reminder = getopt.getopt(sys.argv[2:], 't:d:h:') opts_dict = dict(options) -tenant_id = os.environ.get("TENANT") or opts_dict['-t'] -device_id = os.environ.get("DEVICE_ID") or opts_dict['-d'] -host = os.environ.get("HOST") or opts_dict['-h'] +tenant_id = opts_dict.get('-t') or os.environ["TENANT"] +device_id = opts_dict.get('-d') or os.environ["DEVICE_ID"] +host = opts_dict.get('-h') or os.environ["HOST"] command = sys.argv[1] if command == CLI_OPT_BACKUP_CMD: action = "backup" diff --git a/quickstart/hono_commands_fu.py b/quickstart/hono_commands_fu.py index 30c8235a..ddac9990 100644 --- a/quickstart/hono_commands_fu.py +++ b/quickstart/hono_commands_fu.py @@ -141,8 +141,8 @@ def on_connection_closed(self, event): # Parse command line args options, reminder = getopt.getopt(sys.argv[1:], 't:d:') opts_dict = dict(options) -tenant_id = os.environ.get("TENANT") or opts_dict['-t'] -device_id = os.environ.get("DEVICE_ID") or opts_dict['-d'] +tenant_id = opts_dict.get('-t') or os.environ["TENANT"] +device_id = opts_dict.get('-d') or os.environ["DEVICE_ID"] # AMQP global configurations uri = 'amqps://hono.eclipseprojects.io:15671' diff --git a/quickstart/hono_commands_sb.py b/quickstart/hono_commands_sb.py index 73e256e3..0d2e81f0 100644 --- a/quickstart/hono_commands_sb.py +++ b/quickstart/hono_commands_sb.py @@ -220,9 +220,9 @@ def on_connection_closed(self, event): # Parse command line args options, reminder = getopt.getopt(sys.argv[1:], 't:d:p:') opts_dict = dict(options) -tenant_id = opts_dict['-t'] or os.environ.get("TENANT") -device_id = opts_dict['-d'] or os.environ.get("DEVICE_ID") -new_password = opts_dict['-p'] or os.environ.get("PASSWORD") +tenant_id = opts_dict.get('-t') or os.environ["TENANT"] +device_id = opts_dict.get('-d') or os.environ["DEVICE_ID"] +new_password = opts_dict.get('-p') or os.environ["PASSWORD"] hono_ep = 'https://hono.eclipseprojects.io:28443' diff --git a/quickstart/hono_commands_sm.py b/quickstart/hono_commands_sm.py index 68130c41..599e4040 100644 --- a/quickstart/hono_commands_sm.py +++ b/quickstart/hono_commands_sm.py @@ -215,8 +215,8 @@ def run(self): # Parse command line args options, reminder = getopt.getopt(sys.argv[1:], 't:d:') opts_dict = dict(options) -tenant_id = os.environ.get("TENANT") or opts_dict['-t'] -device_id = os.environ.get("DEVICE_ID") or opts_dict['-d'] +tenant_id = opts_dict.get('-t') or os.environ["TENANT"] +device_id = opts_dict.get('-d') or os.environ["DEVICE_ID"] # AMQP global configurations uri = 'amqps://hono.eclipseprojects.io:15671' diff --git a/quickstart/hono_commands_su.py b/quickstart/hono_commands_su.py index 2263662f..bf1a92f2 100644 --- a/quickstart/hono_commands_su.py +++ b/quickstart/hono_commands_su.py @@ -116,8 +116,8 @@ def on_sendable(self, event): # Parse command line args options, reminder = getopt.getopt(sys.argv[1:], 't:d:') opts_dict = dict(options) -tenant_id = os.environ.get("TENANT") or opts_dict['-t'] -device_id = os.environ.get("DEVICE_ID") or opts_dict['-d'] +tenant_id = opts_dict.get('-t') or os.environ["TENANT"] +device_id = opts_dict.get('-d') or os.environ["DEVICE_ID"] # AMQP global configurations diff --git a/quickstart/hono_events.py b/quickstart/hono_events.py index ff9115c9..b31e6c74 100644 --- a/quickstart/hono_events.py +++ b/quickstart/hono_events.py @@ -41,7 +41,7 @@ def on_message(self, event): # Parse command line args options, reminder = getopt.getopt(sys.argv[1:], 't:') -tenant_id = os.environ.get("TENANT") or dict(options)['-t'] +tenant_id = dict(options).get('-t') or os.environ["TENANT"] uri = 'amqps://hono.eclipseprojects.io:15671' address = 'event/{}'.format(tenant_id)