Updated console commands with constants

This commit is contained in:
Trial97
2020-12-07 11:56:31 +02:00
committed by Dan Christian Bogos
parent dd48ce1057
commit 1146e2ef2f
24 changed files with 77 additions and 61 deletions

View File

@@ -67,6 +67,6 @@ func (self *CmdGetAccounts) RpcResult() interface{} {
func (self *CmdGetAccounts) GetFormatedResult(result interface{}) string {
return GetFormatedSliceResult(result, utils.StringSet{
"MinSleep": {},
utils.MinSleep: {},
})
}

View File

@@ -69,9 +69,9 @@ func (self *CmdActiveSessions) RpcResult() interface{} {
func (self *CmdActiveSessions) GetFormatedResult(result interface{}) string {
return GetFormatedSliceResult(result, utils.StringSet{
"Usage": {},
"DurationIndex": {},
"MaxRateUnit": {},
"DebitInterval": {},
utils.Usage: {},
utils.DurationIndex: {},
utils.MaxRateUnit: {},
utils.DebitInterval: {},
})
}

View File

@@ -76,6 +76,6 @@ func (self *CmdAttributesProcessEvent) RpcResult() interface{} {
func (self *CmdAttributesProcessEvent) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
utils.Usage: {},
})
}

View File

@@ -75,6 +75,6 @@ func (self *CmdChargersProcessEvent) RpcResult() interface{} {
func (self *CmdChargersProcessEvent) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
utils.Usage: {},
})
}

View File

