Skip to content
11 changes: 2 additions & 9 deletions api/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,8 @@
)

defaultCustomMetricsCredentialType := &models.X509Certificate
if len(conf.DefaultCustomMetricsCredentialType) > 0 {
var err error
defaultCustomMetricsCredentialType, err = models.ParseCustomMetricsBindingAuthScheme(
conf.DefaultCustomMetricsCredentialType)
if err != nil {
logger.Fatal("parse-default-credential-type", err, lager.Data{
"default-credential-type": conf.DefaultCustomMetricsCredentialType,
})
}
if basicAuthAvailable := conf.CustomMetricsAuthConfig != nil; basicAuthAvailable {

Check warning on line 92 in api/broker/broker.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary variable declaration and use the expression directly in the condition.

See more on https://sonarcloud.io/project/issues?id=cloudfoundry_app-autoscaler&issues=AZ26n7IUXKDqoXqLX5Oo&open=AZ26n7IUXKDqoXqLX5Oo&pullRequest=1168
defaultCustomMetricsCredentialType = &conf.CustomMetricsAuthConfig.DefaultCustomMetricAuthType
}

pathToParserDir, err := filepath.Abs(filepath.Dir(conf.BindingRequestSchemaPath))
Expand Down
6 changes: 5 additions & 1 deletion api/broker/broker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ var _ = BeforeSuite(func() {
CatalogPath: "../exampleconfig/catalog-example.json",
DashboardRedirectURI: dashBoardURL,
BindingRequestSchemaPath: "./binding_request_parser/meta.schema.json",
DefaultCustomMetricsCredentialType: "binding-secret",
CustomMetricsAuthConfig: &config.CustomMetricsAuthConfig{
BasicAuthHandling: config.BasicAuthHandlingOn,
DefaultCustomMetricAuthType: models.BindingSecret,
BasicAuthHandlingImplConfig: models.BasicAuthHandlingNative{},
},
}

catalogBytes, err := os.ReadFile("../exampleconfig/catalog-example.json")
Expand Down
7 changes: 6 additions & 1 deletion api/brokerserver/broker_server_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/api/brokerserver"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/api/config"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/fakes"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/models"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes"

"github.com/onsi/gomega/ghttp"
Expand Down Expand Up @@ -138,7 +139,11 @@ var _ = BeforeSuite(func() {
MetricsForwarderUrl: "someURL",
MetricsForwarderMtlsUrl: "Mtls-someURL",
},
DefaultCustomMetricsCredentialType: "binding-secret",
CustomMetricsAuthConfig: &config.CustomMetricsAuthConfig{
BasicAuthHandling: config.BasicAuthHandlingOn,
DefaultCustomMetricAuthType: models.BindingSecret,
BasicAuthHandlingImplConfig: models.BasicAuthHandlingNative{},
},
}
fakeCfClient := &fakes.FakeCFClient{}
fakeBindingDB := &fakes.FakeBindingDB{}
Expand Down
6 changes: 5 additions & 1 deletion api/cmd/api/api_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ var _ = SynchronizedBeforeSuite(func() []byte {
conf.RateLimit.MaxAmount = 10
conf.RateLimit.ValidDuration = 1 * time.Second

conf.CredHelperImpl = "default"
conf.CustomMetricsAuthConfig = &config.CustomMetricsAuthConfig{
BasicAuthHandling: config.BasicAuthHandlingOn,
DefaultCustomMetricAuthType: models.BindingSecret,
BasicAuthHandlingImplConfig: models.BasicAuthHandlingNative{},
}

configFile = writeConfig(&conf)

Expand Down
7 changes: 6 additions & 1 deletion api/cmd/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/api/config"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/configutil"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/db"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/models"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/testhelpers"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -231,7 +232,11 @@ var _ = Describe("Api", func() {
Describe("can start with default plugin", func() {
BeforeEach(func() {
pluginPathConfig := conf
pluginPathConfig.CredHelperImpl = "default"
pluginPathConfig.CustomMetricsAuthConfig = &config.CustomMetricsAuthConfig{
BasicAuthHandling: config.BasicAuthHandlingOn,
DefaultCustomMetricAuthType: models.BindingSecret,
BasicAuthHandlingImplConfig: models.BasicAuthHandlingNative{},
}
runner.configPath = writeConfig(&pluginPathConfig).Name()
})
AfterEach(func() {
Expand Down
13 changes: 11 additions & 2 deletions api/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ func main() {
defer func() { _ = policyDb.Close() }()
logger.Debug("Connected to PolicyDB", lager.Data{"dbConfig": conf.Db[db.PolicyDb]})

credentialProvider := cred_helper.CredentialsProvider(conf.CredHelperImpl, conf.StoredProcedureConfig, conf.Db, 10*time.Second, 10*time.Minute, logger, policyDb)
defer func() { _ = credentialProvider.Close() }()
var credentialProvider cred_helper.Credentials
if conf.CustomMetricsAuthConfig != nil {
credentialProvider = cred_helper.CredentialsProvider(
conf.CustomMetricsAuthConfig.BasicAuthHandlingImplConfig,
conf.Db, 10*time.Second, 10*time.Minute, logger, policyDb)
}
defer func() {
if credentialProvider != nil {
_ = credentialProvider.Close()
}
}()

httpStatusCollector := healthendpoint.NewHTTPStatusCollector("autoscaler", "golangapiserver")

Expand Down
Loading
Loading