5
5
import gitlab
6
6
from gitlab import cli
7
7
from gitlab import exceptions as exc
8
- from gitlab import types
8
+ from gitlab import types , utils
9
9
from 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
+ )
11
18
from gitlab .types import RequiredOptional
12
19
13
20
from .access_requests import GroupAccessRequestManager # noqa: F401
47
54
"GroupManager" ,
48
55
"GroupDescendantGroup" ,
49
56
"GroupDescendantGroupManager" ,
57
+ "GroupLDAPGroupLink" ,
58
+ "GroupLDAPGroupLinkManager" ,
50
59
"GroupSubgroup" ,
51
60
"GroupSubgroupManager" ,
52
61
]
@@ -74,6 +83,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
74
83
issues_statistics : GroupIssuesStatisticsManager
75
84
iterations : GroupIterationManager
76
85
labels : GroupLabelManager
86
+ ldap_group_links : "GroupLDAPGroupLinkManager"
77
87
members : GroupMemberManager
78
88
members_all : GroupMemberAllManager
79
89
mergerequests : GroupMergeRequestManager
@@ -168,6 +178,13 @@ def add_ldap_group_link(
168
178
GitlabAuthenticationError: If authentication is not correct
169
179
GitlabCreateError: If the server cannot perform the request
170
180
"""
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
+ )
171
188
path = f"/groups/{ self .encoded_id } /ldap_group_links"
172
189
data = {"cn" : cn , "group_access" : group_access , "provider" : provider }
173
190
self .manager .gitlab .http_post (path , post_data = data , ** kwargs )
@@ -188,29 +205,19 @@ def delete_ldap_group_link(
188
205
GitlabAuthenticationError: If authentication is not correct
189
206
GitlabDeleteError: If the server cannot perform the request
190
207
"""
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
+ )
191
215
path = f"/groups/{ self .encoded_id } /ldap_group_links"
192
216
if provider is not None :
193
217
path += f"/{ provider } "
194
218
path += f"/{ cn } "
195
219
self .manager .gitlab .http_delete (path , ** kwargs )
196
220
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
-
214
221
@cli .register_custom_action ("Group" )
215
222
@exc .on_http_error (exc .GitlabCreateError )
216
223
def ldap_sync (self , ** kwargs : Any ) -> None :
@@ -416,3 +423,44 @@ class GroupDescendantGroupManager(GroupSubgroupManager):
416
423
417
424
_path = "/groups/{group_id}/descendant_groups"
418
425
_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