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
22 changes: 11 additions & 11 deletions magpie/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,9 @@

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

Check warning on line 779 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L779

Added line #L779 was 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 781 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L781

Added line #L781 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 +859,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 863 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L863

Added line #L863 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 865 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L865

Added line #L865 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 871 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L871

Added line #L871 was not covered by tests
return action_resp

def _apply_session(_usr_name=None, _grp_name=None):
Expand Down Expand Up @@ -921,10 +920,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 923 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L923

Added line #L923 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 926 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L926

Added line #L926 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 +1102,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 1106 in magpie/register.py

View check run for this annotation

Codecov / codecov/patch

magpie/register.py#L1105-L1106

Added lines #L1105 - L1106 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