Skip to content

Commit f7c89e4

Browse files
committed
protobuf: Switch to protovalidate
Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent dba9d58 commit f7c89e4

File tree

17 files changed

+70
-76
lines changed

17 files changed

+70
-76
lines changed

bazel/api_build_system.bzl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
load("@com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library")
21
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
32
load("@com_github_grpc_grpc//bazel:python_rules.bzl", _py_proto_library = "py_proto_library")
3+
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
44
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
55
load("@io_bazel_rules_go//go:def.bzl", "go_test")
66
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")
@@ -27,7 +27,7 @@ _COMMON_PROTO_DEPS = [
2727
"@com_google_protobuf//:wrappers_proto",
2828
"@com_google_googleapis//google/api:http_proto",
2929
"@com_google_googleapis//google/rpc:status_proto",
30-
"@com_envoyproxy_protoc_gen_validate//validate:validate_proto",
30+
"@protovalidate//proto/protovalidate/buf/validate:validate_proto",
3131
]
3232

3333
def _proto_mapping(dep, proto_dep_map, proto_suffix):
@@ -68,14 +68,8 @@ def _xds_cc_py_proto_library(
6868
visibility = visibility,
6969
)
7070
cc_proto_library_name = name + _CC_PROTO_SUFFIX
71-
pgv_cc_proto_library(
71+
cc_proto_library(
7272
name = cc_proto_library_name,
73-
linkstatic = linkstatic,
74-
cc_deps = [_cc_proto_mapping(dep) for dep in deps] + [
75-
"@com_google_googleapis//google/api:http_cc_proto",
76-
"@com_google_googleapis//google/api:httpbody_cc_proto",
77-
"@com_google_googleapis//google/rpc:status_cc_proto",
78-
],
7973
deps = [relative_name],
8074
visibility = ["//visibility:public"],
8175
)
@@ -113,9 +107,9 @@ def xds_proto_package(
113107
has_services = has_services,
114108
)
115109

116-
compilers = ["@io_bazel_rules_go//proto:go_proto", "@com_envoyproxy_protoc_gen_validate//bazel/go:pgv_plugin_go"]
110+
compilers = ["@io_bazel_rules_go//proto:go_proto"]
117111
if has_services:
118-
compilers = ["@io_bazel_rules_go//proto:go_proto", "@io_bazel_rules_go//proto:go_grpc_v2", "@com_envoyproxy_protoc_gen_validate//bazel/go:pgv_plugin_go"]
112+
compilers = ["@io_bazel_rules_go//proto:go_proto", "@io_bazel_rules_go//proto:go_grpc_v2"]
119113

120114
# Because RBAC proro depends on googleapis syntax.proto and checked.proto,
121115
# which share the same go proto library, it causes duplicative dependencies.
@@ -127,12 +121,12 @@ def xds_proto_package(
127121
proto = name,
128122
visibility = ["//visibility:public"],
129123
deps = depset([_go_proto_mapping(dep) for dep in deps] + [
130-
"@com_envoyproxy_protoc_gen_validate//validate:go_default_library",
131124
"@org_golang_google_protobuf//types/known/anypb:go_default_library",
132125
"@org_golang_google_protobuf//types/known/durationpb:go_default_library",
133126
"@org_golang_google_protobuf//types/known/structpb:go_default_library",
134127
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
135128
"@org_golang_google_protobuf//types/known/wrapperspb:go_default_library",
129+
"@protovalidate_go_gen//buf/validate",
136130
]).to_list(),
137131
)
138132

udpa/data/orca/v1/orca_load_report.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ option java_multiple_files = true;
1111
option java_package = "com.github.udpa.udpa.data.orca.v1";
1212
option go_package = "github.com/cncf/xds/go/udpa/data/orca/v1";
1313

14-
import "validate/validate.proto";
14+
import "buf/validate/validate.proto";
1515

1616
// See section `ORCA load report format` of the design document in
1717
// :ref:`https://github.com/envoyproxy/envoy/issues/6614`.
1818

1919
message OrcaLoadReport {
2020
// CPU utilization expressed as a fraction of available CPU resources. This
2121
// should be derived from the latest sample or measurement.
22-
double cpu_utilization = 1 [(validate.rules).double.gte = 0, (validate.rules).double.lte = 1];
22+
double cpu_utilization = 1 [(buf.validate.field).double.gte = 0, (buf.validate.field).double.lte = 1];
2323

2424
// Memory utilization expressed as a fraction of available memory
2525
// resources. This should be derived from the latest sample or measurement.
26-
double mem_utilization = 2 [(validate.rules).double.gte = 0, (validate.rules).double.lte = 1];
26+
double mem_utilization = 2 [(buf.validate.field).double.gte = 0, (buf.validate.field).double.lte = 1];
2727

2828
// Total RPS being served by an endpoint. This should cover all services that an endpoint is
2929
// responsible for.
@@ -36,5 +36,5 @@ message OrcaLoadReport {
3636
// Resource utilization values. Each value is expressed as a fraction of total resources
3737
// available, derived from the latest sample or measurement.
3838
map<string, double> utilization = 5
39-
[(validate.rules).map.values.double.gte = 0, (validate.rules).map.values.double.lte = 1];
39+
[(buf.validate.field).map.values.double.gte = 0, (buf.validate.field).map.values.double.lte = 1];
4040
}

xds/core/v3/authority.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package xds.core.v3;
44

55
import "xds/annotations/v3/status.proto";
66

7-
import "validate/validate.proto";
7+
import "buf/validate/validate.proto";
88

99
option java_outer_classname = "AuthorityProto";
1010
option java_multiple_files = true;
@@ -15,7 +15,7 @@ option (xds.annotations.v3.file_status).work_in_progress = true;
1515

1616
// xDS authority information.
1717
message Authority {
18-
string name = 1 [(validate.rules).string = {min_len: 1}];
18+
string name = 1 [(buf.validate.field).string = {min_len: 1}];
1919

2020
// .. space reserved for additional authority addressing information, e.g. for
2121
// resource signing, items such as CA trust chain, cert pinning may be added.

xds/core/v3/cidr.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package xds.core.v3;
55
import "xds/annotations/v3/status.proto";
66
import "google/protobuf/wrappers.proto";
77

8-
import "validate/validate.proto";
8+
import "buf/validate/validate.proto";
99

1010
option java_outer_classname = "CidrRangeProto";
1111
option java_multiple_files = true;
@@ -16,8 +16,8 @@ option go_package = "github.com/cncf/xds/go/xds/core/v3";
1616
// the subnet mask for a `CIDR <https://tools.ietf.org/html/rfc4632>`_ range.
1717
message CidrRange {
1818
// IPv4 or IPv6 address, e.g. ``192.0.0.0`` or ``2001:db8::``.
19-
string address_prefix = 1 [(validate.rules).string = {min_len: 1}];
19+
string address_prefix = 1 [(buf.validate.field).string = {min_len: 1}];
2020

2121
// Length of prefix, e.g. 0, 32. Defaults to 0 when unset.
22-
google.protobuf.UInt32Value prefix_len = 2 [(validate.rules).uint32 = {lte: 128}];
22+
google.protobuf.UInt32Value prefix_len = 2 [(buf.validate.field).uint32 = {lte: 128}];
2323
}

xds/core/v3/collection_entry.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "google/protobuf/any.proto";
77
import "xds/annotations/v3/status.proto";
88
import "xds/core/v3/resource_locator.proto";
99

10-
import "validate/validate.proto";
10+
import "buf/validate/validate.proto";
1111

1212
option java_outer_classname = "CollectionEntryProto";
1313
option java_multiple_files = true;
@@ -33,7 +33,7 @@ message CollectionEntry {
3333
// ``[a-zA-Z0-9_-\./]+`` (TODO(htuch): turn this into a PGV constraint once
3434
// finalized, probably should be a RFC3986 pchar). This name allows
3535
// reference via the #entry directive in ResourceLocator.
36-
string name = 1 [(validate.rules).string.pattern = "^[0-9a-zA-Z_\\-\\.~:]+$"];
36+
string name = 1 [(buf.validate.field).string.pattern = "^[0-9a-zA-Z_\\-\\.~:]+$"];
3737

3838
// The resource's logical version. It is illegal to have the same named xDS
3939
// resource name at a given version with different resource payloads.
@@ -44,7 +44,7 @@ message CollectionEntry {
4444
}
4545

4646
oneof resource_specifier {
47-
option (validate.required) = true;
47+
option (buf.validate.oneof).required = true;
4848

4949
// A resource locator describing how the member resource is to be located.
5050
ResourceLocator locator = 1;

xds/core/v3/extension.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ option java_multiple_files = true;
77
option java_package = "com.github.xds.core.v3";
88
option go_package = "github.com/cncf/xds/go/xds/core/v3";
99

10-
import "validate/validate.proto";
10+
import "buf/validate/validate.proto";
1111
import "google/protobuf/any.proto";
1212

1313
// Message type for extension configuration.
1414
message TypedExtensionConfig {
1515
// The name of an extension. This is not used to select the extension, instead
1616
// it serves the role of an opaque identifier.
17-
string name = 1 [(validate.rules).string = {min_len: 1}];
17+
string name = 1 [(buf.validate.field).string = {min_len: 1}];
1818

1919
// The typed config for the extension. The type URL will be used to identify
2020
// the extension. In the case that the type URL is *xds.type.v3.TypedStruct*
2121
// (or, for historical reasons, *udpa.type.v1.TypedStruct*), the inner type
2222
// URL of *TypedStruct* will be utilized. See the
2323
// :ref:`extension configuration overview
2424
// <config_overview_extension_configuration>` for further details.
25-
google.protobuf.Any typed_config = 2 [(validate.rules).any = {required: true}];
25+
google.protobuf.Any typed_config = 2 [(buf.validate.field).required = true];
2626
}

xds/core/v3/resource_locator.proto

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package xds.core.v3;
55
import "xds/annotations/v3/status.proto";
66
import "xds/core/v3/context_params.proto";
77

8-
import "validate/validate.proto";
8+
import "buf/validate/validate.proto";
99

1010
option java_outer_classname = "ResourceLocatorProto";
1111
option java_multiple_files = true;
@@ -39,7 +39,7 @@ message ResourceLocator {
3939
}
4040

4141
// URI scheme.
42-
Scheme scheme = 1 [(validate.rules).enum = {defined_only: true}];
42+
Scheme scheme = 1 [(buf.validate.field).enum = {defined_only: true}];
4343

4444
// Opaque identifier for the resource. Any '/' will not be escaped during URI
4545
// encoding and will form part of the URI path. This may end
@@ -54,7 +54,7 @@ message ResourceLocator {
5454

5555
// Fully qualified resource type (as in type URL without types.googleapis.com/
5656
// prefix).
57-
string resource_type = 4 [(validate.rules).string = {min_len: 1}];
57+
string resource_type = 4 [(buf.validate.field).string = {min_len: 1}];
5858

5959
oneof context_param_specifier {
6060
// Additional parameters that can be used to select resource variants.
@@ -89,7 +89,7 @@ message ResourceLocator {
8989
// and reserved characters.
9090
message Directive {
9191
oneof directive {
92-
option (validate.required) = true;
92+
option (buf.validate.oneof).required = true;
9393

9494
// An alternative resource locator for fallback if the resource is
9595
// unavailable. For example, take the resource locator:
@@ -106,7 +106,7 @@ message ResourceLocator {
106106
// field specified. When specified, the entry directive allows
107107
// ResourceLocator to directly reference these inlined resources, e.g.
108108
// xdstp://.../foo#entry=bar.
109-
string entry = 2 [(validate.rules).string = {min_len: 1, pattern: "^[0-9a-zA-Z_\\-\\./~:]+$"}];
109+
string entry = 2 [(buf.validate.field).string = {min_len: 1, pattern: "^[0-9a-zA-Z_\\-\\./~:]+$"}];
110110
}
111111
}
112112

xds/core/v3/resource_name.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package xds.core.v3;
55
import "xds/annotations/v3/status.proto";
66
import "xds/core/v3/context_params.proto";
77

8-
import "validate/validate.proto";
8+
import "buf/validate/validate.proto";
99

1010
option java_outer_classname = "ResourceNameProto";
1111
option java_multiple_files = true;
@@ -35,7 +35,7 @@ message ResourceName {
3535

3636
// Fully qualified resource type (as in type URL without types.googleapis.com/
3737
// prefix).
38-
string resource_type = 3 [(validate.rules).string = {min_len: 1}];
38+
string resource_type = 3 [(buf.validate.field).string = {min_len: 1}];
3939

4040
// Additional parameters that can be used to select resource variants.
4141
ContextParams context = 4;

xds/data/orca/v3/orca_load_report.proto

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ option java_multiple_files = true;
77
option java_package = "com.github.xds.data.orca.v3";
88
option go_package = "github.com/cncf/xds/go/xds/data/orca/v3";
99

10-
import "validate/validate.proto";
10+
import "buf/validate/validate.proto";
1111

1212
// See section `ORCA load report format` of the design document in
1313
// https://github.com/envoyproxy/envoy/issues/6614.
@@ -17,11 +17,11 @@ message OrcaLoadReport {
1717
// should be derived from the latest sample or measurement. The value may be
1818
// larger than 1.0 when the usage exceeds the reporter dependent notion of
1919
// soft limits.
20-
double cpu_utilization = 1 [(validate.rules).double.gte = 0];
20+
double cpu_utilization = 1 [(buf.validate.field).double.gte = 0];
2121

2222
// Memory utilization expressed as a fraction of available memory
2323
// resources. This should be derived from the latest sample or measurement.
24-
double mem_utilization = 2 [(validate.rules).double.gte = 0, (validate.rules).double.lte = 1];
24+
double mem_utilization = 2 [(buf.validate.field).double.gte = 0, (buf.validate.field).double.lte = 1];
2525

2626
// Total RPS being served by an endpoint. This should cover all services that an endpoint is
2727
// responsible for.
@@ -35,15 +35,15 @@ message OrcaLoadReport {
3535
// Resource utilization values. Each value is expressed as a fraction of total resources
3636
// available, derived from the latest sample or measurement.
3737
map<string, double> utilization = 5
38-
[(validate.rules).map.values.double.gte = 0, (validate.rules).map.values.double.lte = 1];
38+
[(buf.validate.field).map.values.double.gte = 0, (buf.validate.field).map.values.double.lte = 1];
3939

4040
// Total RPS being served by an endpoint. This should cover all services that an endpoint is
4141
// responsible for.
42-
double rps_fractional = 6 [(validate.rules).double.gte = 0];
42+
double rps_fractional = 6 [(buf.validate.field).double.gte = 0];
4343

4444
// Total EPS (errors/second) being served by an endpoint. This should cover
4545
// all services that an endpoint is responsible for.
46-
double eps = 7 [(validate.rules).double.gte = 0];
46+
double eps = 7 [(buf.validate.field).double.gte = 0];
4747

4848
// Application specific opaque metrics.
4949
map<string, double> named_metrics = 8;
@@ -54,5 +54,5 @@ message OrcaLoadReport {
5454
// This should be derived from the latest sample or measurement.
5555
// The value may be larger than 1.0 when the usage exceeds the reporter
5656
// dependent notion of soft limits.
57-
double application_utilization = 9 [(validate.rules).double.gte = 0];
57+
double application_utilization = 9 [(buf.validate.field).double.gte = 0];
5858
}

xds/type/matcher/v3/cel.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ syntax = "proto3";
33
package xds.type.matcher.v3;
44

55
import "xds/type/v3/cel.proto";
6-
import "validate/validate.proto";
6+
import "buf/validate/validate.proto";
77

88
option java_package = "com.github.xds.type.matcher.v3";
99
option java_outer_classname = "CelProto";
@@ -29,7 +29,7 @@ option go_package = "github.com/cncf/xds/go/xds/type/matcher/v3";
2929
// [#comment: envoy.matching.matchers.cel_matcher]
3030
message CelMatcher {
3131
// Either parsed or checked representation of the CEL program.
32-
type.v3.CelExpression expr_match = 1 [(validate.rules).message = {required: true}];
32+
type.v3.CelExpression expr_match = 1 [(buf.validate.field).required = true];
3333

3434
// Free-form description of the CEL AST, e.g. the original expression text, to be
3535
// used for debugging assistance.

0 commit comments

Comments
 (0)