From a21f93c86db0e3041e9079c69f8801d07b40194e Mon Sep 17 00:00:00 2001 From: Irfan Habib Date: Mon, 20 Nov 2017 09:51:14 +0000 Subject: [PATCH] Fix unsafe casting for mysql Service --- .../backend/datastore/database_cf_config.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/components/app-core/backend/datastore/database_cf_config.go b/components/app-core/backend/datastore/database_cf_config.go index 8f8b0f02b9..f34665eb7f 100644 --- a/components/app-core/backend/datastore/database_cf_config.go +++ b/components/app-core/backend/datastore/database_cf_config.go @@ -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 }