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

Clean up protos #138

Merged
merged 4 commits into from
Jun 3, 2024
Merged

Clean up protos #138

merged 4 commits into from
Jun 3, 2024

Conversation

rmehta19
Copy link
Collaborator

@rmehta19 rmehta19 commented May 24, 2024

Summary of changes:

  • add identity to v2 common.proto
  • tokenmanager accepts v1 and v2 identity
  • regenerate all protos [1]
  • in s2a.go, use proto.Marshal / Unmarshal to convert v1 identity to v2 identity
  • remove usage of v1 common.proto from v2 code

[1]: example commands to regenerate protos (for reference):

protoc -I . --proto_path=internal/proto/v2/s2a --go_out=internal/proto/v2/s2a_go_proto internal/proto/v2/s2a/s2a.proto
protoc --go-grpc_out=internal/proto/v2/s2a_go_proto internal/proto/v2/s2a/s2a.proto

@rmehta19 rmehta19 self-assigned this May 24, 2024
@rmehta19 rmehta19 force-pushed the merge-proto branch 2 times, most recently from e45b501 to e4bf9d3 Compare May 24, 2024 23:44
@@ -65,6 +66,14 @@ func (m *singleTokenAccessTokenManager) DefaultToken() (string, error) {
}

// Token always returns the token managed by the singleTokenAccessTokenManager.
func (m *singleTokenAccessTokenManager) Token(*commonpb.Identity) (string, error) {
func (m *singleTokenAccessTokenManager) Token(identity interface{}) (string, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some notes:

Other option: have two methods: Token(*commonpbv1.Identity) and TokenV2(*commonpb.Identity)

@@ -53,3 +53,25 @@ enum AlpnProtocol {
ALPN_PROTOCOL_HTTP2 = 2;
ALPN_PROTOCOL_HTTP1_1 = 3;
}

message Identity {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we have duplicate copies of the Identity message - is that intentional?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it makes sense to move the Identity here, instead of creating a new copy of definition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes -- duplicating Identity messsage was intentional in common.proto and v2/common.proto, as discussed offline a few month's ago:
"we could also add the Identity message to the V2 files...combining the two common.proto files into one is probably infeasible, I think, because the enums are incompatible". This change aligns the v2 protos with the copy in grpc-proto being used by the S2A Java client: grpc/grpc-proto#149

Re: I wonder if it makes sense to move the Identity here, instead of creating a new copy of definition?

I think this would be possible. We could create identity.proto which just contains the Identity message, and this could be used by both v1 and v2. IIRC, the goal as to not share protos between v1 and v2, but if we are ok with identity.proto being shared between the two, I don't see a problem.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! I had forgotten the details of this discussion. :)

@matthewstevenson88 matthewstevenson88 requested a review from xmenxk May 28, 2024 19:26
@xmenxk
Copy link
Collaborator

xmenxk commented May 28, 2024

Summary of changes:

  • add identity to v2 common.proto
  • tokenmanager accepts v1 and v2 identity
  • regenerate all protos [1]
  • in s2a.go, use proto.Marshal / Unmarshal to convert v1 identity to v2 identity
  • remove usage of v1 common.proto from v2 code

[1]: example commands to regenerate protos (for reference):

protoc -I . --proto_path=internal/proto/v2/s2a --go_out=internal/proto/v2/s2a_go_proto internal/proto/v2/s2a/s2a.proto
protoc --go-grpc_out=internal/proto/v2/s2a_go_proto internal/proto/v2/s2a/s2a.proto

We have a script for proto generation at:
https://github.com/google/s2a-go/blob/main/tools/proto/regenerate_proto.sh

Can we use that script and apply any updates if needed? thanks

@rmehta19
Copy link
Collaborator Author

Summary of changes:

  • add identity to v2 common.proto
  • tokenmanager accepts v1 and v2 identity
  • regenerate all protos [1]
  • in s2a.go, use proto.Marshal / Unmarshal to convert v1 identity to v2 identity
  • remove usage of v1 common.proto from v2 code

[1]: example commands to regenerate protos (for reference):

protoc -I . --proto_path=internal/proto/v2/s2a --go_out=internal/proto/v2/s2a_go_proto internal/proto/v2/s2a/s2a.proto
protoc --go-grpc_out=internal/proto/v2/s2a_go_proto internal/proto/v2/s2a/s2a.proto

We have a script for proto generation at: https://github.com/google/s2a-go/blob/main/tools/proto/regenerate_proto.sh

Can we use that script and apply any updates if needed? thanks

Done -- thanks for pointing this out! Latest commit contains result of running script. The only changes are to the example protos.

default:
return "", fmt.Errorf("Incorrect identity type: %v", v)
}
if identity == nil || cmp.Equal(identity, &commonpbv1.Identity{}, protocmp.Transform()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need a cmp.Equal check against &commonpb.Identity{} as well, or this alone is sufficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this -- done!

s2a.go Outdated
Comment on lines 160 to 177
var marshalledLocalIdentities [][]byte
for _, localIdentity := range localIdentities {
marshalledLocalIdentity, err := proto.Marshal(localIdentity)
if err != nil {
return nil, err
}
marshalledLocalIdentities = append(marshalledLocalIdentities, marshalledLocalIdentity)
}
var v2LocalIdentities []*commonpb.Identity
for _, marshalledLocalIdentity := range marshalledLocalIdentities {
v2LocalIdentity := &commonpb.Identity{}
err := proto.Unmarshal(marshalledLocalIdentity, v2LocalIdentity)
if err != nil {
return nil, err
}
v2LocalIdentities = append(v2LocalIdentities, v2LocalIdentity)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think it would be better to have a separate toProtoIdentity() function for the v2 identity? instead of doing the marshal & un-marshal conversion.

My understanding is that at some point in the future, the v1/legacy code can be removed, and the marshal/unmarshal logic will need to be replaced anyway. wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding is the same as yours. I have added a new toV2ProtoIdentity function in s2a_options.go, and replaced the marshal/unmarshal logic with this.

@rmehta19 rmehta19 merged commit a862ab1 into google:main Jun 3, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants