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