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

Support access to MethodOptions fields at runtime #555

Open
arbassett opened this issue Feb 3, 2021 · 0 comments
Open

Support access to MethodOptions fields at runtime #555

arbassett opened this issue Feb 3, 2021 · 0 comments
Labels
A-build A-tonic C-request Category: A feature request, i.e: not implemented / a PR.

Comments

@arbassett
Copy link

arbassett commented Feb 3, 2021

Feature Request

Crates

tonic-build

Motivation

the option field in methods can be used to access contextual information. an example of this would required permissions

syntax = "proto3";

package teams;

import "annotations.proto";

service Teams {
  rpc CreateTeam  (CreateTeamReq) returns (CreateTeamRes) {
    option (annotation.policy).resource = "teams";
    option (annotation.policy).action = "teams:create";
  }
}

message CreateTeamReq {
}

message CreateTeamRes {
}

Having access to this information at runtime would allow building a interceptor that can generically authorize the request before build called

Proposal

Add option values to request.

This should probably be hidden behind a option in the Builder. ideally this could also include whitelisting options. (example to not include googles grpc http transcoding annotations)

prost seems to already support getting option values for methods via the options.uninterpreted_option

some potential issues may be dealing with multiple files and tracking imports. with the example above there is 3 files used

  • teams.proto
  • annotations.proto
  • policy.proto

the annotations.proto just defines the MethodData while policy.proto contains the message

// annotations.proto
syntax = "proto3";

package annotation;

import "policy.proto";
import "google/protobuf/descriptor.proto";

extend google.protobuf.MethodOptions {
  policy.PolicyInfo policy = 50001;
}

// policy.proto
syntax = "proto3";

package policy;

message PolicyInfo {
  string resource = 1;
  string action = 2;
};

tonic-build has no issue with building this example with annotations.rs being a empty file and policy.rs containing just 1 struct for the message

edit: originally I said the values should be added into metadata but that wouldn't make sense as metadata is for binary and ascii data. after looking around this request also seems related to #255 as the values would have to be stored in something like anymap or http::extentions

@davidpdrsn davidpdrsn added the C-request Category: A feature request, i.e: not implemented / a PR. label Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build A-tonic C-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

2 participants