up libs
This commit is contained in:
1 parent
9f69df64e6
commit
f5139e46ed
10 files changed
+277
-176
No files matched your search
+54
-51
@@ -1,9 +1,10 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
rd "github.com/go-redis/redis"
|
||||
rd "github.com/go-redis/redis/v8"
|
||||
rdLib "github.com/integration-system/isp-lib/v2/redis"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -28,14 +29,13 @@ type accessListController struct{}
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /access_list/get_by_id [POST]
|
||||
func (c accessListController) GetById(req domain.Identity) ([]domain.MethodInfo, error) {
|
||||
if app, err := model.AppRep.GetApplicationById(req.Id); err != nil {
|
||||
func (c accessListController) GetById(request domain.Identity) ([]domain.MethodInfo, error) {
|
||||
err := c.checkAppById(request.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if app == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "application '%d' not found", req.Id)
|
||||
}
|
||||
|
||||
return c.getAccessListById(req.Id)
|
||||
return c.getAccessListById(request.Id)
|
||||
}
|
||||
|
||||
// SetOne godoc
|
||||
@@ -50,37 +50,30 @@ func (c accessListController) GetById(req domain.Identity) ([]domain.MethodInfo,
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /access_list/set_one [POST]
|
||||
func (c accessListController) SetOne(request entity.AccessList) (*domain.CountResponse, error) {
|
||||
if app, err := model.AppRep.GetApplicationById(request.AppId); err != nil {
|
||||
err := c.checkAppById(request.AppId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if app == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "application '%d' not found", request.AppId)
|
||||
}
|
||||
|
||||
var (
|
||||
resp = 0
|
||||
err error
|
||||
)
|
||||
if err := model.DbClient.RunInTransaction(func(repository model.AccessListRepository) error {
|
||||
if resp, err = repository.Upsert(request); err != nil {
|
||||
resp := 0
|
||||
err = model.DbClient.RunInTransaction(func(repository model.AccessListRepository) error {
|
||||
resp, err = repository.Upsert(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
_, err = redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
key := fmt.Sprintf("%d|%s", request.AppId, request.Method)
|
||||
if _, err := p.Set(key, request.Value, 0).Result(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
_, err := p.Set(context.Background(), key, request.Value, 0).Result()
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}); err != nil {
|
||||
})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &domain.CountResponse{Count: resp}, nil
|
||||
}
|
||||
|
||||
return &domain.CountResponse{Count: resp}, nil
|
||||
}
|
||||
|
||||
// SetList godoc
|
||||
@@ -95,18 +88,13 @@ func (c accessListController) SetOne(request entity.AccessList) (*domain.CountRe
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /access_list/set_list [POST]
|
||||
func (c accessListController) SetList(request domain.SetListRequest) ([]domain.MethodInfo, error) {
|
||||
if app, err := model.AppRep.GetApplicationById(request.AppId); err != nil {
|
||||
err := c.checkAppById(request.AppId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if app == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "application '%d' not found", request.AppId)
|
||||
}
|
||||
|
||||
var (
|
||||
oldAccessList = make([]entity.AccessList, 0)
|
||||
err error
|
||||
)
|
||||
|
||||
if err := model.DbClient.RunInTransaction(func(repository model.AccessListRepository) error {
|
||||
oldAccessList := make([]entity.AccessList, 0)
|
||||
err = model.DbClient.RunInTransaction(func(repository model.AccessListRepository) error {
|
||||
if request.RemoveOld == true {
|
||||
oldAccessList, err = repository.DeleteById(request.AppId)
|
||||
if err != nil {
|
||||
@@ -131,41 +119,45 @@ func (c accessListController) SetList(request domain.SetListRequest) ([]domain.M
|
||||
}
|
||||
|
||||
if len(newAccessList) > 0 {
|
||||
if _, err := repository.UpsertArray(newAccessList); err != nil {
|
||||
_, err := repository.UpsertArray(newAccessList)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
_, err := redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
if len(redisDelRequest) > 0 {
|
||||
if _, err := p.Del(redisDelRequest...).Result(); err != nil {
|
||||
_, err := p.Del(context.Background(), redisDelRequest...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(redisMsetRequest) > 0 {
|
||||
if _, err := p.MSet(redisMsetRequest...).Result(); err != nil {
|
||||
_, err := p.MSet(context.Background(), redisMsetRequest...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}); err != nil {
|
||||
})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return c.getAccessListById(request.AppId)
|
||||
}
|
||||
|
||||
return c.getAccessListById(request.AppId)
|
||||
}
|
||||
|
||||
func (c accessListController) getAccessListById(id int32) ([]domain.MethodInfo, error) {
|
||||
if accessList, err := model.AccessListRep.GetByAppId(id); err != nil {
|
||||
accessList, err := model.AccessListRep.GetByAppId(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return c.convertAccessList(accessList), nil
|
||||
}
|
||||
|
||||
return c.convertAccessList(accessList), nil
|
||||
}
|
||||
|
||||
func (accessListController) convertAccessList(accessLists []entity.AccessList) []domain.MethodInfo {
|
||||
@@ -178,3 +170,14 @@ func (accessListController) convertAccessList(accessLists []entity.AccessList) [
|
||||
}
|
||||
return methodInfos
|
||||
}
|
||||
|
||||
func (accessListController) checkAppById(appId int32) error {
|
||||
app, err := model.AppRep.GetApplicationById(appId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if app == nil {
|
||||
return status.Errorf(codes.NotFound, "application '%d' not found", appId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+53
-35
@@ -1,9 +1,10 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
rd "github.com/go-redis/redis"
|
||||
rd "github.com/go-redis/redis/v8"
|
||||
"github.com/integration-system/isp-lib/v2/config"
|
||||
rdLib "github.com/integration-system/isp-lib/v2/redis"
|
||||
_ "github.com/integration-system/isp-lib/v2/structure"
|
||||
@@ -76,41 +77,56 @@ func (c applicationController) CreateUpdateApplication(app entity.Application) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s, e := model.ServiceRep.GetServiceById(app.ServiceId)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
|
||||
s, err := model.ServiceRep.GetServiceById(app.ServiceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s == nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "Service with id %d not found", app.ServiceId)
|
||||
}
|
||||
|
||||
if app.Id == 0 {
|
||||
if existed != nil {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Application with name %s already exists", app.Name)
|
||||
}
|
||||
app, e := model.AppRep.CreateApplication(app)
|
||||
_, _ = c.enrichWithTokens(app)
|
||||
return &domain.AppWithToken{App: app, Tokens: []entity.Token{}}, e
|
||||
} else {
|
||||
if existed != nil && existed.Id != app.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Application with name %s already exists", app.Name)
|
||||
}
|
||||
existed, err = model.AppRep.GetApplicationById(app.Id)
|
||||
|
||||
app, err = model.AppRep.CreateApplication(app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Application with id %d not found", app.Id)
|
||||
}
|
||||
app, e := model.AppRep.UpdateApplication(app)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
arr, err := c.enrichWithTokens(app)
|
||||
|
||||
_, err = c.enrichWithTokens(app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return arr[0], nil
|
||||
|
||||
return &domain.AppWithToken{App: app, Tokens: []entity.Token{}}, nil
|
||||
}
|
||||
|
||||
if existed != nil && existed.Id != app.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Application with name %s already exists", app.Name)
|
||||
}
|
||||
|
||||
existed, err = model.AppRep.GetApplicationById(app.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Application with id %d not found", app.Id)
|
||||
}
|
||||
|
||||
app, err = model.AppRep.UpdateApplication(app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arr, err := c.enrichWithTokens(app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return arr[0], nil
|
||||
|
||||
}
|
||||
|
||||
// GetApplicationById godoc
|
||||
@@ -133,6 +149,7 @@ func (c applicationController) GetApplicationById(identity domain.Identity) (*do
|
||||
if application == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Application with id %d not found", identity.Id)
|
||||
}
|
||||
|
||||
arr, err := c.enrichWithTokens(*application)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -160,8 +177,7 @@ func (applicationController) DeleteApplications(list []int32) (domain.DeleteResp
|
||||
count = 0
|
||||
instanceUuid = config.Get().(*conf.Configuration).InstanceUuid
|
||||
)
|
||||
|
||||
if _, err := redis.Client.Get().UseDb(rdLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
_, err := redis.Client.Get().UseDb(rdLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
return model.DbClient.RunInTransaction(func(
|
||||
appRep model.AppRepository, tokenRep model.TokenRepository, accessRep model.AccessListRepository) error {
|
||||
|
||||
@@ -190,33 +206,34 @@ func (applicationController) DeleteApplications(list []int32) (domain.DeleteResp
|
||||
for i, token := range tokenIdList {
|
||||
keys[i] = fmt.Sprintf("%s|%s", token, instanceUuid)
|
||||
}
|
||||
if _, err := p.Del(keys...).Result(); err != nil {
|
||||
|
||||
_, err := p.Del(context.Background(), keys...).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if count, err = appRep.DeleteApplications(list); err != nil {
|
||||
count, err = appRep.DeleteApplications(list)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(redisDelRequest) > 0 {
|
||||
if _, err := redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
if _, err := p.Del(redisDelRequest...).Result(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}); err != nil {
|
||||
_, err := redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
_, err := p.Del(context.Background(), redisDelRequest...).Result()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}); err != nil {
|
||||
})
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
} else {
|
||||
return domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
return domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
|
||||
// GetSystemTree godoc
|
||||
@@ -302,6 +319,7 @@ func (applicationController) enrichWithTokens(apps ...entity.Application) ([]*do
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, v := range tokens {
|
||||
app := appMap[v.AppId]
|
||||
app.Tokens = append(app.Tokens, v)
|
||||
|
||||
+32
-18
@@ -55,33 +55,43 @@ func (domainController) CreateUpdateDomain(domain entity.Domain, md metadata.MD)
|
||||
}
|
||||
domain.SystemId = int32(sysId)
|
||||
|
||||
sys, e := model.SystemRep.GetSystemById(domain.SystemId)
|
||||
if e != nil {
|
||||
sys, err := model.SystemRep.GetSystemById(domain.SystemId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if sys == nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "System with id %d not found", domain.SystemId)
|
||||
}
|
||||
|
||||
if domain.Id == 0 {
|
||||
if existed != nil {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Domain with name %s already exists", domain.Name)
|
||||
}
|
||||
domain, e := model.DomainRep.CreateDomain(domain)
|
||||
return &domain, e
|
||||
} else {
|
||||
if existed != nil && existed.Id != domain.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Domain with name %s already exists", domain.Name)
|
||||
}
|
||||
existed, err = model.DomainRep.GetDomainById(domain.Id)
|
||||
|
||||
domain, err = model.DomainRep.CreateDomain(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Domain with id %d not found", domain.Id)
|
||||
}
|
||||
domain, e := model.DomainRep.UpdateDomain(domain)
|
||||
return &domain, e
|
||||
return &domain, nil
|
||||
}
|
||||
|
||||
if existed != nil && existed.Id != domain.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Domain with name %s already exists", domain.Name)
|
||||
}
|
||||
|
||||
existed, err = model.DomainRep.GetDomainById(domain.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Domain with id %d not found", domain.Id)
|
||||
}
|
||||
|
||||
domain, err = model.DomainRep.UpdateDomain(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &domain, nil
|
||||
}
|
||||
|
||||
// GetDomainById godoc
|
||||
@@ -96,14 +106,14 @@ func (domainController) CreateUpdateDomain(domain entity.Domain, md metadata.MD)
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/get_domain_by_id [POST]
|
||||
func (domainController) GetDomainById(identity domain.Identity) (*entity.Domain, error) {
|
||||
domain, err := model.DomainRep.GetDomainById(identity.Id)
|
||||
d, err := model.DomainRep.GetDomainById(identity.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if domain == nil {
|
||||
if d == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Domain with id %d not found", identity.Id)
|
||||
}
|
||||
return domain, err
|
||||
return d, err
|
||||
}
|
||||
|
||||
// DeleteDomains godoc
|
||||
@@ -121,6 +131,10 @@ func (domainController) DeleteDomains(list []int32) (domain.DeleteResponse, erro
|
||||
if len(list) == 0 {
|
||||
return domain.DeleteResponse{Deleted: 0}, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
}
|
||||
|
||||
res, err := model.DomainRep.DeleteDomains(list)
|
||||
return domain.DeleteResponse{Deleted: res}, err
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
}
|
||||
return domain.DeleteResponse{Deleted: res}, nil
|
||||
}
|
||||
+33
-17
@@ -62,33 +62,44 @@ func (serviceController) CreateUpdateService(service entity.Service) (*entity.Se
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
domain, e := model.DomainRep.GetDomainById(service.DomainId)
|
||||
if e != nil {
|
||||
|
||||
d, err := model.DomainRep.GetDomainById(service.DomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if domain == nil {
|
||||
if d == nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "Domain with id %d not found", service.DomainId)
|
||||
}
|
||||
|
||||
if service.Id == 0 {
|
||||
if existed != nil {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Service with name %s already exists", service.Name)
|
||||
}
|
||||
service, e := model.ServiceRep.CreateService(service)
|
||||
return &service, e
|
||||
} else {
|
||||
if existed != nil && existed.Id != service.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Service with name %s already exists", service.Name)
|
||||
}
|
||||
existed, err = model.ServiceRep.GetServiceById(service.Id)
|
||||
service, err = model.ServiceRep.CreateService(service)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Service with id %d not found", service.Id)
|
||||
}
|
||||
service, e := model.ServiceRep.UpdateService(service)
|
||||
return &service, e
|
||||
return &service, nil
|
||||
}
|
||||
|
||||
if existed != nil && existed.Id != service.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Service with name %s already exists", service.Name)
|
||||
}
|
||||
|
||||
existed, err = model.ServiceRep.GetServiceById(service.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Service with id %d not found", service.Id)
|
||||
}
|
||||
|
||||
service, err = model.ServiceRep.UpdateService(service)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &service, nil
|
||||
}
|
||||
|
||||
// GetServiceById godoc
|
||||
@@ -110,7 +121,8 @@ func (serviceController) GetServiceById(identity domain.Identity) (*entity.Servi
|
||||
if service == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Service with id %d not found", identity.Id)
|
||||
}
|
||||
return service, err
|
||||
|
||||
return service, nil
|
||||
}
|
||||
|
||||
// DeleteService godoc
|
||||
@@ -128,6 +140,10 @@ func (serviceController) DeleteService(list []int32) (domain.DeleteResponse, err
|
||||
if len(list) == 0 {
|
||||
return domain.DeleteResponse{Deleted: 0}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
}
|
||||
|
||||
res, err := model.ServiceRep.DeleteServices(list)
|
||||
return domain.DeleteResponse{Deleted: res}, err
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
}
|
||||
return domain.DeleteResponse{Deleted: res}, nil
|
||||
}
|
||||
+28
-14
@@ -54,22 +54,32 @@ func (systemController) CreateUpdateSystem(system entity.System) (*entity.System
|
||||
if existed != nil {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "System with name %s already exists", system.Name)
|
||||
}
|
||||
sys, e := model.SystemRep.CreateSystem(system)
|
||||
return &sys, e
|
||||
} else {
|
||||
if existed != nil && existed.Id != system.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "System with name %s already exists", system.Name)
|
||||
}
|
||||
existed, err = model.SystemRep.GetSystemById(system.Id)
|
||||
|
||||
system, err = model.SystemRep.CreateSystem(system)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Error(codes.NotFound, fmt.Sprintf("System with id %d not found", system.Id))
|
||||
}
|
||||
sys, e := model.SystemRep.UpdateSystem(system)
|
||||
return &sys, e
|
||||
return &system, nil
|
||||
}
|
||||
|
||||
if existed != nil && existed.Id != system.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "System with name %s already exists", system.Name)
|
||||
}
|
||||
|
||||
existed, err = model.SystemRep.GetSystemById(system.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if existed == nil {
|
||||
return nil, status.Error(codes.NotFound, fmt.Sprintf("System with id %d not found", system.Id))
|
||||
}
|
||||
|
||||
system, err = model.SystemRep.UpdateSystem(system)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &system, nil
|
||||
|
||||
}
|
||||
|
||||
// GetSystemById godoc
|
||||
@@ -91,7 +101,7 @@ func (systemController) GetSystemById(identity domain.Identity) (*entity.System,
|
||||
if sys == nil {
|
||||
return nil, status.Error(codes.NotFound, fmt.Sprintf("System with id %d not found", identity.Id))
|
||||
}
|
||||
return sys, err
|
||||
return sys, nil
|
||||
}
|
||||
|
||||
// DeleteSystems godoc
|
||||
@@ -109,6 +119,10 @@ func (systemController) DeleteSystems(list []int32) (domain.DeleteResponse, erro
|
||||
if len(list) == 0 {
|
||||
return domain.DeleteResponse{}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
}
|
||||
|
||||
res, err := model.SystemRep.DeleteSystems(list)
|
||||
return domain.DeleteResponse{Deleted: res}, err
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
}
|
||||
return domain.DeleteResponse{Deleted: res}, nil
|
||||
}
|
||||
+14
-15
@@ -1,10 +1,11 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
rd "github.com/go-redis/redis"
|
||||
rd "github.com/go-redis/redis/v8"
|
||||
"github.com/integration-system/isp-lib/v2/config"
|
||||
redisLib "github.com/integration-system/isp-lib/v2/redis"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -143,13 +144,13 @@ func (tokenController) SetIdentityMapForTokenV2(token string, expireTime int64,
|
||||
instanceUuid := config.Get().(*conf.Configuration).InstanceUuid
|
||||
_, e := redis.Client.Get().UseDbTx(redisLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
key := fmt.Sprintf("%s|%s", token, instanceUuid)
|
||||
stat := p.HMSet(key, idMap)
|
||||
stat := p.HMSet(context.Background(), key, idMap)
|
||||
err := stat.Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if expireTime > 0 {
|
||||
err = p.Expire(token, time.Duration(expireTime)*time.Millisecond).Err()
|
||||
err = p.Expire(context.Background(), token, time.Duration(expireTime)*time.Millisecond).Err()
|
||||
}
|
||||
return err
|
||||
})
|
||||
@@ -218,28 +219,26 @@ func (tokenController) revokeTokens(tokens []string) (*domain.DeleteResponse, er
|
||||
var (
|
||||
count = 0
|
||||
instanceUuid = config.Get().(*conf.Configuration).InstanceUuid
|
||||
keys = make([]string, len(tokens))
|
||||
)
|
||||
|
||||
keys := make([]string, len(tokens))
|
||||
for i, token := range tokens {
|
||||
keys[i] = fmt.Sprintf("%s|%s", token, instanceUuid)
|
||||
}
|
||||
|
||||
if err := model.DbClient.RunInTransaction(func(rep model.TokenRepository) error {
|
||||
if deleted, err := rep.DeleteTokens(tokens); err != nil {
|
||||
err := model.DbClient.RunInTransaction(func(rep model.TokenRepository) error {
|
||||
deleted, err := rep.DeleteTokens(tokens)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
count = deleted
|
||||
}
|
||||
count = deleted
|
||||
|
||||
_, err := redis.Client.Get().UseDbTx(redisLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
_, err := p.Del(keys...).Result()
|
||||
_, err = redis.Client.Get().UseDbTx(redisLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
_, err := p.Del(context.Background(), keys...).Result()
|
||||
return err
|
||||
})
|
||||
return err
|
||||
}); err != nil {
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
return &domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
Reference in new issue
Block a user