Skip to content
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: Support LRO mixins over REST #1118

Merged
merged 9 commits into from
Jun 13, 2022
Merged

Conversation

Still to do:
- fix generated import path in operations
- goread service config to change HTTP bindings
This works from the command line:
  curl -i "http://localhost:7469/v1/operations/google.showcase.v1beta1.Echo/Wait/CgwIidqOlQYQl93JqQEaDAoKcmFpbnkganVuZQ==" -H "X-Goog-Api-Client: rest/0.0.0 gapic/0.0.0" -H 'Content-Type: application/json'

Still todo:
- Override HTTP annotations from the config file
@vchudnov-g vchudnov-g requested a review from noahdietz June 10, 2022 23:19
@vchudnov-g vchudnov-g requested a review from a team as a code owner June 10, 2022 23:19
@vchudnov-g
Copy link
Contributor Author

vchudnov-g commented Jun 10, 2022

Note that we also need to add an http rule to the WaitOperation rpc in api-common-proto submodule, which is what's causing CI to fail.

  option (google.api.http) = {
      get: "/v1/{name=operations/**}:wait"
    };

What's SOP for doing this?

@vchudnov-g
Copy link
Contributor Author

Sent out a PR with the HTTP rule: googleapis/api-common-protos#111

router.HandleFunc("/v1beta1/{name:operations/.+}", rest.HandleGetOperation).Methods("GET")
router.HandleFunc("/v1beta1/{name:operations/.+}:delete", rest.HandleDeleteOperation).Methods("DELETE")
router.HandleFunc("/v1beta1/{name:operations/.+}:cancel", rest.HandleCancelOperation).Methods("POST")
router.HandleFunc("/v1/{name:operations/.+}:wait", rest.HandleWaitOperation).Methods("GET")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the approach of generating all the methods in the mixin protos. This means that if they are not referenced in the service config, their http bindings do not get overriden.

And adding WaitOperation to this service config causes a conflict with EchoClient.WaitOperation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we either live with the extra methods, or implement a strategy closer to that in the Go generator to ensure we don't generate the extra methods. Thoughts?

@vchudnov-g
Copy link
Contributor Author

Restructured the code so we only generate code for the listed mixin methods.

Service config path is still hard-coded at the moment.

@@ -13,6 +14,7 @@ require (
github.com/spf13/viper v1.12.0
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: I don't think we need this, we can use stdlib errors because we support go1.13 <

- selector: google.longrunning.Operations.DeleteOperation
delete: '/v1beta1/{name=/operations/*}'
delete: '/v1beta1/{name=operations/**}:delete'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: we shouldn't need the :delete suffix, this isn't a custom method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Thanks for the catch. (And fix)


func init() {
mixinDescriptors = map[string][]*descriptor.FileDescriptorProto{
"google.longrunning.Operations": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: add the other mixin services too (Locations, IAMPolicy)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting some (probably trivial) errors with Locations, so I just excluded the others for now so we could get LRO working. But as you see, I copied your structure from gapic-generator-go so the others would be easy to add back in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants