Skip to content

Commit ad7c8fa

Browse files
authored
feat(groups): add support for listing ldap_group_links (#2371)
1 parent a0553c2 commit ad7c8fa

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

gitlab/v4/objects/groups.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,23 @@ def delete_ldap_group_link(
194194
path += f"/{cn}"
195195
self.manager.gitlab.http_delete(path, **kwargs)
196196

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+
197214
@cli.register_custom_action("Group")
198215
@exc.on_http_error(exc.GitlabCreateError)
199216
def ldap_sync(self, **kwargs: Any) -> None:

tests/unit/objects/test_groups.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
from gitlab.v4.objects.projects import GroupProject, SharedProject
1313

1414
content = {"name": "name", "id": 1, "path": "path"}
15+
ldap_group_links_content = [
16+
{
17+
"cn": None,
18+
"group_access": 40,
19+
"provider": "ldapmain",
20+
"filter": "(memberOf=cn=some_group,ou=groups,ou=fake_ou,dc=sub_dc,dc=example,dc=tld)",
21+
}
22+
]
1523
projects_content = [
1624
{
1725
"id": 9,
@@ -216,6 +224,19 @@ def resp_delete_push_rules_group(no_content):
216224
yield rsps
217225

218226

227+
@pytest.fixture
228+
def resp_list_ldap_group_links(no_content):
229+
with responses.RequestsMock() as rsps:
230+
rsps.add(
231+
method=responses.GET,
232+
url="http://localhost/api/v4/groups/1/ldap_group_links",
233+
json=ldap_group_links_content,
234+
content_type="application/json",
235+
status=200,
236+
)
237+
yield rsps
238+
239+
219240
def test_get_group(gl, resp_groups):
220241
data = gl.groups.get(1)
221242
assert isinstance(data, gitlab.v4.objects.Group)
@@ -261,6 +282,12 @@ def test_list_group_descendant_groups(group, resp_list_subgroups_descendant_grou
261282
assert descendant_groups[0].path == subgroup_descgroup_content[0]["path"]
262283

263284

285+
def test_list_ldap_group_links(group, resp_list_ldap_group_links):
286+
ldap_group_links = group.list_ldap_group_links()
287+
assert isinstance(ldap_group_links, list)
288+
assert ldap_group_links[0]["provider"] == ldap_group_links_content[0]["provider"]
289+
290+
264291
@pytest.mark.skip("GitLab API endpoint not implemented")
265292
def test_refresh_group_export_status(group, resp_export):
266293
export = group.exports.create()

0 commit comments

Comments
 (0)