Skip to content

Commit

Permalink
Change grouper base path for generality #60
Browse files Browse the repository at this point in the history
Update grouper_admin and grouper_query modules accordingly
  • Loading branch information
astrochun committed Sep 21, 2020
1 parent ae25c14 commit 639d496
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/figshare.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions requiam/grouper_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ 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"""

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()
Expand All @@ -46,22 +48,24 @@ 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()

def get_group_details(self, group):
"""Retrieve group details. The full path is needed"""

endpoint = self.url('groups')

params = dict()
params['WsRestFindGroupsRequest'] = {
'wsQueryFilter':
{'queryFilterType': 'FIND_BY_GROUP_NAME_APPROXIMATE',
'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']
Expand All @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions requiam/grouper_query.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 639d496

Please sign in to comment.