From 3f0bf59712b47da1cb53ecaf04a16be37faa00cf Mon Sep 17 00:00:00 2001 From: lostbean Date: Wed, 6 Dec 2023 10:50:02 -0300 Subject: [PATCH] fix linter errors in other modules --- .../container_status_stringifier.go | 2 ++ .../kurtosis_instruction_printer.go | 8 ++++--- .../service_status_stringifier.go | 2 ++ connect-server/server.go | 16 ++++++++----- enclave-manager/server/server.go | 23 +++++++++++++------ 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/cli/cli/helpers/container_status_stringifier/container_status_stringifier.go b/cli/cli/helpers/container_status_stringifier/container_status_stringifier.go index 5d64f07c0b..87da321713 100644 --- a/cli/cli/helpers/container_status_stringifier/container_status_stringifier.go +++ b/cli/cli/helpers/container_status_stringifier/container_status_stringifier.go @@ -17,6 +17,8 @@ func ContainerStatusStringifier(containerStatus kurtosis_core_rpc_api_bindings.C return colorizeStopped(containerStatusStr) case kurtosis_core_rpc_api_bindings.Container_RUNNING: return colorizeRunning(containerStatusStr) + case kurtosis_core_rpc_api_bindings.Container_UNKNOWN: + return containerStatusStr default: return containerStatusStr } diff --git a/cli/cli/helpers/output_printers/kurtosis_instruction_printer.go b/cli/cli/helpers/output_printers/kurtosis_instruction_printer.go index 8fa5303703..465d97e790 100644 --- a/cli/cli/helpers/output_printers/kurtosis_instruction_printer.go +++ b/cli/cli/helpers/output_printers/kurtosis_instruction_printer.go @@ -3,6 +3,10 @@ package output_printers import ( "errors" "fmt" + "strings" + "sync" + "time" + "github.com/bazelbuild/buildtools/build" "github.com/briandowns/spinner" "github.com/fatih/color" @@ -12,9 +16,6 @@ import ( "github.com/kurtosis-tech/kurtosis/cli/cli/out" "github.com/kurtosis-tech/stacktrace" "github.com/sirupsen/logrus" - "strings" - "sync" - "time" ) const ( @@ -184,6 +185,7 @@ func formatInfo(infoMessage string) string { return colorizeInfo(infoMessage) } +// nolint:exhaustive func formatInstruction(instruction *kurtosis_core_rpc_api_bindings.StarlarkInstruction, verbosity run.Verbosity) string { var serializedInstruction string switch verbosity { diff --git a/cli/cli/helpers/service_status_stringifier/service_status_stringifier.go b/cli/cli/helpers/service_status_stringifier/service_status_stringifier.go index d1f6b9b06e..ddefded603 100644 --- a/cli/cli/helpers/service_status_stringifier/service_status_stringifier.go +++ b/cli/cli/helpers/service_status_stringifier/service_status_stringifier.go @@ -17,6 +17,8 @@ func ServiceStatusStringifier(serviceStatus kurtosis_core_rpc_api_bindings.Servi return colorizeStopped(serviceStatusStr) case kurtosis_core_rpc_api_bindings.ServiceStatus_RUNNING: return colorizeRunning(serviceStatusStr) + case kurtosis_core_rpc_api_bindings.ServiceStatus_UNKNOWN: + return serviceStatusStr default: return serviceStatusStr } diff --git a/connect-server/server.go b/connect-server/server.go index dfedc99d14..411283bed4 100644 --- a/connect-server/server.go +++ b/connect-server/server.go @@ -3,17 +3,18 @@ package connect_server import ( "context" "fmt" - "github.com/kurtosis-tech/stacktrace" - "github.com/rs/cors" - "github.com/sirupsen/logrus" - "golang.org/x/net/http2" - "golang.org/x/net/http2/h2c" "log" "net/http" "os" "os/signal" "syscall" "time" + + "github.com/kurtosis-tech/stacktrace" + "github.com/rs/cors" + "github.com/sirupsen/logrus" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" ) const ( @@ -63,6 +64,7 @@ func (server *ConnectServer) RunServerUntilStopped( mux.Handle(server.path, server.handler) + // nolint:exhaustruct httpServer := http.Server{ Addr: fmt.Sprintf(":%v", server.listenPort), Handler: cors.Handler(h2c.NewHandler(mux, &http2.Server{})), @@ -78,7 +80,9 @@ func (server *ConnectServer) RunServerUntilStopped( <-stopper serverStoppedChan := make(chan interface{}) go func() { - httpServer.Shutdown(context.Background()) + if err := httpServer.Shutdown(context.Background()); err != nil { + logrus.WithError(err).Error("Failed to shutdown the HTTP server") + } serverStoppedChan <- nil }() select { diff --git a/enclave-manager/server/server.go b/enclave-manager/server/server.go index d17e7c8c75..cf327283f2 100644 --- a/enclave-manager/server/server.go +++ b/enclave-manager/server/server.go @@ -26,11 +26,13 @@ import ( ) const ( - listenPort = 8081 - grpcServerStopGracePeriod = 5 * time.Second - engineHostUrl = "http://localhost:9710" - kurtosisCloudApiHost = "https://cloud.kurtosis.com" - kurtosisCloudApiPort = 8080 + listenPort = 8081 + grpcServerStopGracePeriod = 5 * time.Second + engineHostUrl = "http://localhost:9710" + kurtosisCloudApiHost = "https://cloud.kurtosis.com" + kurtosisCloudApiPort = 8080 + numberOfElementsAuthHeader = 2 + numberOfElementsHostString = 2 ) type Authentication struct { @@ -60,6 +62,7 @@ func NewWebserver(enforceAuth bool) (*WebServer, error) { apiKeyMutex: &sync.RWMutex{}, apiKeyMap: map[string]*string{}, instanceConfigMap: map[string]*kurtosis_backend_server_rpc_api_bindings.GetCloudInstanceConfigResponse{}, + instanceConfig: nil, }, nil } @@ -83,7 +86,7 @@ func (c *WebServer) ValidateRequestAuthorization( reqToken := header.Get("Authorization") splitToken := strings.Split(reqToken, "Bearer") - if len(splitToken) != 2 { + if len(splitToken) != numberOfElementsAuthHeader { return false, stacktrace.NewError("Authorization token malformed. Bearer token format required") } reqToken = strings.TrimSpace(splitToken[1]) @@ -101,7 +104,7 @@ func (c *WebServer) ValidateRequestAuthorization( } reqHost := header.Get("Host") splitHost := strings.Split(reqHost, ":") - if len(splitHost) != 2 { + if len(splitHost) != numberOfElementsHostString { return false, stacktrace.NewError("Host header malformed. host:port format required") } reqHost = splitHost[0] @@ -227,6 +230,9 @@ func (c *WebServer) RunStarlarkPackage(ctx context.Context, req *connect.Request } starlarkLogsStream, err := (*apiContainerServiceClient).RunStarlarkPackage(ctx, runStarlarkRequest) + if err != nil { + return stacktrace.Propagate(err, "Failed to run package: %s", req.Msg.RunStarlarkPackageArgs.PackageId) + } for starlarkLogsStream.Receive() { resp := starlarkLogsStream.Msg() @@ -333,6 +339,9 @@ func (c *WebServer) DownloadFilesArtifact( } filesArtifactStream, err := (*apiContainerServiceClient).DownloadFilesArtifact(ctx, downloadFilesArtifactRequest) + if err != nil { + return stacktrace.Propagate(err, "Failed to create download stream for file artifact: %s", filesArtifactIdentifier) + } for filesArtifactStream.Receive() { resp := filesArtifactStream.Msg() err = str.Send(resp)