Add print_config flags to cgr-loader and cgr-migrator

This commit is contained in:
armirveliaj
2024-07-02 07:44:20 -04:00
committed by Dan Christian Bogos
parent ac96e53c43
commit 6dc612a32a
5 changed files with 23 additions and 5 deletions

View File

@@ -41,7 +41,8 @@ var (
dfltCfg = config.CgrConfig()
cfgPath = cgrLoaderFlags.String(utils.CfgPathCgr, utils.EmptyString,
"Configuration directory path.")
dataDBType = cgrLoaderFlags.String(utils.DataDBTypeCgr, dfltCfg.DataDbCfg().Type,
printConfig = cgrLoaderFlags.Bool(utils.PrintCfgCgr, false, "Print the configuration object in JSON format")
dataDBType = cgrLoaderFlags.String(utils.DataDBTypeCgr, dfltCfg.DataDbCfg().Type,
"The type of the DataDB database <*redis|*mongo>")
dataDBHost = cgrLoaderFlags.String(utils.DataDBHostCgr, dfltCfg.DataDbCfg().Host,
"The DataDb host to connect to.")
@@ -331,7 +332,10 @@ func main() {
if *dryRun { // We were just asked to parse the data, not saving it
return
}
if *printConfig {
cfgJSON := utils.ToIJSON(ldrCfg.AsMapInterface(ldrCfg.GeneralCfg().RSRSep))
log.Printf("Configuration loaded from %q:\n%s", *cfgPath, cfgJSON)
}
if *remove {
if err = tpReader.RemoveFromDatabase(*verbose, *disableReverse); err != nil {
log.Fatal("Could not delete from database: ", err)

View File

@@ -29,7 +29,11 @@ func TestCGRLoaderFlags(t *testing.T) {
} else if *cfgPath != "/etc/cgrates" {
t.Errorf("Expected /etc/cgrates, received %+v", *cfgPath)
}
if err := cgrLoaderFlags.Parse([]string{"-print_config", "true"}); err != nil {
t.Fatal(err)
} else if *printConfig != true {
t.Errorf("Expected true, received %+v", *printConfig)
}
if err := cgrLoaderFlags.Parse([]string{"-datadb_type", "*redis"}); err != nil {
t.Error(err)
} else if *dataDBType != "*redis" {

View File

@@ -42,8 +42,8 @@ var (
dfltCfg = config.NewDefaultCGRConfig()
cfgPath = cgrMigratorFlags.String(utils.CfgPathCgr, utils.EmptyString,
"Configuration directory path.")
exec = cgrMigratorFlags.String(utils.ExecCgr, utils.EmptyString, "fire up automatic migration "+
printConfig = cgrMigratorFlags.Bool(utils.PrintCfgCgr, false, "Print the configuration object in JSON format")
exec = cgrMigratorFlags.String(utils.ExecCgr, utils.EmptyString, "fire up automatic migration "+
"<*set_versions|*cost_details|*accounts|*actions|*action_triggers|*action_plans|*shared_groups|*filters|*datadb>")
version = cgrMigratorFlags.Bool(utils.VersionCgr, false, "prints the application version")
@@ -281,6 +281,10 @@ func main() {
mgrCfg.CacheCfg(), mgrCfg.DataDbCfg().Opts, mgrCfg.DataDbCfg().Items); err != nil {
log.Fatal(err)
}
if *printConfig {
cfgJSON := utils.ToIJSON(mgrCfg.AsMapInterface(mgrCfg.GeneralCfg().RSRSep))
log.Printf("Configuration loaded from %q:\n%s", *cfgPath, cfgJSON)
}
if sameDataDB {
dmOUT = dmIN

View File

@@ -31,6 +31,11 @@ func TestFlags(t *testing.T) {
} else if *cfgPath != "true" {
t.Errorf("Expected true received:%v ", *cfgPath)
}
if err := cgrMigratorFlags.Parse([]string{"-print_config", "true"}); err != nil {
t.Fatal(err)
} else if *printConfig != true {
t.Errorf("Expected true, received %+v", *printConfig)
}
if err := cgrMigratorFlags.Parse([]string{"-exec", "true"}); err != nil {
t.Fatal(err)
} else if *exec != "true" {

View File

@@ -2661,6 +2661,7 @@ const (
SepCgr = " "
//Cgr engine
CgrEngine = "cgr-engine"
PrintCfgCgr = "print_config"
CheckCfgCgr = "check_config"
PidCgr = "pid"
HttpPrfPthCgr = "httprof_path"