Skip to content

Commit

Permalink
Merge pull request #154 from Ouranosinc/api_change_fixes
Browse files Browse the repository at this point in the history
Fix MagpieProcessStore initialisation following some api changes
  • Loading branch information
fmigneault committed Mar 4, 2019
2 parents 150ae21 + 8b4bfb6 commit 17a2386
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions magpie/adapter/magpieprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ def _find_resource_id(self, parent_resource_id, resource_name):
resp = requests.get(path, cookies=self.magpie_admin_token,
headers=self.json_headers, verify=self.twitcher_ssl_verify)
resp.raise_for_status()
return resp.json()[resource_name]['resource_id']
return resp.json()['service']['resource_id']

path = '{host}/resources/{id}'.format(host=self.magpie_url, id=parent_resource_id)
resp = requests.get(path, cookies=self.magpie_admin_token,
headers=self.json_headers, verify=self.twitcher_ssl_verify)
resp.raise_for_status()
child_res_id = None
parent_resource_info = resp.json()[str(parent_resource_id)]
parent_resource_info = resp.json()['resource']
children_resources = parent_resource_info['children']
for res_id in children_resources:
if children_resources[res_id]['resource_name'] == resource_name:
Expand Down Expand Up @@ -280,7 +280,7 @@ def save_process(self, process, overwrite=True, request=None):
resp = requests.get(path, cookies=self.magpie_admin_token,
headers=self.json_headers, verify=self.twitcher_ssl_verify)
resp.raise_for_status()
ems_res_id = resp.json()[self.magpie_service]['resource_id']
ems_res_id = resp.json()['service']['resource_id']
except KeyError:
raise ProcessRegistrationError("Failed retrieving service resource.")
except Exception as ex:
Expand Down
11 changes: 10 additions & 1 deletion magpie/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
)
from six.moves.urllib.parse import urlparse
from typing import Optional, TYPE_CHECKING
from requests.cookies import RequestsCookieJar
import logging
import requests
if TYPE_CHECKING:
Expand All @@ -22,7 +23,15 @@ def get_admin_cookies(magpie_url, verify=True, raise_message=None):
raise_log(raise_message, logger=LOGGER)
raise resp.raise_for_status()
token_name = get_constant('MAGPIE_COOKIE_NAME')
return {token_name: resp.cookies.get(token_name)}

# use specific domain to differentiate between `.{hostname}` and `{hostname}` variations if applicable
# noinspection PyProtectedMember
request_cookies = resp.cookies
magpie_cookies = list(filter(lambda cookie: cookie.name == token_name, request_cookies))
magpie_domain = urlparse(magpie_url).hostname if len(magpie_cookies) > 1 else None
session_cookies = RequestsCookieJar.get(request_cookies, token_name, domain=magpie_domain)

return {token_name: session_cookies}


def get_settings(container):
Expand Down

0 comments on commit 17a2386

Please sign in to comment.