diff options
author | Leif Johansson <leifj@sunet.se> | 2011-04-05 09:47:55 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-04-05 09:47:55 +0200 |
commit | 79383e47a772e7d9197179c2be8e6b66e160806c (patch) | |
tree | d1ca9d9bba8027135de8a979ec970e22c79ade09 /src/meetingtools/ac | |
parent | ada53ad32e01db69bca2722dc7b836e10b204828 (diff) |
duplicate java provisioning filter logic
Diffstat (limited to 'src/meetingtools/ac')
-rw-r--r-- | src/meetingtools/ac/api.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/meetingtools/ac/api.py b/src/meetingtools/ac/api.py index 679b1ac..bb6847d 100644 --- a/src/meetingtools/ac/api.py +++ b/src/meetingtools/ac/api.py @@ -26,7 +26,10 @@ class ACPResult(): self.status = self.et.find('status') def is_error(self): - return self.status.get('code') != 'ok' + return self.status_code() != 'ok' + + def status_code(self): + return self.status.get('code') def exception(self): raise ACPException,self.status @@ -86,4 +89,38 @@ class ACPClient(): result = self.request('login',{'login':username,'password':password}) if result.is_error(): raise result.exception() -
\ No newline at end of file + + def find_or_create_principal(self,key,value,type,dict): + result = self.request('principal-list',{'filter-%s' % key: value,'filter-type': type}, True) + principal = result.get_principal() + if result.is_error(): + if result.status_code() != 'no_data': + result.exception() + elif not principal: + dict['principal-id'] = principal.get('principal-id') + + update_result = self.request('principal-update',dict) + rp = update_result.get_principal() + if not rp: + rp = principal + return principal + + def find_builtin(self,type): + result = self.request('principal-list', {'filter-type': type}, True) + return result.get_principal() + + def find_group(self,name): + result = self.request('principal-list',{'filter-name':name,'filter-type':'group'},True) + return result.get_principal() + + def add_remove_member(self,principal_id,group_id,is_member): + m = "0" + if is_member: + m = "1" + self.request('group-membership-update',{'group-id': group_id, 'principal-id': principal_id,'is-member':m},True) + + def add_member(self,principal_id,group_id): + return self.add_remove_member(principal_id, group_id, True) + + def remove_member(self,principal_id,group_id): + return self.add_remove_member(principal_id, group_id, False)
\ No newline at end of file |