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

Add support to envoyproxy gRPC validator #156

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ RUN go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc

RUN go get -u github.com/micro/protobuf/protoc-gen-go

RUN go get -d github.com/envoyproxy/protoc-gen-validate
RUN make -C /go/src/github.com/envoyproxy/protoc-gen-validate/ build

RUN go get -u github.com/mwitkow/go-proto-validators/protoc-gen-govalidators

# Add grpc-web support
Expand Down Expand Up @@ -84,6 +87,8 @@ COPY --from=build /go/bin/* /usr/local/bin/
COPY --from=build /tmp/grpc_web_plugin /usr/local/bin/grpc_web_plugin

COPY --from=build /go/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options/ /opt/include/protoc-gen-swagger/options/

COPY --from=build /go/src/github.com/envoyproxy/protoc-gen-validate/ /opt/include/
COPY --from=build /go/src/github.com/mwitkow/go-proto-validators/ /opt/include/github.com/mwitkow/go-proto-validators/

ADD all/entrypoint.sh /usr/local/bin
Expand Down
25 changes: 25 additions & 0 deletions all/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ printUsage() {
echo " --with-gateway Generate grpc-gateway files (experimental)."
echo " --with-docs FORMAT Generate documentation (FORMAT is optional - see https://github.com/pseudomuto/protoc-gen-doc#invoking-the-plugin)"
echo " --with-typescript Generate TypeScript declaration files (.d.ts files) - see https://github.com/improbable-eng/ts-protoc-gen#readme"
echo " --with-validator Generate validations for (${VALIDATOR_SUPPORTED_LANGUAGES[@]}) - see https://github.com/envoyproxy/protoc-gen-validate"
echo " --go-source-relative Make go import paths 'source_relative' - see https://github.com/golang/protobuf#parameters"
echo " --go-package-map Map proto imports to go import paths"
echo " --go-plugin-micro Replaces the Go gRPC plugin with go-micro"
Expand All @@ -33,6 +34,8 @@ printUsage() {

GEN_GATEWAY=false
GEN_DOCS=false
GEN_VALIDATOR=false
VALIDATOR_SUPPORTED_LANGUAGES=("go" "gogo" "cpp" "java" "python")
DOCS_FORMAT="html,index.html"
GEN_TYPESCRIPT=false
LINT=false
Expand Down Expand Up @@ -110,6 +113,10 @@ while test $# -gt 0; do
GEN_TYPESCRIPT=true
shift
;;
--with-validator)
GEN_VALIDATOR=true
shift
;;
--lint)
LINT=true
if [ "$#" -gt 1 ] && [[ $2 != -* ]]; then
Expand Down Expand Up @@ -188,6 +195,16 @@ if [[ ! ${SUPPORTED_LANGUAGES[*]} =~ "$GEN_LANG" ]]; then
exit 1
fi

if [[ "$GEN_VALIDATOR" == true && ! ${VALIDATOR_SUPPORTED_LANGUAGES[*]} =~ "$GEN_LANG" ]]; then
echo "Generating validations are not (yet) supported to $GEN_LANG language. Please specify one of: ${VALIDATOR_SUPPORTED_LANGUAGES[@]}"
exit 1
fi

if [[ "$GEN_VALIDATOR" == true && "$GO_VALIDATOR" == true ]]; then
echo "Hi Gopher! Please select just one of the validators (--go-proto-validator or --with-validator)."
exit 1
fi

if [[ "$GEN_GATEWAY" == true && "$GEN_LANG" != "go" ]]; then
echo "Generating grpc-gateway is Go specific."
exit 1
Expand Down Expand Up @@ -282,6 +299,14 @@ if [[ $GO_VALIDATOR == true && $GEN_LANG == "gogo" ]]; then
GEN_STRING="$GEN_STRING --govalidators_out=gogoimport=true:$OUT_DIR"
fi

if [[ $GEN_VALIDATOR == true && $GEN_LANG == "go" ]]; then
GEN_STRING="$GEN_STRING --validate_out=lang=go:$OUT_DIR"
fi

if [[ $GEN_VALIDATOR == true && $GEN_LANG == "gogo" ]]; then
GEN_STRING="$GEN_STRING --validate_out=lang=gogo:$OUT_DIR"
fi

if [[ $GEN_DOCS == true ]]; then
mkdir -p $OUT_DIR/doc
GEN_STRING="$GEN_STRING --doc_opt=$DOCS_FORMAT --doc_out=$OUT_DIR/doc"
Expand Down