From 5e303a35ec258f0ed8370401a37eed5aaa17e6fe Mon Sep 17 00:00:00 2001 From: Dmitry Savintsev Date: Wed, 27 Sep 2023 22:49:20 +0200 Subject: [PATCH] remove parameter for httpPingOnly Signed-off-by: Dmitry Savintsev --- cmd/timestamp-server/app/serve.go | 2 +- pkg/generated/restapi/configure_timestamp_server.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/timestamp-server/app/serve.go b/cmd/timestamp-server/app/serve.go index a7807b5e0..2c3715f96 100644 --- a/cmd/timestamp-server/app/serve.go +++ b/cmd/timestamp-server/app/serve.go @@ -100,7 +100,7 @@ var serveCmd = &cobra.Command{ host := viper.GetString("host") port := int(viper.GetUint("port")) scheme := viper.GetStringSlice("scheme") - httpPingOnly := viper.GetBool("http-ping-only") + log.Logger.Debugf("httpPingOnly: %t", httpPingOnly) server := server.NewRestAPIServer(host, port, scheme, httpPingOnly, readTimeout, writeTimeout) defer func() { if err := server.Shutdown(); err != nil { diff --git a/pkg/generated/restapi/configure_timestamp_server.go b/pkg/generated/restapi/configure_timestamp_server.go index 197dfc161..59274d017 100644 --- a/pkg/generated/restapi/configure_timestamp_server.go +++ b/pkg/generated/restapi/configure_timestamp_server.go @@ -105,13 +105,14 @@ func (l *logAdapter) Print(v ...interface{}) { // httpPingOnly custom middleware prohibits all entrypoints except // "/ping" on the http (non-HTTPS) server. -func httpPingOnly(endpoint string) func(http.Handler) http.Handler { +func httpPingOnly() func(http.Handler) http.Handler { + const pingpath = "/ping" f := func(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { - if r.URL.Scheme != "https" && !strings.EqualFold(r.URL.Path, endpoint) { + if r.URL.Scheme != "https" && !strings.EqualFold(r.URL.Path, pingpath) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusNotFound) - w.Write([]byte("http server supports only the /ping entrypoint")) //nolint:errcheck + w.Write([]byte("http server supports only the " + pingpath + " entrypoint")) //nolint:errcheck return } h.ServeHTTP(w, r) @@ -130,7 +131,7 @@ func setupGlobalMiddleware(handler http.Handler) http.Handler { returnHandler = middleware.Recoverer(returnHandler) returnHandler = middleware.Heartbeat("/ping")(returnHandler) if cmdparams.IsHTTPPingOnly { - returnHandler = httpPingOnly("/ping")(returnHandler) + returnHandler = httpPingOnly()(returnHandler) } handleCORS := cors.Default().Handler