Skip to content

Commit 52a738b

Browse files
Google APIscopybara-github
authored andcommitted
feat: Add a proto message to describe the resource_type and resource_permission for an API method
PiperOrigin-RevId: 550688034
1 parent 2ad3b4c commit 52a738b

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

google/api/BUILD.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ proto_library(
6868
name = "control_proto",
6969
srcs = ["control.proto"],
7070
visibility = ["//visibility:public"],
71+
deps = [
72+
":policy_proto",
73+
],
7174
)
7275

7376
proto_library(
@@ -169,6 +172,15 @@ proto_library(
169172
deps = [":annotations_proto"],
170173
)
171174

175+
proto_library(
176+
name = "policy_proto",
177+
srcs = ["policy.proto"],
178+
deps = [
179+
":visibility_proto",
180+
"@com_google_protobuf//:descriptor_proto",
181+
],
182+
)
183+
172184
proto_library(
173185
name = "quota_proto",
174186
srcs = ["quota.proto"],
@@ -211,6 +223,7 @@ proto_library(
211223
":metric_proto",
212224
":monitored_resource_proto",
213225
":monitoring_proto",
226+
":policy_proto",
214227
":quota_proto",
215228
":resource_proto",
216229
":source_info_proto",
@@ -286,6 +299,7 @@ java_proto_library(
286299
"metric_proto",
287300
"monitored_resource_proto",
288301
"monitoring_proto",
302+
"policy_proto",
289303
"quota_proto",
290304
"resource_proto",
291305
"routing_proto",
@@ -327,6 +341,7 @@ java_gapic_assembly_gradle_pkg(
327341
"metric_proto",
328342
"monitored_resource_proto",
329343
"monitoring_proto",
344+
"policy_proto",
330345
"quota_proto",
331346
"resource_proto",
332347
"routing_proto",
@@ -449,6 +464,7 @@ go_proto_library(
449464
":log_proto",
450465
":logging_proto",
451466
":monitoring_proto",
467+
":policy_proto",
452468
":quota_proto",
453469
":service_proto",
454470
":source_info_proto",
@@ -585,6 +601,11 @@ cc_proto_library(
585601
deps = [":monitoring_proto"],
586602
)
587603

604+
cc_proto_library(
605+
name = "policy_cc_proto",
606+
deps = [":policy_proto"],
607+
)
608+
588609
cc_proto_library(
589610
name = "quota_cc_proto",
590611
deps = [":quota_proto"],
@@ -740,6 +761,11 @@ py_proto_library(
740761
deps = ["monitoring_proto"],
741762
)
742763

764+
py_proto_library(
765+
name = "policy_py_proto",
766+
deps = [":policy_proto"],
767+
)
768+
743769
py_proto_library(
744770
name = "quota_py_proto",
745771
deps = ["quota_proto"],
@@ -815,6 +841,7 @@ php_proto_library(
815841
"metric_proto",
816842
"monitored_resource_proto",
817843
"monitoring_proto",
844+
"policy_proto",
818845
"quota_proto",
819846
"resource_proto",
820847
"routing_proto",

google/api/control.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ syntax = "proto3";
1616

1717
package google.api;
1818

19+
import "google/api/policy.proto";
20+
1921
option go_package = "google.golang.org/genproto/googleapis/api/serviceconfig;serviceconfig";
2022
option java_multiple_files = true;
2123
option java_outer_classname = "ControlProto";
@@ -33,4 +35,7 @@ message Control {
3335
// feature (like quota and billing) will be enabled. The recommended value for
3436
// most services is servicecontrol.googleapis.com
3537
string environment = 1;
38+
39+
// Defines policies applying to the API methods of the service.
40+
repeated MethodPolicy method_policies = 4;
3641
}

google/api/policy.proto

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
package google.api;
18+
19+
import "google/protobuf/descriptor.proto";
20+
21+
option cc_enable_arenas = true;
22+
option go_package = "google.golang.org/genproto/googleapis/api/serviceconfig;serviceconfig";
23+
option java_multiple_files = true;
24+
option java_outer_classname = "PolicyProto";
25+
option java_package = "com.google.api";
26+
option objc_class_prefix = "GAPI";
27+
28+
// Provides `google.api.field_policy` annotation at proto fields.
29+
extend google.protobuf.FieldOptions {
30+
// See [FieldPolicy][].
31+
FieldPolicy field_policy = 158361448;
32+
}
33+
34+
// Provides `google.api.method_policy` annotation at proto methods.
35+
extend google.protobuf.MethodOptions {
36+
// See [MethodPolicy][].
37+
MethodPolicy method_policy = 161893301;
38+
}
39+
40+
// Google API Policy Annotation
41+
//
42+
// This message defines a simple API policy annotation that can be used to
43+
// annotate API request and response message fields with applicable policies.
44+
// One field may have multiple applicable policies that must all be satisfied
45+
// before a request can be processed. This policy annotation is used to
46+
// generate the overall policy that will be used for automatic runtime
47+
// policy enforcement and documentation generation.
48+
message FieldPolicy {
49+
// Selects one or more request or response message fields to apply this
50+
// `FieldPolicy`.
51+
//
52+
// When a `FieldPolicy` is used in proto annotation, the selector must
53+
// be left as empty. The service config generator will automatically fill
54+
// the correct value.
55+
//
56+
// When a `FieldPolicy` is used in service config, the selector must be a
57+
// comma-separated string with valid request or response field paths,
58+
// such as "foo.bar" or "foo.bar,foo.baz".
59+
string selector = 1;
60+
61+
// Specifies the required permission(s) for the resource referred to by the
62+
// field. It requires the field contains a valid resource reference, and
63+
// the request must pass the permission checks to proceed. For example,
64+
// "resourcemanager.projects.get".
65+
string resource_permission = 2;
66+
67+
// Specifies the resource type for the resource referred to by the field.
68+
string resource_type = 3;
69+
}
70+
71+
// Defines policies applying to an RPC method.
72+
message MethodPolicy {
73+
// Selects a method to which these policies should be enforced, for example,
74+
// "google.pubsub.v1.Subscriber.CreateSubscription".
75+
//
76+
// Refer to [selector][google.api.DocumentationRule.selector] for syntax
77+
// details.
78+
//
79+
// NOTE: This field must not be set in the proto annotation. It will be
80+
// automatically filled by the service config compiler .
81+
string selector = 9;
82+
83+
// Policies that are applicable to the request message.
84+
repeated FieldPolicy request_policies = 2;
85+
}

0 commit comments

Comments
 (0)