fixed scicat for new httpclient
This commit is contained in:
@ -24,6 +24,7 @@ class HttpClient(AuthMixin):
|
||||
def __init__(self, address):
|
||||
self.address = address
|
||||
self._verify_certificate = True
|
||||
self.login_path = self.address + "/users/login"
|
||||
super().__init__(address)
|
||||
|
||||
def authenticate(self, username, password):
|
||||
@ -54,7 +55,7 @@ class HttpClient(AuthMixin):
|
||||
return requests.post(url, json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json()
|
||||
|
||||
def _login(self, payload=None, headers=None, timeout=10):
|
||||
return requests.post(self.address + "/users/login", json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json()
|
||||
return requests.post(self.login_path, json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json()
|
||||
|
||||
@staticmethod
|
||||
def make_filter(where:dict=None, limit:int=0, skip:int=0, fields:dict=None, include:dict=None, order:list=None):
|
||||
|
@ -1,28 +1,35 @@
|
||||
from .authmixin import AuthMixin, AuthError, HEADER_JSON
|
||||
from .utils import post_request, get_request
|
||||
from .httpclient import HttpClient
|
||||
|
||||
|
||||
class SciCat(AuthMixin):
|
||||
class SciCatRestAPI(HttpClient):
|
||||
def __init__(self, url):
|
||||
super().__init__(url)
|
||||
self.login_path = "https://dacat.psi.ch/auth/msad"
|
||||
|
||||
def authenticate(self, username, password):
|
||||
url = self.address + "/users/login"
|
||||
auth_payload = {
|
||||
"username": username,
|
||||
"password": password
|
||||
}
|
||||
res = post_request(url, auth_payload, HEADER_JSON)
|
||||
res = self._login(auth_payload, HEADER_JSON)
|
||||
try:
|
||||
token = res["id"]
|
||||
token = res["access_token"]
|
||||
except KeyError as e:
|
||||
raise SciCatAuthError(res) from e
|
||||
else:
|
||||
return token
|
||||
|
||||
class SciCat():
|
||||
|
||||
def __init__(self, url="https://dacat.psi.ch/api/v3/"):
|
||||
self.http_client = SciCatRestAPI(url)
|
||||
|
||||
|
||||
@property
|
||||
def proposals(self):
|
||||
url = self.address + "/proposals"
|
||||
headers = self.auth_headers #TODO
|
||||
return get_request(url, headers=headers)
|
||||
url = self.http_client.address + "/proposals"
|
||||
return self.http_client.get_request(url, headers=HEADER_JSON)
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user