revise IPService implementation

This commit is contained in:
ionutboangiu
2025-12-04 14:10:05 +02:00
committed by Dan Christian Bogos
parent 5aee85a12d
commit eb372148d1
34 changed files with 1201 additions and 1666 deletions

View File

@@ -180,7 +180,7 @@ func testDspChcPrecacheStatus(t *testing.T) {
utils.CacheResourceProfiles: utils.MetaReady,
utils.CacheResources: utils.MetaReady,
utils.CacheIPProfiles: utils.MetaReady,
utils.CacheIPs: utils.MetaReady,
utils.CacheIPAllocations: utils.MetaReady,
utils.CacheTimings: utils.MetaReady,
utils.CacheStatQueueProfiles: utils.MetaReady,
utils.CacheStatQueues: utils.MetaReady,

View File

@@ -40,73 +40,74 @@ func (dS *DispatcherService) IPsV1Ping(ctx *context.Context, args *utils.CGREven
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1Ping, args, rpl)
}
func (dS *DispatcherService) IPsV1GetIPsForEvent(ctx *context.Context, args *utils.CGREvent,
reply *engine.IPs) (err error) {
func (dS *DispatcherService) IPsV1GetIPAllocationForEvent(ctx *context.Context, args *utils.CGREvent,
reply *engine.IPAllocations) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args != nil && args.Tenant != utils.EmptyString {
tnt = args.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1GetIPsForEvent, tnt,
if err = dS.authorize(utils.IPsV1GetIPAllocationForEvent, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1GetIPsForEvent, args, reply)
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1GetIPAllocationForEvent, args, reply)
}
func (dS *DispatcherService) IPsV1AuthorizeIPs(ctx *context.Context, args *utils.CGREvent,
func (dS *DispatcherService) IPsV1AuthorizeIP(ctx *context.Context, args *utils.CGREvent,
reply *engine.AllocatedIP) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args != nil && args.Tenant != utils.EmptyString {
tnt = args.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1AuthorizeIP, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1AuthorizeIP, args, reply)
}
func (dS *DispatcherService) IPsV1AllocateIP(ctx *context.Context, args *utils.CGREvent,
reply *engine.AllocatedIP) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args != nil && args.Tenant != utils.EmptyString {
tnt = args.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1AllocateIP, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1AllocateIP, args, reply)
}
func (dS *DispatcherService) IPsV1ReleaseIP(ctx *context.Context, args *utils.CGREvent,
reply *string) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args != nil && args.Tenant != utils.EmptyString {
tnt = args.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1AuthorizeIPs, tnt,
if err = dS.authorize(utils.IPsV1ReleaseIP, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1AuthorizeIPs, args, reply)
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1ReleaseIP, args, reply)
}
func (dS *DispatcherService) IPsV1AllocateIPs(ctx *context.Context, args *utils.CGREvent,
func (dS *DispatcherService) IPsV1ClearIPAllocations(ctx *context.Context, args *engine.ClearIPAllocationsArgs,
reply *string) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args != nil && args.Tenant != utils.EmptyString {
tnt = args.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1AllocateIPs, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1AllocateIPs, args, reply)
}
func (dS *DispatcherService) IPsV1ReleaseIPs(ctx *context.Context, args *utils.CGREvent,
reply *string) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args != nil && args.Tenant != utils.EmptyString {
tnt = args.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1ReleaseIPs, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.MetaIPs, utils.IPsV1ReleaseIPs, args, reply)
}
func (dS *DispatcherService) IPsV1GetIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IP) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString {
tnt = args.TenantID.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1GetIP, tnt,
if err = dS.authorize(utils.IPsV1ClearIPAllocations, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
@@ -115,5 +116,23 @@ func (dS *DispatcherService) IPsV1GetIP(ctx *context.Context, args *utils.Tenant
Tenant: tnt,
ID: args.ID,
APIOpts: args.APIOpts,
}, utils.MetaIPs, utils.IPsV1GetIP, args, reply)
}, utils.MetaIPs, utils.IPsV1ClearIPAllocations, args, reply)
}
func (dS *DispatcherService) IPsV1GetIPAllocations(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IPAllocations) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString {
tnt = args.TenantID.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.IPsV1GetIPAllocations, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{
Tenant: tnt,
ID: args.ID,
APIOpts: args.APIOpts,
}, utils.MetaIPs, utils.IPsV1GetIPAllocations, args, reply)
}

View File

@@ -234,13 +234,13 @@ func (dS *DispatcherService) ReplicatorSv1GetResourceProfile(ctx *context.Contex
}, utils.MetaReplicator, utils.ReplicatorSv1GetResourceProfile, args, reply)
}
func (dS *DispatcherService) ReplicatorSv1GetIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IP) (err error) {
func (dS *DispatcherService) ReplicatorSv1GetIPAllocations(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IPAllocations) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString {
tnt = args.TenantID.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1GetIP, tnt,
if err = dS.authorize(utils.ReplicatorSv1GetIPAllocations, tnt,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
@@ -249,7 +249,7 @@ func (dS *DispatcherService) ReplicatorSv1GetIP(ctx *context.Context, args *util
Tenant: tnt,
ID: args.ID,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1GetIP, args, reply)
}, utils.MetaReplicator, utils.ReplicatorSv1GetIPAllocations, args, reply)
}
func (dS *DispatcherService) ReplicatorSv1GetIPProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.IPProfile) (err error) {
@@ -716,15 +716,15 @@ func (dS *DispatcherService) ReplicatorSv1SetResourceProfile(ctx *context.Contex
}, utils.MetaReplicator, utils.ReplicatorSv1SetResourceProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetIP(ctx *context.Context, args *engine.IPWithAPIOpts, rpl *string) (err error) {
func (dS *DispatcherService) ReplicatorSv1SetIPAllocations(ctx *context.Context, args *engine.IPAllocationsWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.IPWithAPIOpts{
IP: &engine.IP{},
args = &engine.IPAllocationsWithAPIOpts{
IPAllocations: &engine.IPAllocations{},
}
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1SetIP, args.Tenant,
if err = dS.authorize(utils.ReplicatorSv1SetIPAllocations, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
@@ -732,7 +732,7 @@ func (dS *DispatcherService) ReplicatorSv1SetIP(ctx *context.Context, args *engi
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1SetIP, args, rpl)
}, utils.MetaReplicator, utils.ReplicatorSv1SetIPAllocations, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1SetIPProfile(ctx *context.Context, args *engine.IPProfileWithAPIOpts, rpl *string) (err error) {
@@ -1169,7 +1169,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveResourceProfile(ctx *context.Con
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveResourceProfile, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveIP(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) {
func (dS *DispatcherService) ReplicatorSv1RemoveIPAllocations(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{},
@@ -1177,7 +1177,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveIP(ctx *context.Context, args *u
}
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.ReplicatorSv1RemoveIP, args.Tenant,
if err = dS.authorize(utils.ReplicatorSv1RemoveIPAllocations, args.Tenant,
utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return
}
@@ -1185,7 +1185,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveIP(ctx *context.Context, args *u
return dS.Dispatch(&utils.CGREvent{
Tenant: args.Tenant,
APIOpts: args.APIOpts,
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveIP, args, rpl)
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveIPAllocations, args, rpl)
}
func (dS *DispatcherService) ReplicatorSv1RemoveIPProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) {