From 3b940e9070ac838c64e335a09733f2323bad7c94 Mon Sep 17 00:00:00 2001 From: AaronV77 Date: Thu, 19 Apr 2018 13:49:58 -0500 Subject: [PATCH] Updated the authentication to work with QuestWeb, and added a method for getting the status of a providers authentication. --- quest/api/__init__.py | 3 ++- quest/api/services.py | 26 ++++++++++++++++++++++++-- quest/services/cuahsi_hs.py | 5 ++--- quest/services/kitware_girder.py | 4 ++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/quest/api/__init__.py b/quest/api/__init__.py index b6254bd4..51e92e10 100644 --- a/quest/api/__init__.py +++ b/quest/api/__init__.py @@ -25,6 +25,7 @@ 'download_options', 'get_active_project', 'get_api_version', + 'get_auth_status', 'get_collections', 'get_datasets', 'get_features', @@ -56,7 +57,6 @@ 'save_settings', 'set_active_project', 'stage_for_download', - 'stage_for_publish', 'unauthenticate_provider', 'update_metadata', # replaces update_collection, update_feature, update_dataset 'update_settings', @@ -150,6 +150,7 @@ get_services, add_provider, delete_provider, + get_auth_status, authenticate_provider, unauthenticate_provider, ) diff --git a/quest/api/services.py b/quest/api/services.py index 1dd2a195..0b39c6dc 100644 --- a/quest/api/services.py +++ b/quest/api/services.py @@ -4,6 +4,7 @@ """ from __future__ import absolute_import from __future__ import print_function +from ..api.database import get_db, db_session from .. import util import os import requests @@ -167,7 +168,28 @@ def delete_provider(uri): return msg -def authenticate_provider(uri): +def get_auth_status(uri): + """Check to see if a provider has been authenticated + + Args: + uri (string, Required): + uri of 'user service' + Returns: + True on success + False on not authenticated + + """ + db = get_db() + with db_session: + p = db.Providers.select().filter(provider=uri).first() + + if p is None: + return False + + return True + + +def authenticate_provider(uri, **kwargs): """Authenticate the user. Args: @@ -178,7 +200,7 @@ def authenticate_provider(uri): """ driver = util.load_providers()[uri] - driver.authenticate_me() + driver.authenticate_me(**kwargs) def unauthenticate_provider(uri): diff --git a/quest/services/cuahsi_hs.py b/quest/services/cuahsi_hs.py index 100caf9e..ec33c387 100644 --- a/quest/services/cuahsi_hs.py +++ b/quest/services/cuahsi_hs.py @@ -4,7 +4,6 @@ from shapely.geometry import Point, box from ..api.metadata import get_metadata from ..util import param_util -from getpass import getpass import pandas as pd import param import os @@ -260,8 +259,8 @@ def get_hs(self, auth=None, require_valid_auth=False): def authenticate_me(self, **kwargs): - username = input("Enter Username: ") - password = getpass("Enter Password: ") + username = kwargs['username'] + password = kwargs['password'] try: auth = HydroShareAuthBasic(username=username, password=password) diff --git a/quest/services/kitware_girder.py b/quest/services/kitware_girder.py index ba7bd674..af1f8e6c 100644 --- a/quest/services/kitware_girder.py +++ b/quest/services/kitware_girder.py @@ -77,8 +77,8 @@ def get_gc(self): def authenticate_me(self, **kwargs): connection_info = 'https://data.kitware.com/api/v1' - username = input("Enter Username: ") - password = getpass("Enter Password: ") + username = kwargs['username'] + password = kwargs['password'] try: gc = girder_client.GirderClient(apiUrl=connection_info)