mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Added default tenant in apiers/v1 and modified tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
4b62ce17b9
commit
01e7003331
@@ -38,10 +38,14 @@ type AccountActionTiming struct {
|
||||
}
|
||||
|
||||
func (apierSv1 *APIerSv1) GetAccountActionPlan(attrs *utils.TenantAccount, reply *[]*AccountActionTiming) error {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"Tenant", "Account"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.Account}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(strings.Join(missing, ","), "")
|
||||
}
|
||||
acntID := utils.ConcatenatedKey(attrs.Tenant, attrs.Account)
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
acntID := utils.ConcatenatedKey(tnt, attrs.Account)
|
||||
acntATsIf, err := guardian.Guardian.Guard(func() (interface{}, error) {
|
||||
acntAPids, err := apierSv1.DataManager.GetAccountActionPlans(acntID, false, utils.NonTransactional)
|
||||
if err != nil && err != utils.ErrNotFound {
|
||||
@@ -91,10 +95,14 @@ func (apierSv1 *APIerSv1) RemoveActionTiming(attrs *AttrRemoveActionTiming, repl
|
||||
}
|
||||
var accID string
|
||||
if len(attrs.Account) != 0 { // Presence of Account requires complete account details to be provided
|
||||
if missing := utils.MissingStructFields(attrs, []string{"Tenant", "Account"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.Account}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
accID = utils.ConcatenatedKey(attrs.Tenant, attrs.Account)
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
accID = utils.ConcatenatedKey(tnt, attrs.Account)
|
||||
}
|
||||
|
||||
var remAcntAPids []string // list of accounts who's indexes need modification
|
||||
@@ -173,10 +181,14 @@ func (apierSv1 *APIerSv1) RemoveActionTiming(attrs *AttrRemoveActionTiming, repl
|
||||
|
||||
// SetAccount adds a new account into dataDb. If already defined, returns success.
|
||||
func (apierSv1 *APIerSv1) SetAccount(attr *utils.AttrSetAccount, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.Account}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
accID := utils.ConcatenatedKey(attr.Tenant, attr.Account)
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
accID := utils.ConcatenatedKey(tnt, attr.Account)
|
||||
dirtyActionPlans := make(map[string]*engine.ActionPlan)
|
||||
_, err = guardian.Guardian.Guard(func() (interface{}, error) {
|
||||
var ub *engine.Account
|
||||
@@ -294,11 +306,15 @@ func (apierSv1 *APIerSv1) SetAccount(attr *utils.AttrSetAccount, reply *string)
|
||||
}
|
||||
|
||||
func (apierSv1 *APIerSv1) RemoveAccount(attr *utils.AttrRemoveAccount, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.Account}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
dirtyActionPlans := make(map[string]*engine.ActionPlan)
|
||||
accID := utils.ConcatenatedKey(attr.Tenant, attr.Account)
|
||||
accID := utils.ConcatenatedKey(tnt, attr.Account)
|
||||
_, err = guardian.Guardian.Guard(func() (interface{}, error) {
|
||||
// remove it from all action plans
|
||||
_, err := guardian.Guardian.Guard(func() (interface{}, error) {
|
||||
@@ -428,7 +444,7 @@ func (apierSv1 *APIerSv1) DebitBalance(attr *AttrAddBalance, reply *string) erro
|
||||
}
|
||||
|
||||
func (apierSv1 *APIerSv1) modifyBalance(aType string, attr *AttrAddBalance, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "BalanceType", "Value"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.Account, utils.BalanceType, utils.Value}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
var balance *engine.BalanceFilter
|
||||
@@ -439,8 +455,11 @@ func (apierSv1 *APIerSv1) modifyBalance(aType string, attr *AttrAddBalance, repl
|
||||
if attr.Value != 0 {
|
||||
balance.Value = &utils.ValueFormula{Static: math.Abs(attr.Value)}
|
||||
}
|
||||
|
||||
accID := utils.ConcatenatedKey(attr.Tenant, attr.Account)
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
accID := utils.ConcatenatedKey(tnt, attr.Account)
|
||||
if _, err = apierSv1.DataManager.GetAccount(accID); err != nil {
|
||||
// create account if does not exist
|
||||
account := &engine.Account{
|
||||
@@ -502,7 +521,7 @@ func (apierSv1 *APIerSv1) modifyBalance(aType string, attr *AttrAddBalance, repl
|
||||
// SetBalance sets the balance for the given account
|
||||
// if the account is not already created it will create the account also
|
||||
func (apierSv1 *APIerSv1) SetBalance(attr *utils.AttrSetBalance, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "BalanceType"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.Account, utils.BalanceType}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
var balance *engine.BalanceFilter
|
||||
@@ -517,8 +536,12 @@ func (apierSv1 *APIerSv1) SetBalance(attr *utils.AttrSetBalance, reply *string)
|
||||
(balance.Uuid == nil || *balance.Uuid == "") {
|
||||
return utils.NewErrMandatoryIeMissing("BalanceID", "or", "BalanceUUID")
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
|
||||
accID := utils.ConcatenatedKey(attr.Tenant, attr.Account)
|
||||
accID := utils.ConcatenatedKey(tnt, attr.Account)
|
||||
if _, err = apierSv1.DataManager.GetAccount(accID); err != nil {
|
||||
// create account if not exists
|
||||
account := &engine.Account{
|
||||
@@ -576,11 +599,15 @@ func (apierSv1 *APIerSv1) SetBalance(attr *utils.AttrSetBalance, reply *string)
|
||||
// SetBalances sets multiple balances for the given account
|
||||
// if the account is not already created it will create the account also
|
||||
func (apierSv1 *APIerSv1) SetBalances(attr *utils.AttrSetBalances, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "Balances"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.Account, utils.Balances}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
|
||||
accID := utils.ConcatenatedKey(attr.Tenant, attr.Account)
|
||||
accID := utils.ConcatenatedKey(tnt, attr.Account)
|
||||
if _, err = apierSv1.DataManager.GetAccount(accID); err != nil {
|
||||
// create account if not exists
|
||||
account := &engine.Account{
|
||||
@@ -655,7 +682,7 @@ func (apierSv1 *APIerSv1) SetBalances(attr *utils.AttrSetBalances, reply *string
|
||||
|
||||
// RemoveBalances remove the matching balances for the account
|
||||
func (apierSv1 *APIerSv1) RemoveBalances(attr *utils.AttrSetBalance, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "BalanceType"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.Account, utils.BalanceType}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
var balance *engine.BalanceFilter
|
||||
@@ -663,8 +690,12 @@ func (apierSv1 *APIerSv1) RemoveBalances(attr *utils.AttrSetBalance, reply *stri
|
||||
return
|
||||
}
|
||||
balance.Type = utils.StringPointer(attr.BalanceType)
|
||||
tnt := attr.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
|
||||
accID := utils.ConcatenatedKey(attr.Tenant, attr.Account)
|
||||
accID := utils.ConcatenatedKey(tnt, attr.Account)
|
||||
if _, err := apierSv1.DataManager.GetAccount(accID); err != nil {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ func (apierSv1 *APIerSv1) ImportTariffPlanFromFolder(attrs *utils.AttrImportTPFr
|
||||
|
||||
// Sets a specific rating profile working with data directly in the DataDB without involving storDb
|
||||
func (apierSv1 *APIerSv1) SetRatingProfile(attrs *utils.AttrSetRatingProfile, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"Tenant", "ToR", "Subject", "RatingPlanActivations"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"ToR", "Subject", "RatingPlanActivations"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
for _, rpa := range attrs.RatingPlanActivations {
|
||||
@@ -407,8 +407,12 @@ func (apierSv1 *APIerSv1) SetRatingProfile(attrs *utils.AttrSetRatingProfile, re
|
||||
return fmt.Errorf("%s:RatingPlanActivation:%v", utils.ErrMandatoryIeMissing.Error(), missing)
|
||||
}
|
||||
}
|
||||
tnt := attrs.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
keyID := utils.ConcatenatedKey(utils.META_OUT,
|
||||
attrs.Tenant, attrs.Category, attrs.Subject)
|
||||
tnt, attrs.Category, attrs.Subject)
|
||||
var rpfl *engine.RatingProfile
|
||||
if !attrs.Overwrite {
|
||||
if rpfl, err = apierSv1.DataManager.GetRatingProfile(keyID, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound {
|
||||
@@ -434,7 +438,7 @@ func (apierSv1 *APIerSv1) SetRatingProfile(attrs *utils.AttrSetRatingProfile, re
|
||||
&engine.RatingPlanActivation{
|
||||
ActivationTime: at,
|
||||
RatingPlanId: ra.RatingPlanId,
|
||||
FallbackKeys: utils.FallbackSubjKeys(attrs.Tenant,
|
||||
FallbackKeys: utils.FallbackSubjKeys(tnt,
|
||||
attrs.Category, ra.FallbackSubjects)})
|
||||
}
|
||||
if err := apierSv1.DataManager.SetRatingProfile(rpfl, utils.NonTransactional); err != nil {
|
||||
@@ -452,10 +456,11 @@ func (apierSv1 *APIerSv1) SetRatingProfile(attrs *utils.AttrSetRatingProfile, re
|
||||
|
||||
// GetRatingProfileIDs returns list of resourceProfile IDs registered for a tenant
|
||||
func (apierSv1 *APIerSv1) GetRatingProfileIDs(args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error {
|
||||
if missing := utils.MissingStructFields(args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.RATING_PROFILE_PREFIX + "*out:" + args.Tenant + ":"
|
||||
prfx := utils.RATING_PROFILE_PREFIX + "*out:" + tnt + ":"
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -472,9 +477,12 @@ func (apierSv1 *APIerSv1) GetRatingProfileIDs(args *utils.PaginatorWithTenant, r
|
||||
}
|
||||
|
||||
func (apierSv1 *APIerSv1) GetRatingProfile(attrs *utils.AttrGetRatingProfile, reply *engine.RatingProfile) (err error) {
|
||||
if missing := utils.MissingStructFields(attrs, []string{"Tenant", "Category", "Subject"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(attrs, []string{utils.Category, utils.Subject}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if attrs.Tenant == utils.EmptyString {
|
||||
attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if rpPrf, err := apierSv1.DataManager.GetRatingProfile(attrs.GetID(),
|
||||
false, utils.NonTransactional); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
|
||||
@@ -104,6 +104,7 @@ var (
|
||||
testApierRemAccountActionTriggers,
|
||||
testApierSetAccount,
|
||||
testApierGetAccountActionPlan,
|
||||
testApierGetAccountActionPlanWithoutTenant,
|
||||
testApierITGetScheduledActionsForAccount,
|
||||
testApierRemUniqueIDActionTiming,
|
||||
testApierGetAccount,
|
||||
@@ -1317,6 +1318,20 @@ func testApierGetAccountActionPlan(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testApierGetAccountActionPlanWithoutTenant(t *testing.T) {
|
||||
var reply []*AccountActionTiming
|
||||
req := utils.TenantAccount{Account: "dan7"}
|
||||
if err := rater.Call(utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.GetAccountActionPlan: ", err.Error())
|
||||
} else if len(reply) != 1 {
|
||||
t.Error("Unexpected action plan received: ", utils.ToJSON(reply))
|
||||
} else {
|
||||
if reply[0].ActionPlanId != "ATMS_1" {
|
||||
t.Errorf("Unexpected ActionoveAccountPlanId received")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we have scheduled actions
|
||||
func testApierITGetScheduledActionsForAccount(t *testing.T) {
|
||||
var rply []*scheduler.ScheduledAction
|
||||
|
||||
@@ -43,10 +43,11 @@ func (apierSv1 *APIerSv1) GetAttributeProfile(arg *utils.TenantIDWithOpts, reply
|
||||
|
||||
// GetAttributeProfileIDs returns list of attributeProfile IDs registered for a tenant
|
||||
func (apierSv1 *APIerSv1) GetAttributeProfileIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error {
|
||||
if missing := utils.MissingStructFields(args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.AttributeProfilePrefix + args.Tenant + ":"
|
||||
prfx := utils.AttributeProfilePrefix + tnt + ":"
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -65,11 +66,12 @@ func (apierSv1 *APIerSv1) GetAttributeProfileIDs(args *utils.PaginatorWithTenant
|
||||
// GetAttributeProfileIDsCount sets in reply var the total number of AttributeProfileIDs registered for a tenant
|
||||
// returns ErrNotFound in case of 0 AttributeProfileIDs
|
||||
func (apierSv1 *APIerSv1) GetAttributeProfileIDsCount(args *utils.TenantWithOpts, reply *int) (err error) {
|
||||
if missing := utils.MissingStructFields(args, []string{utils.Tenant}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
var keys []string
|
||||
prfx := utils.AttributeProfilePrefix + args.Tenant + ":"
|
||||
prfx := utils.AttributeProfilePrefix + tnt + ":"
|
||||
if keys, err = apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -89,7 +91,7 @@ type AttributeWithCache struct {
|
||||
|
||||
//SetAttributeProfile add/update a new Attribute Profile
|
||||
func (apierSv1 *APIerSv1) SetAttributeProfile(alsWrp *AttributeWithCache, reply *string) error {
|
||||
if missing := utils.MissingStructFields(alsWrp.AttributeProfile, []string{"Tenant", "ID", "Attributes"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(alsWrp.AttributeProfile, []string{utils.Tenant, utils.ID, utils.Attributes}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
for _, attr := range alsWrp.Attributes {
|
||||
@@ -123,10 +125,14 @@ func (apierSv1 *APIerSv1) SetAttributeProfile(alsWrp *AttributeWithCache, reply
|
||||
|
||||
//RemoveAttributeProfile remove a specific Attribute Profile
|
||||
func (apierSv1 *APIerSv1) RemoveAttributeProfile(arg *utils.TenantIDWithCache, reply *string) error {
|
||||
if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := apierSv1.DataManager.RemoveAttributeProfile(arg.Tenant, arg.ID,
|
||||
tnt := arg.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if err := apierSv1.DataManager.RemoveAttributeProfile(tnt, arg.ID,
|
||||
utils.NonTransactional, true); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -134,8 +140,8 @@ func (apierSv1 *APIerSv1) RemoveAttributeProfile(arg *utils.TenantIDWithCache, r
|
||||
if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheAttributeProfiles: time.Now().UnixNano()}); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheAttributeProfiles,
|
||||
utils.ConcatenatedKey(arg.Tenant, arg.ID), nil, nil, arg.Opts); err != nil {
|
||||
if err := apierSv1.CallCache(arg.Cache, tnt, utils.CacheAttributeProfiles,
|
||||
utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.Opts); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -733,9 +733,10 @@ func testAttributeSProcessEventWithHeader(t *testing.T) {
|
||||
func testAttributeSGetAttPrfIDs(t *testing.T) {
|
||||
expected := []string{"ATTR_2", "ATTR_PASS", "ATTR_1", "ATTR_3", "ATTR_Header", "AttributeWithNonSubstitute"}
|
||||
var result []string
|
||||
if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &result); err == nil ||
|
||||
err.Error() != utils.NewErrMandatoryIeMissing("Tenant").Error() {
|
||||
t.Errorf("Expected error recived reply %+v with err=%v", result, err)
|
||||
if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expected) != len(result) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -27,10 +27,14 @@ import (
|
||||
|
||||
// GetChargerProfile returns a Charger Profile
|
||||
func (apierSv1 *APIerSv1) GetChargerProfile(arg *utils.TenantID, reply *engine.ChargerProfile) error {
|
||||
if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if cpp, err := apierSv1.DataManager.GetChargerProfile(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil {
|
||||
tnt := arg.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
if cpp, err := apierSv1.DataManager.GetChargerProfile(tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
} else {
|
||||
*reply = *cpp
|
||||
@@ -40,10 +44,11 @@ func (apierSv1 *APIerSv1) GetChargerProfile(arg *utils.TenantID, reply *engine.C
|
||||
|
||||
// GetChargerProfileIDs returns list of chargerProfile IDs registered for a tenant
|
||||
func (apierSv1 *APIerSv1) GetChargerProfileIDs(args *utils.PaginatorWithTenant, chPrfIDs *[]string) error {
|
||||
if missing := utils.MissingStructFields(args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
tnt := args.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.ChargerProfilePrefix + args.Tenant + ":"
|
||||
prfx := utils.ChargerProfilePrefix + tnt + ":"
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -31,10 +31,14 @@ import (
|
||||
|
||||
// GetDispatcherProfile returns a Dispatcher Profile
|
||||
func (apierSv1 *APIerSv1) GetDispatcherProfile(arg *utils.TenantID, reply *engine.DispatcherProfile) error {
|
||||
if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
dpp, err := apierSv1.DataManager.GetDispatcherProfile(arg.Tenant, arg.ID, true, true, utils.NonTransactional)
|
||||
tnt := arg.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
dpp, err := apierSv1.DataManager.GetDispatcherProfile(tnt, arg.ID, true, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -44,10 +48,10 @@ func (apierSv1 *APIerSv1) GetDispatcherProfile(arg *utils.TenantID, reply *engin
|
||||
|
||||
// GetDispatcherProfileIDs returns list of dispatcherProfile IDs registered for a tenant
|
||||
func (apierSv1 *APIerSv1) GetDispatcherProfileIDs(tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error {
|
||||
if missing := utils.MissingStructFields(tenantArg, []string{utils.Tenant}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tenant := tenantArg.Tenant
|
||||
if tenant == utils.EmptyString {
|
||||
tenant = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.DispatcherProfilePrefix + tenant + ":"
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
@@ -115,10 +119,14 @@ func (apierSv1 *APIerSv1) RemoveDispatcherProfile(arg *utils.TenantIDWithCache,
|
||||
|
||||
// GetDispatcherHost returns a Dispatcher Host
|
||||
func (apierSv1 *APIerSv1) GetDispatcherHost(arg *utils.TenantID, reply *engine.DispatcherHost) error {
|
||||
if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
dpp, err := apierSv1.DataManager.GetDispatcherHost(arg.Tenant, arg.ID, true, false, utils.NonTransactional)
|
||||
tnt := arg.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
dpp, err := apierSv1.DataManager.GetDispatcherHost(tnt, arg.ID, true, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
@@ -128,10 +136,10 @@ func (apierSv1 *APIerSv1) GetDispatcherHost(arg *utils.TenantID, reply *engine.D
|
||||
|
||||
// GetDispatcherHostIDs returns list of dispatcherHost IDs registered for a tenant
|
||||
func (apierSv1 *APIerSv1) GetDispatcherHostIDs(tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error {
|
||||
if missing := utils.MissingStructFields(tenantArg, []string{utils.Tenant}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tenant := tenantArg.Tenant
|
||||
if tenant == utils.EmptyString {
|
||||
tenant = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.DispatcherHostPrefix + tenant + ":"
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
|
||||
@@ -170,11 +170,13 @@ func testDispatcherSSetDispatcherProfile(t *testing.T) {
|
||||
|
||||
func testDispatcherSGetDispatcherProfileIDs(t *testing.T) {
|
||||
var result []string
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfileIDs,
|
||||
&utils.PaginatorWithTenant{}, &result); err == nil {
|
||||
t.Errorf("Expected: %s , received: %v", utils.NewErrMandatoryIeMissing(utils.Tenant).Error(), err)
|
||||
}
|
||||
expected := []string{"Dsp1"}
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfileIDs,
|
||||
&utils.PaginatorWithTenant{}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(result) != len(expected) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfileIDs,
|
||||
&utils.PaginatorWithTenant{Tenant: dispatcherProfile.Tenant}, &result); err != nil {
|
||||
t.Error(err)
|
||||
@@ -293,11 +295,13 @@ func testDispatcherSSetDispatcherHost(t *testing.T) {
|
||||
|
||||
func testDispatcherSGetDispatcherHostIDs(t *testing.T) {
|
||||
var result []string
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHostIDs,
|
||||
&utils.PaginatorWithTenant{}, &result); err == nil {
|
||||
t.Errorf("Expected: %s , received: %v", utils.NewErrMandatoryIeMissing(utils.Tenant), err)
|
||||
}
|
||||
expected := []string{"DspHst1"}
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHostIDs,
|
||||
&utils.PaginatorWithTenant{}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(result) != len(expected) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHostIDs,
|
||||
&utils.PaginatorWithTenant{Tenant: dispatcherHost.Tenant}, &result); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -292,6 +292,7 @@ const (
|
||||
Category = "Category"
|
||||
Contexts = "Contexts"
|
||||
Account = "Account"
|
||||
Balances = "Balances"
|
||||
Subject = "Subject"
|
||||
Destination = "Destination"
|
||||
SetupTime = "SetupTime"
|
||||
|
||||
Reference in New Issue
Block a user