mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
Protect new subsystems against empty event in APIs
This commit is contained in:
@@ -204,6 +204,9 @@ func (alS *AttributeService) V1GetAttributeForEvent(ev *utils.CGREvent,
|
||||
|
||||
func (alS *AttributeService) V1ProcessEvent(ev *utils.CGREvent,
|
||||
reply *AttrSProcessEventReply) (err error) {
|
||||
if ev.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
evReply, err := alS.processEvent(ev)
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
|
||||
@@ -530,8 +530,10 @@ func (rS *ResourceService) processThresholds(r *Resource) (err error) {
|
||||
|
||||
// V1ResourcesForEvent returns active resource configs matching the event
|
||||
func (rS *ResourceService) V1ResourcesForEvent(args utils.ArgRSv1ResourceUsage, reply *Resources) (err error) {
|
||||
if args.CGREvent.Tenant == "" {
|
||||
return utils.NewErrMandatoryIeMissing("Tenant")
|
||||
if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
var mtcRLs Resources
|
||||
if args.UsageID != "" { // only cached if UsageID is present
|
||||
@@ -559,6 +561,9 @@ func (rS *ResourceService) V1AuthorizeResources(args utils.ArgRSv1ResourceUsage,
|
||||
if missing := utils.MissingStructFields(&args, []string{"UsageID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
mtcRLs := rS.cachedResourcesForEvent(args.TenantID())
|
||||
if mtcRLs == nil {
|
||||
if mtcRLs, err = rS.matchingResourcesForEvent(&args.CGREvent, args.UsageTTL); err != nil {
|
||||
@@ -589,6 +594,9 @@ func (rS *ResourceService) V1AllocateResource(args utils.ArgRSv1ResourceUsage, r
|
||||
if missing := utils.MissingStructFields(&args, []string{"UsageID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
var wasCached bool
|
||||
mtcRLs := rS.cachedResourcesForEvent(args.UsageID)
|
||||
if mtcRLs == nil {
|
||||
@@ -645,6 +653,9 @@ func (rS *ResourceService) V1ReleaseResource(args utils.ArgRSv1ResourceUsage, re
|
||||
if missing := utils.MissingStructFields(&args, []string{"UsageID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
mtcRLs := rS.cachedResourcesForEvent(args.UsageID)
|
||||
if mtcRLs == nil {
|
||||
if mtcRLs, err = rS.matchingResourcesForEvent(&args.CGREvent, args.UsageTTL); err != nil {
|
||||
|
||||
@@ -268,6 +268,8 @@ func (sS *StatService) processEvent(ev *utils.CGREvent) (err error) {
|
||||
func (sS *StatService) V1ProcessEvent(ev *utils.CGREvent, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if ev.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
if err = sS.processEvent(ev); err == nil {
|
||||
*reply = utils.OK
|
||||
@@ -279,6 +281,8 @@ func (sS *StatService) V1ProcessEvent(ev *utils.CGREvent, reply *string) (err er
|
||||
func (sS *StatService) V1GetStatQueuesForEvent(ev *utils.CGREvent, reply *[]string) (err error) {
|
||||
if missing := utils.MissingStructFields(ev, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if ev.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
var sQs StatQueues
|
||||
if sQs, err = sS.matchingStatQueuesForEvent(ev); err != nil {
|
||||
|
||||
@@ -348,6 +348,8 @@ type optsGetSuppliers struct {
|
||||
func (spS *SupplierService) V1GetSuppliers(args *ArgsGetSuppliers, reply *SortedSuppliers) (err error) {
|
||||
if missing := utils.MissingStructFields(&args.CGREvent, []string{"Tenant", "ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
sSps, err := spS.sortedSuppliersForEvent(args)
|
||||
if err != nil {
|
||||
|
||||
@@ -328,6 +328,8 @@ func (tS *ThresholdService) processEvent(args *ArgsProcessEvent) (hits int, err
|
||||
func (tS *ThresholdService) V1ProcessEvent(args *ArgsProcessEvent, reply *int) (err error) {
|
||||
if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
if hits, err := tS.processEvent(args); err != nil {
|
||||
return err
|
||||
@@ -341,6 +343,8 @@ func (tS *ThresholdService) V1ProcessEvent(args *ArgsProcessEvent, reply *int) (
|
||||
func (tS *ThresholdService) V1GetThresholdsForEvent(args *ArgsProcessEvent, reply *Thresholds) (err error) {
|
||||
if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
} else if args.CGREvent.Event == nil {
|
||||
return utils.NewErrMandatoryIeMissing("Event")
|
||||
}
|
||||
var ts Thresholds
|
||||
if ts, err = tS.matchingThresholdsForEvent(args); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user