diff --git a/config/config.go b/config/config.go index d3a8c44eb..4b7679482 100644 --- a/config/config.go +++ b/config/config.go @@ -50,27 +50,22 @@ func newDbDefaults() dbDefaults { utils.MySQL: map[string]string{ "DbName": "cgrates", "DbPort": "3306", - "DbPass": "CGRateS.org", }, utils.Postgres: map[string]string{ "DbName": "cgrates", "DbPort": "5432", - "DbPass": "CGRateS.org", }, utils.Mongo: map[string]string{ "DbName": "cgrates", "DbPort": "27017", - "DbPass": "", }, utils.Redis: map[string]string{ "DbName": "10", "DbPort": "6379", - "DbPass": "", }, utils.Internal: map[string]string{ "DbName": "internal", "DbPort": "internal", - "DbPass": "internal", }, } return deflt @@ -92,13 +87,6 @@ func (dbDflt dbDefaults) dbPort(dbType string, flagInput string) string { return dbDflt[dbType]["DbPort"] } -func (dbDflt dbDefaults) dbPass(dbType string, flagInput string) string { - if flagInput != utils.MetaDynamic { - return flagInput - } - return dbDflt[dbType]["DbPass"] -} - func init() { cgrCfg = NewDefaultCGRConfig() dbDefaultsCfg = newDbDefaults() diff --git a/config/config_defaults.go b/config/config_defaults.go index 766bf634d..3a86b97ce 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -360,12 +360,12 @@ const CGRATES_CFG_JSON = ` // "kafkaTopicProcessed": "", the topic were the events are sent after they are processed // SQL - // "dbName": "cgrates", // the name of the database from were the events are read - // "tableName": "cdrs", // the name of the table from were the events are read + // "sqlDBName": "cgrates", // the name of the database from were the events are read + // "sqlTableName": "cdrs", // the name of the table from were the events are read // "sslMode": "disable", // the ssl mode for postgres db - // "dbNameProcessed": "", // the name of the database were the events are sent after they are processed - // "tableNameProcessed": "", // the name of the table were the events are sent after they are processed + // "sqlDBNameProcessed": "", // the name of the database were the events are sent after they are processed + // "sqlTableNameProcessed": "", // the name of the table were the events are sent after they are processed // "sslModeProcessed": "", // the ssl mode for postgres db // SQS and S3 diff --git a/config/config_test.go b/config/config_test.go index 656fbd2ef..6782b9067 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -878,14 +878,6 @@ func TestDbDefaultsMetaDynamic(t *testing.T) { flagInput := utils.MetaDynamic dbs := []string{utils.Mongo, utils.Redis, utils.MySQL, utils.Internal} for _, dbtype := range dbs { - host := dbdf.dbHost(flagInput) - if host != utils.Localhost { - t.Errorf("received: %+v, expecting: %+v", host, utils.Localhost) - } - user := dbdf.dbUser(flagInput) - if user != utils.CGRateSLwr { - t.Errorf("received: %+v, expecting: %+v", user, utils.CGRateSLwr) - } port := dbdf.dbPort(dbtype, flagInput) if port != dbdf[dbtype]["DbPort"] { t.Errorf("received: %+v, expecting: %+v", port, dbdf[dbtype]["DbPort"]) @@ -894,26 +886,13 @@ func TestDbDefaultsMetaDynamic(t *testing.T) { if name != dbdf[dbtype]["DbName"] { t.Errorf("received: %+v, expecting: %+v", name, dbdf[dbtype]["DbName"]) } - pass := dbdf.dbPass(dbtype, flagInput) - if pass != dbdf[dbtype]["DbPass"] { - t.Errorf("received: %+v, expecting: %+v", pass, dbdf[dbtype]["DbPass"]) - } } } func TestDbDefaults(t *testing.T) { dbdf := newDbDefaults() - flagInput := "NonMetaDynamic" dbs := []string{utils.Mongo, utils.Redis, utils.MySQL, utils.Internal, utils.Postgres} for _, dbtype := range dbs { - host := dbdf.dbHost(flagInput) - if host != flagInput { - t.Errorf("Expected %+v, received %+v", flagInput, host) - } - user := dbdf.dbUser(flagInput) - if user != flagInput { - t.Errorf("Expected %+v, received %+v", flagInput, user) - } port := dbdf.dbPort(dbtype, "1234") if port != "1234" { t.Errorf("Expected %+v, received %+v", "1234", port) @@ -922,10 +901,6 @@ func TestDbDefaults(t *testing.T) { if name != utils.CGRateSLwr { t.Errorf("Expected %+v, received %+v", utils.CGRateSLwr, name) } - pass := dbdf.dbPass(dbtype, utils.EmptyString) - if pass != utils.EmptyString { - t.Errorf("Expected %+v, received %+v", utils.EmptyString, pass) - } } } diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json index 1355e7c98..d969d5537 100644 --- a/data/conf/samples/ees/cgrates.json +++ b/data/conf/samples/ees/cgrates.json @@ -395,7 +395,7 @@ "attempts": 1, "opts": { "dbName": "exportedDatabase", // if dbName is not present "cgrates" will be used as default - "tableName": "expTable", // tableName is mandatory in opts for sql exporter + "sqlTableName": "expTable", // tableName is mandatory in opts for sql exporter "sslMode": "disable", "maxIdleConns": "10", "maxOpenConns": "100", @@ -415,8 +415,8 @@ "export_path": "mysql://cgrates:CGRateS.org@127.0.0.1:3306", "attempts": 1, "opts": { - "dbName": "exportedDatabase", - "tableName": "expTable", + "sqlDBName": "exportedDatabase", + "sqlTableName": "expTable", "sslMode": "disable", "maxIdleConns": "10", "maxOpenConns": "100", diff --git a/ers/sql_it_test.go b/ers/sql_it_test.go index 588d2b5f3..998674f36 100644 --- a/ers/sql_it_test.go +++ b/ers/sql_it_test.go @@ -96,9 +96,9 @@ func testSQLInitConfig(t *testing.T) { "concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited "source_path": "*mysql://cgrates:CGRateS.org@127.0.0.1:3306", // read data from this path "opts": { - "dbName":"cgrates2", - "dbNameProcessed":"cgrates2", - "tableNameProcessed":"cdrs2", + "sqlDBName":"cgrates2", + "sqlDBNameProcessed":"cgrates2", + "sqlTableNameProcessed":"cdrs2", }, "processed_path": "", // move processed data here "tenant": "cgrates.org", // tenant used by import @@ -373,9 +373,9 @@ func testSQLInitConfig2(t *testing.T) { "concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited "source_path": "*mysql://cgrates:CGRateS.org@127.0.0.1:3306", // read data from this path "opts": { - "dbName":"cgrates2", - "dbNameProcessed":"cgrates2", - "tableNameProcessed":"cdrs2", + "sqlDBName":"cgrates2", + "sqlDBNameProcessed":"cgrates2", + "sqlTableNameProcessed":"cdrs2", }, "processed_path": "", // move processed data here "tenant": "cgrates.org", // tenant used by import diff --git a/ers/sql_test.go b/ers/sql_test.go index f5c7004c7..eae49850c 100644 --- a/ers/sql_test.go +++ b/ers/sql_test.go @@ -41,13 +41,13 @@ func TestSQLSetURL(t *testing.T) { inURL := "*mysql://cgrates:CGRateS.org@127.0.0.1:3306" outURL := "*mysql://cgrates:CGRateS.org@127.0.0.1:3306" if err := sql.setURL(inURL, outURL, map[string]interface{}{ - "dbName": "cgrates2", - "tableName": "cdrs2", - "sslMode": "enabled", + utils.SQLDBName: "cgrates2", + utils.SQLTableName: "cdrs2", + "sslMode": "enabled", - "dbNameProcessed": "cgrates3", - "tableNameProcessed": "cdrs3", - "sslModeProcessed": "enabled", + utils.SQLDBName + utils.ProcessedOpt: "cgrates3", + utils.SQLTableName + utils.ProcessedOpt: "cdrs3", + "sslModeProcessed": "enabled", }); err != nil { t.Fatal(err) } else if expsql.connString != sql.connString { @@ -76,13 +76,13 @@ func TestSQLSetURL(t *testing.T) { inURL = "*postgres://cgrates:CGRateS.org@127.0.0.1:3306" outURL = "*postgres://cgrates:CGRateS.org@127.0.0.1:3306" if err := sql.setURL(inURL, outURL, map[string]interface{}{ - "dbName": "cgrates2", - "tableName": "cdrs2", - "sslMode": "enabled", + utils.SQLDBName: "cgrates2", + utils.SQLTableName: "cdrs2", + "sslMode": "enabled", - "dbNameProcessed": "cgrates3", - "tableNameProcessed": "cdrs3", - "sslModeProcessed": "enabled", + utils.SQLDBName + utils.ProcessedOpt: "cgrates3", + utils.SQLTableName + utils.ProcessedOpt: "cdrs3", + "sslModeProcessed": "enabled", }); err != nil { t.Fatal(err) } else if expsql.connString != sql.connString { @@ -111,13 +111,13 @@ func TestSQLSetURL(t *testing.T) { inURL = "*postgres://cgrates:CGRateS.org@127.0.0.1:3306" outURL = "" if err := sql.setURL(inURL, outURL, map[string]interface{}{ - "dbName": "cgrates2", - "tableName": "cdrs2", - "sslMode": "enabled", + utils.SQLDBName: "cgrates2", + utils.SQLTableName: "cdrs2", + "sslMode": "enabled", - "dbNameProcessed": "cgrates2", - "tableNameProcessed": "cdrs2", - "sslModeProcessed": "enabled", + utils.SQLDBName + utils.ProcessedOpt: "cgrates2", + utils.SQLTableName + utils.ProcessedOpt: "cdrs2", + "sslModeProcessed": "enabled", }); err != nil { t.Fatal(err) } else if expsql.connString != sql.connString { diff --git a/utils/consts.go b/utils/consts.go index 85bb39425..bf7c2cae5 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -2331,9 +2331,13 @@ const ( // s3 S3Bucket = "s3BucketID" S3FolderPath = "s3FolderPath" - SQLTableName = "tableName" - SQLDefaultSSLMode = "disable" + + // sql SQLDefaultDBName = "cgrates" + SQLDefaultSSLMode = "disable" + + SQLDBName = "sqlDBName" + SQLTableName = "sqlTableName" // fileCSV RowLengthOpt = "RowLength"