You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
typeListSCIMProvisionedIdentitiesOptionsstruct {
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 scim.go, I'm seeing that "Filter" already has "omitempty" on it. Are you sure you are using the latest version of this repo?
typeListSCIMProvisionedIdentitiesOptionsstruct {
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"`
}
typeListSCIMProvisionedIdentitiesOptionsstruct {
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 addOptions we use the query.Values to "mount" the query params from the structs.
The test that exists called TestListSCIMProvisionedIdentitiesOptions_Marshal is using the testJSONMarshal to validate. The function Test whether the marshaling of v produces JSON that corresponds to the want string..
Since the tag used refers to json, then the test is passing as expected.
I applied the change and created a test for it and I opened a draft pull request here #2680
I would like feedback on the nomenclatures and structure of the test.
An "interesting" point is that the old test (TestListSCIMProvisionedIdentitiesOptions_Marshal) did not break, even though it doesn't have the "json" tags.
About the test not breaking, I think I found something about that.
Inside the function testJSONMarshal we use the parameter want only once, together with the function json.Unmarshal. But when we do this,Unmarshal is not differentiating between uppercase and lowercase letters (it's case-insensitive).
From json.Unmarshal docs:
To unmarshal JSON into a struct, Unmarshal matches incoming object keys to the keys used by Marshal (either the struct field name or its tag), preferring an exact match but also accepting a case-insensitive match.
Case one: All good!
Case one: {StartIndex:1 Count:10 Filter:test1}
Case two: All good!
Case two: {StartIndex:2 Count:20 Filter:test2}
Case three: All good!
Case three: {StartIndex:3 Count:30 Filter:test3}
Program exited.
So for example, if we take the TestUpdateAttributeForSCIMUserOptions_Marshal test and change the want variable so that the fields start with uppercase letters, the test will still pass successfully.
Activity
exageraldo commentedon Feb 26, 2023
When trying to do the request in a "manual" way (
client.NewRequest+client.Do), the pagination worked perfectly.exageraldo commentedon Feb 26, 2023
I'm also having problems trying to use the caching module (
github.com/gregjones/httpcache) with SCIM routes. It's not creating caches at all.I don't know if these problems are related or not.
gmlewis commentedon Feb 26, 2023
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.
gmlewis commentedon Feb 26, 2023
Also, I'm OOO for a week starting tonight but hopefully others will be able to help you out.
exageraldo commentedon Feb 26, 2023
I notice that the "Filter" field is not omitted as in the other requests.
Within the
ListSCIMProvisionedIdentitiesOptionsstruct the tags start with "json" and not "url" (check more heregithub.com/google/go-querystring/query) as in the other options structures (likeRepositoryListOptionsorCommitsListOptions).I would suggest this solution:
I would like to ask if I can contribute to this solution.
gmlewis commentedon Feb 26, 2023
Hmmm... I'm not seeing a reason for your query parameters to have been capitalized, and in the repo on line 79 of
scim.go, I'm seeing that "Filter" already has "omitempty" on it. Are you sure you are using the latest version of this repo?https://github.com/google/go-github/blob/master/github/scim.go#L68-L80
exageraldo commentedon Feb 26, 2023
yeah, I'm using the latest version.
My suggestion is only to change the prefix of the fields in the
ListSCIMProvisionedIdentitiesOptionsstructure from "json" to "url".Into the function
addOptionswe use thequery.Valuesto "mount" the query params from the structs.A sample from the module docs:
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.
RepositoryListOptions
CommitsListOptions
exageraldo commentedon Feb 26, 2023
The test that exists called
TestListSCIMProvisionedIdentitiesOptions_Marshalis using thetestJSONMarshalto validate. The functionTest whether the marshaling of v produces JSON that corresponds to the want string..Since the tag used refers to json, then the test is passing as expected.
gmlewis commentedon Feb 26, 2023
Ah, I apologize, I misunderstood. Yes, it sounds like what you recommend is what is needed.
The issue is yours. Thanks, @exageraldo !
exageraldo commentedon Feb 26, 2023
Thanks a lot! it's a bit late here now, but by tomorrow I'll send something for review.
exageraldo commentedon Feb 27, 2023
I applied the change and created a test for it and I opened a draft pull request here #2680
I would like feedback on the nomenclatures and structure of the test.
An "interesting" point is that the old test (
TestListSCIMProvisionedIdentitiesOptions_Marshal) did not break, even though it doesn't have the "json" tags.exageraldo commentedon Feb 27, 2023
About the test not breaking, I think I found something about that.
Inside the function
testJSONMarshalwe use the parameterwantonly once, together with the functionjson.Unmarshal. But when we do this,Unmarshalis not differentiating between uppercase and lowercase letters (it's case-insensitive).From
json.Unmarshaldocs:Here are the cases I tested (in go playground):
Output:
So for example, if we take the
TestUpdateAttributeForSCIMUserOptions_Marshaltest and change thewantvariable so that the fields start with uppercase letters, the test will still pass successfully.Output:
That seems to be an old and long conversation: golang/go#14750
Fix SCIM query params (#2680)
Fix SCIM query params (google#2680)
Fix SCIM query params (google#2680)