From 3fe8935ff76cc6761b11c9984de96479868dbd49 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 20 Jan 2022 16:23:50 -0500 Subject: [PATCH 1/7] Update .envrc with better stuff Make use of direnv's stdlib having `has` which replaces the old `which ... &>/dev/null`. This also sources env vars from .env files which should not be added to git and allow for local user to override/add things without git trying to track it. Finally, add ./bin to both PATH and GOBIN to avoid contamination of global GOBIN. Signed-off-by: Manuel Mendez --- .envrc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.envrc b/.envrc index c8c4a987a..3da85f28b 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,7 @@ +has nix && use nix +dotenv_if_exists +PATH_add bin +path_add GOBIN bin + export TINKERBELL_GRPC_AUTHORITY=127.0.0.1:42113 export TINKERBELL_CERT_URL=http://127.0.0.1:42114/cert - -which nix &>/dev/null && use nix && unset GOPATH From d6ee59c2c43c655d517b79b80d9ea511fac8871c Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Mon, 24 Jan 2022 13:11:44 -0500 Subject: [PATCH 2/7] http: Get rid of useless logger variable in SetupHTTP lg is already of copy of the arg so theres no need to create a function variable to copy the arg when just naming it logger would do. Signed-off-by: Manuel Mendez --- http-server/http_server.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/http-server/http_server.go b/http-server/http_server.go index 1b60451a8..c13589bf3 100644 --- a/http-server/http_server.go +++ b/http-server/http_server.go @@ -36,9 +36,7 @@ type Config struct { } // SetupHTTP setup and return an HTTP server. -func SetupHTTP(ctx context.Context, lg log.Logger, config *Config, errCh chan<- error) { - logger = lg - +func SetupHTTP(ctx context.Context, logger log.Logger, config *Config, errCh chan<- error) { cp := x509.NewCertPool() ok := cp.AppendCertsFromPEM(config.CertPEM) if !ok { From 37754b8734525d2477373b3b63fb1583caaa8166 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Mon, 24 Jan 2022 17:52:27 -0500 Subject: [PATCH 3/7] http: Drop global gitRevJSON by returning a closure Yay one global variable down, many more to go. Signed-off-by: Manuel Mendez --- http-server/http_server.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/http-server/http_server.go b/http-server/http_server.go index c13589bf3..ef5acb9cd 100644 --- a/http-server/http_server.go +++ b/http-server/http_server.go @@ -20,10 +20,9 @@ import ( ) var ( - gitRev = "unknown" - gitRevJSON []byte - startTime = time.Now() - logger log.Logger + gitRev = "unknown" + startTime = time.Now() + logger log.Logger ) type Config struct { @@ -74,8 +73,7 @@ func SetupHTTP(ctx context.Context, logger log.Logger, config *Config, errCh cha http.ServeContent(w, r, "server.pem", config.ModTime, bytes.NewReader(config.CertPEM)) }) http.Handle("/metrics", promhttp.Handler()) - setupGitRevJSON() - http.HandleFunc("/version", versionHandler) + http.HandleFunc("/version", getGitRevJSONHandler()) http.HandleFunc("/healthz", healthCheckHandler) http.Handle("/", BasicAuth(config.HTTPBasicAuthUsername, config.HTTPBasicAuthPassword, mux)) @@ -98,11 +96,6 @@ func SetupHTTP(ctx context.Context, logger log.Logger, config *Config, errCh cha }() } -func versionHandler(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "application/json") - _, _ = w.Write(gitRevJSON) -} - func healthCheckHandler(w http.ResponseWriter, _ *http.Request) { res := struct { GitRev string `json:"git_rev"` @@ -123,7 +116,7 @@ func healthCheckHandler(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write(b) } -func setupGitRevJSON() { +func getGitRevJSONHandler() http.HandlerFunc { res := struct { GitRev string `json:"git_rev"` Service string `json:"service_name"` @@ -137,7 +130,11 @@ func setupGitRevJSON() { logger.Error(err) panic(err) } - gitRevJSON = b + + return func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write(b) + } } // BasicAuth adds authentication to the routes handled by handler From c71b8a03f2dda6beaa5db61f237ded628c9bf6f2 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 25 Jan 2022 14:12:00 -0500 Subject: [PATCH 4/7] Drop protoc-gen-grpc-gateway Signed-off-by: Manuel Mendez --- buf.gen.yaml | 3 --- go.sum | 2 -- tools.go | 1 - 3 files changed, 6 deletions(-) diff --git a/buf.gen.yaml b/buf.gen.yaml index 37880023d..f4a9f27fb 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -8,6 +8,3 @@ plugins: opt: - paths=source_relative - require_unimplemented_servers=false - - name: grpc-gateway - out: . - opt: paths=source_relative diff --git a/go.sum b/go.sum index b66b47239..76057e72e 100644 --- a/go.sum +++ b/go.sum @@ -462,7 +462,6 @@ github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASx github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= @@ -573,7 +572,6 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= diff --git a/tools.go b/tools.go index 4abdeca73..bf2b59d96 100644 --- a/tools.go +++ b/tools.go @@ -5,7 +5,6 @@ package tools import ( _ "github.com/bufbuild/buf/cmd/buf" - _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway" _ "github.com/matryer/moq" _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" _ "google.golang.org/protobuf/cmd/protoc-gen-go" From 6c58846507fbab45d7c545660ca7705c58e67c76 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 25 Jan 2022 13:38:04 -0500 Subject: [PATCH 5/7] server: Drop json rpc support Pretty sure no one is using this over grpc rpc support and thus is a lot of useless complexity. So lets get rid of unused code! Signed-off-by: Manuel Mendez --- cmd/tink-server/main.go | 9 +- http-server/http_server.go | 67 +--- protos/hardware/hardware.pb.gw.go | 575 ------------------------------ protos/template/template.pb.gw.go | 466 ------------------------ protos/workflow/workflow.pb.gw.go | 566 ----------------------------- 5 files changed, 6 insertions(+), 1677 deletions(-) delete mode 100644 protos/hardware/hardware.pb.gw.go delete mode 100644 protos/template/template.pb.gw.go delete mode 100644 protos/workflow/workflow.pb.gw.go diff --git a/cmd/tink-server/main.go b/cmd/tink-server/main.go index d87d11661..a3691b469 100644 --- a/cmd/tink-server/main.go +++ b/cmd/tink-server/main.go @@ -188,12 +188,9 @@ func NewRootCommand(config *DaemonConfig, logger log.Logger) *cobra.Command { }, errCh) httpServer.SetupHTTP(ctx, logger, &httpServer.Config{ - CertPEM: cert, - ModTime: modT, - GRPCAuthority: config.GRPCAuthority, - HTTPAuthority: config.HTTPAuthority, - HTTPBasicAuthUsername: config.HTTPBasicAuthUsername, - HTTPBasicAuthPassword: config.HTTPBasicAuthPassword, + CertPEM: cert, + ModTime: modT, + HTTPAuthority: config.HTTPAuthority, }, errCh) select { diff --git a/http-server/http_server.go b/http-server/http_server.go index ef5acb9cd..9b612402c 100644 --- a/http-server/http_server.go +++ b/http-server/http_server.go @@ -3,20 +3,14 @@ package httpserver import ( "bytes" "context" - "crypto/subtle" - "crypto/x509" "encoding/json" - "net" "net/http" "runtime" "time" - grpcRuntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/packethost/pkg/log" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus/promhttp" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" ) var ( @@ -26,56 +20,19 @@ var ( ) type Config struct { - CertPEM []byte - ModTime time.Time - GRPCAuthority string - HTTPAuthority string - HTTPBasicAuthUsername string - HTTPBasicAuthPassword string + CertPEM []byte + ModTime time.Time + HTTPAuthority string } // SetupHTTP setup and return an HTTP server. func SetupHTTP(ctx context.Context, logger log.Logger, config *Config, errCh chan<- error) { - cp := x509.NewCertPool() - ok := cp.AppendCertsFromPEM(config.CertPEM) - if !ok { - logger.Error(errors.New("parse cert")) - } - - creds := credentials.NewClientTLSFromCert(cp, "") - - mux := grpcRuntime.NewServeMux() - - dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(creds)} - - grpcEndpoint := config.GRPCAuthority - host, _, err := net.SplitHostPort(grpcEndpoint) - if err != nil { - logger.Error(err) - } - if host == "" { - grpcEndpoint = "localhost" + grpcEndpoint - } - err = RegisterHardwareServiceHandlerFromEndpoint(ctx, mux, grpcEndpoint, dialOpts) - if err != nil { - logger.Error(err) - } - err = RegisterTemplateHandlerFromEndpoint(ctx, mux, grpcEndpoint, dialOpts) - if err != nil { - logger.Error(err) - } - err = RegisterWorkflowSvcHandlerFromEndpoint(ctx, mux, grpcEndpoint, dialOpts) - if err != nil { - logger.Error(err) - } - http.HandleFunc("/cert", func(w http.ResponseWriter, r *http.Request) { http.ServeContent(w, r, "server.pem", config.ModTime, bytes.NewReader(config.CertPEM)) }) http.Handle("/metrics", promhttp.Handler()) http.HandleFunc("/version", getGitRevJSONHandler()) http.HandleFunc("/healthz", healthCheckHandler) - http.Handle("/", BasicAuth(config.HTTPBasicAuthUsername, config.HTTPBasicAuthPassword, mux)) srv := &http.Server{ Addr: config.HTTPAuthority, @@ -136,21 +93,3 @@ func getGitRevJSONHandler() http.HandlerFunc { _, _ = w.Write(b) } } - -// BasicAuth adds authentication to the routes handled by handler -// skips authentication if both authUsername and authPassword aren't set. -func BasicAuth(authUsername, authPassword string, handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if authUsername != "" || authPassword != "" { - user, pass, ok := r.BasicAuth() - if !ok || subtle.ConstantTimeCompare([]byte(user), []byte(authUsername)) != 1 || - subtle.ConstantTimeCompare([]byte(pass), []byte(authPassword)) != 1 { - w.Header().Set("WWW-Authenticate", `Basic realm="Tink Realm"`) - w.WriteHeader(401) - _, _ = w.Write([]byte("401 Unauthorized\n")) - return - } - } - handler.ServeHTTP(w, r) - }) -} diff --git a/protos/hardware/hardware.pb.gw.go b/protos/hardware/hardware.pb.gw.go deleted file mode 100644 index 72be82ae1..000000000 --- a/protos/hardware/hardware.pb.gw.go +++ /dev/null @@ -1,575 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: protos/hardware/hardware.proto - -/* -Package hardware is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package hardware - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var ( - _ codes.Code - _ io.Reader - _ status.Status - _ = runtime.String - _ = utilities.NewDoubleArray - _ = descriptor.ForMessage - _ = metadata.Join -) - -func request_HardwareService_Push_0(ctx context.Context, marshaler runtime.Marshaler, client HardwareServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq PushRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Push(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_HardwareService_Push_0(ctx context.Context, marshaler runtime.Marshaler, server HardwareServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq PushRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Push(ctx, &protoReq) - return msg, metadata, err -} - -func request_HardwareService_ByMAC_0(ctx context.Context, marshaler runtime.Marshaler, client HardwareServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.ByMAC(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_HardwareService_ByMAC_0(ctx context.Context, marshaler runtime.Marshaler, server HardwareServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.ByMAC(ctx, &protoReq) - return msg, metadata, err -} - -func request_HardwareService_ByIP_0(ctx context.Context, marshaler runtime.Marshaler, client HardwareServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.ByIP(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_HardwareService_ByIP_0(ctx context.Context, marshaler runtime.Marshaler, server HardwareServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.ByIP(ctx, &protoReq) - return msg, metadata, err -} - -var filter_HardwareService_ByID_0 = &utilities.DoubleArray{Encoding: map[string]int{"id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} - -func request_HardwareService_ByID_0(ctx context.Context, marshaler runtime.Marshaler, client HardwareServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_HardwareService_ByID_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.ByID(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_HardwareService_ByID_0(ctx context.Context, marshaler runtime.Marshaler, server HardwareServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_HardwareService_ByID_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.ByID(ctx, &protoReq) - return msg, metadata, err -} - -func request_HardwareService_All_0(ctx context.Context, marshaler runtime.Marshaler, client HardwareServiceClient, req *http.Request, pathParams map[string]string) (HardwareService_AllClient, runtime.ServerMetadata, error) { - var protoReq Empty - var metadata runtime.ServerMetadata - - stream, err := client.All(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_HardwareService_Delete_0(ctx context.Context, marshaler runtime.Marshaler, client HardwareServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq DeleteRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := client.Delete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_HardwareService_Delete_0(ctx context.Context, marshaler runtime.Marshaler, server HardwareServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq DeleteRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := server.Delete(ctx, &protoReq) - return msg, metadata, err -} - -// RegisterHardwareServiceHandlerServer registers the http handlers for service HardwareService to "mux". -// UnaryRPC :call HardwareServiceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterHardwareServiceHandlerFromEndpoint instead. -func RegisterHardwareServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server HardwareServiceServer) error { - mux.Handle("POST", pattern_HardwareService_Push_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_HardwareService_Push_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_Push_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("POST", pattern_HardwareService_ByMAC_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_HardwareService_ByMAC_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_ByMAC_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("POST", pattern_HardwareService_ByIP_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_HardwareService_ByIP_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_ByIP_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_HardwareService_ByID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_HardwareService_ByID_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_ByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_HardwareService_All_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - mux.Handle("DELETE", pattern_HardwareService_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_HardwareService_Delete_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_Delete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - return nil -} - -// RegisterHardwareServiceHandlerFromEndpoint is same as RegisterHardwareServiceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterHardwareServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterHardwareServiceHandler(ctx, mux, conn) -} - -// RegisterHardwareServiceHandler registers the http handlers for service HardwareService to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterHardwareServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterHardwareServiceHandlerClient(ctx, mux, NewHardwareServiceClient(conn)) -} - -// RegisterHardwareServiceHandlerClient registers the http handlers for service HardwareService -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "HardwareServiceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "HardwareServiceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "HardwareServiceClient" to call the correct interceptors. -func RegisterHardwareServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client HardwareServiceClient) error { - mux.Handle("POST", pattern_HardwareService_Push_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_HardwareService_Push_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_Push_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("POST", pattern_HardwareService_ByMAC_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_HardwareService_ByMAC_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_ByMAC_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("POST", pattern_HardwareService_ByIP_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_HardwareService_ByIP_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_ByIP_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_HardwareService_ByID_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_HardwareService_ByID_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_ByID_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_HardwareService_All_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_HardwareService_All_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_All_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("DELETE", pattern_HardwareService_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_HardwareService_Delete_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_HardwareService_Delete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - return nil -} - -var ( - pattern_HardwareService_Push_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "hardware"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_HardwareService_ByMAC_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "hardware", "mac"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_HardwareService_ByIP_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "hardware", "ip"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_HardwareService_ByID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "hardware", "id"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_HardwareService_All_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "hardware"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_HardwareService_Delete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "hardware", "id"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_HardwareService_Push_0 = runtime.ForwardResponseMessage - - forward_HardwareService_ByMAC_0 = runtime.ForwardResponseMessage - - forward_HardwareService_ByIP_0 = runtime.ForwardResponseMessage - - forward_HardwareService_ByID_0 = runtime.ForwardResponseMessage - - forward_HardwareService_All_0 = runtime.ForwardResponseStream - - forward_HardwareService_Delete_0 = runtime.ForwardResponseMessage -) diff --git a/protos/template/template.pb.gw.go b/protos/template/template.pb.gw.go deleted file mode 100644 index 2fd274907..000000000 --- a/protos/template/template.pb.gw.go +++ /dev/null @@ -1,466 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: protos/template/template.proto - -/* -Package template is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package template - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var ( - _ codes.Code - _ io.Reader - _ status.Status - _ = runtime.String - _ = utilities.NewDoubleArray - _ = descriptor.ForMessage - _ = metadata.Join -) - -func request_TemplateService_CreateTemplate_0(ctx context.Context, marshaler runtime.Marshaler, client TemplateServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq WorkflowTemplate - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.CreateTemplate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_TemplateService_CreateTemplate_0(ctx context.Context, marshaler runtime.Marshaler, server TemplateServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq WorkflowTemplate - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.CreateTemplate(ctx, &protoReq) - return msg, metadata, err -} - -var filter_TemplateService_GetTemplate_0 = &utilities.DoubleArray{Encoding: map[string]int{"id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} - -func request_TemplateService_GetTemplate_0(ctx context.Context, marshaler runtime.Marshaler, client TemplateServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - if protoReq.GetBy == nil { - protoReq.GetBy = &GetRequest_Id{} - } else if _, ok := protoReq.GetBy.(*GetRequest_Id); !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *GetRequest_Id, but: %t\n", protoReq.GetBy) - } - protoReq.GetBy.(*GetRequest_Id).Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_TemplateService_GetTemplate_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.GetTemplate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_TemplateService_GetTemplate_0(ctx context.Context, marshaler runtime.Marshaler, server TemplateServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - if protoReq.GetBy == nil { - protoReq.GetBy = &GetRequest_Id{} - } else if _, ok := protoReq.GetBy.(*GetRequest_Id); !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *GetRequest_Id, but: %t\n", protoReq.GetBy) - } - protoReq.GetBy.(*GetRequest_Id).Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_TemplateService_GetTemplate_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.GetTemplate(ctx, &protoReq) - return msg, metadata, err -} - -var filter_TemplateService_DeleteTemplate_0 = &utilities.DoubleArray{Encoding: map[string]int{"id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} - -func request_TemplateService_DeleteTemplate_0(ctx context.Context, marshaler runtime.Marshaler, client TemplateServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - if protoReq.GetBy == nil { - protoReq.GetBy = &GetRequest_Id{} - } else if _, ok := protoReq.GetBy.(*GetRequest_Id); !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *GetRequest_Id, but: %t\n", protoReq.GetBy) - } - protoReq.GetBy.(*GetRequest_Id).Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_TemplateService_DeleteTemplate_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.DeleteTemplate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_TemplateService_DeleteTemplate_0(ctx context.Context, marshaler runtime.Marshaler, server TemplateServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - if protoReq.GetBy == nil { - protoReq.GetBy = &GetRequest_Id{} - } else if _, ok := protoReq.GetBy.(*GetRequest_Id); !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *GetRequest_Id, but: %t\n", protoReq.GetBy) - } - protoReq.GetBy.(*GetRequest_Id).Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_TemplateService_DeleteTemplate_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.DeleteTemplate(ctx, &protoReq) - return msg, metadata, err -} - -var filter_TemplateService_ListTemplates_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} - -func request_TemplateService_ListTemplates_0(ctx context.Context, marshaler runtime.Marshaler, client TemplateServiceClient, req *http.Request, pathParams map[string]string) (TemplateService_ListTemplatesClient, runtime.ServerMetadata, error) { - var protoReq ListRequest - var metadata runtime.ServerMetadata - - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_TemplateService_ListTemplates_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - stream, err := client.ListTemplates(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -// RegisterTemplateServiceHandlerServer registers the http handlers for service TemplateService to "mux". -// UnaryRPC :call TemplateServiceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterTemplateServiceHandlerFromEndpoint instead. -func RegisterTemplateServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server TemplateServiceServer) error { - mux.Handle("POST", pattern_TemplateService_CreateTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_TemplateService_CreateTemplate_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TemplateService_CreateTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_TemplateService_GetTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_TemplateService_GetTemplate_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TemplateService_GetTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("DELETE", pattern_TemplateService_DeleteTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_TemplateService_DeleteTemplate_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TemplateService_DeleteTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_TemplateService_ListTemplates_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - return nil -} - -// RegisterTemplateServiceHandlerFromEndpoint is same as RegisterTemplateServiceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterTemplateServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterTemplateServiceHandler(ctx, mux, conn) -} - -// RegisterTemplateServiceHandler registers the http handlers for service TemplateService to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterTemplateServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterTemplateServiceHandlerClient(ctx, mux, NewTemplateServiceClient(conn)) -} - -// RegisterTemplateServiceHandlerClient registers the http handlers for service TemplateService -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "TemplateServiceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "TemplateServiceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "TemplateServiceClient" to call the correct interceptors. -func RegisterTemplateServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client TemplateServiceClient) error { - mux.Handle("POST", pattern_TemplateService_CreateTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_TemplateService_CreateTemplate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TemplateService_CreateTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_TemplateService_GetTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_TemplateService_GetTemplate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TemplateService_GetTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("DELETE", pattern_TemplateService_DeleteTemplate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_TemplateService_DeleteTemplate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TemplateService_DeleteTemplate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_TemplateService_ListTemplates_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_TemplateService_ListTemplates_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TemplateService_ListTemplates_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - }) - - return nil -} - -var ( - pattern_TemplateService_CreateTemplate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "templates"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_TemplateService_GetTemplate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "templates", "id"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_TemplateService_DeleteTemplate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "templates", "id"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_TemplateService_ListTemplates_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "templates"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_TemplateService_CreateTemplate_0 = runtime.ForwardResponseMessage - - forward_TemplateService_GetTemplate_0 = runtime.ForwardResponseMessage - - forward_TemplateService_DeleteTemplate_0 = runtime.ForwardResponseMessage - - forward_TemplateService_ListTemplates_0 = runtime.ForwardResponseStream -) diff --git a/protos/workflow/workflow.pb.gw.go b/protos/workflow/workflow.pb.gw.go deleted file mode 100644 index 5922b5991..000000000 --- a/protos/workflow/workflow.pb.gw.go +++ /dev/null @@ -1,566 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: protos/workflow/workflow.proto - -/* -Package workflow is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package workflow - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var ( - _ codes.Code - _ io.Reader - _ status.Status - _ = runtime.String - _ = utilities.NewDoubleArray - _ = descriptor.ForMessage - _ = metadata.Join -) - -func request_WorkflowService_CreateWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq CreateRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.CreateWorkflow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_WorkflowService_CreateWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, server WorkflowServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq CreateRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.CreateWorkflow(ctx, &protoReq) - return msg, metadata, err -} - -func request_WorkflowService_GetWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := client.GetWorkflow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_WorkflowService_GetWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, server WorkflowServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := server.GetWorkflow(ctx, &protoReq) - return msg, metadata, err -} - -func request_WorkflowService_DeleteWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := client.DeleteWorkflow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_WorkflowService_DeleteWorkflow_0(ctx context.Context, marshaler runtime.Marshaler, server WorkflowServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := server.DeleteWorkflow(ctx, &protoReq) - return msg, metadata, err -} - -func request_WorkflowService_ListWorkflows_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (WorkflowService_ListWorkflowsClient, runtime.ServerMetadata, error) { - var protoReq Empty - var metadata runtime.ServerMetadata - - stream, err := client.ListWorkflows(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_WorkflowService_GetWorkflowContext_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := client.GetWorkflowContext(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_WorkflowService_GetWorkflowContext_0(ctx context.Context, marshaler runtime.Marshaler, server WorkflowServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := server.GetWorkflowContext(ctx, &protoReq) - return msg, metadata, err -} - -func request_WorkflowService_ShowWorkflowEvents_0(ctx context.Context, marshaler runtime.Marshaler, client WorkflowServiceClient, req *http.Request, pathParams map[string]string) (WorkflowService_ShowWorkflowEventsClient, runtime.ServerMetadata, error) { - var protoReq GetRequest - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - stream, err := client.ShowWorkflowEvents(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -// RegisterWorkflowServiceHandlerServer registers the http handlers for service WorkflowService to "mux". -// UnaryRPC :call WorkflowServiceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterWorkflowServiceHandlerFromEndpoint instead. -func RegisterWorkflowServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server WorkflowServiceServer) error { - mux.Handle("POST", pattern_WorkflowService_CreateWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_WorkflowService_CreateWorkflow_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_CreateWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_WorkflowService_GetWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_WorkflowService_GetWorkflow_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_GetWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("DELETE", pattern_WorkflowService_DeleteWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_WorkflowService_DeleteWorkflow_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_DeleteWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_WorkflowService_ListWorkflows_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - mux.Handle("GET", pattern_WorkflowService_GetWorkflowContext_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_WorkflowService_GetWorkflowContext_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_GetWorkflowContext_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_WorkflowService_ShowWorkflowEvents_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - return nil -} - -// RegisterWorkflowServiceHandlerFromEndpoint is same as RegisterWorkflowServiceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterWorkflowServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterWorkflowServiceHandler(ctx, mux, conn) -} - -// RegisterWorkflowServiceHandler registers the http handlers for service WorkflowService to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterWorkflowServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterWorkflowServiceHandlerClient(ctx, mux, NewWorkflowServiceClient(conn)) -} - -// RegisterWorkflowServiceHandlerClient registers the http handlers for service WorkflowService -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "WorkflowServiceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "WorkflowServiceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "WorkflowServiceClient" to call the correct interceptors. -func RegisterWorkflowServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client WorkflowServiceClient) error { - mux.Handle("POST", pattern_WorkflowService_CreateWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_WorkflowService_CreateWorkflow_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_CreateWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_WorkflowService_GetWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_WorkflowService_GetWorkflow_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_GetWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("DELETE", pattern_WorkflowService_DeleteWorkflow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_WorkflowService_DeleteWorkflow_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_DeleteWorkflow_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_WorkflowService_ListWorkflows_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_WorkflowService_ListWorkflows_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_ListWorkflows_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_WorkflowService_GetWorkflowContext_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_WorkflowService_GetWorkflowContext_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_GetWorkflowContext_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - mux.Handle("GET", pattern_WorkflowService_ShowWorkflowEvents_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_WorkflowService_ShowWorkflowEvents_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_WorkflowService_ShowWorkflowEvents_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - }) - - return nil -} - -var ( - pattern_WorkflowService_CreateWorkflow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "workflows"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_WorkflowService_GetWorkflow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "workflows", "id"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_WorkflowService_DeleteWorkflow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "workflows", "id"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_WorkflowService_ListWorkflows_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "workflows"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_WorkflowService_GetWorkflowContext_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v1", "workflows", "id", "state"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_WorkflowService_ShowWorkflowEvents_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v1", "workflows", "id", "events"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_WorkflowService_CreateWorkflow_0 = runtime.ForwardResponseMessage - - forward_WorkflowService_GetWorkflow_0 = runtime.ForwardResponseMessage - - forward_WorkflowService_DeleteWorkflow_0 = runtime.ForwardResponseMessage - - forward_WorkflowService_ListWorkflows_0 = runtime.ForwardResponseStream - - forward_WorkflowService_GetWorkflowContext_0 = runtime.ForwardResponseMessage - - forward_WorkflowService_ShowWorkflowEvents_0 = runtime.ForwardResponseStream -) From 4de6942204d10144a9199d1eb6e474cdcc941054 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 25 Jan 2022 17:19:40 -0500 Subject: [PATCH 6/7] http: Drop http_handlers{,_test}.go http_handlers.go only contained the logic for translating json rpc -> grpc in the Register{Hardware,Template,Workflow}ServiceHandlerFromEndpoint functions. Since we don't need them they can go away. Since there's not http_handlers.go we don't need http_handlers_test.go either. Signed-off-by: Manuel Mendez --- go.mod | 1 - http-server/http_handlers.go | 598 ------------------------------ http-server/http_handlers_test.go | 349 ----------------- 3 files changed, 948 deletions(-) delete mode 100644 http-server/http_handlers.go delete mode 100644 http-server/http_handlers_test.go diff --git a/go.mod b/go.mod index aca4d37fd..9eaf57d52 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/google/uuid v1.3.0 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 - github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/ktr0731/evans v0.10.0 github.com/lib/pq v1.10.1 diff --git a/http-server/http_handlers.go b/http-server/http_handlers.go deleted file mode 100644 index 7ef9f7310..000000000 --- a/http-server/http_handlers.go +++ /dev/null @@ -1,598 +0,0 @@ -package httpserver - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io" - "net/http" - tt "text/template" - - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "github.com/tinkerbell/tink/pkg" - "github.com/tinkerbell/tink/protos/hardware" - "github.com/tinkerbell/tink/protos/template" - "github.com/tinkerbell/tink/protos/workflow" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - "google.golang.org/protobuf/encoding/protojson" -) - -// RegisterHardwareServiceHandlerFromEndpoint serves Hardware requests at the -// given endpoint over GRPC. -func RegisterHardwareServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - logger.Info("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - logger.Info("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - client := hardware.NewHardwareServiceClient(conn) - - // hardware push handler | POST /v1/hardware - hardwarePushPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "hardware"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("POST", hardwarePushPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var hw pkg.HardwareWrapper - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", berr).Error()) - return - } - - if err := json.NewDecoder(newReader()).Decode(&hw); err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", err).Error()) - return - } - - if hw.Hardware == nil || hw.Id == "" { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "invalid hardware data, must contain an id").Error()) - return - } - - if _, err := client.Push(ctx, &hardware.PushRequest{Data: hw.Hardware}); err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, fmt.Sprintf(`{"status": "ok", "msg": "hardware data pushed successfully", "id": "%v"}`, hw.Id)) - }) - - // hardware mac handler | POST /v1/hardware/mac - hardwareByMACPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "hardware", "mac"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("POST", hardwareByMACPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr hardware.GetRequest - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", berr).Error()) - return - } - - if err := json.NewDecoder(newReader()).Decode(&gr); err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", err).Error()) - return - } - - hw, err := client.ByMAC(context.Background(), &hardware.GetRequest{Mac: gr.Mac}) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - b, err := json.Marshal(pkg.HardwareWrapper{Hardware: hw}) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - } - writeResponse(w, http.StatusOK, string(b)) - }) - - // hardware ip handler | POST /v1/hardware/ip - hardwareByIPPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "hardware", "ip"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("POST", hardwareByIPPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr hardware.GetRequest - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", berr).Error()) - return - } - - if err := json.NewDecoder(newReader()).Decode(&gr); err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", err).Error()) - return - } - - hw, err := client.ByIP(context.Background(), &hardware.GetRequest{Ip: gr.Ip}) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - b, err := json.Marshal(pkg.HardwareWrapper{Hardware: hw}) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, string(b)) - }) - - // hardware id handler | GET /v1/hardware/{id} - hardwareByIDPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "hardware", "id"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", hardwareByIDPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr hardware.GetRequest - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - gr.Id, err = runtime.String(val) - - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err).Error()) - return - } - - hw, err := client.ByID(context.Background(), &hardware.GetRequest{Id: gr.Id}) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - b, err := json.Marshal(pkg.HardwareWrapper{Hardware: hw}) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, string(b)) - }) - - // hardware all handler | GET /v1/hardware - hardwareAllPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "hardware"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", hardwareAllPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - alls, err := client.All(context.Background(), &hardware.Empty{}) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - var hw *hardware.Hardware - - for hw, err = alls.Recv(); err == nil && hw != nil; hw, err = alls.Recv() { - b, err := json.Marshal(pkg.HardwareWrapper{Hardware: hw}) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, string(b)) - } - if err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - }) - - // hardware delete handler | DELETE /v1/hardware/{id} - hardwareDeletePattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "hardware", "id"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("DELETE", hardwareDeletePattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var dr hardware.DeleteRequest - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - dr.Id, err = runtime.String(val) - - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err).Error()) - return - } - - if _, err := client.Delete(context.Background(), &dr); err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, fmt.Sprintf(`{"status": "ok", "msg": "hardware deleted successfully", "id": "%v"}`, dr.Id)) - }) - - return nil -} - -// RegisterTemplateHandlerFromEndpoint serves Template requests at the given -// endpoint over GRPC. -func RegisterTemplateHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - logger.Info("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - logger.Info("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - client := template.NewTemplateServiceClient(conn) - - // template create handler | POST /v1/templates - templateCreatePattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "templates"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("POST", templateCreatePattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var tmpl template.WorkflowTemplate - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", berr).Error()) - return - } - - if err := json.NewDecoder(newReader()).Decode(&tmpl); err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", err).Error()) - return - } - - if tmpl.Data != "" { - if err := tryParseTemplate(tmpl.Data); err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - res, err := client.CreateTemplate(context.Background(), &tmpl) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, fmt.Sprintf(`{"status": "ok", "msg": "template created successfully", "id": "%v"}`, res.Id)) - } - }) - - // template get by id handler | GET /v1/templates/{id} - templateGetByIDPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "templates", "id"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", templateGetByIDPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr template.GetRequest - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - id, err := runtime.String(val) - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err).Error()) - return - } - gr.GetBy = &template.GetRequest_Id{Id: id} - - t, err := client.GetTemplate(context.Background(), &gr) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, t.Data) - }) - - // template get by name handler | GET /v1/templates/name/{name} - templateGetByNamePattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 2}, []string{"v1", "templates", "name"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", templateGetByNamePattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr template.GetRequest - val, ok := pathParams["name"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name").Error()) - return - } - - name, err := runtime.String(val) - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err).Error()) - return - } - gr.GetBy = &template.GetRequest_Name{Name: name} - - t, err := client.GetTemplate(context.Background(), &gr) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, t.Data) - }) - - // template delete handler | DELETE /v1/templates/{id} - templateDeletePattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "templates", "id"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("DELETE", templateDeletePattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr template.GetRequest - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - id, err := runtime.String(val) - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err).Error()) - return - } - gr.GetBy = &template.GetRequest_Id{Id: id} - - if _, err := client.DeleteTemplate(context.Background(), &gr); err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, fmt.Sprintf(`{"status": "ok", "msg": "template deleted successfully", "id": "%v"}`, gr.GetId())) - }) - - // template list handler | GET /v1/templates?name= - templateListPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "templates"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", templateListPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - nameFilter := "*" // default filter will match everything - if query := req.URL.Query()["name"]; len(query) > 0 { - nameFilter = query[0] - } - - list, err := client.ListTemplates(context.Background(), &template.ListRequest{ - FilterBy: &template.ListRequest_Name{ - Name: nameFilter, - }, - }) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - var tmp *template.WorkflowTemplate - - for tmp, err = list.Recv(); err == nil && tmp.Name != ""; tmp, err = list.Recv() { - m := protojson.MarshalOptions{UseProtoNames: true} - s, err := m.Marshal(tmp) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, string(s)) - } - - if err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusInternalServerError, err.Error()) - } - }) - - return nil -} - -// RegisterWorkflowSvcHandlerFromEndpoint serves Workflow requests at the given -// endpoint over GRPC. -func RegisterWorkflowSvcHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - logger.Info("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - logger.Info("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - client := workflow.NewWorkflowServiceClient(conn) - - // workflow create handler | POST /v1/workflows - workflowCreatePattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "workflows"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("POST", workflowCreatePattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var cr workflow.CreateRequest - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", berr).Error()) - return - } - - if err := json.NewDecoder(newReader()).Decode(&cr); err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "%v", err).Error()) - return - } - - wf, err := client.CreateWorkflow(context.Background(), &cr) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, fmt.Sprintf(`{"status": "ok", "msg": "workflow created successfully", "id": "%v"}`, wf.Id)) - }) - - // workflow get handler | GET /v1/workflows/{id} - workflowGetPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "workflows", "id"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", workflowGetPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr workflow.GetRequest - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - gr.Id, err = runtime.String(val) - - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err).Error()) - return - } - - wf, err := client.GetWorkflow(context.Background(), &gr) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - writeResponse(w, http.StatusOK, wf.Data) - }) - - // workflow delete handler | DELETE /v1/workflows/{id} - workflowDeletePattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "workflows", "id"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("DELETE", workflowDeletePattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - gr := workflow.GetRequest{} - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - gr.Id, err = runtime.String(val) - - if _, err := client.DeleteWorkflow(context.Background(), &gr); err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, fmt.Sprintf(`{"status": "ok", "msg": "workflow deleted successfully", "id": "%v"}`, gr.Id)) - }) - - // workflow list handler | GET /v1/workflows - workflowListPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "workflows"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", workflowListPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - list, err := client.ListWorkflows(context.Background(), &workflow.Empty{}) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - - var wf *workflow.Workflow - - for wf, err = list.Recv(); err == nil && wf.Id != ""; wf, err = list.Recv() { - m := protojson.MarshalOptions{UseProtoNames: true} - s, err := m.Marshal(wf) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, string(s)) - } - - if err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - }) - - // workflow state handler | GET /v1/workflows/{id}/state - workflowStatePattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v1", "workflows", "id", "state"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", workflowStatePattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr workflow.GetRequest - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - gr.Id, err = runtime.String(val) - - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err).Error()) - return - } - - wfc, err := client.GetWorkflowContext(context.Background(), &gr) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - m := protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: true} - s, err := m.Marshal(wfc) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, string(s)) - }) - - // workflow events handler | GET /v1/workflows/{id}/events - workflowEventsPattern := runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v1", "workflows", "id", "events"}, "", runtime.AssumeColonVerbOpt(true))) - mux.Handle("GET", workflowEventsPattern, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - var gr workflow.GetRequest - val, ok := pathParams["id"] - if !ok { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id").Error()) - return - } - - gr.Id, err = runtime.String(val) - - if err != nil { - writeResponse(w, http.StatusBadRequest, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err).Error()) - return - } - - events, err := client.ShowWorkflowEvents(context.Background(), &gr) - if err != nil { - logger.Error(err) - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - var event *workflow.WorkflowActionStatus - - for event, err = events.Recv(); err == nil && event != nil; event, err = events.Recv() { - m := protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: true} - s, err := m.Marshal(event) - if err != nil { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - writeResponse(w, http.StatusOK, string(s)) - } - if err != nil && !errors.Is(err, io.EOF) { - writeResponse(w, http.StatusInternalServerError, err.Error()) - return - } - }) - - return nil -} - -func tryParseTemplate(data string) error { - tmpl := *tt.New("") - if _, err := tmpl.Parse(data); err != nil { - return err - } - return nil -} - -// writeResponse appends a new line after res. -func writeResponse(w http.ResponseWriter, st int, res string) { - w.WriteHeader(st) - if _, err := w.Write([]byte(fmt.Sprintln(res))); err != nil { - logger.Info(err) - } -} diff --git a/http-server/http_handlers_test.go b/http-server/http_handlers_test.go deleted file mode 100644 index b1534d604..000000000 --- a/http-server/http_handlers_test.go +++ /dev/null @@ -1,349 +0,0 @@ -package httpserver - -import ( - "context" - "encoding/json" - "errors" - "io/ioutil" - "net" - "net/http" - "net/http/httptest" - "os" - "strings" - "testing" - - grpcRuntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/packethost/pkg/log" - "github.com/tinkerbell/tink/protos/hardware" - "google.golang.org/grpc" - "google.golang.org/grpc/test/bufconn" -) - -const bufSize = 1024 * 1024 - -var lis *bufconn.Listener - -func bufDialer(context.Context, string) (net.Conn, error) { - return lis.Dial() -} - -type server struct { - hardware.UnimplementedHardwareServiceServer -} - -func (s *server) Push(_ context.Context, in *hardware.PushRequest) (*hardware.Empty, error) { - hw := in.Data - if hw.Id == "" { - err := errors.New("id must be set to a UUID, got id: " + hw.Id) - return &hardware.Empty{}, err - } - - _, err := json.Marshal(hw) - if err != nil { - logger.Error(err) - } - - // pretend to push into the db - - return &hardware.Empty{}, err -} - -func TestMain(m *testing.M) { - logger, _ = log.Init("github.com/tinkerbell/tink") - lis = bufconn.Listen(bufSize) - s := grpc.NewServer() - hardware.RegisterHardwareServiceServer(s, &server{}) - go func() { - if err := s.Serve(lis); err != nil { - logger.Info("Server exited with error: %v", err) - } - }() - os.Exit(m.Run()) -} - -func TestHardwarePushHandler(t *testing.T) { - for name, test := range handlerTests { - t.Log(name) - - mux := grpcRuntime.NewServeMux() - dialOpts := []grpc.DialOption{grpc.WithContextDialer(bufDialer), grpc.WithInsecure()} - grpcEndpoint := "localhost:42113" - - err := RegisterHardwareServiceHandlerFromEndpoint(context.Background(), mux, grpcEndpoint, dialOpts) - if err != nil { - t.Fatal(err) - } - - req, err := http.NewRequest("POST", "/v1/hardware", nil) - if err != nil { - t.Fatal(err) - } - - req.Body = ioutil.NopCloser(strings.NewReader(test.json)) - resp := httptest.NewRecorder() - - mux.ServeHTTP(resp, req) - - if status := resp.Code; status != test.status { - t.Errorf("handler returned wrong status code: got %v want %v", - status, test.status) - } - - t.Log(resp.Body.String()) - } -} - -var handlerTests = map[string]struct { - id string - status int - error string - json string -}{ - "hardware push": { - id: "fde7c87c-d154-447e-9fce-7eb7bdec90c0", - status: http.StatusOK, - json: hardwarePushData, - }, - "tinkerbell no metadata": { - id: "363115b0-f03d-4ce5-9a15-5514193d131a", - status: http.StatusOK, - json: hardwarePushDataNoMetadata, - }, - "hardware push no id": { - status: http.StatusBadRequest, - json: hardwarePushDataNoID, - }, - "hardware push invalid json": { - status: http.StatusBadRequest, - json: hardwarePushDataInvalidJSON, - }, -} - -const ( - hardwarePushData = ` -{ - "id": "0eba0bf8-3772-4b4a-ab9f-6ebe93b90a94", - "metadata": { - "test": "testing unos dos tres", - "bonding_mode": 5, - "custom": { - "preinstalled_operating_system_version": {}, - "private_subnets": [] - }, - "facility": { - "facility_code": "ewr1", - "plan_slug": "c2.medium.x86", - "plan_version_slug": "" - }, - "instance": { - "crypted_root_password": "redacted", - "operating_system_version": { - "distro": "ubuntu", - "os_slug": "ubuntu_18_04", - "version": "18.04" - }, - "storage": { - "disks": [ - { - "device": "/dev/sda", - "partitions": [ - { - "label": "BIOS", - "number": 1, - "size": 4096 - }, - { - "label": "SWAP", - "number": 2, - "size": 3993600 - }, - { - "label": "ROOT", - "number": 3, - "size": 0 - } - ], - "wipe_table": true - } - ], - "filesystems": [ - { - "mount": { - "create": { - "options": ["-L", "ROOT"] - }, - "device": "/dev/sda3", - "format": "ext4", - "point": "/" - } - }, - { - "mount": { - "create": { - "options": ["-L", "SWAP"] - }, - "device": "/dev/sda2", - "format": "swap", - "point": "none" - } - } - ] - } - }, - "manufacturer": { - "id": "", - "slug": "" - }, - "state": "" - }, - "network": { - "interfaces": [ - { - "dhcp": { - "arch": "x86_64", - "hostname": "server001", - "ip": { - "address": "192.168.1.5", - "gateway": "192.168.1.1", - "netmask": "255.255.255.248" - }, - "lease_time": 86400, - "mac": "00:00:00:00:00:00", - "name_servers": [], - "time_servers": [], - "uefi": false - }, - "netboot": { - "allow_pxe": true, - "allow_workflow": true, - "ipxe": { - "contents": "#!ipxe", - "url": "http://url/menu.ipxe" - }, - "osie": { - "base_url": "", - "initrd": "", - "kernel": "vmlinuz-x86_64" - } - } - } - ] - } -} -` - hardwarePushDataNoMetadata = ` -{ - "network":{ - "interfaces":[ - { - "dhcp":{ - "mac":"ec:0d:9a:c0:01:0c", - "hostname":"server001", - "lease_time":86400, - "arch":"x86_64", - "ip":{ - "address":"192.168.1.5", - "netmask":"255.255.255.248", - "gateway":"192.168.1.1" - } - }, - "netboot":{ - "allow_pxe":true, - "allow_workflow":true, - "ipxe":{ - "url":"http://url/menu.ipxe", - "contents":"#!ipxe" - }, - "osie":{ - "kernel":"vmlinuz-x86_64" - } - } - } - ] - }, - "id":"363115b0-f03d-4ce5-9a15-5514193d131a" - } -` - hardwarePushDataNoID = ` -{ - "metadata": { - "facility": { - "facility_code": "ewr1", - "plan_slug": "c2.medium.x86", - "plan_version_slug": "" - }, - "instance": {}, - "state": "" - }, - "network": { - "interfaces": [ - { - "dhcp": { - "arch": "x86_64", - "ip": { - "address": "192.168.1.5", - "gateway": "192.168.1.1", - "netmask": "255.255.255.248" - }, - "mac": "00:00:00:00:00:00", - "uefi": false - }, - "netboot": { - "allow_pxe": true, - "allow_workflow": true - } - } - ] - } -} -` - hardwarePushDataInvalidJSON = ` - "id": "363115b0-f03d-4ce5-9a15-5514193d131a", - "metadata": { - "bonding_mode": 5, - "custom": { - "preinstalled_operating_system_version": {}, - "private_subnets": [] - }, - "facility": { - "facility_code": "ewr1", - "plan_slug": "c2.medium.x86", - "plan_version_slug": "" - }, - "instance": {}, - "network": { - "interfaces": [ - { - "dhcp": { - "arch": "x86_64", - "hostname": "server001", - "ip": { - "address": "192.168.1.5", - "gateway": "192.168.1.1", - "netmask": "255.255.255.248" - }, - "lease_time": 86400, - "mac": "00:00:00:00:00:00", - "name_servers": [], - "time_servers": [], - "uefi": false - }, - "netboot": { - "allow_pxe": true, - "allow_workflow": true, - "ipxe": { - "contents": "#!ipxe", - "url": "http://url/menu.ipxe" - }, - "osie": { - "base_url": "", - "initrd": "", - "kernel": "vmlinuz-x86_64" - } - } - } - ] - } -} -` -) From 740cfec26f5eed175bf9acc4ee1bf614abd1a375 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 25 Jan 2022 14:46:01 -0500 Subject: [PATCH 7/7] Get rid of HTTP auth env/config vars These are no longer needed. Signed-off-by: Manuel Mendez --- cmd/tink-server/main.go | 28 ++++++++++------------------ docker-compose.yaml | 4 ---- docs/ENVVARS.md | 2 -- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/cmd/tink-server/main.go b/cmd/tink-server/main.go index a3691b469..66f3adb93 100644 --- a/cmd/tink-server/main.go +++ b/cmd/tink-server/main.go @@ -27,18 +27,16 @@ var version = "devel" // DaemonConfig represents all the values you can configure as part of the tink-server. // You can change the configuration via environment variable, or file, or command flags. type DaemonConfig struct { - Facility string - PGDatabase string - PGUSer string - PGPassword string - PGSSLMode string - OnlyMigration bool - GRPCAuthority string - TLSCert string - CertDir string - HTTPAuthority string - HTTPBasicAuthUsername string - HTTPBasicAuthPassword string + Facility string + PGDatabase string + PGUSer string + PGPassword string + PGSSLMode string + OnlyMigration bool + GRPCAuthority string + TLSCert string + CertDir string + HTTPAuthority string } func (c *DaemonConfig) AddFlags(fs *pflag.FlagSet) { @@ -87,12 +85,6 @@ func (c *DaemonConfig) PopulateFromLegacyEnvVar() { if httpAuthority := os.Getenv("TINKERBELL_HTTP_AUTHORITY"); httpAuthority != "" { c.HTTPAuthority = httpAuthority } - if basicAuthUser := os.Getenv("TINK_AUTH_USERNAME"); basicAuthUser != "" { - c.HTTPBasicAuthUsername = basicAuthUser - } - if basicAuthPass := os.Getenv("TINK_AUTH_PASSWORD"); basicAuthPass != "" { - c.HTTPBasicAuthPassword = basicAuthPass - } } func main() { diff --git a/docker-compose.yaml b/docker-compose.yaml index 8828f3013..2cb3a21fb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -30,8 +30,6 @@ services: PGUSER: tinkerbell TINKERBELL_GRPC_AUTHORITY: :42113 TINKERBELL_HTTP_AUTHORITY: :42114 - TINK_AUTH_USERNAME: ${TINKERBELL_TINK_USERNAME} - TINK_AUTH_PASSWORD: ${TINKERBELL_TINK_PASSWORD} depends_on: tink-server-migration: condition: service_started @@ -64,8 +62,6 @@ services: PGUSER: tinkerbell TINKERBELL_GRPC_AUTHORITY: :42113 TINKERBELL_HTTP_AUTHORITY: :42114 - TINK_AUTH_USERNAME: ${TINKERBELL_TINK_USERNAME} - TINK_AUTH_PASSWORD: ${TINKERBELL_TINK_PASSWORD} depends_on: db: condition: service_healthy diff --git a/docs/ENVVARS.md b/docs/ENVVARS.md index 9501b1838..f44d9c8dc 100644 --- a/docs/ENVVARS.md +++ b/docs/ENVVARS.md @@ -4,8 +4,6 @@ The follow describes environment variables available to be set when running Tink | Name | Type | Service(s) | Description | | ---------------------------------------------------------------------------------------------- | ------ | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | -| `TINK_AUTH_USERNAME=tink` | string | server | username to use for basic auth to http endpoints | -| `TINK_AUTH_PASSWORD=tink` | string | server | password to use for basic auth to http endpoints | | `TINKERBELL_CERT_URL=http://127.0.0.1:42114/cert` | string | cli/worker | url from which to get a TLS certificate, needed when Tink Server's TLS cert is signed by an unknown certificate authority, ie self-signed | | `CERTS_DIR=/certs` | string | server | a directory which contains the `bundle.pem` and `server-key.pem` files, for use when running Tink with TLS | | `TINKERBELL_CERTS_DIR=/certs` | string | server | same as `CERTS_DIR`, deprecated in server |