-
Notifications
You must be signed in to change notification settings - Fork 0
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
ref: Use Rate Limits #10
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
15c447c
Add rate limit annotations to groups
mgaeta 0cefb77
Refactor users list to use pagination and rate limits
mgaeta 869ec4f
Add group provisioning
mgaeta 72f6d91
fix lint
mgaeta 484d5b1
Use User Search API to get users
mgaeta a22e7a4
lint
mgaeta cc9188a
fix tests
mgaeta 0e558ab
fix missing query parameter
mgaeta e708c31
filter out deactivated users
mgaeta 279c9eb
fix
mgaeta c2a64f9
revert user list back to 2d scheme
mgaeta 976ca00
User search + group members
mgaeta a06e2c5
fix tests
mgaeta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
CurrentUserUrlPath = "/wiki/rest/api/user/current" | ||
GroupsListUrlPath = "/wiki/rest/api/group" | ||
getUsersByGroupIdUrlPath = "/wiki/rest/api/group/%s/membersByGroupId" | ||
groupBaseUrlPath = "/wiki/rest/api/group/userByGroupId" | ||
spacePermissionsCreateUrlPath = "/wiki/rest/api/space/%s/permissions" | ||
spacePermissionsUpdateUrlPath = "/wiki/rest/api/space/%s/permissions/%s" | ||
SpacesListUrlPath = "/wiki/api/v2/spaces" | ||
spacesGetUrlPath = "/wiki/api/v2/spaces/%s" | ||
SpacePermissionsListUrlPath = "/wiki/api/v2/spaces/%s/permissions" | ||
SearchUrlPath = "/wiki/rest/api/search/user" | ||
addUsersToGroupUrlPath = "/wiki/rest/api/group/userByGroupId?groupId=%s" | ||
removeUsersFromGroupUrlPath = "/wiki/rest/api/group/userByGroupId?groupId=%s&accountId=%s" | ||
) | ||
|
||
type Option = func(*url.URL) (*url.URL, error) | ||
|
||
func withQueryParameters(parameters map[string]interface{}) Option { | ||
return func(url *url.URL) (*url.URL, error) { | ||
query := url.Query() | ||
for key, interfaceValue := range parameters { | ||
var stringValue string | ||
switch actualValue := interfaceValue.(type) { | ||
case string: | ||
stringValue = actualValue | ||
case int: | ||
stringValue = strconv.Itoa(actualValue) | ||
case bool: | ||
if actualValue { | ||
stringValue = "1" | ||
} else { | ||
stringValue = "0" | ||
} | ||
default: | ||
return nil, fmt.Errorf("invalid query parameter type %s", actualValue) | ||
} | ||
query.Set(key, stringValue) | ||
} | ||
url.RawQuery = query.Encode() | ||
return url, nil | ||
} | ||
} | ||
|
||
// withLimitAndOffset adds `start` and `limit` query parameters to a URL. This | ||
// pagination parameter is only used by the v1 REST API. | ||
func withLimitAndOffset(pageToken string, pageSize int) Option { | ||
maximum := pageSize | ||
if maximum == 0 || maximum > maxResults { | ||
maximum = maxResults | ||
} | ||
|
||
return withQueryParameters(map[string]interface{}{ | ||
"limit": maximum, | ||
"start": pageToken, | ||
}) | ||
} | ||
|
||
// WithPaginationCursor uses Confluence Cloud's REST API v2 pagination scheme. | ||
func WithPaginationCursor( | ||
pageSize int, | ||
paginationCursor string, | ||
) Option { | ||
maximum := pageSize | ||
if maximum == 0 || maximum > maxResults { | ||
maximum = maxResults | ||
} | ||
|
||
parameters := map[string]interface{}{ | ||
"limit": maximum, | ||
} | ||
if paginationCursor != "" { | ||
parameters["cursor"] = paginationCursor | ||
} | ||
|
||
return withQueryParameters(parameters) | ||
} | ||
|
||
func (c *ConfluenceClient) parse( | ||
path string, | ||
options ...Option, | ||
) (*url.URL, error) { | ||
parsed, err := url.Parse(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse request path '%s': %w", path, err) | ||
} | ||
parsedUrl := c.apiBase.ResolveReference(parsed) | ||
for _, option := range options { | ||
parsedUrl, err = option(parsedUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return parsedUrl, nil | ||
} |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -12,3 +12,14 @@ func annotationsForUserResourceType() annotations.Annotations { | |
annos.Update(&v2.SkipEntitlementsAndGrants{}) | ||
return annos | ||
} | ||
|
||
func WithRateLimitAnnotations( | ||
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. A function like this one should probably live in baton-sdk at some point. |
||
ratelimitDescriptionAnnotations ...*v2.RateLimitDescription, | ||
) annotations.Annotations { | ||
outputAnnotations := annotations.Annotations{} | ||
for _, annotation := range ratelimitDescriptionAnnotations { | ||
outputAnnotations.Append(annotation) | ||
} | ||
|
||
return outputAnnotations | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Tip
Codebase Verification
Comprehensive testing needed for
Revoke
methodThe
Revoke
method ingroupResourceType
does not appear to have any direct unit tests. To ensure its functionality and reliability, it is crucial to add comprehensive tests for this method.pkg/connector/group.go
Analysis chain
New method looks good! Ensure comprehensive testing.
The
Revoke
method encapsulates the logic for removing users from groups and handles rate limit data. Ensure that the method is thoroughly tested.Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 62
Script:
Length of output: 141145
Script:
Length of output: 43