Update Watchtower to use grpc-gateway v2 (#204)
* Migration to grpc gateway v2.
This commit is contained in:
1 parent
6de1f7ee16
commit
f47046f158
67 files changed
+2281
-2070
No files matched your search
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/hashicorp/vault/internalshared/configutil"
|
||||
"github.com/hashicorp/vault/sdk/helper/strutil"
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/roles"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/scopes"
|
||||
"github.com/hashicorp/watchtower/internal/servers/controller/handlers/users"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
type HandlerProperties struct {
|
||||
@@ -55,7 +56,23 @@ func handleGrpcGateway(c *Controller) (http.Handler, error) {
|
||||
// Register*ServiceHandlerServer methods ignore the passed in ctx. Using the baseContext now just in case this changes
|
||||
// in the future, at which point we'll want to be using the baseContext.
|
||||
ctx := c.baseContext
|
||||
mux := runtime.NewServeMux(runtime.WithProtoErrorHandler(handlers.ErrorHandler(c.logger)))
|
||||
mux := runtime.NewServeMux(
|
||||
runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.HTTPBodyMarshaler{
|
||||
Marshaler: &runtime.JSONPb{
|
||||
MarshalOptions: protojson.MarshalOptions{
|
||||
// Ensures the json marshaler uses the snake casing as defined in the proto field names.
|
||||
UseProtoNames: true,
|
||||
// Do not add fields set to zero value to json.
|
||||
EmitUnpopulated: false,
|
||||
},
|
||||
UnmarshalOptions: protojson.UnmarshalOptions{
|
||||
// Allows requests to contain unknown fields.
|
||||
DiscardUnknown: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
runtime.WithErrorHandler(handlers.ErrorHandler(c.logger)),
|
||||
)
|
||||
hcs, err := host_catalogs.NewService(c.StaticHostRepoFn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create host catalog handler service: %w", err)
|
||||
|
||||
Reference in new issue
Block a user