Skip to content

Add support for query ldap groups links #1612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

andrewlarssen
Copy link

You can currently add or delete ldap links but you can't query existing links

@andrewlarssen
Copy link
Author

For issue #1609

@andrewlarssen
Copy link
Author

Have tested this manually on a real gitlab instance. I could not see any automated tests for gitlab -> ldap features

@codecov-commenter
Copy link

codecov-commenter commented Sep 26, 2021

Codecov Report

Merging #1612 (772e79a) into master (7ea4ddc) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1612      +/-   ##
==========================================
+ Coverage   91.59%   91.61%   +0.01%     
==========================================
  Files          74       74              
  Lines        4272     4279       +7     
==========================================
+ Hits         3913     3920       +7     
  Misses        359      359              
Flag Coverage Δ
cli_func_v4 81.63% <100.00%> (+0.03%) ⬆️
py_func_v4 80.64% <100.00%> (+0.03%) ⬆️
unit 83.40% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gitlab/v4/objects/groups.py 87.87% <100.00%> (+0.67%) ⬆️

@andrewlarssen
Copy link
Author

Fixed 2 linting issues. One was commit message so had to force push

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @andrewlarssen! Just a comment on naming consistency. If you're able to add some unit tests to this, would also be great! Here https://github.com/python-gitlab/python-gitlab/blob/master/tests/unit/objects/test_groups.py or you could create a new test_ldap_links.py if it's getting too crowded there. Unit tests mock the responses so we can test EE features there.

While reviewing this I noticed our existing method for deletion uses deprecated API endpoints: https://docs.gitlab.com/ee/api/groups.html#delete-ldap-group-link

So as a bonus if you find time, I think these methods actually could be removed and you can add the CreateMixin/DeleteMixin to the manager, and ObjectDeleteMixin to the object. Then we could remove the custom methods here:

@cli.register_custom_action("Group", ("cn", "group_access", "provider"))
@exc.on_http_error(exc.GitlabCreateError)
def add_ldap_group_link(self, cn, group_access, provider, **kwargs):
"""Add an LDAP group link.
Args:
cn (str): CN of the LDAP group
group_access (int): Minimum access level for members of the LDAP
group
provider (str): LDAP provider for the LDAP group
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabCreateError: If the server cannot perform the request
"""
path = "/groups/%s/ldap_group_links" % self.get_id()
data = {"cn": cn, "group_access": group_access, "provider": provider}
self.manager.gitlab.http_post(path, post_data=data, **kwargs)
@cli.register_custom_action("Group", ("cn",), ("provider",))
@exc.on_http_error(exc.GitlabDeleteError)
def delete_ldap_group_link(self, cn, provider=None, **kwargs):
"""Delete an LDAP group link.
Args:
cn (str): CN of the LDAP group
provider (str): LDAP provider for the LDAP group
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabDeleteError: If the server cannot perform the request
"""
path = "/groups/%s/ldap_group_links" % self.get_id()
if provider is not None:
path += "/%s" % provider
path += "/%s" % cn
self.manager.gitlab.http_delete(path)
)

This would be a breaking change, but we have a major release coming up anyway. Let me know if this makes sense or you need help. Also, you'll just need to amend your message again as commitlint does not like capitalized sentences :)

Comment on lines +41 to +42
"GroupLdapLinks",
"GroupLdapLinksManager",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other objects, we should use the single (the API also supports adding a single link)

Suggested change
"GroupLdapLinks",
"GroupLdapLinksManager",
"GroupLdapLink",
"GroupLdapLinkManager",

@@ -71,6 +73,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
subgroups: "GroupSubgroupManager"
variables: GroupVariableManager
wikis: GroupWikiManager
ldap_group_links: "GroupLdapLinksManager"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ldap_group_links: "GroupLdapLinksManager"
ldap_group_links: "GroupLdapLinkManager"

@@ -320,6 +323,16 @@ class GroupSubgroupManager(ListMixin, RESTManager):
_types = {"skip_groups": types.ListAttribute}


class GroupLdapLinks(RESTObject):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GroupLdapLinks(RESTObject):
class GroupLdapLink(RESTObject):

Comment on lines +330 to +332
class GroupLdapLinksManager(ListMixin, RESTManager):
_path = "/groups/%(group_id)s/ldap_group_links"
_obj_cls = GroupLdapLinks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GroupLdapLinksManager(ListMixin, RESTManager):
_path = "/groups/%(group_id)s/ldap_group_links"
_obj_cls = GroupLdapLinks
class GroupLdapLinkManager(ListMixin, RESTManager):
_path = "/groups/%(group_id)s/ldap_group_links"
_obj_cls = GroupLdapLink

@github-actions
Copy link

github-actions bot commented Jan 8, 2022

This Pull Request (PR) was marked stale because it has been open 90 days with no activity. Please remove the stale label or comment on this PR. Otherwise, it will be closed in 15 days.

@github-actions github-actions bot added the stale label Jan 8, 2022
@github-actions
Copy link

This PR was closed because it has been marked stale for 15 days with no activity. If this PR is still valid, please re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants