55import gitlab
66from gitlab import cli
77from gitlab import exceptions as exc
8- from gitlab import types
8+ from gitlab import types , utils
99from gitlab .base import RESTManager , RESTObject
10- from gitlab .mixins import CRUDMixin , ListMixin , ObjectDeleteMixin , SaveMixin
10+ from gitlab .mixins import (
11+ CreateMixin ,
12+ CRUDMixin ,
13+ DeleteMixin ,
14+ ListMixin ,
15+ ObjectDeleteMixin ,
16+ SaveMixin ,
17+ )
1118from gitlab .types import RequiredOptional
1219
1320from .access_requests import GroupAccessRequestManager # noqa: F401
4754 "GroupManager" ,
4855 "GroupDescendantGroup" ,
4956 "GroupDescendantGroupManager" ,
57+ "GroupLDAPGroupLink" ,
58+ "GroupLDAPGroupLinkManager" ,
5059 "GroupSubgroup" ,
5160 "GroupSubgroupManager" ,
5261]
@@ -74,6 +83,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
7483 issues_statistics : GroupIssuesStatisticsManager
7584 iterations : GroupIterationManager
7685 labels : GroupLabelManager
86+ ldap_group_links : "GroupLDAPGroupLinkManager"
7787 members : GroupMemberManager
7888 members_all : GroupMemberAllManager
7989 mergerequests : GroupMergeRequestManager
@@ -168,6 +178,13 @@ def add_ldap_group_link(
168178 GitlabAuthenticationError: If authentication is not correct
169179 GitlabCreateError: If the server cannot perform the request
170180 """
181+ utils .warn (
182+ message = (
183+ "The add_ldap_group_link() method is deprecated and will be removed "
184+ "in a future version. Use ldap_group_links.create() instead."
185+ ),
186+ category = DeprecationWarning ,
187+ )
171188 path = f"/groups/{ self .encoded_id } /ldap_group_links"
172189 data = {"cn" : cn , "group_access" : group_access , "provider" : provider }
173190 self .manager .gitlab .http_post (path , post_data = data , ** kwargs )
@@ -188,29 +205,19 @@ def delete_ldap_group_link(
188205 GitlabAuthenticationError: If authentication is not correct
189206 GitlabDeleteError: If the server cannot perform the request
190207 """
208+ utils .warn (
209+ message = (
210+ "The delete_ldap_group_link() method is deprecated and will be "
211+ "removed in a future version. Use ldap_group_links.delete() instead."
212+ ),
213+ category = DeprecationWarning ,
214+ )
191215 path = f"/groups/{ self .encoded_id } /ldap_group_links"
192216 if provider is not None :
193217 path += f"/{ provider } "
194218 path += f"/{ cn } "
195219 self .manager .gitlab .http_delete (path , ** kwargs )
196220
197- @cli .register_custom_action ("Group" )
198- @exc .on_http_error (exc .GitlabGetError )
199- def list_ldap_group_links (
200- self , ** kwargs : Any
201- ) -> Union [gitlab .GitlabList , List [Dict [str , Any ]]]:
202- """List LDAP group links.
203-
204- Args:
205- **kwargs: Extra options to send to the server (e.g. sudo)
206-
207- Raises:
208- GitlabAuthenticationError: If authentication is not correct
209- GitlabGetError: If the server cannot perform the request
210- """
211- path = f"/groups/{ self .encoded_id } /ldap_group_links"
212- return self .manager .gitlab .http_list (path , ** kwargs )
213-
214221 @cli .register_custom_action ("Group" )
215222 @exc .on_http_error (exc .GitlabCreateError )
216223 def ldap_sync (self , ** kwargs : Any ) -> None :
@@ -416,3 +423,44 @@ class GroupDescendantGroupManager(GroupSubgroupManager):
416423
417424 _path = "/groups/{group_id}/descendant_groups"
418425 _obj_cls : Type [GroupDescendantGroup ] = GroupDescendantGroup
426+
427+
428+ class GroupLDAPGroupLink (RESTObject ):
429+ _repr_attr = "provider"
430+
431+ def _get_link_attrs (self ) -> Dict [str , str ]:
432+ # https://docs.gitlab.com/ee/api/groups.html#add-ldap-group-link-with-cn-or-filter
433+ # https://docs.gitlab.com/ee/api/groups.html#delete-ldap-group-link-with-cn-or-filter
434+ # We can tell what attribute to use based on the data returned
435+ data = {"provider" : self .provider }
436+ if self .cn :
437+ data ["cn" ] = self .cn
438+ else :
439+ data ["filter" ] = self .filter
440+
441+ return data
442+
443+ def delete (self , ** kwargs : Any ) -> None :
444+ """Delete the LDAP group link from the server.
445+
446+ Args:
447+ **kwargs: Extra options to send to the server (e.g. sudo)
448+
449+ Raises:
450+ GitlabAuthenticationError: If authentication is not correct
451+ GitlabDeleteError: If the server cannot perform the request
452+ """
453+ if TYPE_CHECKING :
454+ assert isinstance (self .manager , DeleteMixin )
455+ self .manager .delete (
456+ self .encoded_id , query_data = self ._get_link_attrs (), ** kwargs
457+ )
458+
459+
460+ class GroupLDAPGroupLinkManager (ListMixin , CreateMixin , DeleteMixin , RESTManager ):
461+ _path = "/groups/{group_id}/ldap_group_links"
462+ _obj_cls : Type [GroupLDAPGroupLink ] = GroupLDAPGroupLink
463+ _from_parent_attrs = {"group_id" : "id" }
464+ _create_attrs = RequiredOptional (
465+ required = ("provider" , "group_access" ), exclusive = ("cn" , "filter" )
466+ )
0 commit comments