-
Notifications
You must be signed in to change notification settings - Fork 671
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
Conversation
For issue #1609 |
Have tested this manually on a real gitlab instance. I could not see any automated tests for gitlab -> ldap features |
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
2322542
to
772e79a
Compare
Fixed 2 linting issues. One was commit message so had to force push |
There was a problem hiding this 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:
python-gitlab/gitlab/v4/objects/groups.py
Lines 112 to 150 in 227607c
@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 :)
"GroupLdapLinks", | ||
"GroupLdapLinksManager", |
There was a problem hiding this comment.
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)
"GroupLdapLinks", | |
"GroupLdapLinksManager", | |
"GroupLdapLink", | |
"GroupLdapLinkManager", |
@@ -71,6 +73,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
subgroups: "GroupSubgroupManager" | |||
variables: GroupVariableManager | |||
wikis: GroupWikiManager | |||
ldap_group_links: "GroupLdapLinksManager" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ldap_group_links: "GroupLdapLinksManager" | |
ldap_group_links: "GroupLdapLinkManager" |
@@ -320,6 +323,16 @@ class GroupSubgroupManager(ListMixin, RESTManager): | |||
_types = {"skip_groups": types.ListAttribute} | |||
|
|||
|
|||
class GroupLdapLinks(RESTObject): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class GroupLdapLinks(RESTObject): | |
class GroupLdapLink(RESTObject): |
class GroupLdapLinksManager(ListMixin, RESTManager): | ||
_path = "/groups/%(group_id)s/ldap_group_links" | ||
_obj_cls = GroupLdapLinks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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. |
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. |
You can currently add or delete ldap links but you can't query existing links