summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-06-13 22:01:48 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2018-06-13 22:01:48 +0200
commitebf822cef7e686d8a198dcf419c20b1bfb88dea3 (patch)
treecedd504652d23863f6e7350805cec15cbd75842d
parent5183069722224914bd6c2d25996163861183415b (diff)
downloadgitlab-ebf822cef7e686d8a198dcf419c20b1bfb88dea3.tar.gz
Add support for the LDAP gorups API
-rw-r--r--docs/gl_objects/groups.rst15
-rw-r--r--gitlab/__init__.py1
-rw-r--r--gitlab/v4/objects.py44
-rwxr-xr-xtools/ee-test.py1
4 files changed, 59 insertions, 2 deletions
diff --git a/docs/gl_objects/groups.rst b/docs/gl_objects/groups.rst
index 9eddcd9..5ef5469 100644
--- a/docs/gl_objects/groups.rst
+++ b/docs/gl_objects/groups.rst
@@ -177,12 +177,23 @@ LDAP group links
Add an LDAP group link to an existing GitLab group::
- group.add_ldap_group_link(ldap_group_cn, gitlab.DEVELOPER_ACCESS, 'main')
+ group.add_ldap_group_link(ldap_group_cn, gitlab.DEVELOPER_ACCESS, 'ldapmain')
Remove a link::
- group.delete_ldap_group_link(ldap_group_cn, 'main')
+ group.delete_ldap_group_link(ldap_group_cn, 'ldapmain')
Sync the LDAP groups::
group.ldap_sync()
+
+You can use the ``ldapgroups`` manager to list available LDAP groups::
+
+ # listing (supports pagination)
+ ldap_groups = gl.ldapgroups.list()
+
+ # filter using a group name
+ ldap_groups = gl.ldapgroups.list(search='foo')
+
+ # list the groups for a specific LDAP provider
+ ldap_groups = gl.ldapgroups.list(search='foo', provider='ldapmain')
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index b6ef5b5..4a79551 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -111,6 +111,7 @@ class Gitlab(object):
self.groups = objects.GroupManager(self)
self.hooks = objects.HookManager(self)
self.issues = objects.IssueManager(self)
+ self.ldapgroups = objects.LDAPGroupManager(self)
self.licenses = objects.LicenseManager(self)
self.namespaces = objects.NamespaceManager(self)
self.notificationsettings = objects.NotificationSettingsManager(self)
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index d01d32f..4a401df 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -907,6 +907,50 @@ class IssueManager(ListMixin, RESTManager):
_types = {'labels': types.ListAttribute}
+class LDAPGroup(RESTObject):
+ _id_attr = None
+
+
+class LDAPGroupManager(RESTManager):
+ _path = '/ldap/groups'
+ _obj_cls = LDAPGroup
+ _list_filters = ('search', 'provider')
+
+ @exc.on_http_error(exc.GitlabListError)
+ def list(self, **kwargs):
+ """Retrieve a list of objects.
+
+ Args:
+ all (bool): If True, return all the items, without pagination
+ per_page (int): Number of items to retrieve per request
+ page (int): ID of the page to return (starts with page 1)
+ as_list (bool): If set to False and no pagination option is
+ defined, return a generator instead of a list
+ **kwargs: Extra options to send to the Gitlab server (e.g. sudo)
+
+ Returns:
+ list: The list of objects, or a generator if `as_list` is False
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabListError: If the server cannot perform the request
+ """
+ data = kwargs.copy()
+ if self.gitlab.per_page:
+ data.setdefault('per_page', self.gitlab.per_page)
+
+ if 'provider' in data:
+ path = '/ldap/%s/groups' % data['provider']
+ else:
+ path = self._path
+
+ obj = self.gitlab.http_list(path, **data)
+ if isinstance(obj, list):
+ return [self._obj_cls(self, item) for item in obj]
+ else:
+ return base.RESTObjectList(self, self._obj_cls, obj)
+
+
class License(RESTObject):
_id_attr = 'key'
diff --git a/tools/ee-test.py b/tools/ee-test.py
index 40e4f07..b171e68 100755
--- a/tools/ee-test.py
+++ b/tools/ee-test.py
@@ -77,6 +77,7 @@ start_log('LDAP links')
if hasattr(group1, 'ldap_group_links'):
for link in group1.ldap_group_links:
group1.delete_ldap_group_link(link['cn'], link['provider'])
+assert(gl.ldapgroups.list())
group1.add_ldap_group_link(LDAP_CN, 30, LDAP_PROVIDER)
group1.ldap_sync()
group1.delete_ldap_group_link(LDAP_CN)