- Notifications
You must be signed in to change notification settings - Fork676
feat(groups): add LDAP link manager and deprecate old API endpoints#2379
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
15 changes: 13 additions & 2 deletionsdocs/gl_objects/groups.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
86 changes: 67 additions & 19 deletionsgitlab/v4/objects/groups.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5,9 +5,16 @@ | ||
import gitlab | ||
from gitlab import cli | ||
from gitlab import exceptions as exc | ||
from gitlab import types, utils | ||
from gitlab.base import RESTManager, RESTObject | ||
from gitlab.mixins import ( | ||
CreateMixin, | ||
CRUDMixin, | ||
DeleteMixin, | ||
ListMixin, | ||
ObjectDeleteMixin, | ||
SaveMixin, | ||
) | ||
from gitlab.types import RequiredOptional | ||
from .access_requests import GroupAccessRequestManager # noqa: F401 | ||
@@ -47,6 +54,8 @@ | ||
"GroupManager", | ||
"GroupDescendantGroup", | ||
"GroupDescendantGroupManager", | ||
"GroupLDAPGroupLink", | ||
"GroupLDAPGroupLinkManager", | ||
"GroupSubgroup", | ||
"GroupSubgroupManager", | ||
] | ||
@@ -74,6 +83,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
issues_statistics: GroupIssuesStatisticsManager | ||
iterations: GroupIterationManager | ||
labels: GroupLabelManager | ||
ldap_group_links: "GroupLDAPGroupLinkManager" | ||
members: GroupMemberManager | ||
members_all: GroupMemberAllManager | ||
mergerequests: GroupMergeRequestManager | ||
@@ -168,6 +178,13 @@ def add_ldap_group_link( | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabCreateError: If the server cannot perform the request | ||
""" | ||
utils.warn( | ||
message=( | ||
"The add_ldap_group_link() method is deprecated and will be removed " | ||
"in a future version. Use ldap_group_links.create() instead." | ||
), | ||
category=DeprecationWarning, | ||
) | ||
path = f"/groups/{self.encoded_id}/ldap_group_links" | ||
data = {"cn": cn, "group_access": group_access, "provider": provider} | ||
self.manager.gitlab.http_post(path, post_data=data, **kwargs) | ||
@@ -188,29 +205,19 @@ def delete_ldap_group_link( | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabDeleteError: If the server cannot perform the request | ||
""" | ||
utils.warn( | ||
message=( | ||
"The delete_ldap_group_link() method is deprecated and will be " | ||
"removed in a future version. Use ldap_group_links.delete() instead." | ||
), | ||
category=DeprecationWarning, | ||
) | ||
path = f"/groups/{self.encoded_id}/ldap_group_links" | ||
if provider is not None: | ||
path += f"/{provider}" | ||
path += f"/{cn}" | ||
self.manager.gitlab.http_delete(path, **kwargs) | ||
Comment on lines -197 to -212 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. No deprecation needed as we haven't released it yet. | ||
@cli.register_custom_action("Group") | ||
@exc.on_http_error(exc.GitlabCreateError) | ||
def ldap_sync(self, **kwargs: Any) -> None: | ||
@@ -416,3 +423,44 @@ class GroupDescendantGroupManager(GroupSubgroupManager): | ||
_path = "/groups/{group_id}/descendant_groups" | ||
_obj_cls: Type[GroupDescendantGroup] = GroupDescendantGroup | ||
class GroupLDAPGroupLink(RESTObject): | ||
_repr_attr = "provider" | ||
def _get_link_attrs(self) -> Dict[str, str]: | ||
# https://docs.gitlab.com/ee/api/groups.html#add-ldap-group-link-with-cn-or-filter | ||
# https://docs.gitlab.com/ee/api/groups.html#delete-ldap-group-link-with-cn-or-filter | ||
# We can tell what attribute to use based on the data returned | ||
data = {"provider": self.provider} | ||
if self.cn: | ||
data["cn"] = self.cn | ||
else: | ||
data["filter"] = self.filter | ||
return data | ||
def delete(self, **kwargs: Any) -> None: | ||
"""Delete the LDAP group link from the server. | ||
Args: | ||
**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 | ||
""" | ||
if TYPE_CHECKING: | ||
assert isinstance(self.manager, DeleteMixin) | ||
self.manager.delete( | ||
self.encoded_id, query_data=self._get_link_attrs(), **kwargs | ||
) | ||
class GroupLDAPGroupLinkManager(ListMixin, CreateMixin, DeleteMixin, RESTManager): | ||
_path = "/groups/{group_id}/ldap_group_links" | ||
_obj_cls: Type[GroupLDAPGroupLink] = GroupLDAPGroupLink | ||
_from_parent_attrs = {"group_id": "id"} | ||
_create_attrs = RequiredOptional( | ||
required=("provider", "group_access"), exclusive=("cn", "filter") | ||
) |
34 changes: 28 additions & 6 deletionstests/functional/api/test_groups.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletionstests/unit/objects/test_groups.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.