Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsafe casting for mysql Service #1381

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions components/app-core/backend/datastore/database_cf_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,24 @@ func findDatabaseConfig(vcapServices map[string][]VCAPService, db *DatabaseConfi

// If we found a service, then use it
if len(service.Name) > 0 {
dbCredentials := service.Credentials
db.Username = fmt.Sprintf("%v", dbCredentials["username"])
db.Password = fmt.Sprintf("%v", dbCredentials["password"])
db.Host = fmt.Sprintf("%v", dbCredentials["hostname"])
db.SSLMode = "disable"
db.Port, _ = strconv.Atoi(fmt.Sprintf("%v", dbCredentials["port"]))
if isPostgresService(service) {
dbCredentials := service.Credentials
db.DatabaseProvider = "pgsql"
db.Username = fmt.Sprintf("%v", dbCredentials["username"])
db.Password = fmt.Sprintf("%v", dbCredentials["password"])
db.Database = fmt.Sprintf("%v", dbCredentials["dbname"])
db.Host = fmt.Sprintf("%v", dbCredentials["hostname"])
db.Port, _ = strconv.Atoi(fmt.Sprintf("%v", dbCredentials["port"]))
db.SSLMode = "disable"
log.Infof("Discovered Cloud Foundry postgres service and applied config")
return true
} else if isMySQLService(service) {
dbCredentials := service.Credentials
db.DatabaseProvider = "mysql"
db.Username = fmt.Sprintf("%v", dbCredentials["username"])
db.Password = fmt.Sprintf("%v", dbCredentials["password"])
db.Database = fmt.Sprintf("%v", dbCredentials["name"])
db.Host = fmt.Sprintf("%v", dbCredentials["hostname"])
db.Port = (int)(dbCredentials["port"].(float64))
db.SSLMode = "disable"
log.Infof("Discovered Cloud Foundry mysql service and applied config")
return true
}
}

return false
}

Expand Down