From 7099ea7e13bfe9187d264458573aafcfc53aa609 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 9 May 2018 18:58:56 +0100 Subject: [PATCH] add wrapper to get signed in pan.do/ra api --- ox/api.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ox/api.py b/ox/api.py index 6f9aa67..4b56fa6 100644 --- a/ox/api.py +++ b/ox/api.py @@ -137,3 +137,27 @@ class API(object): for chunk in iter(lambda: u.read(chunk_size), b''): fd.write(chunk) shutil.move(tmpname, filename) + + +def signin(site): + from getpass import getpass + from .web import auth + api = API('https://%s/api/' % site) + update = False + try: + credentials = auth.get(site) + except: + credentials = {} + print('Please provide your username and password for %s:' % site) + credentials['username'] = input('Username: ') + credentials['password'] = getpass('Password: ') + update = True + r = api.signin(**credentials) + if 'errors' in r.get('data', {}): + for kv in r['data']['errors'].items(): + print('%s: %s' % kv) + sys.exit(1) + if update: + auth.update(site, credentials) + return api +