Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit 30d8eb0a authored by Rob Carleski's avatar Rob Carleski 🇮🇸
Browse files

Add ability to manipulate groups via their CNs

parent 40f357f8
......@@ -84,6 +84,22 @@ class Client:
self.token = r.json()['access_token']
def _patient_get(self, endpoint):
for x in range(int(self.retries)):
r = self.session.get(
url=self.call_url + endpoint,
headers=self.headers,
timeout=self.timeout
)
if r.status_code == requests.codes.ok:
if r.json():
return r.json()
else:
time.sleep(float(self.backoff_factor)**x)
continue
else:
return False
def _validate_name(self, name):
"""Validate a given name against MCommunity standards
......@@ -129,30 +145,23 @@ class Client:
return name.lower()
name = self._validate_name(name)
endpoint = self.call_url + '/find/both/{}'.format(name)
for x in range(int(self.retries)):
r = self.session.get(
url=endpoint,
headers=self.headers,
timeout=self.timeout
)
if r.status_code == requests.codes.ok:
if r.json():
break
else:
time.sleep(float(self.backoff_factor)**x)
continue
else:
raise Exception('Unable to find {} in Mcommunity'.format(name))
data = r.json()
for item in data:
if item['person']:
if item['naming'] == name:
return item['dn'].lower()
elif item['group']:
if item['displayName'] == name:
return item['dn'].lower()
data = self._patient_get('/find/both/{}'.format(name))
if data:
for item in data:
if item['person']:
if item['naming'].lower() == name.lower():
return item['dn'].lower()
elif item['group']:
if item['displayName'].lower() == name.lower():
return item['dn'].lower()
else:
_group = self._patient_get('/profile/dn/{}'.format(
item['dn']
))
if _group:
if name in _group['group'][0]['aliases']:
return item['dn'].lower()
raise Exception('Unable to find {} in Mcommunity'.format(name))
def _apply_update(self, endpoint):
"""Generic update function
......
[
{
"dn": "cn=testgroup,ou=User Groups,ou=Groups,dc=umich,dc=edu",
"naming": null,
"displayName": "testgroup",
"email": null,
"displayTitle": null,
"title": null,
"affiliation": null,
"description": null,
"member": false,
"owner": false,
"moderator": false,
"person": false,
"group": true,
"external": false,
"securityEquals": null,
"groupMembership": null,
"role": null
}
]
......@@ -13,6 +13,12 @@ def test_group_fetch(mock_mcomm):
assert conn.group_data['name'] == 'testgroup'
def test_group_fetch_by_cn(mock_mcomm):
conn = mcommunity.Client(config=config)
conn.fetch_group('alias1')
assert conn.group_data['name'] == 'testgroup'
def test_person_fetch(mock_mcomm):
conn = mcommunity.Client(config=config)
person = conn.fetch_person('testuser')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment