Skip to content

Commit

Permalink
feat(groups): add support for listing ldap_group_links (#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayisbadat committed Nov 16, 2022
1 parent a0553c2 commit ad7c8fa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gitlab/v4/objects/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ def delete_ldap_group_link(
path += f"/{cn}"
self.manager.gitlab.http_delete(path, **kwargs)

@cli.register_custom_action("Group")
@exc.on_http_error(exc.GitlabGetError)
def list_ldap_group_links(
self, **kwargs: Any
) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
"""List LDAP group links.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server cannot perform the request
"""
path = f"/groups/{self.encoded_id}/ldap_group_links"
return self.manager.gitlab.http_list(path, **kwargs)

@cli.register_custom_action("Group")
@exc.on_http_error(exc.GitlabCreateError)
def ldap_sync(self, **kwargs: Any) -> None:
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/objects/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
from gitlab.v4.objects.projects import GroupProject, SharedProject

content = {"name": "name", "id": 1, "path": "path"}
ldap_group_links_content = [
{
"cn": None,
"group_access": 40,
"provider": "ldapmain",
"filter": "(memberOf=cn=some_group,ou=groups,ou=fake_ou,dc=sub_dc,dc=example,dc=tld)",
}
]
projects_content = [
{
"id": 9,
Expand Down Expand Up @@ -216,6 +224,19 @@ def resp_delete_push_rules_group(no_content):
yield rsps


@pytest.fixture
def resp_list_ldap_group_links(no_content):
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/groups/1/ldap_group_links",
json=ldap_group_links_content,
content_type="application/json",
status=200,
)
yield rsps


def test_get_group(gl, resp_groups):
data = gl.groups.get(1)
assert isinstance(data, gitlab.v4.objects.Group)
Expand Down Expand Up @@ -261,6 +282,12 @@ def test_list_group_descendant_groups(group, resp_list_subgroups_descendant_grou
assert descendant_groups[0].path == subgroup_descgroup_content[0]["path"]


def test_list_ldap_group_links(group, resp_list_ldap_group_links):
ldap_group_links = group.list_ldap_group_links()
assert isinstance(ldap_group_links, list)
assert ldap_group_links[0]["provider"] == ldap_group_links_content[0]["provider"]


@pytest.mark.skip("GitLab API endpoint not implemented")
def test_refresh_group_export_status(group, resp_export):
export = group.exports.create()
Expand Down

0 comments on commit ad7c8fa

Please sign in to comment.