-
Notifications
You must be signed in to change notification settings - Fork 0
Add group membership provisioning (Grant/Revoke) #33
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,38 @@ func (b *groupBuilder) Grants(ctx context.Context, resource *v2.Resource, pToken | |
| return grantResources, "", nil, nil | ||
| } | ||
|
|
||
| func (b *groupBuilder) Grant(ctx context.Context, principal *v2.Resource, entitlement *v2.Entitlement) (annotations.Annotations, error) { | ||
| if principal.Id.ResourceType != userResourceType.Id { | ||
| return nil, fmt.Errorf("baton-atlassian: only users can be granted group membership") | ||
| } | ||
|
|
||
| groupID := entitlement.Resource.Id.Resource | ||
| userID := principal.Id.Resource | ||
|
|
||
| err := b.client.AddUserToGroup(ctx, groupID, userID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("baton-atlassian: failed to add user to group: %w", err) | ||
| } | ||
|
|
||
| return nil, nil | ||
|
Comment on lines
+209
to
+214
Contributor
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. 🟡 Suggestion: Grant is not idempotent. If the user is already a member, Atlassian's membership POST typically returns 409, which surfaces here as an error and fails the access request. Consider detecting the already-exists case and returning |
||
| } | ||
|
|
||
| func (b *groupBuilder) Revoke(ctx context.Context, grant *v2.Grant) (annotations.Annotations, error) { | ||
| if grant.Principal.Id.ResourceType != userResourceType.Id { | ||
| return nil, fmt.Errorf("baton-atlassian: only users can be removed from group membership") | ||
| } | ||
|
|
||
| groupID := grant.Entitlement.Resource.Id.Resource | ||
| userID := grant.Principal.Id.Resource | ||
|
|
||
| err := b.client.RemoveUserFromGroup(ctx, groupID, userID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("baton-atlassian: failed to remove user from group: %w", err) | ||
| } | ||
|
|
||
| return nil, nil | ||
|
Comment on lines
+225
to
+230
Contributor
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. 🟡 Suggestion: Revoke is not idempotent. If the membership no longer exists, the DELETE likely returns 404 and this returns an error rather than treating it as already-revoked. Consider detecting not-found and returning |
||
| } | ||
|
|
||
| func parseIntoGroupResource(group client.Group) (*v2.Resource, error) { | ||
| profile := map[string]interface{}{ | ||
| "name": group.Name, | ||
|
|
||
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.
🟡 Suggestion: This deletes the membership by treating
accountIDas the final path segment of.../memberships/{id}. Confirm the Atlassian Admin v2 membership API keys the DELETE on the user'saccountIdrather than a distinct membership ID — if it expects a membership ID, revokes will 404. The PR notes manual testing is still pending, so please verify this against a live tenant. (confidence: low)