-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat: implement partial client updates #2411
Conversation
wow, git made such a strange diff :) probably easiest to just look at the |
getting the following error when I try to regenerate the sdk: ❯ make sdk
GOBIN=/Users/mattbonnell/dev/go/github.com/ory/hydra/.bin/ go install github.com/ory/cli
# github.com/ory/jsonschema/v3/httploader
../../../../../go/pkg/mod/github.com/ory/jsonschema/v3@v3.0.1/httploader/httploader.go:27:15: undefined: httpx.NewResilientClientLatencyToleranceMedium
# github.com/ory/cli/cmd/dev/newsletter
../../../../../go/pkg/mod/github.com/ory/cli@v0.0.35/cmd/dev/newsletter/pkg.go:86:12: undefined: httpx.NewResilientClientLatencyToleranceMedium
make: *** [.bin/cli] Error 2 |
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.
This looks pretty much like what I imagined! We obviously need a few tests and so on :) But I think this is almost good as is
client/handler.go
Outdated
"net/http" | ||
"time" | ||
|
||
jsonpatch "github.com/evanphx/json-patch" |
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.
Is this the best library for the job? What alternatives do we have?
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.
The JSON Patch site gives two options for Go implementations, this and another library, https://github.com/mattbaird/jsonpatch. Between the two, this one has more stars (551 vs 89) and more contributors (41 vs 8). This one was also updated more recently (January vs last August). Additionally, this library also supports Merge Patch, which was indicated as a potential alternative in ory/meta#2.
For these reasons, I felt this was the better choice between the two.
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.
Perfect, thank you!
client/handler.go
Outdated
original, err := json.Marshal(c) | ||
if err != nil { | ||
h.r.Writer().WriteError(w, r, err) | ||
return | ||
} | ||
modified, err := patch.Apply(original) | ||
if err != nil { | ||
h.r.Writer().WriteError(w, r, err) | ||
return | ||
} | ||
if err := json.Unmarshal(modified, c); err != nil { | ||
h.r.Writer().WriteError(w, r, err) | ||
return | ||
} |
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.
I think we could wrap this, including DecodePatch, in a helper function in x and add a few test there? Alternatively we could also add this to ory/x/decoderx
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.
I think that would be a good idea! Will investigate this.
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.
Awesome, thank you :)
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.
done! defined a helper in x/json.go
91669b5
to
90081b5
Compare
You can bum ory/cli to a newer version which should fix that! |
Hey, can you help me understand the Isn't I had added the The PR is failing in CI currently at this sdk generation step. |
4a5221c
to
e2f4cba
Compare
I'll look into this now |
because
and
share the operation id. So one should be update and the other maybe patchOAuth2Client? |
spec/api.json
Outdated
"schemes": ["http", "https"], | ||
"tags": ["admin"], | ||
"summary": "Patch an OAuth 2.0 Client", | ||
"operationId": "patchOAuth2Client", |
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.
@aeneasr following up from your last comment:
that's the thing though, it is patchOAuth2Client
as I've defined it, but it seems when that swagger generate
command is run, it replaces spec/api.json
and in the replaced version it has two updateOAuth2Client
s defined for some reason. If you eliminate that first generate command, everything works as expected.
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.
ohhh, i see. i think i was doing things wrong. hang on.
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.
ok. think i've fixed it now.
Hm, generate step failing in pipeline with #!/bin/bash -eo pipefail
swagger generate spec -m -o spec/api.json $(printf -- " -x %s" internal/httpclient -x gopkg.in/square/go-jose.v2)
expected argument for flag `-x, --exclude', but got option `-x'
|
8494cf0
to
ee2b8c4
Compare
LMK when good for another 👀 |
hey, yes ready, looks like all checks are passing edit: pulled in latest changes from master and there seems to be a vulnerability in the version of protobuf being used, causing |
I opened #2434 to fix the nancy warning |
client/handler.go
Outdated
return | ||
} | ||
|
||
if err := x.ApplyJSONPatch(patchJSON, c); err != nil { |
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.
It shouldn't be allowed to update the ID of the client as that is immutable iirc!
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.
Good catch, will fix
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.
fixed.
…hydra into feat/partial-client-updates
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.
Awesome! This looks pretty much good to go, but I think we need another test for the handler which also includes the ID behavior test! Another option would be to add a „deny list“ to the JSON PATCH helper which returns an error if a specific path is updated (e.g. ID). This would make it more general purpose and easier to test :)
done! |
…hydra into feat/partial-client-updates
Thank you! Appreciate your contributions as always :) |
Related issue
#2385
Proposed changes
Checklist
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
security@ory.sh) from the maintainers to push
the changes.
works.
Further comments