Skip to content

Commit

Permalink
Add grouper_admin module
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochun committed Jul 28, 2020
1 parent 3e3b765 commit 65ea345
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions requiam/grouper_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import requests
import pandas as pd

from .commons import figshare_stem


class GrouperAPI:

def __init__(self, grouper_host, grouper_base_path, grouper_user, grouper_password):

self.grouper_host = grouper_host
self.grouper_base_dn = grouper_base_path
self.grouper_user = grouper_user
self.grouper_password = grouper_password

self.endpoint = 'https://{}/{}'.format(grouper_host, grouper_base_path)
self.headers = {'Content-Type': 'text/x-json'}

def get_group_list(self, group_type):
"""Retrieve list of groups in a Grouper stem"""

if group_type not in ['portal', 'quota', '']:
raise ValueError("Incorrect [group_type] input")

grouper_group = figshare_stem(group_type)

params = dict()
params['WsRestFindGroupsRequest'] = {'wsQueryFilter':
{'queryFilterType': 'FIND_BY_STEM_NAME',
'stemName': grouper_group}}

rsp = requests.post(self.endpoint, auth=(self.grouper_user, self.grouper_password),
json=params, headers=self.headers)

return rsp.json()

def check_group_exists(self, group, group_type):
"""Check whether a Grouper group exists within a Grouper stem"""

if group_type not in ['portal', 'quota']:
raise ValueError("Incorrect [group_type] input")

if group_type:
grouper_group = figshare_stem('portal')

result = self.get_group_list(group_type)

group_df = pd.DataFrame(result['WsFindGroupsResults']['groupResults'])

df_query = group_df.loc[group_df['displayExtension'] == group]
status = True if not df_query.empty else False
return status



0 comments on commit 65ea345

Please sign in to comment.