@@ -21,6 +21,8 @@ package console
import (
"fmt"
"strings"
"github.com/cgrates/cgrates/utils"
)
var (
@@ -62,8 +64,8 @@ func GetCommandValue(command string, verbose bool) (Commander, error) {
var cmdName string
var cmdArgs string
if firstSpace <= 0 {
cmdName = command[:len(command)]
cmdArgs = ""
cmdName = command
cmdArgs = utils.EmptyString
} else {
cmdName = command[:firstSpace]
cmdArgs = command[firstSpace+1:]

View File

@@ -104,11 +104,11 @@ func (ce *CommandExecuter) ClientArgs() (args []string) {
// To be overwritten by commands that do not need a rpc call
func (ce *CommandExecuter) LocalExecute() string {
return ""
return utils.EmptyString
}
func ToJSON(line string) (jsn []byte) {
if !strings.Contains(line, "=") && line != "" {
if !strings.Contains(line, utils.AttrValueSep) && line != utils.EmptyString {
line = fmt.Sprintf("Item=\"%s\"", line)
}
jsn = append(jsn, '{')
@@ -117,7 +117,7 @@ func ToJSON(line string) (jsn []byte) {
jsn = append(jsn, []byte(fmt.Sprintf("\"%s\":%s,", group[1], group[2]))...)
}
}
jsn = bytes.TrimRight(jsn, ",")
jsn = bytes.TrimRight(jsn, utils.FIELDS_SEP)
jsn = append(jsn, '}')
return
}
@@ -155,11 +155,11 @@ func getStringValue(v interface{}, defaultDurationFields utils.StringSet) string
}
func getSliceAsString(mp []interface{}, defaultDurationFields utils.StringSet) (out string) {
out = "["
out = utils.IdxStart
for _, v := range mp {
out += fmt.Sprintf(`%s,`, getStringValue(v, defaultDurationFields))
}
return strings.TrimSuffix(out, ",") + "]"
return strings.TrimSuffix(out, utils.FIELDS_SEP) + utils.IdxEnd
}
func getMapAsString(mp map[string]interface{}, defaultDurationFields utils.StringSet) (out string) {
@@ -175,19 +175,19 @@ func getMapAsString(mp map[string]interface{}, defaultDurationFields utils.Strin
keylist = append(keylist, fmt.Sprintf(`"%s":%s`, k, getStringValue(v, defaultDurationFields)))
}
sort.Strings(keylist)
return fmt.Sprintf(`{%s}`, strings.Join(keylist, ","))
return fmt.Sprintf(`{%s}`, strings.Join(keylist, utils.FIELDS_SEP))
}
func GetFormatedResult(result interface{}, defaultDurationFields utils.StringSet) string {
jsonResult, _ := json.Marshal(result)
var mp map[string]interface{}
if err := json.Unmarshal(jsonResult, &mp); err != nil {
out, _ := json.MarshalIndent(result, "", " ")
out, _ := json.MarshalIndent(result, utils.EmptyString, " ")
return string(out)
}
mpstr := getMapAsString(mp, defaultDurationFields)
var out bytes.Buffer
json.Indent(&out, []byte(mpstr), "", " ")
json.Indent(&out, []byte(mpstr), utils.EmptyString, " ")
return out.String()
}
@@ -195,16 +195,16 @@ func GetFormatedSliceResult(result interface{}, defaultDurationFields utils.Stri
jsonResult, _ := json.Marshal(result)
var mp []interface{}
if err := json.Unmarshal(jsonResult, &mp); err != nil {
out, _ := json.MarshalIndent(result, "", " ")
out, _ := json.MarshalIndent(result, utils.EmptyString, " ")
return string(out)
}
mpstr := getSliceAsString(mp, defaultDurationFields)
var out bytes.Buffer
json.Indent(&out, []byte(mpstr), "", " ")
json.Indent(&out, []byte(mpstr), utils.EmptyString, " ")
return out.String()
}
func (ce *CommandExecuter) GetFormatedResult(result interface{}) string {
out, _ := json.MarshalIndent(result, "", " ")
out, _ := json.MarshalIndent(result, utils.EmptyString, " ")
return string(out)
}

View File

@@ -28,7 +28,7 @@ func init() {
c := &CmdGetCost{
name: "cost",
rpcMethod: utils.APIerSv1GetCost,
clientArgs: []string{"Tenant", "Category", "Subject", "AnswerTime", "Destination", "Usage"},
clientArgs: []string{utils.Tenant, utils.Category, utils.Subject, utils.AnswerTime, utils.Destination, utils.Usage},
rpcParams: &v1.AttrGetCost{},
}
commands[c.Name()] = c
@@ -73,9 +73,9 @@ func (self *CmdGetCost) ClientArgs() []string {
func (self *CmdGetCost) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
"GroupIntervalStart": {},
"RateIncrement": {},
"RateUnit": {},
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
}

View File

@@ -66,9 +66,9 @@ func (self *CmdGetCostDetails) RpcResult() interface{} {
func (self *CmdGetCostDetails) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
"GroupIntervalStart": {},
"RateIncrement": {},
"RateUnit": {},
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
}

View File

@@ -28,7 +28,7 @@ func init() {
c := &CmdGetDataCost{
name: "datacost",
rpcMethod: utils.APIerSv1GetDataCost,
clientArgs: []string{"Category", "Tenant", "Account", "Subject", "StartTime", "Usage"},
clientArgs: []string{utils.Category, utils.Tenant, utils.Account, utils.Subject, utils.StartTime, utils.Usage},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -72,9 +72,9 @@ func (self *CmdGetDataCost) ClientArgs() []string {
func (self *CmdGetDataCost) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
"GroupIntervalStart": {},
"RateIncrement": {},
"RateUnit": {},
utils.Usage: {},
utils.GroupIntervalStart: {},
utils.RateIncrement: {},
utils.RateUnit: {},
})
}

View File

@@ -27,7 +27,7 @@ func init() {
c := &CmdDebit{
name: "debit",
rpcMethod: utils.ResponderDebit,
clientArgs: []string{"Category", "ToR", "Tenant", "Subject", "Account", "Destination", "TimeStart", "TimeEnd", "CallDuration", "FallbackSubject", "DryRun"},
clientArgs: []string{utils.Category, utils.ToR, utils.Tenant, utils.Subject, utils.Account, utils.Destination, utils.TimeStart, utils.TimeEnd, utils.CallDuration, utils.FallbackSubject, utils.DryRun},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}

View File

@@ -27,7 +27,7 @@ func init() {
c := &CmdMaxDebit{
name: "debit_max",
rpcMethod: utils.ResponderMaxDebit,
clientArgs: []string{"Category", "ToR", "Tenant", "Subject", "Account", "Destination", "TimeStart", "TimeEnd", "CallDuration", "FallbackSubject"},
clientArgs: []string{utils.Category, utils.ToR, utils.Tenant, utils.Subject, utils.Account, utils.Destination, utils.TimeStart, utils.TimeEnd, utils.CallDuration, utils.FallbackSubject},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}

View File

@@ -31,7 +31,7 @@ func init() {
c := &CmdGetMaxDuration{
name: "maxduration",
rpcMethod: utils.ResponderGetMaxSessionTime,
clientArgs: []string{"Category", "ToR", "Tenant", "Subject", "Account", "Destination", "TimeStart", "TimeEnd", "CallDuration", "FallbackSubject"},
clientArgs: []string{utils.Category, utils.ToR, utils.Tenant, utils.Subject, utils.Account, utils.Destination, utils.TimeStart, utils.TimeEnd, utils.CallDuration, utils.FallbackSubject},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -81,6 +81,6 @@ func (self *CmdGetMaxDuration) GetFormatedResult(result interface{}) string {
if tv, canCast := result.(*time.Duration); canCast {
return fmt.Sprintf(`"%s"`, tv.String())
}
out, _ := json.MarshalIndent(result, "", " ")
out, _ := json.MarshalIndent(result, utils.EmptyString, " ")
return string(out)
}

View File

@@ -18,15 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import "github.com/cgrates/cgrates/engine"
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetMaxUsage{
name: "maxusage",
rpcMethod: "APIerSv1.GetMaxUsage",
clientArgs: []string{"ToR", "RequestType", "Tenant",
"Category", "Account", "Subject", "Destination",
"SetupTime", "AnswerTime", "Usage", "ExtraFields"},
rpcMethod: utils.APIerSv1GetMaxUsage,
clientArgs: []string{utils.ToR, utils.RequestType, utils.Tenant,
utils.Category, utils.Account, utils.Subject, utils.Destination,
utils.SetupTime, utils.AnswerTime, utils.Usage, utils.ExtraFields},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}

View File

@@ -20,6 +20,7 @@ package console
import (
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
func init() {
@@ -48,7 +49,7 @@ func (self *CmdParse) Name() string {
}
func (self *CmdParse) RpcMethod() string {
return ""
return utils.EmptyString
}
func (self *CmdParse) RpcParams(reset bool) interface{} {
@@ -67,10 +68,10 @@ func (self *CmdParse) PostprocessRpcParams() error {
}
func (self *CmdParse) LocalExecute() string {
if self.rpcParams.Expression == "" {
if self.rpcParams.Expression == utils.EmptyString {
return "Empty expression error"
}
if self.rpcParams.Value == "" {
if self.rpcParams.Value == utils.EmptyString {
return "Empty value error"
}
if rsrField, err := config.NewRSRParser(self.rpcParams.Expression); err != nil {

View File

@@ -68,9 +68,9 @@ func (self *CmdPassiveSessions) RpcResult() interface{} {
func (self *CmdPassiveSessions) GetFormatedResult(result interface{}) string {
return GetFormatedSliceResult(result, utils.StringSet{
"Usage": {},
"DurationIndex": {},
"MaxRateUnit": {},
"DebitInterval": {},
utils.Usage: {},
utils.DurationIndex: {},
utils.MaxRateUnit: {},
utils.DebitInterval: {},
})
}

View File

@@ -67,6 +67,6 @@ func (self *CmdGetResourceProfile) RpcResult() interface{} {
func (self *CmdGetResourceProfile) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"UsageTTL": {},
utils.UsageTTL: {},
})
}

View File

@@ -77,7 +77,7 @@ func (self *CmdSessionsInitiate) RpcResult() interface{} {
func (self *CmdSessionsInitiate) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
"MaxUsage": {},
utils.Usage: {},
utils.CapMaxUsage: {},
})
}

View File

@@ -77,7 +77,7 @@ func (self *CmdSessionsProcessEvent) RpcResult() interface{} {
func (self *CmdSessionsProcessEvent) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
"MaxUsage": {},
utils.Usage: {},
utils.CapMaxUsage: {},
})
}

View File

@@ -77,7 +77,7 @@ func (self *CmdSessionsUpdate) RpcResult() interface{} {
func (self *CmdSessionsUpdate) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"Usage": {},
"MaxUsage": {},
utils.Usage: {},
utils.CapMaxUsage: {},
})
}

View File

@@ -67,6 +67,6 @@ func (self *CmdGetStatQueueProfile) RpcResult() interface{} {
func (self *CmdGetStatQueueProfile) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"TTL": {},
utils.TTL: {},
})
}

View File

@@ -69,6 +69,6 @@ func (self *CmdGetThreshold) RpcResult() interface{} {
func (self *CmdGetThreshold) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"MinSleep": {},
utils.MinSleep: {},
})
}

View File

@@ -69,6 +69,6 @@ func (self *CmdGetThresholdProfile) RpcResult() interface{} {
func (self *CmdGetThresholdProfile) GetFormatedResult(result interface{}) string {
return GetFormatedResult(result, utils.StringSet{
"MinSleep": {},
utils.MinSleep: {},
})
}

View File

@@ -68,6 +68,6 @@ func (self *CmdGetTriggers) RpcResult() interface{} {
func (self *CmdGetTriggers) GetFormatedResult(result interface{}) string {
return GetFormatedSliceResult(result, utils.StringSet{
"MinSleep": {},
utils.MinSleep: {},
})
}

View File

@@ -311,6 +311,15 @@ const (
SetupTime = "SetupTime"
AnswerTime = "AnswerTime"
Usage = "Usage"
DurationIndex = "DurationIndex"
MaxRateUnit = "MaxRateUnit"
DebitInterval = "DebitInterval"
TimeStart = "TimeStart"
TimeEnd = "TimeEnd"
CallDuration = "CallDuration"
FallbackSubject = "FallbackSubject"
DryRun = "DryRun"
ExtraFields = "ExtraFields"
CustomValue = "CustomValue"
Value = "Value"
LastUsed = "LastUsed"
@@ -1403,6 +1412,7 @@ const (
APIerSv1RemoveActionTrigger = "APIerSv1.RemoveActionTrigger"
APIerSv1GetAccount = "APIerSv1.GetAccount"
APIerSv1GetAttributeProfileIDsCount = "APIerSv1.GetAttributeProfileIDsCount"
APIerSv1GetMaxUsage = "APIerSv1.GetMaxUsage"
)
// APIerSv1 TP APIs