Skip to content

Commit

Permalink
Make golangcli-lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
joergdw committed Mar 13, 2023
1 parent 6c240c3 commit 96022b2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/autoscaler/api/cmd/api/api_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main_test

import (
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"
"fmt"
"io"
"net/http"
"os"
"time"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"

. "code.cloudfoundry.org/app-autoscaler/src/autoscaler/testhelpers"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/api/config"
Expand Down Expand Up @@ -245,8 +246,8 @@ var _ = Describe("Api", func() {
// healthendpoint.READINESS_PATH, healthendpoint.PPROF_PATH, healthendpoint.PROMETHEUS_PATH}

cfg = basicAuthConfig // Setting password only for `basicAuthConfig` is not sufficient,
// since the server-process does not use that configuration.
// Alternatively, basiAuthConfig could be just a pointer.
// since the server-process does not use that configuration.
// Alternatively, basiAuthConfig could be just a pointer.
runner.configPath = writeConfig(&cfg).Name()
runner.Start()
})
Expand Down
3 changes: 2 additions & 1 deletion src/autoscaler/healthendpoint/health_readiness_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package healthendpoint_test

import (
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"
"io"
"net/http"
"net/url"
"sync"
"sync/atomic"
"time"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/models"

"github.com/pkg/errors"
Expand Down
10 changes: 2 additions & 8 deletions src/autoscaler/healthendpoint/server.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package healthendpoint

import (
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"
"fmt"
"net/http"
"net/http/pprof"
"os"
"time"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"

"github.com/prometheus/client_golang/prometheus/promhttp"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/models"
Expand Down Expand Up @@ -35,7 +36,6 @@ func (bam *basicAuthenticationMiddleware) middleware(next http.Handler) http.Han

if !authOK || bcrypt.CompareHashAndPassword(bam.usernameHash, []byte(username)) != nil ||
bcrypt.CompareHashAndPassword(bam.passwordHash, []byte(password)) != nil {

http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
Expand All @@ -47,7 +47,6 @@ func (bam *basicAuthenticationMiddleware) middleware(next http.Handler) http.Han
// Make sure that username and password is not empty
func NewServerWithBasicAuth(conf models.HealthConfig, healthCheckers []Checker, logger lager.Logger,
gatherer prometheus.Gatherer, time func() time.Time) (ifrit.Runner, error) {

healthRouter, err := NewHealthRouterWithBasicAuth(conf, healthCheckers, logger, gatherer, time)
if err != nil {
return nil, err
Expand All @@ -65,7 +64,6 @@ func NewServerWithBasicAuth(conf models.HealthConfig, healthCheckers []Checker,

func NewHealthRouterWithBasicAuth(conf models.HealthConfig, healthCheckers []Checker, logger lager.Logger,
gatherer prometheus.Gatherer, time func() time.Time) (*mux.Router, error) {

router := mux.NewRouter()
authMiddleware, err := createBasicAuthMiddleware(logger, conf.HealthCheckUsernameHash,
conf.HealthCheckUsername, conf.HealthCheckPasswordHash, conf.HealthCheckPassword)
Expand Down Expand Up @@ -106,7 +104,6 @@ func NewHealthRouterWithBasicAuth(conf models.HealthConfig, healthCheckers []Che
// Returns an error in case BasicAuth is required but the configuration is not set up properly.
func addLivelinessHandlers(conf models.HealthConfig, mainRouter *mux.Router, time func() time.Time,
authMiddleware *basicAuthenticationMiddleware) error {

livenessHandler := common.VarsFunc(readiness([]Checker{}, time))
livenessRouter := mainRouter.PathPrefix(routes.LivenessPath).Subrouter()

Expand All @@ -129,7 +126,6 @@ func addLivelinessHandlers(conf models.HealthConfig, mainRouter *mux.Router, tim
func addReadinessHandler(conf models.HealthConfig, mainRouter *mux.Router,
authMiddleware *basicAuthenticationMiddleware, healthCheckers []Checker, time func() time.Time,
) error {

readinessRouter := mainRouter.PathPrefix("/health").Subrouter()
if endpointsNeedsProtection(routes.ReadinessPath, conf) {
readinessRouter.Use(authMiddleware.middleware)
Expand All @@ -150,7 +146,6 @@ func addReadinessHandler(conf models.HealthConfig, mainRouter *mux.Router,
// Returns an error in case BasicAuth is required but the configuration is not set up properly.
func addPprofHandlers(conf models.HealthConfig, mainRouter *mux.Router,
authMiddleware *basicAuthenticationMiddleware) error {

pprofRouter := mainRouter.PathPrefix(routes.PprofPath).Subrouter()

if endpointsNeedsProtection(routes.PprofPath, conf) {
Expand All @@ -176,7 +171,6 @@ func addPprofHandlers(conf models.HealthConfig, mainRouter *mux.Router,
// Returns an error in case BasicAuth is required but the configuration is not set up properly.
func addPrometheusHandler(mainRouter *mux.Router, conf models.HealthConfig,
authMiddleware *basicAuthenticationMiddleware, gatherer prometheus.Gatherer) error {

promHandler := promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{})

prometheusRouter := mainRouter.PathPrefix(routes.PrometheusPath).Subrouter()
Expand Down
12 changes: 6 additions & 6 deletions src/autoscaler/integration/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (components *Components) PrepareGolangApiServerConfig(dbURI string, publicA
},
Health: models.HealthConfig{
UnprotectedEndpoints: []string{"", routes.LivenessPath,
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
PublicApiServer: apiConfig.ServerConfig{
Port: publicApiPort,
TLS: models.TLSCerts{
Expand Down Expand Up @@ -397,7 +397,7 @@ func (components *Components) PrepareEventGeneratorConfig(dbUri string, port int
},
Health: models.HealthConfig{
UnprotectedEndpoints: []string{"", routes.LivenessPath,
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
Server: egConfig.ServerConfig{
Port: port,
TLS: models.TLSCerts{
Expand Down Expand Up @@ -462,7 +462,7 @@ func (components *Components) PrepareScalingEngineConfig(dbURI string, port int,
},
Health: models.HealthConfig{
UnprotectedEndpoints: []string{"", routes.LivenessPath,
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
Server: seConfig.ServerConfig{
Port: port,
TLS: models.TLSCerts{
Expand Down Expand Up @@ -500,7 +500,7 @@ func (components *Components) PrepareOperatorConfig(dbURI string, ccUAAURL strin
},
Health: models.HealthConfig{
UnprotectedEndpoints: []string{"", routes.LivenessPath,
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
CF: cf.Config{
API: ccUAAURL,
ClientID: "admin",
Expand Down Expand Up @@ -570,7 +570,7 @@ func (components *Components) PrepareMetricsGatewayConfig(dbURI string, metricSe
},
Health: models.HealthConfig{
UnprotectedEndpoints: []string{"", routes.LivenessPath,
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
EnvelopChanSize: 500,
NozzleCount: 1,
MetricServerAddrs: metricServerAddresses,
Expand Down Expand Up @@ -616,7 +616,7 @@ func (components *Components) PrepareMetricsServerConfig(dbURI string, httpClien
},
Health: models.HealthConfig{
UnprotectedEndpoints: []string{"", routes.LivenessPath,
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}},
HttpClientTimeout: httpClientTimeout,
NodeAddrs: []string{"localhost"},
NodeIndex: 0,
Expand Down

0 comments on commit 96022b2

Please sign in to comment.