From 639d496ebd6325b955a27fd1c063b627333ce3d8 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 21 Sep 2020 09:41:26 -0700 Subject: [PATCH] Change grouper base path for generality #60 Update grouper_admin and grouper_query modules accordingly --- config/figshare.ini | 2 +- requiam/grouper_admin.py | 15 +++++++++------ requiam/grouper_query.py | 8 +++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config/figshare.ini b/config/figshare.ini index c17b9475..0e122e02 100644 --- a/config/figshare.ini +++ b/config/figshare.ini @@ -18,7 +18,7 @@ ldap_base_dn = dc=eds,dc=arizona,dc=edu ldap_user = figshare ldap_password = ***override*** grouper_host = grouper.iam.arizona.edu -grouper_base_path = grouper-ws/servicesRest/json/v2_2_001/groups +grouper_base_path = grouper-ws/servicesRest/json/v2_2_001 grouper_user = figshare grouper_password = ***override*** batch_size = 100 diff --git a/requiam/grouper_admin.py b/requiam/grouper_admin.py index ecf99b05..03eafa08 100644 --- a/requiam/grouper_admin.py +++ b/requiam/grouper_admin.py @@ -29,7 +29,7 @@ def __init__(self, grouper_host, grouper_base_path, grouper_user, def url(self, endpoint): """Return URL endpoint""" - return f"{self.endpoint}/{endpoint}" + return join(self.endpoint, endpoint) def get_group_list(self, group_type): """Retrieve list of groups in a Grouper stem""" @@ -37,6 +37,8 @@ def get_group_list(self, group_type): if group_type not in ['portal', 'quota', 'test', '']: raise ValueError("Incorrect [group_type] input") + endpoint = self.url('groups') + grouper_stem = figshare_stem(group_type, production=self.grouper_production) params = dict() @@ -46,7 +48,7 @@ def get_group_list(self, group_type): 'stemName': grouper_stem} } - rsp = requests.post(self.endpoint, json=params, headers=self.headers, + rsp = requests.post(endpoint, json=params, headers=self.headers, auth=(self.grouper_user, self.grouper_password)) return rsp.json() @@ -54,6 +56,8 @@ def get_group_list(self, group_type): def get_group_details(self, group): """Retrieve group details. The full path is needed""" + endpoint = self.url('groups') + params = dict() params['WsRestFindGroupsRequest'] = { 'wsQueryFilter': @@ -61,7 +65,7 @@ def get_group_details(self, group): 'groupName': group} } - rsp = requests.post(self.endpoint, json=params, headers=self.headers, + rsp = requests.post(endpoint, json=params, headers=self.headers, auth=(self.grouper_user, self.grouper_password)) return rsp.json()['WsFindGroupsResults']['groupResults'] @@ -87,7 +91,7 @@ def check_group_exists(self, group, group_type): def add_group(self, group, group_type, description): """Create Grouper group within a Grouper stem""" - endpoint = self.url("") + endpoint = self.url("groups") if group_type not in ['portal', 'quota', 'test']: raise ValueError("Incorrect [group_type] input") @@ -134,8 +138,7 @@ def add_privilege(self, access_group, target_group, target_group_type, privilege :return: True on success, otherwise raises GrouperAPIException """ - # This is a hack. The endpoint needs to change so "groups" is not hardcoded. - endpoint = join(dirname(self.endpoint), 'grouperPrivileges') + endpoint = self.url('grouperPrivileges') # Check privileges if isinstance(privileges, str): diff --git a/requiam/grouper_query.py b/requiam/grouper_query.py index d21d61f2..d66595de 100644 --- a/requiam/grouper_query.py +++ b/requiam/grouper_query.py @@ -1,5 +1,6 @@ import requests +from os.path import join from .delta import Delta from .manual_override import update_entries from .commons import figshare_stem @@ -33,9 +34,10 @@ def __init__(self, grouper_host, grouper_base_path, grouper_user, grouper_passwo self.grouper_password = grouper_password self.grouper_group = grouper_group - self.grouper_group_members_url = 'https://{}/{}/{}/members'.format(grouper_host, - grouper_base_path, - grouper_group) + self.endpoint = f'https://{grouper_host}/{grouper_base_path}' + + self.grouper_group_members_url = join(self.endpoint, + f'groups/{grouper_group}/members') rsp = requests.get(self.grouper_group_members_url, auth=(grouper_user, grouper_password))