-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor metricsforwarder config loading and enhance DB URL customiz…
…ation - Implement parsing and customization of the stored procedure DB URL with configurable username and password. - Move the TLS config materialization for the syslog-client outside of the conditional block. - Update tests to reflect changes in config loading and to test new DB URL customization logic. - Add username and password fields to the StoredProcedureConfig struct.
- Loading branch information
1 parent
ede42ac
commit e753aa7
Showing
3 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ var _ = Describe("Config", func() { | |
|
||
When("VCAP_SERVICES has relational db service bind to app for policy db", func() { | ||
BeforeEach(func() { | ||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns(getVcapConfigWithCredImplementation("default"), nil) | ||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns([]byte(`{ "cred_helper_impl": "default" }`), nil) // #nosec G101 | ||
expectedDbUrl = "postgres://foo:[email protected]:5432/policy_db?sslcert=%2Ftmp%2Fclient_cert.sslcert&sslkey=%2Ftmp%2Fclient_key.sslkey&sslrootcert=%2Ftmp%2Fserver_ca.sslrootcert" // #nosec G101 | ||
}) | ||
|
||
|
@@ -108,7 +108,7 @@ var _ = Describe("Config", func() { | |
|
||
When("storedProcedure_db service is provided and cred_helper_impl is stored_procedure", func() { | ||
BeforeEach(func() { | ||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns(getVcapConfigWithCredImplementation("stored_procedure"), nil) | ||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns([]byte(`{ "cred_helper_impl": "stored_procedure" }`), nil) // #nosec G101 | ||
expectedDbUrl = "postgres://foo:[email protected]:5432/policy_db?sslcert=%2Ftmp%2Fclient_cert.sslcert&sslkey=%2Ftmp%2Fclient_key.sslkey&sslrootcert=%2Ftmp%2Fserver_ca.sslrootcert" // #nosec G101 | ||
}) | ||
|
||
|
@@ -121,11 +121,39 @@ var _ = Describe("Config", func() { | |
actualDbName := mockVCAPConfigurationReader.MaterializeDBFromServiceArgsForCall(1) | ||
Expect(actualDbName).To(Equal(db.StoredProcedureDb)) | ||
}) | ||
|
||
When("storedProcedure_db config has username and password", func() { | ||
var storedProcedureUsername, storedProcedurePassword string | ||
|
||
BeforeEach(func() { | ||
storedProcedureUsername = "storedProcedureUsername" | ||
storedProcedurePassword = "storedProcedurePassword" | ||
|
||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns([]byte( | ||
`{ "cred_helper_impl": "stored_procedure", | ||
"stored_procedure_binding_credential_config": { | ||
"username": "`+storedProcedureUsername+`", | ||
"password": "`+storedProcedurePassword+`" | ||
}, | ||
}`), | ||
nil, | ||
) // #nosec G101 | ||
}) | ||
|
||
It("should prioritize the username and password from the config", func() { | ||
// url should include the username and password from the config | ||
Expect(err).NotTo(HaveOccurred()) | ||
_, storeProcedureFound := conf.Db[db.StoredProcedureDb] | ||
Expect(storeProcedureFound).To(BeTrue()) | ||
Expect(conf.Db[db.StoredProcedureDb].URL).To(ContainSubstring(fmt.Sprintf("%s:%s", storedProcedureUsername, storedProcedurePassword))) | ||
}) | ||
}) | ||
}) | ||
|
||
When("storedProcedure_db service is provided and cred_helper_impl is default", func() { | ||
BeforeEach(func() { | ||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns(getVcapConfigWithCredImplementation("default"), nil) | ||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns([]byte( | ||
`{ "cred_helper_impl": "default" }`), nil) // #nosec G101 | ||
expectedDbUrl = "postgres://foo:[email protected]:5432/policy_db?sslcert=%2Ftmp%2Fclient_cert.sslcert&sslkey=%2Ftmp%2Fclient_key.sslkey&sslrootcert=%2Ftmp%2Fserver_ca.sslrootcert" // #nosec G101 | ||
}) | ||
|
||
|
@@ -138,7 +166,6 @@ var _ = Describe("Config", func() { | |
|
||
When("VCAP_SERVICES has metricsforwarder config", func() { | ||
BeforeEach(func() { | ||
|
||
mockVCAPConfigurationReader.GetServiceCredentialContentReturns([]byte(` { | ||
"cache_cleanup_interval":"10h", | ||
"cache_ttl":"90s", | ||
|
@@ -414,7 +441,3 @@ health: | |
}) | ||
}) | ||
}) | ||
|
||
func getVcapConfigWithCredImplementation(credHelperImplementation string) []byte { | ||
return []byte(`{ "cred_helper_impl": "` + credHelperImplementation + `" }`) // #nosec G101 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters