Handler hostcatalogs (#86)
* Created host catalog service.
* Fixing uri generation for create.
* Use newly submitted static host catalog.
* Copying over tests from projects.
* Fix UpdateHostCatalogRequest merging proto.
* Properly use static host catalog prefixes in tests.
* Correct test to verify the expected uri and id prefix is set.
* Add test for unsetting descriptions.
* Correct bad spelling in comment.
* Tweaking variable names.
* Adding Stringer to the catalog type and setting the type on the response.
* Setting up the catalogType to contain more info regarding its type.
* Validate the type field in requests.
* Remove unused method.
* Comment describing invariants around types.
* Wiring in the repo into the static catalog handler.
* Updated comments to the exported methods.
* fix: return the result of handlers.NotFoundError instead of just calling it.
* Fixing typos referencing just hosts instead of host catlogs.
* Update NewService returns an error and a non pointer type.
* Pull "org_id" and "project_id" into constants and the validation of them into the ValidateAncestors.
* Check errors for all Register*HandlerServer calls.
* fix: Remove left over reference that could cause a panic.
* fix: Changing "x := []string{}" to "var x []string"
* fix: Log errors in test cleanup.
* Changing the code to use google.golang.org/protobuf instead of the older github based protobuf library.
* Changing all t.Fatal checks to require.NoError calls.
* Changing unrecognized prefixes to Invalid Argument instead of Not Found.
* fix: toDbUpdateMask now returns error if it was unable to find any valid paths.
* Define CreatedTime, UpdatedTime, and Type at initialization time in toProto.
* Remove unused host catalog from test.
* Change a t.Fatal to a require.NoError that I missed earlier.
* Change shutdown error logging to t.Errorfs.
* Shorten validateX function names.
* Inline API responses.
* Add todo to make a new repo per request.
* Inline regex check for invalid id.
* Change stored repos into repo creating functions which satisfies ICU-223.
* Wrap proto comments to be under 80 characters long.
* Remove the exception on the read only fields that can be set in an Update request.
* Removing out of date comment.
* Use iam.TestScopes instead of making the project myself.
* Renaming files to be consistant with go test standards and resource naming standards.
* Remove TODO related to a task completed in an earlier commit.
* Fix the previous commit which removed the wrong TODO.
This commit is contained in:
1 parent
7d4993fb61
commit
7f6e78e66e
12 files changed
+1201
-143
No files matched your search
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -28,7 +29,7 @@ type HandlerProperties struct {
|
||||
|
||||
// Handler returns an http.Handler for the services. This can be used on
|
||||
// its own to mount the Vault API within another web server.
|
||||
func (c *Controller) handler(props HandlerProperties) http.Handler {
|
||||
func (c *Controller) handler(props HandlerProperties) (http.Handler, error) {
|
||||
// Create the muxer to handle the actual endpoints
|
||||
mux := http.NewServeMux()
|
||||
|
||||
@@ -46,25 +47,41 @@ func (c *Controller) handler(props HandlerProperties) http.Handler {
|
||||
mux.Handle("/passthrough/", prefixHandler)
|
||||
}
|
||||
|
||||
mux.Handle("/v1/", handleGrpcGateway(c))
|
||||
h, err := handleGrpcGateway(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mux.Handle("/v1/", h)
|
||||
|
||||
corsWrappedHandler := wrapHandlerWithCors(mux, props)
|
||||
commonWrappedHandler := wrapHandlerWithCommonFuncs(corsWrappedHandler, c, props)
|
||||
|
||||
return commonWrappedHandler
|
||||
return commonWrappedHandler, nil
|
||||
}
|
||||
|
||||
func handleGrpcGateway(c *Controller) http.Handler {
|
||||
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)))
|
||||
services.RegisterHostCatalogServiceHandlerServer(ctx, mux, &host_catalogs.Service{})
|
||||
services.RegisterHostSetServiceHandlerServer(ctx, mux, &host_sets.Service{})
|
||||
services.RegisterHostServiceHandlerServer(ctx, mux, &hosts.Service{})
|
||||
services.RegisterProjectServiceHandlerServer(ctx, mux, projects.NewService(c.IamRepo))
|
||||
hcs, err := host_catalogs.NewService(c.StaticHostRepoFn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create host catalog handler service: %w", err)
|
||||
}
|
||||
if err := services.RegisterHostCatalogServiceHandlerServer(ctx, mux, hcs); err != nil {
|
||||
return nil, fmt.Errorf("failed to register host catalog service handler: %w", err)
|
||||
}
|
||||
if err := services.RegisterHostSetServiceHandlerServer(ctx, mux, &host_sets.Service{}); err != nil {
|
||||
return nil, fmt.Errorf("failed to register host set service handler: %w", err)
|
||||
}
|
||||
if err := services.RegisterHostServiceHandlerServer(ctx, mux, &hosts.Service{}); err != nil {
|
||||
return nil, fmt.Errorf("failed to register host service handler: %w", err)
|
||||
}
|
||||
if err := services.RegisterProjectServiceHandlerServer(ctx, mux, projects.NewService(c.IamRepoFn)); err != nil {
|
||||
return nil, fmt.Errorf("failed to register project service handler: %w", err)
|
||||
}
|
||||
|
||||
return mux
|
||||
return mux, nil
|
||||
}
|
||||
|
||||
func wrapHandlerWithCommonFuncs(h http.Handler, c *Controller, props HandlerProperties) http.Handler {
|
||||
|
||||
Reference in new issue
Block a user