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 for REST server extensions #1101

Merged
merged 1 commit into from
May 7, 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
3 changes: 3 additions & 0 deletions api/server/sdk/rest_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func (s *sdkRestGateway) restServerSetupHandlers() (http.Handler, error) {
api.RegisterOpenStoragePolicyHandler,
}

// REST Gateway extensions
handlers = append(handlers, s.config.RestServerExtensions...)

// Register the REST Gateway handlers
for _, handler := range handlers {
err := handler(context.Background(), gmux, conn)
Expand Down
17 changes: 13 additions & 4 deletions api/server/sdk/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/libopenstorage/openstorage/alerts"
"github.com/libopenstorage/openstorage/api"
"github.com/libopenstorage/openstorage/api/spec"
Expand Down Expand Up @@ -118,7 +119,15 @@ type ServerConfig struct {
// func(gs *grpc.Server) {
// api.RegisterCustomService(gs, customHandler)
// })
ServerExtensions []func(s *grpc.Server)
GrpcServerExtensions []func(grpcServer *grpc.Server)

// RestServerExtensions allows for extensions to be added
// to the SDK Rest Gateway server.
//
// To add your own service to the SDK REST Server, simply add your handlers
// to the RestSererExtensions slice. These handlers will be registered on the
// REST Gateway http server.
RestServerExtensions []func(context.Context, *runtime.ServeMux, *grpc.ClientConn) error
}

// Server is an implementation of the gRPC SDK interface
Expand Down Expand Up @@ -464,7 +473,7 @@ func (s *sdkGrpcServer) Start() error {
api.RegisterOpenStorageRoleServer(grpcServer, s.roleServer)
}

s.RegisterServerExtensions(grpcServer)
s.registerServerExtensions(grpcServer)

return grpcServer
})
Expand All @@ -475,8 +484,8 @@ func (s *sdkGrpcServer) Start() error {
return nil
}

func (s *sdkGrpcServer) RegisterServerExtensions(grpcServer *grpc.Server) {
for _, ext := range s.config.ServerExtensions {
func (s *sdkGrpcServer) registerServerExtensions(grpcServer *grpc.Server) {
for _, ext := range s.config.GrpcServerExtensions {
ext(grpcServer)
}
}
Expand Down