From 29278b52a7c67659182e80c03e261d5979d4c523 Mon Sep 17 00:00:00 2001 From: htuch Date: Tue, 7 Nov 2017 16:09:13 -0800 Subject: [PATCH] validate: initial constraints support. (#226) * Import @com_lyft_protoc_gen_validate for validate.proto annotations. * Example annotation in address.proto (BindConfig). * Process optional/required annotations in protodoc. Signed-off-by: Harvey Tuch --- .gitignore | 1 + WORKSPACE | 2 ++ api/BUILD | 2 ++ api/address.proto | 4 +++- bazel/api_build_system.bzl | 6 +++++- bazel/repositories.bzl | 9 +++++++++ ci/do_ci.sh | 2 +- tools/generate_listeners.pyc | Bin 2312 -> 0 bytes tools/protodoc/BUILD | 5 ++++- tools/protodoc/protodoc.py | 36 ++++++++++++++++++++++++++--------- 10 files changed, 54 insertions(+), 13 deletions(-) delete mode 100644 tools/generate_listeners.pyc diff --git a/.gitignore b/.gitignore index 08bc2485..1ff3954b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bazel-* +*.pyc build_docs/ generated/ diff --git a/WORKSPACE b/WORKSPACE index 6e03ec7d..d93f6054 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -42,6 +42,8 @@ git_repository( commit = "4374be38e9a75ff5957c3922adb155d32086fe14", ) load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains") +load("@com_lyft_protoc_gen_validate//bazel:go_proto_library.bzl", "go_proto_repositories") +go_proto_repositories(shared=0) go_rules_dependencies() go_register_toolchains() load("@io_bazel_rules_go//proto:def.bzl", "proto_register_toolchains") diff --git a/api/BUILD b/api/BUILD index ff151704..4c3337fe 100644 --- a/api/BUILD +++ b/api/BUILD @@ -30,6 +30,7 @@ proto_library( "@com_google_protobuf//:struct_proto", "@com_google_protobuf//:timestamp_proto", "@com_google_protobuf//:wrappers_proto", + "@com_lyft_protoc_gen_validate//validate:validate_proto", "@googleapis//:http_api_protos_lib", ], ) @@ -46,6 +47,7 @@ go_grpc_library( "@com_github_golang_protobuf//ptypes/timestamp:go_default_library", "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", "@org_golang_google_genproto//googleapis/api/annotations:go_default_library", + "@com_lyft_protoc_gen_validate//validate:go_default_library", ], ) diff --git a/api/address.proto b/api/address.proto index 8879f11a..3d6ed30b 100644 --- a/api/address.proto +++ b/api/address.proto @@ -4,6 +4,8 @@ package envoy.api.v2; import "google/protobuf/wrappers.proto"; +import "validate/validate.proto"; + // protodoc-title: Network related configuration elements // [V2-API-DIFF] Addresses now have .proto structure. @@ -37,7 +39,7 @@ message SocketAddress { message BindConfig { // The address to bind to when creating a socket. - SocketAddress source_address = 1; + SocketAddress source_address = 1 [(validate.rules).message.required = true]; } // Addresses specify either a logical or physical address and port, which are diff --git a/bazel/api_build_system.bzl b/bazel/api_build_system.bzl index d53fd96b..f363486e 100644 --- a/bazel/api_build_system.bzl +++ b/bazel/api_build_system.bzl @@ -17,7 +17,10 @@ def api_py_proto_library(name, srcs = [], deps = [], has_services = 0): srcs = srcs, default_runtime = "@com_google_protobuf//:protobuf_python", protoc = "@com_google_protobuf//:protoc", - deps = [_PySuffix(d) for d in deps] + ["@googleapis//:http_api_protos_py"], + deps = [_PySuffix(d) for d in deps] + [ + "@com_lyft_protoc_gen_validate//validate:validate_py", + "@googleapis//:http_api_protos_py", + ], visibility = ["//visibility:public"], ) @@ -35,6 +38,7 @@ def api_proto_library(name, srcs = [], deps = [], has_services = 0, require_py = "@com_google_protobuf//:timestamp_proto", "@com_google_protobuf//:wrappers_proto", "@googleapis//:http_api_protos_lib", + "@com_lyft_protoc_gen_validate//validate:validate_proto", ], visibility = ["//visibility:public"], ) diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 79c1a35f..c921dcc1 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -1,7 +1,16 @@ GOOGLEAPIS_SHA = "5c6df0cd18c6a429eab739fb711c27f6e1393366" # May 14, 2017 PROMETHEUS_SHA = "6f3806018612930941127f2a7c6c453ba2c527d2" # Nov 02, 2017 +PGV_GIT_SHA = "f3332cbd75bb28f711377dfb84761ef0d52eca0f" +PGV_TAR_SHA = "039ffa842eb62495b6aca305a4eb3d6dc3ac1dd056e228fba5e720161ddfb9c1" + def api_dependencies(): + native.http_archive( + name = "com_lyft_protoc_gen_validate", + strip_prefix = "protoc-gen-validate-" + PGV_GIT_SHA, + sha256 = PGV_TAR_SHA, + url = "https://github.com/lyft/protoc-gen-validate/archive/" + PGV_GIT_SHA + ".tar.gz", + ) native.new_http_archive( name = "googleapis", strip_prefix = "googleapis-" + GOOGLEAPIS_SHA, diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 3ee9f971..882b2302 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -17,6 +17,6 @@ elif [[ "$1" == "bazel.docs" ]]; then echo "generating docs..." ./docs/build.sh else - echo "Invalid do_ci.sh target. The only valid target is bazel.build." + echo "Invalid do_ci.sh target. The only valid targets are bazel.{docs,test}." exit 1 fi diff --git a/tools/generate_listeners.pyc b/tools/generate_listeners.pyc deleted file mode 100644 index 97e0b4dae53d192926b4f1dd11bf50e8026ec10e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2312 zcmbVN-ESL35T8AN#7^wQNn2?65Ec~4LMTBzAc3L?kISVE_ZZ|$6OAMWj% zrYLy|@BM@LgLvVM7vA7Ev*#Fu5T#abZf9l8I*u|d(QEIOoX6s^&jN5vhbH%Svs zx9Cby)S@$@;#Z2=r7>Ek?N{zUV2>LVZLpKdh%{ozCYZL%Rp)xOiPg=8LyO+RrmL## z13-h`77&a7z^~7+kzIq(=T>J?FbnPJ(l|AF7L4;E4Xrb-GS;@3k8ChI`EcoIvHfq3 zOiU7)rPu2)oLV~zMtPR$k&O{K4YP2f3w9cDB9-zvz}xIXSd^&fg1G8SMb@Kfg|3J$ zJ^56n3w-sML50^q^6B?#*y&4QZLAKpF*xNY{}RRc9!IT145SLnzK_Gg=pG*~>a56Z zZW~ag{6fzxmpx;zC`iqu2aQCScd*(u`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