Skip to content

fix permissions update from config using requests code path #610

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

Merged
merged 11 commits into from
Jun 11, 2024
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Features / Changes
~~~~~~~~~~~~~~~~~~~~~
* Security fix: bump Docker base ``python:3.11-alpine3.19``.

Bug Fixes
~~~~~~~~~
* Fix `Permission` update from configuration file using the ``requests`` code path.

.. _changes_4.0.0:

`4.0.0 <https://github.com/Ouranosinc/Magpie/tree/4.0.0>`_ (2024-04-26)
Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def ignore_down_providers():
# ignore false-positive broken links to local doc files used for rendering on GitHub
"CHANGES.rst",
r"docs/\w+.rst",
"https://wso2.com/", # sporadic broken (probably robots or similar)
"https://docs.wso2.com/*",
"https://pcmdi.llnl.gov/", # works, but very often causes false-positive 'broken' links
] + ignore_down_providers()
linkcheck_anchors_ignore = [
Expand Down
23 changes: 12 additions & 11 deletions magpie/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,10 @@

res_path = None
if _use_request(cookies_or_session):
res_path = get_magpie_url() + ServiceResourcesAPI.path.format(service_name=svc_name)
magpie_url = magpie_url or get_magpie_url()
res_path = magpie_url + ServiceResourcesAPI.path.format(service_name=svc_name)

Check warning on line 780 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L779-L780

Added lines #L779 - L780 were not covered by tests
res_resp = requests.get(res_path, cookies=cookies_or_session, timeout=5)
svc_json = get_json(res_resp)[svc_name] # type: JSON
res_dict = svc_json["resources"]
res_dict = get_json(res_resp)[svc_name] # type: JSON

Check warning on line 782 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L782

Added line #L782 was not covered by tests
else:
from magpie.api.management.service.service_formats import format_service_resources
svc = models.Service.by_service_name(svc_name, db_session=cookies_or_session)
Expand Down Expand Up @@ -860,16 +860,16 @@
Apply operation using HTTP request.
"""
action_oper = None
if usr_name:
action_oper = UserResourcePermissionsAPI.format(user_name=_usr_name, resource_id=resource_id)
if grp_name:
action_oper = GroupResourcePermissionsAPI.format(group_name=_grp_name, resource_id=resource_id)
if _usr_name:
action_oper = UserResourcePermissionsAPI.path.format(user_name=_usr_name, resource_id=resource_id)

Check warning on line 864 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L864

Added line #L864 was not covered by tests
if _grp_name:
action_oper = GroupResourcePermissionsAPI.path.format(group_name=_grp_name, resource_id=resource_id)

Check warning on line 866 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L866

Added line #L866 was not covered by tests
if not action_oper:
return None
action_func = requests.post if create_perm else requests.delete
action_body = {"permission": perm.json()}
action_path = "{url}{path}".format(url=magpie_url, path=action_oper)
action_resp = action_func(action_path, json=action_body, cookies=cookies_or_session)
action_resp = action_func(action_path, json=action_body, cookies=cookies_or_session, timeout=5)

Check warning on line 872 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L872

Added line #L872 was not covered by tests
return action_resp

def _apply_session(_usr_name=None, _grp_name=None):
Expand Down Expand Up @@ -921,10 +921,10 @@
if _use_request(cookies_or_session):
if _usr_name:
path = "{url}{path}".format(url=magpie_url, path=UsersAPI.path)
return requests.post(path, json=usr_data, timeout=5)
return requests.post(path, json=usr_data, cookies=cookies_or_session, timeout=5)

Check warning on line 924 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L924

Added line #L924 was not covered by tests
if _grp_name:
path = "{url}{path}".format(url=magpie_url, path=GroupsAPI.path)
return requests.post(path, json=grp_data, timeout=5)
return requests.post(path, json=grp_data, cookies=cookies_or_session, timeout=5)

Check warning on line 927 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L927

Added line #L927 was not covered by tests
else:
if _usr_name:
from magpie.api.management.user.user_utils import create_user
Expand Down Expand Up @@ -1103,7 +1103,8 @@
if svc_resp.status_code != 200:
_handle_permission("Unknown service [{!s}]".format(svc_name), i, raise_errors=raise_errors)
continue
service_info = get_json(svc_resp)[svc_name]
service_json = get_json(svc_resp)
service_info = service_json.get(svc_name) or service_json.get("service") # format depends on magpie version

Check warning on line 1107 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L1106-L1107

Added lines #L1106 - L1107 were not covered by tests
else:
transaction.commit() # force any pending transaction to be applied to find possible dependencies
svc = models.Service.by_service_name(svc_name, db_session=cookies_or_session)
Expand Down
Loading