From 64451d2bf7591839ca1c3328ce16d4431bb1c663 Mon Sep 17 00:00:00 2001 From: David Hontecillas Date: Wed, 18 Dec 2024 20:03:26 +0100 Subject: [PATCH] make the grpc services match the proto definitions --- docker-compose.yml | 8 +++++-- images/grpc/flights/cmd/server/main.go | 2 +- images/grpc/flights/go.mod | 11 ++++++---- images/grpc/flights/go.sum | 22 ------------------- images/grpc/genlib/flights/flights.pb.go | 2 +- images/grpc/genlib/flights/flights_grpc.pb.go | 2 +- images/grpc/genlib/lib/geoposition.pb.go | 2 +- images/grpc/genlib/lib/location.pb.go | 2 +- images/grpc/genlib/lib/pagination.pb.go | 2 +- images/grpc/genlib/lib/time_range.pb.go | 2 +- images/grpc/genlib/trains/trains.pb.go | 2 +- images/grpc/genlib/trains/trains_grpc.pb.go | 2 +- images/grpc/trains/cmd/server/main.go | 15 +++++++++---- images/grpc/trains/go.mod | 2 ++ images/grpc/trains/go.sum | 2 -- 15 files changed, 35 insertions(+), 43 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index cfe5fc9..3637da0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -111,11 +111,15 @@ services: - krakend_ee restart: always grpc_flights: - image: krakend/grpc_flights_fake:latest + # image: krakend/grpc_flights:latest + build: + context: images/grpc/flights ports: - "4242:4242" grpc_trains: - image: krakend/grpc_trains_fake:latest + # image: krakend/grpc_trains:latest + build: + context: images/grpc/trains ports: - "4243:4243" chat: diff --git a/images/grpc/flights/cmd/server/main.go b/images/grpc/flights/cmd/server/main.go index dc88fcb..4e4a7f4 100644 --- a/images/grpc/flights/cmd/server/main.go +++ b/images/grpc/flights/cmd/server/main.go @@ -16,7 +16,7 @@ func main() { flightspb.RegisterFlightsServer(s, fes) // TODO: select the listen port - fmt.Printf("binding to :4242") + fmt.Printf("binding to :4242\n") ls, err := net.Listen("tcp", ":4242") if err != nil { fmt.Printf("cannot bind to port: %s\n", err.Error()) diff --git a/images/grpc/flights/go.mod b/images/grpc/flights/go.mod index e93d9ad..788e9a2 100644 --- a/images/grpc/flights/go.mod +++ b/images/grpc/flights/go.mod @@ -2,15 +2,18 @@ module github.com/krakendio/playground-enterprise/grpc/flights go 1.20 -require google.golang.org/grpc v1.57.0 +replace github.com/krakendio/playground-enterprise/images/grpc/genlib/flights => ../genlib/flights + +require ( + github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230919101031-fce6544db29e + google.golang.org/grpc v1.57.0 + google.golang.org/protobuf v1.31.0 +) require ( github.com/golang/protobuf v1.5.3 // indirect - github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230919101031-fce6544db29e // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect - google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 // indirect - google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/images/grpc/flights/go.sum b/images/grpc/flights/go.sum index 1233d86..bbeb087 100644 --- a/images/grpc/flights/go.sum +++ b/images/grpc/flights/go.sum @@ -1,44 +1,22 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230518154016-798be9f2e364 h1:yWVZqUyUHNqnanA3QmKk+vJYqN1VUFY7uewz5a76i+k= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230518154016-798be9f2e364/go.mod h1:L22KcqLCsbT0Wb7e0PTZm2cpEetRapzvoI438nddgIw= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230523094503-74a0a31d1ed1 h1:IyyZRaEGw8bBVi+dP17rOBb7rvm7GVEvvc8iZoe1o3Y= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230523094503-74a0a31d1ed1/go.mod h1:L22KcqLCsbT0Wb7e0PTZm2cpEetRapzvoI438nddgIw= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230820144907-62cfdeb9111e h1:rWWTho6HCGM0F8b9j0ddz5gcDSlW3kyVAHmK0IyX95E= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230820144907-62cfdeb9111e/go.mod h1:L22KcqLCsbT0Wb7e0PTZm2cpEetRapzvoI438nddgIw= github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230919101031-fce6544db29e h1:8/gU+Tsk4v/fC3kpLIBLGd+JyUd2IvFZtCtDHGF0DAU= github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230919101031-fce6544db29e/go.mod h1:L22KcqLCsbT0Wb7e0PTZm2cpEetRapzvoI438nddgIw= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g= -google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878 h1:lv6/DhyiFFGsmzxbsUUTOkN29II+zeWHxvT8Lpdxsv0= google.golang.org/genproto/googleapis/rpc v0.0.0-20230815205213-6bfd019c3878/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= -google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= -google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/images/grpc/genlib/flights/flights.pb.go b/images/grpc/genlib/flights/flights.pb.go index 0b8e4b5..6430ac2 100644 --- a/images/grpc/genlib/flights/flights.pb.go +++ b/images/grpc/genlib/flights/flights.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.29.0 -// protoc v4.24.2 +// protoc v5.28.3 // source: flights/flights.proto package flights diff --git a/images/grpc/genlib/flights/flights_grpc.pb.go b/images/grpc/genlib/flights/flights_grpc.pb.go index a4f15b6..6ac92da 100644 --- a/images/grpc/genlib/flights/flights_grpc.pb.go +++ b/images/grpc/genlib/flights/flights_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.24.2 +// - protoc v5.28.3 // source: flights/flights.proto package flights diff --git a/images/grpc/genlib/lib/geoposition.pb.go b/images/grpc/genlib/lib/geoposition.pb.go index 0c04815..2b1ce3f 100644 --- a/images/grpc/genlib/lib/geoposition.pb.go +++ b/images/grpc/genlib/lib/geoposition.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.29.0 -// protoc v4.24.2 +// protoc v5.28.3 // source: lib/geoposition.proto package lib diff --git a/images/grpc/genlib/lib/location.pb.go b/images/grpc/genlib/lib/location.pb.go index 4b8b601..93f6d78 100644 --- a/images/grpc/genlib/lib/location.pb.go +++ b/images/grpc/genlib/lib/location.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.29.0 -// protoc v4.24.2 +// protoc v5.28.3 // source: lib/location.proto package lib diff --git a/images/grpc/genlib/lib/pagination.pb.go b/images/grpc/genlib/lib/pagination.pb.go index 9405204..b57b0f7 100644 --- a/images/grpc/genlib/lib/pagination.pb.go +++ b/images/grpc/genlib/lib/pagination.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.29.0 -// protoc v4.24.2 +// protoc v5.28.3 // source: lib/pagination.proto package lib diff --git a/images/grpc/genlib/lib/time_range.pb.go b/images/grpc/genlib/lib/time_range.pb.go index 850c553..d14d936 100644 --- a/images/grpc/genlib/lib/time_range.pb.go +++ b/images/grpc/genlib/lib/time_range.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.29.0 -// protoc v4.24.2 +// protoc v5.28.3 // source: lib/time_range.proto package lib diff --git a/images/grpc/genlib/trains/trains.pb.go b/images/grpc/genlib/trains/trains.pb.go index d6bee6b..0e1df89 100644 --- a/images/grpc/genlib/trains/trains.pb.go +++ b/images/grpc/genlib/trains/trains.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.29.0 -// protoc v4.24.2 +// protoc v5.28.3 // source: trains/trains.proto package trains diff --git a/images/grpc/genlib/trains/trains_grpc.pb.go b/images/grpc/genlib/trains/trains_grpc.pb.go index ff41357..6ec551f 100644 --- a/images/grpc/genlib/trains/trains_grpc.pb.go +++ b/images/grpc/genlib/trains/trains_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.24.2 +// - protoc v5.28.3 // source: trains/trains.proto package trains diff --git a/images/grpc/trains/cmd/server/main.go b/images/grpc/trains/cmd/server/main.go index 2b8af87..0409bdb 100644 --- a/images/grpc/trains/cmd/server/main.go +++ b/images/grpc/trains/cmd/server/main.go @@ -7,6 +7,8 @@ import ( "fmt" "io/ioutil" "net" + "os" + "strings" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -18,10 +20,15 @@ import ( func main() { fes := NewTrainsEchoServer() - s := grpc.NewServer( - grpc.Creds(loadCredentials()), - grpc.UnaryInterceptor(checkClientCert), - ) + opts := make([]grpc.ServerOption, 0, 4) + + strUseTLS := os.Getenv("GRPC_TRAINS_USE_TLS") + if strings.ToLower(strUseTLS) == "true" { + opts = append(opts, grpc.Creds(loadCredentials())) + opts = append(opts, grpc.UnaryInterceptor(checkClientCert)) + } + + s := grpc.NewServer(opts...) trainspb.RegisterTrainsServer(s, fes) // TODO: select the listen port diff --git a/images/grpc/trains/go.mod b/images/grpc/trains/go.mod index 5260cf1..781ea71 100644 --- a/images/grpc/trains/go.mod +++ b/images/grpc/trains/go.mod @@ -2,6 +2,8 @@ module github.com/playground-enterprise/images/grpc/trains go 1.20 +replace github.com/krakendio/playground-enterprise/images/grpc/genlib/trains => ../genlib/trains + require ( github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230919101031-fce6544db29e google.golang.org/grpc v1.54.0 diff --git a/images/grpc/trains/go.sum b/images/grpc/trains/go.sum index f64b216..fc8e09d 100644 --- a/images/grpc/trains/go.sum +++ b/images/grpc/trains/go.sum @@ -3,8 +3,6 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230518154016-798be9f2e364 h1:yWVZqUyUHNqnanA3QmKk+vJYqN1VUFY7uewz5a76i+k= -github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230518154016-798be9f2e364/go.mod h1:L22KcqLCsbT0Wb7e0PTZm2cpEetRapzvoI438nddgIw= github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230919101031-fce6544db29e h1:8/gU+Tsk4v/fC3kpLIBLGd+JyUd2IvFZtCtDHGF0DAU= github.com/krakendio/playground-enterprise/images/grpc/genlib v0.0.0-20230919101031-fce6544db29e/go.mod h1:L22KcqLCsbT0Wb7e0PTZm2cpEetRapzvoI438nddgIw= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=