Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebf822c

Browse files
author
Gauvain Pocentek
committed
Add support for the LDAP gorups API
1 parent5183069 commitebf822c

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

‎docs/gl_objects/groups.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,23 @@ LDAP group links
177177

178178
Add an LDAP group link to an existing GitLab group::
179179

180-
group.add_ldap_group_link(ldap_group_cn, gitlab.DEVELOPER_ACCESS, 'main')
180+
group.add_ldap_group_link(ldap_group_cn, gitlab.DEVELOPER_ACCESS, 'ldapmain')
181181

182182
Remove a link::
183183

184-
group.delete_ldap_group_link(ldap_group_cn, 'main')
184+
group.delete_ldap_group_link(ldap_group_cn, 'ldapmain')
185185

186186
Sync the LDAP groups::
187187

188188
group.ldap_sync()
189+
190+
You can use the ``ldapgroups`` manager to list available LDAP groups::
191+
192+
# listing (supports pagination)
193+
ldap_groups = gl.ldapgroups.list()
194+
195+
# filter using a group name
196+
ldap_groups = gl.ldapgroups.list(search='foo')
197+
198+
# list the groups for a specific LDAP provider
199+
ldap_groups = gl.ldapgroups.list(search='foo', provider='ldapmain')

‎gitlab/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(self, url, private_token=None, oauth_token=None, email=None,
111111
self.groups=objects.GroupManager(self)
112112
self.hooks=objects.HookManager(self)
113113
self.issues=objects.IssueManager(self)
114+
self.ldapgroups=objects.LDAPGroupManager(self)
114115
self.licenses=objects.LicenseManager(self)
115116
self.namespaces=objects.NamespaceManager(self)
116117
self.notificationsettings=objects.NotificationSettingsManager(self)

‎gitlab/v4/objects.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,50 @@ class IssueManager(ListMixin, RESTManager):
907907
_types= {'labels':types.ListAttribute}
908908

909909

910+
classLDAPGroup(RESTObject):
911+
_id_attr=None
912+
913+
914+
classLDAPGroupManager(RESTManager):
915+
_path='/ldap/groups'
916+
_obj_cls=LDAPGroup
917+
_list_filters= ('search','provider')
918+
919+
@exc.on_http_error(exc.GitlabListError)
920+
deflist(self,**kwargs):
921+
"""Retrieve a list of objects.
922+
923+
Args:
924+
all (bool): If True, return all the items, without pagination
925+
per_page (int): Number of items to retrieve per request
926+
page (int): ID of the page to return (starts with page 1)
927+
as_list (bool): If set to False and no pagination option is
928+
defined, return a generator instead of a list
929+
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
930+
931+
Returns:
932+
list: The list of objects, or a generator if `as_list` is False
933+
934+
Raises:
935+
GitlabAuthenticationError: If authentication is not correct
936+
GitlabListError: If the server cannot perform the request
937+
"""
938+
data=kwargs.copy()
939+
ifself.gitlab.per_page:
940+
data.setdefault('per_page',self.gitlab.per_page)
941+
942+
if'provider'indata:
943+
path='/ldap/%s/groups'%data['provider']
944+
else:
945+
path=self._path
946+
947+
obj=self.gitlab.http_list(path,**data)
948+
ifisinstance(obj,list):
949+
return [self._obj_cls(self,item)foriteminobj]
950+
else:
951+
returnbase.RESTObjectList(self,self._obj_cls,obj)
952+
953+
910954
classLicense(RESTObject):
911955
_id_attr='key'
912956

‎tools/ee-test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def end_log():
7777
ifhasattr(group1,'ldap_group_links'):
7878
forlinkingroup1.ldap_group_links:
7979
group1.delete_ldap_group_link(link['cn'],link['provider'])
80+
assert(gl.ldapgroups.list())
8081
group1.add_ldap_group_link(LDAP_CN,30,LDAP_PROVIDER)
8182
group1.ldap_sync()
8283
group1.delete_ldap_group_link(LDAP_CN)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp