Skip to content

cris: make dimcli work with cris api #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dimcli/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def __init__(self, show_results=False, verbose=True, auth_session=False):
if self._CONNECTION.token:
# if already logged in, reuse connection
self._url = self._CONNECTION.url
self._headers = {'Authorization': "JWT " + self._CONNECTION.token}
if 'cris-api' in self._url:
self._headers = {'Authorization': "Bearer " + self._CONNECTION.token}
else:
self._headers = {'Authorization': "JWT " + self._CONNECTION.token}
self.verify_ssl = self._CONNECTION.verify_ssl
else:
self._print_please_login()
Expand All @@ -105,7 +108,10 @@ def _refresh_login(self):
if self._CONNECTION:
self._CONNECTION.refresh_login()
self._url = self._CONNECTION.url
self._headers = {'Authorization': "JWT " + self._CONNECTION.token}
if 'cris-api' in self._url:
self._headers = {'Authorization': "Bearer " + self._CONNECTION.token}
else:
self._headers = {'Authorization': "JWT " + self._CONNECTION.token}
self.verify_ssl = self._CONNECTION.verify_ssl
else:
printDebug("Warning: please login first.")
Expand Down Expand Up @@ -1011,4 +1017,4 @@ def __repr__(self):
# 2019-12-17: for backward compatibility
# remove once all notebooks code has been updated
Result = DslDataset
Dataset = DslDataset
Dataset = DslDataset
20 changes: 15 additions & 5 deletions dimcli/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,17 @@ def login(self,

login_data = {'username': username, 'password': password, 'key': key}

# POST AUTH REQUEST
response = requests.post(URL_AUTH, json=login_data, verify=verify_ssl)
response.raise_for_status()
if 'cris-api' in URL_QUERY:
login_data = {'api_key': key}
response = requests.get(URL_AUTH, params=login_data, verify=verify_ssl)
response.raise_for_status()
token = response.text
else:
# POST AUTH REQUEST
response = requests.post(URL_AUTH, json=login_data, verify=verify_ssl)
response.raise_for_status()

token = response.json()['token']
token = response.json()['token']

self.instance = instance
self.url = URL_QUERY
Expand Down Expand Up @@ -194,7 +200,11 @@ def _get_endpoint_urls(self, user_url):

"""
url_auth, url_query = None, None
if "/api/" in user_url:
if "cris-api" in user_url:
domain = user_url.split("/api/")[0]
url_auth = domain + "/token"
url_query = domain + "/api/query"
elif "/api/" in user_url:
# savy user passing the full QUERY URL
domain = user_url.split("/api/")[0]
url_auth = domain + "/api/auth.json"
Expand Down