Skip to content

Commit 59dd03d

Browse files
committed
Rudimentary client
1 parent 51acaa1 commit 59dd03d

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

mrmat_python_api_flask/client.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def oidc_check_auth(config: Dict, discovery: Dict, device_auth: Dict):
9898
raise ClientException(msg=body['error_description'])
9999
elif resp.status_code == 200:
100100
return resp.json()
101+
log.info('Waiting for %d seconds', wait)
101102
sleep(wait)
102103

103104

@@ -116,13 +117,25 @@ def parse_args(argv: List[str]) -> Optional[Namespace]:
116117
parser.add_argument('-q', '--quiet', action='store_true', dest='quiet', help='Silent Operation')
117118
parser.add_argument('-d', '--debug', action='store_true', dest='debug', help='Debug')
118119

120+
parser.add_argument('--host',
121+
dest='host',
122+
required=False,
123+
default='localhost',
124+
help='Host interface to connect to')
125+
parser.add_argument('--port',
126+
dest='port',
127+
required=False,
128+
default=8080,
129+
help='Port to connect to')
130+
119131
config_group_file = parser.add_argument_group(title='File Configuration',
120132
description='Configure the client via a config file')
121133
config_group_file.add_argument('--config', '-c',
122134
dest='config',
123135
required=False,
124-
default=os.path.join(os.environ['HOME'], 'etc',
125-
'mrmat-python-api-flask-client.json'),
136+
default=os.path.expanduser(os.path.join('~',
137+
'etc',
138+
'mrmat-python-api-flask-client.json')),
126139
help='Path to the configuration file for the flask client')
127140

128141
config_group_manual = parser.add_argument_group(title='Manual Configuration',
@@ -187,7 +200,7 @@ def main(argv=None) -> int:
187200
raise ClientException(msg='No expires_in in device_auth')
188201

189202
# Adding the user code to the URL is convenient, but not as secure as it could be
190-
log.info('Please visit {} within {} seconds and enter code {}. Or just visit {}',
203+
log.info('Please visit %s within %d seconds and enter code %s. Or just visit %s',
191204
device_auth['verification_uri'],
192205
device_auth['expires_in'],
193206
device_auth['user_code'],
@@ -199,9 +212,9 @@ def main(argv=None) -> int:
199212
#
200213
# We're using requests directly here because requests_oauthlib doesn't support device code flow directly
201214

202-
resp = requests.get('http://127.0.0.1:5000/api/greeting/v3/',
215+
resp = requests.get(f'http://{args.host}:{args.port}/api/greeting/v3/',
203216
headers={'Authorization': f'Bearer {auth["id_token"]}'})
204-
log.info('Status Code: {}', resp.status_code)
217+
log.info('Status Code: %d', resp.status_code)
205218
log.info(resp.content)
206219

207220
return 0

0 commit comments

Comments
 (0)