add linter, update swagger doc
This commit is contained in:
1 parent
c4a34c6cd2
commit
091f3ed06e
25 files changed
+1893
-115
No files matched your search
@@ -4,14 +4,15 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
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"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
"isp-system-service/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"
|
||||
)
|
||||
|
||||
var AccessList accessListController
|
||||
@@ -65,8 +66,10 @@ func (c accessListController) SetOne(request entity.AccessList) (*domain.CountRe
|
||||
_, err = redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
key := fmt.Sprintf("%d|%s", request.AppId, request.Method)
|
||||
_, err := p.Set(context.Background(), key, request.Value, 0).Result()
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
@@ -95,7 +98,7 @@ func (c accessListController) SetList(request domain.SetListRequest) ([]domain.M
|
||||
|
||||
oldAccessList := make([]entity.AccessList, 0)
|
||||
err = model.DbClient.RunInTransaction(func(repository model.AccessListRepository) error {
|
||||
if request.RemoveOld == true {
|
||||
if request.RemoveOld {
|
||||
oldAccessList, err = repository.DeleteById(request.AppId)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -142,6 +145,7 @@ func (c accessListController) SetList(request domain.SetListRequest) ([]domain.M
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
@@ -168,6 +172,7 @@ func (accessListController) convertAccessList(accessLists []entity.AccessList) [
|
||||
Value: access.Value,
|
||||
}
|
||||
}
|
||||
|
||||
return methodInfos
|
||||
}
|
||||
|
||||
@@ -179,5 +184,6 @@ func (accessListController) checkAppById(appId int32) error {
|
||||
if app == nil {
|
||||
return status.Errorf(codes.NotFound, "application '%d' not found", appId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -4,6 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
"isp-system-service/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"
|
||||
@@ -12,11 +18,6 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
"isp-system-service/redis"
|
||||
)
|
||||
|
||||
var Application applicationController
|
||||
@@ -38,6 +39,7 @@ func (c applicationController) GetApplications(list []int32) ([]*domain.AppWithT
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.enrichWithTokens(res...)
|
||||
}
|
||||
|
||||
@@ -56,6 +58,7 @@ func (c applicationController) GetApplicationsByServiceId(identity domain.Identi
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.enrichWithTokens(arr...)
|
||||
}
|
||||
|
||||
@@ -126,7 +129,6 @@ func (c applicationController) CreateUpdateApplication(app entity.Application) (
|
||||
}
|
||||
|
||||
return arr[0], nil
|
||||
|
||||
}
|
||||
|
||||
// GetApplicationById godoc
|
||||
@@ -154,6 +156,7 @@ func (c applicationController) GetApplicationById(identity domain.Identity) (*do
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return arr[0], nil
|
||||
}
|
||||
|
||||
@@ -180,7 +183,6 @@ func (applicationController) DeleteApplications(list []int32) (domain.DeleteResp
|
||||
_, 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 {
|
||||
|
||||
accessList, err := accessRep.GetByAppIdList(list)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -221,18 +223,21 @@ func (applicationController) DeleteApplications(list []int32) (domain.DeleteResp
|
||||
if len(redisDelRequest) > 0 {
|
||||
_, 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
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
}
|
||||
|
||||
return domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
|
||||
@@ -290,7 +295,8 @@ func (applicationController) GetSystemTree(md metadata.MD) ([]*domain.DomainWith
|
||||
|
||||
for _, app := range apps {
|
||||
s := servicesMap[app.ServiceId]
|
||||
s.Apps = append(s.Apps, &domain.SimpleApp{Id: app.Id,
|
||||
s.Apps = append(s.Apps, &domain.SimpleApp{
|
||||
Id: app.Id,
|
||||
Name: app.Name,
|
||||
Type: app.Type,
|
||||
Description: app.Description,
|
||||
@@ -324,5 +330,6 @@ func (applicationController) enrichWithTokens(apps ...entity.Application) ([]*do
|
||||
app := appMap[v.AppId]
|
||||
app.Tokens = append(app.Tokens, v)
|
||||
}
|
||||
|
||||
return enriched, nil
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
_ "github.com/integration-system/isp-lib/v2/structure"
|
||||
"github.com/integration-system/isp-lib/v2/utils"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
)
|
||||
|
||||
var Domain domainController
|
||||
@@ -30,6 +31,7 @@ func (domainController) GetDomainsBySystemId(md metadata.MD) ([]entity.Domain, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return model.DomainRep.GetDomainsBySystemId(int32(sysId))
|
||||
}
|
||||
|
||||
@@ -72,6 +74,7 @@ func (domainController) CreateUpdateDomain(domain entity.Domain, md metadata.MD)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &domain, nil
|
||||
}
|
||||
|
||||
@@ -91,6 +94,7 @@ func (domainController) CreateUpdateDomain(domain entity.Domain, md metadata.MD)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &domain, nil
|
||||
}
|
||||
|
||||
@@ -113,6 +117,7 @@ func (domainController) GetDomainById(identity domain.Identity) (*entity.Domain,
|
||||
if d == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Domain with id %d not found", identity.Id)
|
||||
}
|
||||
|
||||
return d, err
|
||||
}
|
||||
|
||||
@@ -136,5 +141,6 @@ func (domainController) DeleteDomains(list []int32) (domain.DeleteResponse, erro
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
}
|
||||
|
||||
return domain.DeleteResponse{Deleted: res}, nil
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var Service serviceController
|
||||
@@ -27,6 +28,7 @@ func (serviceController) GetService(list []int32) ([]entity.Service, error) {
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -79,6 +81,7 @@ func (serviceController) CreateUpdateService(service entity.Service) (*entity.Se
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &service, nil
|
||||
}
|
||||
|
||||
@@ -145,5 +148,6 @@ func (serviceController) DeleteService(list []int32) (domain.DeleteResponse, err
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
}
|
||||
|
||||
return domain.DeleteResponse{Deleted: res}, nil
|
||||
}
|
||||
@@ -3,12 +3,13 @@ package controller
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
_ "github.com/integration-system/isp-lib/v2/structure"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
_ "github.com/integration-system/isp-lib/v2/structure"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var System systemController
|
||||
@@ -30,6 +31,7 @@ func (systemController) GetSystems(list []int32) ([]entity.System, error) {
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -59,6 +61,7 @@ func (systemController) CreateUpdateSystem(system entity.System) (*entity.System
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &system, nil
|
||||
}
|
||||
|
||||
@@ -78,8 +81,8 @@ func (systemController) CreateUpdateSystem(system entity.System) (*entity.System
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &system, nil
|
||||
|
||||
return &system, nil
|
||||
}
|
||||
|
||||
// GetSystemById godoc
|
||||
@@ -101,6 +104,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, nil
|
||||
}
|
||||
|
||||
@@ -124,5 +128,6 @@ func (systemController) DeleteSystems(list []int32) (domain.DeleteResponse, erro
|
||||
if err != nil {
|
||||
return domain.DeleteResponse{}, err
|
||||
}
|
||||
|
||||
return domain.DeleteResponse{Deleted: res}, nil
|
||||
}
|
||||
@@ -66,6 +66,7 @@ func (c tokenController) CreateToken(req domain.CreateTokenRequest) (*domain.App
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.setIdentityMapForToken(tokenInfo, m)
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@@ -152,8 +153,10 @@ func (tokenController) SetIdentityMapForTokenV2(token string, expireTime int64,
|
||||
if expireTime > 0 {
|
||||
err = p.Expire(context.Background(), token, time.Duration(expireTime)*time.Millisecond).Err()
|
||||
}
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -208,6 +211,7 @@ func (c tokenController) revokeTokensForApp(identity domain.Identity) (*domain.D
|
||||
for i, t := range tokens {
|
||||
tokenIdList[i] = t.Token
|
||||
}
|
||||
|
||||
return c.revokeTokens(tokenIdList)
|
||||
}
|
||||
|
||||
@@ -233,12 +237,15 @@ func (tokenController) revokeTokens(tokens []string) (*domain.DeleteResponse, er
|
||||
|
||||
_, err = redis.Client.Get().UseDbTx(redisLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
_, err := p.Del(context.Background(), keys...).Result()
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
Reference in new issue
Block a user