-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
SCIM routes pagination #2679
Comments
When trying to do the request in a "manual" way ( func (gc *GithubClient) ManualListScimProviderUsers(organizationName string) (allSamlUsers []*github.SCIMUserAttributes, err error) {
startIndex := 1
req, err := gc.client.NewRequest(
"GET",
fmt.Sprintf("scim/v2/organizations/%s/Users", organizationName),
nil,
)
q := req.URL.Query()
q.Add("count", fmt.Sprint(gc.perPage))
q.Add("startIndex", fmt.Sprint(startIndex))
for {
req.URL.RawQuery = q.Encode()
scimList := &github.SCIMProvisionedIdentities{}
_, err = gc.client.Do(
context.Background(),
req,
scimList,
)
if err != nil {
fmt.Printf("error: %v", err)
return nil, err
}
allSamlUsers = append(allSamlUsers, scimList.Resources...)
if len(scimList.Resources) < gc.perPage {
break
}
startIndex += gc.perPage
q.Set("startIndex", fmt.Sprint(startIndex))
}
return allSamlUsers, nil
} |
I'm also having problems trying to use the caching module ( I don't know if these problems are related or not. |
Hmmm... That's very odd. I'm on my phone right now, but did you search the code to see if we are capitalizing those parameters? Also, there is another thread already discussing httpcache if you want to search for it... Hopefully you will find it useful, but I know others have had challenges using it too. |
Also, I'm OOO for a week starting tonight but hopefully others will be able to help you out. |
I notice that the "Filter" field is not omitted as in the other requests. I would suggest this solution: type ListSCIMProvisionedIdentitiesOptions struct {
StartIndex *int `url:"startIndex,omitempty"` // Used for pagination: the index of the first result to return. (Optional.)
Count *int `url:"count,omitempty"` // Used for pagination: the number of results to return. (Optional.)
// ...
Filter *string `url:"filter,omitempty"`
} I would like to ask if I can contribute to this solution. |
Hmmm... I'm not seeing a reason for your query parameters to have been capitalized, and in the repo on line 79 of https://github.com/google/go-github/blob/master/github/scim.go#L68-L80 |
yeah, I'm using the latest version. My suggestion is only to change the prefix of the fields in the type ListSCIMProvisionedIdentitiesOptions struct {
StartIndex *int `json:"startIndex,omitempty"` // Used for pagination: the index of the first result to return. (Optional.)
Count *int `json:"count,omitempty"` // Used for pagination: the number of results to return. (Optional.)
// ...
Filter *string `json:"filter,omitempty"`
} type ListSCIMProvisionedIdentitiesOptions struct {
StartIndex *int `url:"startIndex,omitempty"` // Used for pagination: the index of the first result to return. (Optional.)
Count *int `url:"count,omitempty"` // Used for pagination: the number of results to return. (Optional.)
// ...
Filter *string `url:"filter,omitempty"`
} Into the function A sample from the module docs: type Options struct {
Query string `url:"q"`
ShowAll bool `url:"all"`
Page int `url:"page"`
}
opt := Options{ "foo", true, 2 }
v, _ := query.Values(opt)
fmt.Print(v.Encode()) // will output: "q=foo&all=true&page=2" Tags used in other optional parameter structures start with "url". That way the query is assembled correctly and then added to the end of the url. type RepositoryListOptions struct {
Visibility string `url:"visibility,omitempty"`
Affiliation string `url:"affiliation,omitempty"`
Type string `url:"type,omitempty"`
Sort string `url:"sort,omitempty"`
Direction string `url:"direction,omitempty"`
ListOptions
} type CommitsListOptions struct {
SHA string `url:"sha,omitempty"`
Path string `url:"path,omitempty"`
Author string `url:"author,omitempty"`
Since time.Time `url:"since,omitempty"`
Until time.Time `url:"until,omitempty"`
ListOptions
} |
The test that exists called |
Ah, I apologize, I misunderstood. Yes, it sounds like what you recommend is what is needed. |
Thanks a lot! it's a bit late here now, but by tomorrow I'll send something for review. |
I applied the change and created a test for it and I opened a draft pull request here #2680 An "interesting" point is that the old test ( |
About the test not breaking, I think I found something about that. Inside the function From
Here are the cases I tested (in go playground): package main
import (
"encoding/json"
"fmt"
)
func main() {
u := struct {
StartIndex int `url:"startIndex,omitempty"`
Count int `url:"count,omitempty"`
Filter string `url:"filter,omitempty"`
}{
StartIndex: 1,
Count: 10,
Filter: "test",
}
caseOne := `{
"startIndex": 1,
"count": 10,
"filter": "test1"
}`
if err := json.Unmarshal([]byte(caseOne), &u); err != nil {
fmt.Printf("Case one: Unable to unmarshal JSON for %v: %v", caseOne, err)
} else {
fmt.Println("Case one: All good!")
fmt.Printf("Case one: %+v\n", u)
}
caseTwo := `{
"StartIndex": 2,
"Count": 20,
"Filter": "test2"
}`
if err := json.Unmarshal([]byte(caseTwo), &u); err != nil {
fmt.Printf("Case two: Unable to unmarshal JSON for %v: %v", caseTwo, err)
} else {
fmt.Println("Case two: All good!")
fmt.Printf("Case two: %+v\n", u)
}
caseThree := `{
"startindex": 3,
"count": 30,
"filter": "test3"
}`
if err := json.Unmarshal([]byte(caseThree), &u); err != nil {
fmt.Printf("Case three: Unable to unmarshal JSON for %v: %v", caseThree, err)
} else {
fmt.Println("Case three: All good!")
fmt.Printf("Case three: %+v\n", u)
}
} Output:
So for example, if we take the func TestUpdateAttributeForSCIMUserOptions_Marshal(t *testing.T) {
testJSONMarshal(t, &UpdateAttributeForSCIMUserOptions{}, `{}`)
u := &UpdateAttributeForSCIMUserOptions{
Schemas: []string{"test", "schema"},
Operations: UpdateAttributeForSCIMUserOperations{
Op: "TestOp",
Path: String("path"),
},
}
want := `{
"Schemas": ["test", "schema"],
"Operations": {
"Op": "TestOp",
"Path": "path"
}
}`
testJSONMarshal(t, u, want)
} Output:
That seems to be an old and long conversation: golang/go#14750 |
I'm facing a issue when I try to paginate resources from the SCIM provisioned identities list (
client.SCIM.ListSCIMProvisionedIdentities
) and when I try to set the number of items per page.When I added the httpdebug module, I noticed that the query strings are being sent with the first letter capitalized.
In the documentation the parameters start with lower case letters.
And if the parameters are not sent exactly as in the documentation, the value is ignored.
This makes it impossible to paginate this resource because even if the
StartIndex
value is changed and sent, the value is not identified by the Github API.The text was updated successfully, but these errors were encountered: