From 1ceefd7d700caf18f2390b94aa81d9f0207a4d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Solbj=C3=B8rg?= Date: Tue, 2 Apr 2019 00:58:09 +0200 Subject: =?UTF-8?q?chore:=20Refactor=20to=20get=20switches=20from=20gondul?= =?UTF-8?q?=20before=20executing=20labler=20=E2=99=BB=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gondul.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'gondul.py') diff --git a/gondul.py b/gondul.py index 65c18fa..74c1a23 100644 --- a/gondul.py +++ b/gondul.py @@ -61,6 +61,16 @@ def _sort_switches(switches): return sorted(switches, key=lambda x: (int(x[1:].split("-")[0]), x.split("-")[1])) -def fetch_gondul_switches(match="^e(.*)"): - # credentials = _generate_credentials() - return _sort_switches(_match_switches(_do_switches_request())) +def fetch_gondul_switches(api=None, endpoint=None, username=None, password=None, match="^e(.*)"): + # Use provided arg instead of environment variable if defined. + _api = api if api is not None else GONDUL_API + _endpoint = endpoint if endpoint is not None else GONDUL_SWITCHES_ENDPOINT + _username = username if username is not None else GONDUL_USERNAME + _password = password if password is not None else GONDUL_PASSWORD + credentials = _generate_credentials(_username, _password) + + return _sort_switches( + _match_switches( + _do_switches_request( + api=_api, endpoint=_endpoint, credentials=credentials), + match=match)) -- cgit v1.2.3