Skip to content

Commit

Permalink
add credential type as default in bosh configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
asalan316 committed Jun 26, 2024
1 parent 8adf72c commit 66e75e4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
7 changes: 7 additions & 0 deletions jobs/golangapiserver/spec
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ properties:
- broker_username: user2
broker_password: password2
default: ''
autoscaler.apiserver.broker.credential_type:
description: |
The list of credential types to authenticate with custom metrics api. If credential_type "binding-secret" is used, then username and password are generated by the broker. Also, credential_type "binding-secret" is default, if no credential_type is provided.
example:
- credential_type: binding-secret
- credential_type: X509
default: 'binding-secret'
autoscaler.apiserver.broker.server.catalog:
description: ""
autoscaler.apiserver.broker.server.dashboard_redirect_uri:
Expand Down
1 change: 1 addition & 0 deletions jobs/golangapiserver/templates/apiserver.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ catalog_schema_path: /var/vcap/packages/golangapiserver/catalog.schema.json
info_file_path: /var/vcap/jobs/golangapiserver/config/info.json
policy_schema_path: /var/vcap/packages/golangapiserver/policy_json.schema.json
dashboard_redirect_uri: <%= p("autoscaler.apiserver.broker.server.dashboard_redirect_uri") %>
credential_type: <%= p("autoscaler.apiserver.broker.credential_type") %>

health:
port: <%= p("autoscaler.apiserver.health.port") %>
Expand Down
14 changes: 9 additions & 5 deletions src/autoscaler/api/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ func (b *Broker) Bind(ctx context.Context, instanceID string, bindingID string,
logger.Error("get-default-policy", err)
return result, err
}
credentialType, err := getOrDefaultCredentialType(policyJson, logger)
customMetricsCredentialType := b.conf.CustomMetricsCredentialType
credentialType, err := getOrDefaultCredentialType(policyJson, customMetricsCredentialType, logger)
if err != nil {
logger.Error("getOrDefaultCredentialType %w", err)
return result, err
Expand Down Expand Up @@ -618,10 +619,14 @@ func (b *Broker) Bind(ctx context.Context, instanceID string, bindingID string,
return result, nil
}

func getOrDefaultCredentialType(policyJson json.RawMessage, logger lager.Logger) (*models.CredentialType, error) {
func getOrDefaultCredentialType(policyJson json.RawMessage, credentialTypeConfig string, logger lager.Logger) (*models.CredentialType, error) {
credentialType := &models.CredentialType{}
if credentialTypeConfig == "" {
logger.Error("error: Credential Type in the configuration is empty", ErrInvalidCredentialType)
return credentialType, nil
}
if len(policyJson) == 0 {
credentialType.CredentialType = "binding-secret"
credentialType.CredentialType = credentialTypeConfig
return credentialType, nil
}
err := json.Unmarshal(policyJson, &credentialType)
Expand All @@ -631,8 +636,7 @@ func getOrDefaultCredentialType(policyJson json.RawMessage, logger lager.Logger)
}
// credential-type in policyJson is not set
if credentialType.CredentialType == "" {
//TODO - set default value from bosh specs
credentialType.CredentialType = "binding-secret"
credentialType.CredentialType = credentialTypeConfig
}
logger.Debug("getOrDefaultCredentialType", lager.Data{"credential-Type": credentialType})
return credentialType, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ var _ = BeforeSuite(func() {
MetricsForwarderUrl: "someURL",
MetricsForwarderMtlsUrl: "Mtls-someURL",
},
CustomMetricsCredentialType: "binding-secret",
}
fakeBindingDB := &fakes.FakeBindingDB{}
fakePolicyDB := &fakes.FakePolicyDB{}
Expand Down
45 changes: 23 additions & 22 deletions src/autoscaler/api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,29 @@ type LowerUpperThresholdConfig struct {
}

type Config struct {
Logging helpers.LoggingConfig `yaml:"logging"`
BrokerServer helpers.ServerConfig `yaml:"broker_server"`
PublicApiServer helpers.ServerConfig `yaml:"public_api_server"`
DB map[string]db.DatabaseConfig `yaml:"db"`
BrokerCredentials []BrokerCredentialsConfig `yaml:"broker_credentials"`
APIClientId string `yaml:"api_client_id"`
PlanCheck *PlanCheckConfig `yaml:"plan_check"`
CatalogPath string `yaml:"catalog_path"`
CatalogSchemaPath string `yaml:"catalog_schema_path"`
DashboardRedirectURI string `yaml:"dashboard_redirect_uri"`
PolicySchemaPath string `yaml:"policy_schema_path"`
Scheduler SchedulerConfig `yaml:"scheduler"`
ScalingEngine ScalingEngineConfig `yaml:"scaling_engine"`
EventGenerator EventGeneratorConfig `yaml:"event_generator"`
CF cf.Config `yaml:"cf"`
InfoFilePath string `yaml:"info_file_path"`
MetricsForwarder MetricsForwarderConfig `yaml:"metrics_forwarder"`
Health helpers.HealthConfig `yaml:"health"`
RateLimit models.RateLimitConfig `yaml:"rate_limit"`
CredHelperImpl string `yaml:"cred_helper_impl"`
StoredProcedureConfig *models.StoredProcedureConfig `yaml:"stored_procedure_binding_credential_config"`
ScalingRules ScalingRulesConfig `yaml:"scaling_rules"`
Logging helpers.LoggingConfig `yaml:"logging"`
BrokerServer helpers.ServerConfig `yaml:"broker_server"`
PublicApiServer helpers.ServerConfig `yaml:"public_api_server"`
DB map[string]db.DatabaseConfig `yaml:"db"`
BrokerCredentials []BrokerCredentialsConfig `yaml:"broker_credentials"`
APIClientId string `yaml:"api_client_id"`
PlanCheck *PlanCheckConfig `yaml:"plan_check"`
CatalogPath string `yaml:"catalog_path"`
CatalogSchemaPath string `yaml:"catalog_schema_path"`
DashboardRedirectURI string `yaml:"dashboard_redirect_uri"`
PolicySchemaPath string `yaml:"policy_schema_path"`
Scheduler SchedulerConfig `yaml:"scheduler"`
ScalingEngine ScalingEngineConfig `yaml:"scaling_engine"`
EventGenerator EventGeneratorConfig `yaml:"event_generator"`
CF cf.Config `yaml:"cf"`
InfoFilePath string `yaml:"info_file_path"`
MetricsForwarder MetricsForwarderConfig `yaml:"metrics_forwarder"`
Health helpers.HealthConfig `yaml:"health"`
RateLimit models.RateLimitConfig `yaml:"rate_limit"`
CredHelperImpl string `yaml:"cred_helper_impl"`
StoredProcedureConfig *models.StoredProcedureConfig `yaml:"stored_procedure_binding_credential_config"`
ScalingRules ScalingRulesConfig `yaml:"scaling_rules"`
CustomMetricsCredentialType string `yaml:"credential_type"`
}

type PlanCheckConfig struct {
Expand Down

0 comments on commit 66e75e4

Please sign in to comment.