Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48f0aaa40c | ||
|
|
09ec0b3f88 | ||
|
|
bef400d0d9 | ||
|
|
7108122102 | ||
|
|
8b8bc04fbf | ||
|
|
9de75322e5 | ||
|
|
51dfcdb9ba |
No files matched your search
@@ -3,14 +3,14 @@ package assembly
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/integration-system/isp-kit/app"
|
|
||||||
"github.com/integration-system/isp-kit/bootstrap"
|
|
||||||
"github.com/integration-system/isp-kit/cluster"
|
|
||||||
"github.com/integration-system/isp-kit/dbrx"
|
|
||||||
"github.com/integration-system/isp-kit/dbx"
|
|
||||||
"github.com/integration-system/isp-kit/grpc"
|
|
||||||
"github.com/integration-system/isp-kit/log"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/app"
|
||||||
|
"github.com/txix-open/isp-kit/bootstrap"
|
||||||
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
|
"github.com/txix-open/isp-kit/dbrx"
|
||||||
|
"github.com/txix-open/isp-kit/dbx"
|
||||||
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
"isp-system-service/conf"
|
"isp-system-service/conf"
|
||||||
"isp-system-service/migrations"
|
"isp-system-service/migrations"
|
||||||
)
|
)
|
||||||
@@ -23,7 +23,7 @@ type Assembly struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
||||||
dbCli := dbrx.New(dbx.WithMigration(boot.MigrationsDir))
|
dbCli := dbrx.New(dbx.WithMigrationRunner(boot.MigrationsDir, boot.App.Logger()))
|
||||||
server := grpc.NewServer()
|
server := grpc.NewServer()
|
||||||
|
|
||||||
return &Assembly{
|
return &Assembly{
|
||||||
|
|||||||
+19
-17
@@ -1,10 +1,10 @@
|
|||||||
package assembly
|
package assembly
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/integration-system/isp-kit/db"
|
"github.com/txix-open/isp-kit/db"
|
||||||
"github.com/integration-system/isp-kit/grpc/endpoint"
|
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||||
"github.com/integration-system/isp-kit/grpc/isp"
|
"github.com/txix-open/isp-kit/grpc/isp"
|
||||||
"github.com/integration-system/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"isp-system-service/conf"
|
"isp-system-service/conf"
|
||||||
"isp-system-service/controller"
|
"isp-system-service/controller"
|
||||||
"isp-system-service/repository"
|
"isp-system-service/repository"
|
||||||
@@ -36,34 +36,36 @@ func (l Locator) Handler(cfg conf.Remote) isp.BackendServiceServer {
|
|||||||
accessListRep := repository.NewAccessList(l.db)
|
accessListRep := repository.NewAccessList(l.db)
|
||||||
applicationRep := repository.NewApplication(l.db)
|
applicationRep := repository.NewApplication(l.db)
|
||||||
domainRep := repository.NewDomain(l.db)
|
domainRep := repository.NewDomain(l.db)
|
||||||
serviceRep := repository.NewService(l.db)
|
groupRep := repository.NewApplicationGroup(l.db)
|
||||||
tokenRep := repository.NewToken(l.db)
|
tokenRep := repository.NewToken(l.db)
|
||||||
|
|
||||||
secureService := secure.NewService(tokenRep, accessListRep)
|
secureApplicationGroup := secure.NewApplicationGroup(tokenRep, accessListRep)
|
||||||
accessListService := service.NewAccessList(txManager, accessListRep, applicationRep)
|
accessListService := service.NewAccessList(txManager, accessListRep, applicationRep)
|
||||||
applicationService := service.NewApplication(txManager, applicationRep, domainRep, serviceRep, tokenRep)
|
applicationService := service.NewApplication(txManager, applicationRep, domainRep, groupRep, tokenRep)
|
||||||
domainService := service.NewDomain(domainRep)
|
domainService := service.NewDomain(domainRep)
|
||||||
serviceService := service.NewService(domainRep, serviceRep)
|
applicationGroupService := service.NewApplicationGroup(domainRep, groupRep)
|
||||||
|
|
||||||
jwtService := service.NewTokenSource()
|
jwtService := service.NewTokenSource()
|
||||||
tokenService := service.NewToken(jwtService, applicationService, txManager,
|
tokenService := service.NewToken(jwtService, applicationService, txManager,
|
||||||
applicationRep, domainRep, serviceRep, tokenRep,
|
applicationRep, domainRep, groupRep, tokenRep,
|
||||||
)
|
)
|
||||||
|
|
||||||
secureController := controller.NewSecure(secureService)
|
secureController := controller.NewSecure(secureApplicationGroup)
|
||||||
accessListController := controller.NewAccessList(accessListService)
|
accessListController := controller.NewAccessList(accessListService)
|
||||||
applicationController := controller.NewApplication(applicationService)
|
applicationController := controller.NewApplication(applicationService)
|
||||||
domainController := controller.NewDomain(domainService)
|
domainController := controller.NewDomain(domainService)
|
||||||
serviceController := controller.NewService(serviceService)
|
serviceController := controller.NewService(applicationGroupService)
|
||||||
|
groupController := controller.NewApplicationGroup(applicationGroupService)
|
||||||
tokenController := controller.NewToken(tokenService)
|
tokenController := controller.NewToken(tokenService)
|
||||||
|
|
||||||
c := routes.Controllers{
|
c := routes.Controllers{
|
||||||
Secure: secureController,
|
Secure: secureController,
|
||||||
AccessList: accessListController,
|
AccessList: accessListController,
|
||||||
Domain: domainController,
|
Domain: domainController,
|
||||||
Service: serviceController,
|
Service: serviceController,
|
||||||
Application: applicationController,
|
ApplicationGroup: groupController,
|
||||||
Token: tokenController,
|
Application: applicationController,
|
||||||
|
Token: tokenController,
|
||||||
}
|
}
|
||||||
mapper := endpoint.DefaultWrapper(l.logger, endpoint.BodyLogger(l.logger))
|
mapper := endpoint.DefaultWrapper(l.logger, endpoint.BodyLogger(l.logger))
|
||||||
server := routes.Handler(mapper, c)
|
server := routes.Handler(mapper, c)
|
||||||
|
|||||||
+5
-5
@@ -3,14 +3,14 @@ package conf
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/integration-system/isp-kit/dbx"
|
"github.com/txix-open/isp-kit/dbx"
|
||||||
"github.com/integration-system/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"github.com/integration-system/isp-kit/rc/schema"
|
"github.com/txix-open/isp-kit/rc/schema"
|
||||||
"github.com/integration-system/jsonschema"
|
"github.com/txix-open/jsonschema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, t *jsonschema.Type) {
|
schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, t *jsonschema.Schema) {
|
||||||
t.Type = "string"
|
t.Type = "string"
|
||||||
t.Enum = []interface{}{"debug", "info", "error", "fatal"}
|
t.Enum = []interface{}{"debug", "info", "error", "fatal"}
|
||||||
})
|
})
|
||||||
|
|||||||
+14
-14
@@ -12,8 +12,8 @@ import (
|
|||||||
type ApplicationService interface {
|
type ApplicationService interface {
|
||||||
GetById(ctx context.Context, appId int) (*domain.ApplicationWithTokens, error)
|
GetById(ctx context.Context, appId int) (*domain.ApplicationWithTokens, error)
|
||||||
GetByIdList(ctx context.Context, idList []int) ([]*domain.ApplicationWithTokens, error)
|
GetByIdList(ctx context.Context, idList []int) ([]*domain.ApplicationWithTokens, error)
|
||||||
GetByServiceId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error)
|
GetByApplicationGroupId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error)
|
||||||
SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithService, error)
|
SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithApplicationGroup, error)
|
||||||
CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error)
|
CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error)
|
||||||
Delete(ctx context.Context, idList []int) (int, error)
|
Delete(ctx context.Context, idList []int) (int, error)
|
||||||
}
|
}
|
||||||
@@ -66,30 +66,30 @@ func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.Appl
|
|||||||
return c.service.GetByIdList(ctx, req)
|
return c.service.GetByIdList(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByServiceId godoc
|
// GetByApplicationGroupId godoc
|
||||||
// @Tags application
|
// @Tags application
|
||||||
// @Summary Получить список приложений по идентификатору сервиса
|
// @Summary Получить список приложений по идентификатору группы приложений
|
||||||
// @Description Возвращает список приложений по запрошенному идентификатору сервиса
|
// @Description Возвращает список приложений по запрошенному идентификатору группы приложений
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
// @Param body body domain.Identity true "Идентификатор группы приложений"
|
||||||
// @Success 200 {array} domain.ApplicationWithTokens
|
// @Success 200 {array} domain.ApplicationWithTokens
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /application/get_applications_by_service_id [POST]
|
// @Router /application/get_applications_by_service_id [POST]
|
||||||
func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) {
|
func (c Application) GetByApplicationGroupId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) {
|
||||||
return c.service.GetByServiceId(ctx, req.Id)
|
return c.service.GetByApplicationGroupId(ctx, req.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSystemTree godoc
|
// GetSystemTree godoc
|
||||||
// @Tags application
|
// @Tags application
|
||||||
// @Summary Метод получения системного дерева
|
// @Summary Метод получения системного дерева
|
||||||
// @Description Возвращает описание взаимосвязей сервисов и приложений
|
// @Description Возвращает описание взаимосвязей группы приложений и приложений
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} domain.DomainWithService
|
// @Success 200 {array} domain.DomainWithApplicationGroup
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /application/get_system_tree [POST]
|
// @Router /application/get_system_tree [POST]
|
||||||
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithService, error) {
|
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithApplicationGroup, error) {
|
||||||
return c.service.SystemTree(ctx, domain.DefaultSystemId)
|
return c.service.SystemTree(ctx, domain.DefaultSystemId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,12 +109,12 @@ func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithSer
|
|||||||
func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
||||||
result, err := c.service.CreateUpdate(ctx, req)
|
result, err := c.service.CreateUpdate(ctx, req)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrServiceNotFound):
|
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "service with id %d not found", req.ServiceId)
|
return nil, status.Errorf(codes.InvalidArgument, "application group with id %d not found", req.ApplicationGroupId)
|
||||||
case errors.Is(err, domain.ErrApplicationDuplicateName):
|
case errors.Is(err, domain.ErrApplicationDuplicateName):
|
||||||
return nil, status.Errorf(codes.AlreadyExists, "application with name %s already exists", req.Name)
|
return nil, status.Errorf(codes.AlreadyExists, "application with name %s already exists", req.Name)
|
||||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||||
return nil, status.Errorf(codes.NotFound, "Application with id %d not found", req.Id)
|
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.Id)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, err
|
return nil, err
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
"isp-system-service/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApplicationGroupService interface {
|
||||||
|
GetById(ctx context.Context, id int) (*domain.ApplicationGroup, error)
|
||||||
|
GetByIdList(ctx context.Context, idList []int) ([]domain.ApplicationGroup, error)
|
||||||
|
CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error)
|
||||||
|
Delete(ctx context.Context, idList []int) (int, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApplicationGroup struct {
|
||||||
|
service ApplicationGroupService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApplicationGroup(service ApplicationGroupService) ApplicationGroup {
|
||||||
|
return ApplicationGroup{
|
||||||
|
service: service,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetById godoc
|
||||||
|
// @Tags application_group
|
||||||
|
// @Summary Получить группу приложений по идентификатору
|
||||||
|
// @Description Возвращает описание группы приложений по ее идентификатору
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body domain.Identity true "Идентификатор группы приложений"
|
||||||
|
// @Success 200 {object} domain.ApplicationGroup
|
||||||
|
// @Failure 404 {object} domain.GrpcError
|
||||||
|
// @Failure 500 {object} domain.GrpcError
|
||||||
|
// @Router /application_group/get_group_by_id [POST]
|
||||||
|
func (c ApplicationGroup) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationGroup, error) {
|
||||||
|
result, err := c.service.GetById(ctx, req.Id)
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||||
|
return nil, status.Errorf(codes.NotFound, "application group with id %d not found", req.Id)
|
||||||
|
case err != nil:
|
||||||
|
return nil, err
|
||||||
|
default:
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get godoc
|
||||||
|
// @Tags application_group
|
||||||
|
// @Summary Получить список группы приложений
|
||||||
|
// @Description Возвращает список групп приложений по их идентификаторам
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body []integer false "Массив идентификаторов групп приложений"
|
||||||
|
// @Success 200 {array} domain.ApplicationGroup
|
||||||
|
// @Failure 500 {object} domain.GrpcError
|
||||||
|
// @Router /application_group/get_group [POST]
|
||||||
|
func (c ApplicationGroup) Get(ctx context.Context, req []int) ([]domain.ApplicationGroup, error) {
|
||||||
|
return c.service.GetByIdList(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateUpdate godoc
|
||||||
|
// @Tags application_group
|
||||||
|
// @Summary Создать/обновить группу приложений
|
||||||
|
// @Description Если группы приложений с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body domain.ApplicationGroupCreateUpdateRequest true "Объект группы приложений"
|
||||||
|
// @Success 200 {object} domain.ApplicationGroup
|
||||||
|
// @Failure 400 {object} domain.GrpcError
|
||||||
|
// @Failure 404 {object} domain.GrpcError
|
||||||
|
// @Failure 409 {object} domain.GrpcError
|
||||||
|
// @Failure 500 {object} domain.GrpcError
|
||||||
|
// @Router /application_group/create_update_group [POST]
|
||||||
|
func (c ApplicationGroup) CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error) {
|
||||||
|
req.DomainId = 1 // Хардкодом проставляем domainId = 1
|
||||||
|
|
||||||
|
result, err := c.service.CreateUpdate(ctx, req)
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, domain.ErrDomainNotFound):
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "domain with id %d not found", req.DomainId)
|
||||||
|
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||||
|
return nil, status.Errorf(codes.NotFound, "application group with id %d not found", req.Id)
|
||||||
|
case errors.Is(err, domain.ErrApplicationGroupDuplicateName):
|
||||||
|
return nil, status.Errorf(codes.AlreadyExists, "application group with name %s already exists", req.Name)
|
||||||
|
case err != nil:
|
||||||
|
return nil, err
|
||||||
|
default:
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete godoc
|
||||||
|
// @Tags application_group
|
||||||
|
// @Summary Удалить группы приложений
|
||||||
|
// @Description Удаляет группы приложений по списку их идентификаторов, возвращает количество удаленных групп
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body []integer true "Массив идентификаторов групп приложений"
|
||||||
|
// @Success 200 {object} domain.DeleteResponse
|
||||||
|
// @Failure 400 {object} domain.GrpcError
|
||||||
|
// @Failure 500 {object} domain.GrpcError
|
||||||
|
// @Router /application_group/delete_group [POST]
|
||||||
|
func (c ApplicationGroup) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||||
|
if len(req) == 0 {
|
||||||
|
return nil, status.Error(codes.InvalidArgument, "at least one id are required")
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := c.service.Delete(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &domain.DeleteResponse{
|
||||||
|
Deleted: result,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
+11
-11
@@ -10,10 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ServiceService interface {
|
type ServiceService interface {
|
||||||
GetById(ctx context.Context, id int) (*domain.Service, error)
|
GetById(ctx context.Context, id int) (*domain.ApplicationGroup, error)
|
||||||
GetByIdList(ctx context.Context, idList []int) ([]domain.Service, error)
|
GetByIdList(ctx context.Context, idList []int) ([]domain.ApplicationGroup, error)
|
||||||
GetByDomainId(ctx context.Context, domainId int) ([]domain.Service, error)
|
GetByDomainId(ctx context.Context, domainId int) ([]domain.ApplicationGroup, error)
|
||||||
CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error)
|
CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error)
|
||||||
Delete(ctx context.Context, idList []int) (int, error)
|
Delete(ctx context.Context, idList []int) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,10 +38,10 @@ func NewService(service ServiceService) Service {
|
|||||||
// @Failure 404 {object} domain.GrpcError
|
// @Failure 404 {object} domain.GrpcError
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /service/get_service_by_id [POST]
|
// @Router /service/get_service_by_id [POST]
|
||||||
func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Service, error) {
|
func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationGroup, error) {
|
||||||
result, err := c.service.GetById(ctx, req.Id)
|
result, err := c.service.GetById(ctx, req.Id)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrServiceNotFound):
|
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||||
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -60,7 +60,7 @@ func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Serv
|
|||||||
// @Success 200 {array} domain.Service
|
// @Success 200 {array} domain.Service
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /service/get_service [POST]
|
// @Router /service/get_service [POST]
|
||||||
func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
func (c Service) Get(ctx context.Context, req []int) ([]domain.ApplicationGroup, error) {
|
||||||
return c.service.GetByIdList(ctx, req)
|
return c.service.GetByIdList(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
|||||||
// @Success 200 {array} domain.Service
|
// @Success 200 {array} domain.Service
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /service/get_services_by_domain_id [POST]
|
// @Router /service/get_services_by_domain_id [POST]
|
||||||
func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.Service, error) {
|
func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.ApplicationGroup, error) {
|
||||||
return c.service.GetByDomainId(ctx, req.Id)
|
return c.service.GetByDomainId(ctx, req.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,14 +91,14 @@ func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]doma
|
|||||||
// @Failure 409 {object} domain.GrpcError
|
// @Failure 409 {object} domain.GrpcError
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /service/create_update_service [POST]
|
// @Router /service/create_update_service [POST]
|
||||||
func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) {
|
func (c Service) CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error) {
|
||||||
result, err := c.service.CreateUpdate(ctx, req)
|
result, err := c.service.CreateUpdate(ctx, req)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrDomainNotFound):
|
case errors.Is(err, domain.ErrDomainNotFound):
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "domain with id %d not found", req.DomainId)
|
return nil, status.Errorf(codes.InvalidArgument, "domain with id %d not found", req.DomainId)
|
||||||
case errors.Is(err, domain.ErrServiceNotFound):
|
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||||
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
||||||
case errors.Is(err, domain.ErrServiceDuplicateName):
|
case errors.Is(err, domain.ErrApplicationGroupDuplicateName):
|
||||||
return nil, status.Errorf(codes.AlreadyExists, "service with name %s already exists", req.Name)
|
return nil, status.Errorf(codes.AlreadyExists, "service with name %s already exists", req.Name)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
+2
-2
@@ -55,8 +55,8 @@ func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||||
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.AppId)
|
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.AppId)
|
||||||
case errors.Is(err, domain.ErrServiceNotFound):
|
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||||
return nil, status.Errorf(codes.NotFound, "service for app_id id %d not found", req.AppId)
|
return nil, status.Errorf(codes.NotFound, "application group for app_id id %d not found", req.AppId)
|
||||||
case errors.Is(err, domain.ErrDomainNotFound):
|
case errors.Is(err, domain.ErrDomainNotFound):
|
||||||
return nil, status.Errorf(codes.NotFound, "domain for app_id %d not found", req.AppId)
|
return nil, status.Errorf(codes.NotFound, "domain for app_id %d not found", req.AppId)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
|
|||||||
-1563
File diff suppressed because it is too large.
Load diff
+12
-12
@@ -5,21 +5,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
ServiceId int
|
ApplicationGroupId int
|
||||||
Type string
|
Type string
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApplicationCreateUpdateRequest struct {
|
type ApplicationCreateUpdateRequest struct {
|
||||||
Id int
|
Id int
|
||||||
Name string `valid:"required~Required"`
|
Name string `valid:"required~Required"`
|
||||||
Description string
|
Description string
|
||||||
ServiceId int `valid:"required~Required"`
|
ApplicationGroupId int `valid:"required~Required"`
|
||||||
Type string `valid:"required~Required,in(SYSTEM|MOBILE)"`
|
Type string `valid:"required~Required,in(SYSTEM|MOBILE)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApplicationWithTokens struct {
|
type ApplicationWithTokens struct {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type ApplicationGroup struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
@@ -13,14 +13,14 @@ type Service struct {
|
|||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceCreateUpdateRequest struct {
|
type ApplicationGroupCreateUpdateRequest struct {
|
||||||
Id int
|
Id int
|
||||||
Name string `valid:"required~Required"`
|
Name string `valid:"required~Required"`
|
||||||
Description string
|
Description string
|
||||||
DomainId int `valid:"required~Required"`
|
DomainId int `valid:"required~Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceWithApps struct {
|
type ApplicationGroupWithApps struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
+5
-5
@@ -19,9 +19,9 @@ type Domain struct {
|
|||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type DomainWithService struct {
|
type DomainWithApplicationGroup struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Services []*ServiceWithApps
|
ApplicationGroup []*ApplicationGroupWithApps
|
||||||
}
|
}
|
||||||
+2
-2
@@ -8,8 +8,8 @@ var (
|
|||||||
ErrDomainNotFound = errors.New("domain not found")
|
ErrDomainNotFound = errors.New("domain not found")
|
||||||
ErrDomainDuplicateName = errors.New("domain name already exist")
|
ErrDomainDuplicateName = errors.New("domain name already exist")
|
||||||
|
|
||||||
ErrServiceNotFound = errors.New("service not found")
|
ErrApplicationGroupNotFound = errors.New("application group not found")
|
||||||
ErrServiceDuplicateName = errors.New("service name already exist")
|
ErrApplicationGroupDuplicateName = errors.New("application group name already exist")
|
||||||
|
|
||||||
ErrSystemNotFound = errors.New("system not found")
|
ErrSystemNotFound = errors.New("system not found")
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -11,10 +11,10 @@ type AuthenticateResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AuthData struct {
|
type AuthData struct {
|
||||||
SystemId int
|
SystemId int
|
||||||
DomainId int
|
DomainId int
|
||||||
ServiceId int
|
ApplicationGroupId int
|
||||||
ApplicationId int
|
ApplicationId int
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthorizeRequest struct {
|
type AuthorizeRequest struct {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Description *string
|
Description *string
|
||||||
ServiceId int
|
ApplicationGroupId int
|
||||||
Type string
|
Type string
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type ApplicationGroup struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Description *string
|
Description *string
|
||||||
+6
-6
@@ -12,10 +12,10 @@ type Token struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AuthData struct {
|
type AuthData struct {
|
||||||
SystemId int
|
SystemId int
|
||||||
DomainId int
|
DomainId int
|
||||||
ServiceId int
|
ApplicationGroupIdId int
|
||||||
AppId int
|
AppId int
|
||||||
ExpireTime int
|
ExpireTime int
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
@@ -1,86 +1,75 @@
|
|||||||
module isp-system-service
|
module isp-system-service
|
||||||
|
|
||||||
go 1.17
|
go 1.22
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/squirrel v1.5.3
|
github.com/Masterminds/squirrel v1.5.4
|
||||||
github.com/integration-system/isp-kit v1.10.4
|
|
||||||
github.com/integration-system/isp-lib/v2 v2.10.0
|
|
||||||
github.com/integration-system/jsonschema v1.0.1
|
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/pressly/goose v2.7.0+incompatible
|
github.com/pressly/goose v2.7.0+incompatible
|
||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.9.0
|
||||||
google.golang.org/grpc v1.48.0
|
github.com/txix-open/isp-kit v1.31.4
|
||||||
|
github.com/txix-open/jsonschema v1.2.0
|
||||||
|
google.golang.org/grpc v1.64.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.1.0 // indirect
|
github.com/bahlo/generic-list-go v0.2.0 // indirect
|
||||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
|
||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
|
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/buger/jsonparser v1.1.1 // indirect
|
||||||
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
github.com/getsentry/sentry-go v0.27.0 // indirect
|
||||||
github.com/go-openapi/jsonreference v0.20.0 // indirect
|
github.com/go-logr/logr v1.4.1 // indirect
|
||||||
github.com/go-openapi/spec v0.20.5 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-openapi/swag v0.21.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/iancoleman/strcase v0.3.0 // indirect
|
||||||
github.com/iancoleman/strcase v0.2.0 // indirect
|
|
||||||
github.com/integration-system/bellows v1.0.1 // indirect
|
|
||||||
github.com/integration-system/isp-etp-go/v2 v2.1.3 // indirect
|
|
||||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
|
||||||
github.com/jackc/pgconn v1.12.1 // indirect
|
|
||||||
github.com/jackc/pgio v1.0.0 // indirect
|
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
github.com/jackc/pgx/v5 v5.5.5 // indirect
|
||||||
github.com/jackc/pgtype v1.11.0 // indirect
|
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||||
github.com/jackc/pgx/v4 v4.16.1 // indirect
|
github.com/jmoiron/sqlx v1.4.0 // indirect
|
||||||
github.com/jmoiron/sqlx v1.3.5 // indirect
|
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/compress v1.15.8 // indirect
|
|
||||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
github.com/mfridman/interpolate v0.0.2 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
|
||||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
|
||||||
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/prometheus/client_golang v1.12.2 // indirect
|
github.com/pressly/goose/v3 v3.20.0 // indirect
|
||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/prometheus/client_golang v1.19.0 // indirect
|
||||||
github.com/prometheus/common v0.36.0 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/procfs v0.7.3 // indirect
|
github.com/prometheus/common v0.53.0 // indirect
|
||||||
github.com/spf13/afero v1.8.2 // indirect
|
github.com/prometheus/procfs v0.14.0 // indirect
|
||||||
github.com/spf13/cast v1.5.0 // indirect
|
github.com/sethvargo/go-retry v0.2.4 // indirect
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
github.com/txix-open/bellows v1.2.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/txix-open/etp/v3 v3.0.0 // indirect
|
||||||
github.com/spf13/viper v1.12.0 // indirect
|
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 // indirect
|
||||||
github.com/subosito/gotenv v1.4.0 // indirect
|
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||||
github.com/swaggo/swag v1.7.0 // indirect
|
go.opentelemetry.io/otel v1.26.0 // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.26.0 // indirect
|
||||||
go.uber.org/multierr v1.8.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.26.0 // indirect
|
||||||
go.uber.org/zap v1.21.0 // indirect
|
go.opentelemetry.io/otel/metric v1.26.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
go.opentelemetry.io/otel/sdk v1.26.0 // indirect
|
||||||
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
|
go.opentelemetry.io/otel/trace v1.26.0 // indirect
|
||||||
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
|
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
golang.org/x/tools v0.1.10 // indirect
|
golang.org/x/crypto v0.22.0 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20220713161829-9c7dac0a6568 // indirect
|
golang.org/x/net v0.24.0 // indirect
|
||||||
google.golang.org/protobuf v1.28.0 // indirect
|
golang.org/x/sync v0.7.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.66.6 // indirect
|
golang.org/x/sys v0.19.0 // indirect
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
|
||||||
|
google.golang.org/protobuf v1.33.0 // indirect
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
nhooyr.io/websocket v1.8.7 // indirect
|
nhooyr.io/websocket v1.8.11 // indirect
|
||||||
)
|
)
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/integration-system/isp-kit/bootstrap"
|
"github.com/txix-open/isp-kit/bootstrap"
|
||||||
"github.com/integration-system/isp-kit/shutdown"
|
"github.com/txix-open/isp-kit/shutdown"
|
||||||
"isp-system-service/assembly"
|
"isp-system-service/assembly"
|
||||||
"isp-system-service/conf"
|
"isp-system-service/conf"
|
||||||
"isp-system-service/routes"
|
"isp-system-service/routes"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -13,10 +13,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
insertDomain = "INSERT INTO %s.domain (id, name, description, system_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
insertDomain = "INSERT INTO %s.domain (id, name, description, system_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
||||||
insertService = "INSERT INTO %s.service (id, name, description, domain_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
insertApplicationGroup = "INSERT INTO %s.application_group (id, name, description, domain_id) VALUES (%d, '%s', '%s', %d) RETURNING id;"
|
||||||
insertApp = "INSERT INTO %s.application (id, name, description, service_id, type) VALUES (%d, '%s', '%s', %d, '%s') RETURNING id;"
|
insertApp = "INSERT INTO %s.application (id, name, description, application_group_id, type) VALUES (%d, '%s', '%s', %d, '%s') RETURNING id;"
|
||||||
insertToken = "INSERT INTO %s.token (token, app_id, expire_time) VALUES ('%s', %d, %d);"
|
insertToken = "INSERT INTO %s.token (token, app_id, expire_time) VALUES ('%s', %d, %d);"
|
||||||
|
|
||||||
setSeqQuery = "SELECT setval('%s.%s_id_seq' :: regclass, %d);"
|
setSeqQuery = "SELECT setval('%s.%s_id_seq' :: regclass, %d);"
|
||||||
|
|
||||||
@@ -35,9 +35,9 @@ type initializeMigration struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type identity struct {
|
type identity struct {
|
||||||
domainId int
|
domainId int
|
||||||
appId int
|
appId int
|
||||||
serviceId int
|
applicationGroupId int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *initializeMigration) SetParams(migrationDir string, schema string) {
|
func (i *initializeMigration) SetParams(migrationDir string, schema string) {
|
||||||
@@ -47,19 +47,19 @@ func (i *initializeMigration) SetParams(migrationDir string, schema string) {
|
|||||||
|
|
||||||
func (i *initializeMigration) Up(tx *sql.Tx) error {
|
func (i *initializeMigration) Up(tx *sql.Tx) error {
|
||||||
path := filepath.Join(i.migrationDir, initFile)
|
path := filepath.Join(i.migrationDir, initFile)
|
||||||
bytes, err := ioutil.ReadFile(path)
|
bytes, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "read file")
|
return errors.WithMessage(err, "read file")
|
||||||
}
|
}
|
||||||
|
|
||||||
list := make([]domain.DomainWithService, 0)
|
list := make([]domain.DomainWithApplicationGroup, 0)
|
||||||
err = json.Unmarshal(bytes, &list)
|
err = json.Unmarshal(bytes, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "json unmarshal")
|
return errors.WithMessage(err, "json unmarshal")
|
||||||
}
|
}
|
||||||
|
|
||||||
lastDomainId := 0
|
lastDomainId := 0
|
||||||
lastServiceId := 0
|
lastApplicationGroupId := 0
|
||||||
lastAppId := 0
|
lastAppId := 0
|
||||||
for _, domainInfo := range list {
|
for _, domainInfo := range list {
|
||||||
last, err := i.insert(tx, domainInfo)
|
last, err := i.insert(tx, domainInfo)
|
||||||
@@ -69,8 +69,8 @@ func (i *initializeMigration) Up(tx *sql.Tx) error {
|
|||||||
if last.domainId > lastDomainId {
|
if last.domainId > lastDomainId {
|
||||||
lastDomainId = last.domainId
|
lastDomainId = last.domainId
|
||||||
}
|
}
|
||||||
if last.serviceId > lastServiceId {
|
if last.applicationGroupId > lastApplicationGroupId {
|
||||||
lastServiceId = last.serviceId
|
lastApplicationGroupId = last.applicationGroupId
|
||||||
}
|
}
|
||||||
if last.appId > lastAppId {
|
if last.appId > lastAppId {
|
||||||
lastAppId = last.appId
|
lastAppId = last.appId
|
||||||
@@ -82,9 +82,9 @@ func (i *initializeMigration) Up(tx *sql.Tx) error {
|
|||||||
return errors.WithMessage(err, "set domain")
|
return errors.WithMessage(err, "set domain")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = i.setSeq(tx, "service", lastServiceId)
|
err = i.setSeq(tx, "application_group", lastApplicationGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "set service")
|
return errors.WithMessage(err, "set application group")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = i.setSeq(tx, "application", lastAppId)
|
err = i.setSeq(tx, "application", lastAppId)
|
||||||
@@ -99,22 +99,22 @@ func (i *initializeMigration) Down(tx *sql.Tx) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithService) (*identity, error) {
|
func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithApplicationGroup) (*identity, error) {
|
||||||
domainId, err := i.insertNode(tx, insertDomain, true, i.schema, domainInfo.Id, domainInfo.Name, domainInfo.Description, 1)
|
domainId, err := i.insertNode(tx, insertDomain, true, i.schema, domainInfo.Id, domainInfo.Name, domainInfo.Description, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "insert domain")
|
return nil, errors.WithMessage(err, "insert domain")
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceId := 0
|
applicationGroupId := 0
|
||||||
appId := 0
|
appId := 0
|
||||||
for _, service := range domainInfo.Services {
|
for _, applicationGroup := range domainInfo.ApplicationGroup {
|
||||||
serviceId, err = i.insertNode(tx, insertService, true, i.schema, service.Id, service.Name, service.Description, domainId)
|
applicationGroupId, err = i.insertNode(tx, insertApplicationGroup, true, i.schema, applicationGroup.Id, applicationGroup.Name, applicationGroup.Description, domainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "insert service")
|
return nil, errors.WithMessage(err, "insert application group")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, app := range service.Apps {
|
for _, app := range applicationGroup.Apps {
|
||||||
appId, err = i.insertNode(tx, insertApp, true, i.schema, app.Id, app.Name, app.Description, serviceId, app.Type)
|
appId, err = i.insertNode(tx, insertApp, true, i.schema, app.Id, app.Name, app.Description, applicationGroupId, app.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "insert application")
|
return nil, errors.WithMessage(err, "insert application")
|
||||||
}
|
}
|
||||||
@@ -129,9 +129,9 @@ func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &identity{
|
return &identity{
|
||||||
domainId: domainId,
|
domainId: domainId,
|
||||||
appId: appId,
|
appId: appId,
|
||||||
serviceId: serviceId,
|
applicationGroupId: applicationGroupId,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE service RENAME TO application_group;
|
||||||
|
|
||||||
|
ALTER TABLE application RENAME COLUMN service_id TO application_group_id;
|
||||||
|
|
||||||
|
ALTER TABLE application RENAME CONSTRAINT UQ_name_service_id TO UQ_name_application_group_id;
|
||||||
|
|
||||||
|
ALTER TABLE application RENAME CONSTRAINT FK_service_id__domain_id TO FK_application_group_id__domain_id;
|
||||||
|
|
||||||
|
ALTER TRIGGER modify_service ON application_group RENAME TO modify_application_group;
|
||||||
|
-- +goose Down
|
||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/integration-system/isp-kit/db"
|
|
||||||
"github.com/integration-system/isp-kit/db/query"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/db"
|
||||||
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"isp-system-service/domain"
|
"isp-system-service/domain"
|
||||||
"isp-system-service/entity"
|
"isp-system-service/entity"
|
||||||
)
|
)
|
||||||
|
|||||||
+16
-16
@@ -5,9 +5,9 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/integration-system/isp-kit/db"
|
|
||||||
"github.com/integration-system/isp-kit/db/query"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/db"
|
||||||
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"isp-system-service/domain"
|
"isp-system-service/domain"
|
||||||
"isp-system-service/entity"
|
"isp-system-service/entity"
|
||||||
)
|
)
|
||||||
@@ -24,7 +24,7 @@ func NewApplication(db db.DB) Application {
|
|||||||
|
|
||||||
func (r Application) GetApplicationById(ctx context.Context, id int) (*entity.Application, error) {
|
func (r Application) GetApplicationById(ctx context.Context, id int) (*entity.Application, error) {
|
||||||
q := `
|
q := `
|
||||||
SELECT id, name, description, service_id, type, created_at, updated_at
|
SELECT id, name, description, application_group_id, type, created_at, updated_at
|
||||||
FROM application
|
FROM application
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`
|
`
|
||||||
@@ -42,7 +42,7 @@ func (r Application) GetApplicationById(ctx context.Context, id int) (*entity.Ap
|
|||||||
|
|
||||||
func (r Application) GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error) {
|
func (r Application) GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error) {
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Select("id", "name", "description", "service_id", "type", "created_at", "updated_at").
|
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||||
From("application").
|
From("application").
|
||||||
Where(squirrel.Eq{"id": idList}).
|
Where(squirrel.Eq{"id": idList}).
|
||||||
OrderBy("created_at DESC").
|
OrderBy("created_at DESC").
|
||||||
@@ -60,11 +60,11 @@ func (r Application) GetApplicationByIdList(ctx context.Context, idList []int) (
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Application) GetApplicationByServiceIdList(ctx context.Context, serviceIdList []int) ([]entity.Application, error) {
|
func (r Application) GetApplicationByApplicationGroupIdList(ctx context.Context, applicationGroupIdList []int) ([]entity.Application, error) {
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Select("id", "name", "description", "service_id", "type", "created_at", "updated_at").
|
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||||
From("application").
|
From("application").
|
||||||
Where(squirrel.Eq{"service_id": serviceIdList}).
|
Where(squirrel.Eq{"application_group_id": applicationGroupIdList}).
|
||||||
OrderBy("created_at DESC").
|
OrderBy("created_at DESC").
|
||||||
ToSql()
|
ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -80,14 +80,14 @@ func (r Application) GetApplicationByServiceIdList(ctx context.Context, serviceI
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Application) GetApplicationByNameAndServiceId(ctx context.Context, name string, serviceId int) (*entity.Application, error) {
|
func (r Application) GetApplicationByNameAndApplicationGroupId(ctx context.Context, name string, applicationGroupId int) (*entity.Application, error) {
|
||||||
q := `
|
q := `
|
||||||
SELECT id, name, description, service_id, type, created_at, updated_at
|
SELECT id, name, description, application_group_id, type, created_at, updated_at
|
||||||
FROM application
|
FROM application
|
||||||
WHERE name = $1 AND service_id = $2
|
WHERE name = $1 AND application_group_id = $2
|
||||||
`
|
`
|
||||||
result := entity.Application{}
|
result := entity.Application{}
|
||||||
err := r.db.SelectRow(ctx, &result, q, name, serviceId)
|
err := r.db.SelectRow(ctx, &result, q, name, applicationGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -98,16 +98,16 @@ func (r Application) GetApplicationByNameAndServiceId(ctx context.Context, name
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Application) CreateApplication(ctx context.Context, name string, desc string, serviceId int, appType string) (
|
func (r Application) CreateApplication(ctx context.Context, name string, desc string, applicationGroupId int, appType string) (
|
||||||
*entity.Application, error) {
|
*entity.Application, error) {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO application
|
INSERT INTO application
|
||||||
(name, description, service_id, type)
|
(name, description, application_group_id, type)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
RETURNING id, name, description, service_id, type, created_at, updated_at
|
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||||
`
|
`
|
||||||
result := entity.Application{}
|
result := entity.Application{}
|
||||||
err := r.db.SelectRow(ctx, &result, q, name, desc, serviceId, appType)
|
err := r.db.SelectRow(ctx, &result, q, name, desc, applicationGroupId, appType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "select row db")
|
return nil, errors.WithMessagef(err, "select row db")
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ func (r Application) UpdateApplication(ctx context.Context, id int, name string,
|
|||||||
SET name = $2,
|
SET name = $2,
|
||||||
description = $3
|
description = $3
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
RETURNING id, name, description, service_id, type, created_at, updated_at
|
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||||
`
|
`
|
||||||
result := entity.Application{}
|
result := entity.Application{}
|
||||||
err := r.db.SelectRow(ctx, &result, q, id, name, description)
|
err := r.db.SelectRow(ctx, &result, q, id, name, description)
|
||||||
|
|||||||
@@ -5,34 +5,34 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/integration-system/isp-kit/db"
|
|
||||||
"github.com/integration-system/isp-kit/db/query"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/db"
|
||||||
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"isp-system-service/domain"
|
"isp-system-service/domain"
|
||||||
"isp-system-service/entity"
|
"isp-system-service/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type ApplicationGroup struct {
|
||||||
db db.DB
|
db db.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(db db.DB) Service {
|
func NewApplicationGroup(db db.DB) ApplicationGroup {
|
||||||
return Service{
|
return ApplicationGroup{
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Service) GetServiceById(ctx context.Context, id int) (*entity.Service, error) {
|
func (r ApplicationGroup) GetApplicationGroupById(ctx context.Context, id int) (*entity.ApplicationGroup, error) {
|
||||||
q := `
|
q := `
|
||||||
SELECT id, name, description, domain_id, created_at, updated_at
|
SELECT id, name, description, domain_id, created_at, updated_at
|
||||||
FROM service
|
FROM application_group
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`
|
`
|
||||||
result := entity.Service{}
|
result := entity.ApplicationGroup{}
|
||||||
err := r.db.SelectRow(ctx, &result, q, id)
|
err := r.db.SelectRow(ctx, &result, q, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, domain.ErrServiceNotFound
|
return nil, domain.ErrApplicationGroupNotFound
|
||||||
}
|
}
|
||||||
return nil, errors.WithMessage(err, "select row db")
|
return nil, errors.WithMessage(err, "select row db")
|
||||||
}
|
}
|
||||||
@@ -40,10 +40,10 @@ func (r Service) GetServiceById(ctx context.Context, id int) (*entity.Service, e
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Service) GetServiceByIdList(ctx context.Context, idList []int) ([]entity.Service, error) {
|
func (r ApplicationGroup) GetApplicationGroupByIdList(ctx context.Context, idList []int) ([]entity.ApplicationGroup, error) {
|
||||||
q, arg, err := query.New().
|
q, arg, err := query.New().
|
||||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||||
From("service").
|
From("application_group").
|
||||||
Where(squirrel.Eq{"id": idList}).
|
Where(squirrel.Eq{"id": idList}).
|
||||||
OrderBy("created_at DESC").
|
OrderBy("created_at DESC").
|
||||||
ToSql()
|
ToSql()
|
||||||
@@ -51,7 +51,7 @@ func (r Service) GetServiceByIdList(ctx context.Context, idList []int) ([]entity
|
|||||||
return nil, errors.WithMessage(err, "build query")
|
return nil, errors.WithMessage(err, "build query")
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]entity.Service, 0)
|
result := make([]entity.ApplicationGroup, 0)
|
||||||
err = r.db.Select(ctx, &result, q, arg...)
|
err = r.db.Select(ctx, &result, q, arg...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "select db")
|
return nil, errors.WithMessagef(err, "select db")
|
||||||
@@ -60,10 +60,10 @@ func (r Service) GetServiceByIdList(ctx context.Context, idList []int) ([]entity
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Service) GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error) {
|
func (r ApplicationGroup) GetApplicationGroupByDomainId(ctx context.Context, domainIdList []int) ([]entity.ApplicationGroup, error) {
|
||||||
q, arg, err := query.New().
|
q, arg, err := query.New().
|
||||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||||
From("service").
|
From("application_group").
|
||||||
Where(squirrel.Eq{"domain_id": domainIdList}).
|
Where(squirrel.Eq{"domain_id": domainIdList}).
|
||||||
OrderBy("created_at DESC").
|
OrderBy("created_at DESC").
|
||||||
ToSql()
|
ToSql()
|
||||||
@@ -71,7 +71,7 @@ func (r Service) GetServiceByDomainId(ctx context.Context, domainIdList []int) (
|
|||||||
return nil, errors.WithMessage(err, "build query")
|
return nil, errors.WithMessage(err, "build query")
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]entity.Service, 0)
|
result := make([]entity.ApplicationGroup, 0)
|
||||||
err = r.db.Select(ctx, &result, q, arg...)
|
err = r.db.Select(ctx, &result, q, arg...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "select db")
|
return nil, errors.WithMessagef(err, "select db")
|
||||||
@@ -80,17 +80,17 @@ func (r Service) GetServiceByDomainId(ctx context.Context, domainIdList []int) (
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Service) GetServiceByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.Service, error) {
|
func (r ApplicationGroup) GetSApplicationGroupByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.ApplicationGroup, error) {
|
||||||
q := `
|
q := `
|
||||||
SELECT id, name, description, domain_id, created_at, updated_at
|
SELECT id, name, description, domain_id, created_at, updated_at
|
||||||
FROM service
|
FROM application_group
|
||||||
WHERE name = $1 AND domain_id = $2
|
WHERE name = $1 AND domain_id = $2
|
||||||
`
|
`
|
||||||
result := entity.Service{}
|
result := entity.ApplicationGroup{}
|
||||||
err := r.db.SelectRow(ctx, &result, q, name, domainId)
|
err := r.db.SelectRow(ctx, &result, q, name, domainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, domain.ErrServiceNotFound
|
return nil, domain.ErrApplicationGroupNotFound
|
||||||
}
|
}
|
||||||
return nil, errors.WithMessage(err, "select db")
|
return nil, errors.WithMessage(err, "select db")
|
||||||
}
|
}
|
||||||
@@ -98,14 +98,14 @@ func (r Service) GetServiceByNameAndDomainId(ctx context.Context, name string, d
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Service) CreateService(ctx context.Context, name string, desc string, domainId int) (*entity.Service, error) {
|
func (r ApplicationGroup) CreateApplicationGroup(ctx context.Context, name string, desc string, domainId int) (*entity.ApplicationGroup, error) {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO service
|
INSERT INTO application_group
|
||||||
(name, description, domain_id)
|
(name, description, domain_id)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||||
`
|
`
|
||||||
result := entity.Service{}
|
result := entity.ApplicationGroup{}
|
||||||
err := r.db.SelectRow(ctx, &result, q, name, desc, domainId)
|
err := r.db.SelectRow(ctx, &result, q, name, desc, domainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "select row db")
|
return nil, errors.WithMessage(err, "select row db")
|
||||||
@@ -114,18 +114,18 @@ func (r Service) CreateService(ctx context.Context, name string, desc string, do
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Service) UpdateService(ctx context.Context, id int, name string, description string) (*entity.Service, error) {
|
func (r ApplicationGroup) UpdateApplicationGroup(ctx context.Context, id int, name string, description string) (*entity.ApplicationGroup, error) {
|
||||||
q := `
|
q := `
|
||||||
UPDATE service
|
UPDATE application_group
|
||||||
SET name = $1, description = $2
|
SET name = $1, description = $2
|
||||||
WHERE id = $3
|
WHERE id = $3
|
||||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||||
`
|
`
|
||||||
result := entity.Service{}
|
result := entity.ApplicationGroup{}
|
||||||
err := r.db.SelectRow(ctx, &result, q, name, description, id)
|
err := r.db.SelectRow(ctx, &result, q, name, description, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, domain.ErrServiceNotFound
|
return nil, domain.ErrApplicationGroupNotFound
|
||||||
}
|
}
|
||||||
return nil, errors.WithMessage(err, "select row db")
|
return nil, errors.WithMessage(err, "select row db")
|
||||||
}
|
}
|
||||||
@@ -133,9 +133,9 @@ func (r Service) UpdateService(ctx context.Context, id int, name string, descrip
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Service) DeleteService(ctx context.Context, idList []int) (int, error) {
|
func (r ApplicationGroup) DeleteApplicationGroup(ctx context.Context, idList []int) (int, error) {
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Delete("service").
|
Delete("application_group").
|
||||||
Where(squirrel.Eq{"id": idList}).
|
Where(squirrel.Eq{"id": idList}).
|
||||||
ToSql()
|
ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/integration-system/isp-kit/db"
|
|
||||||
"github.com/integration-system/isp-kit/db/query"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/db"
|
||||||
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"isp-system-service/domain"
|
"isp-system-service/domain"
|
||||||
"isp-system-service/entity"
|
"isp-system-service/entity"
|
||||||
)
|
)
|
||||||
|
|||||||
+6
-6
@@ -5,9 +5,9 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/integration-system/isp-kit/db"
|
|
||||||
"github.com/integration-system/isp-kit/db/query"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/db"
|
||||||
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"isp-system-service/domain"
|
"isp-system-service/domain"
|
||||||
"isp-system-service/entity"
|
"isp-system-service/entity"
|
||||||
)
|
)
|
||||||
@@ -97,14 +97,14 @@ func (r Token) DeleteToken(ctx context.Context, tokens []string) (int, error) {
|
|||||||
|
|
||||||
func (r Token) AuthDataByToken(ctx context.Context, token string) (*entity.AuthData, error) {
|
func (r Token) AuthDataByToken(ctx context.Context, token string) (*entity.AuthData, error) {
|
||||||
q := `
|
q := `
|
||||||
SELECT system_id, domain_id, service_id, app_id, token.expire_time, token.created_at
|
SELECT system_id, domain_id, application_group_id, app_id, token.expire_time, token.created_at
|
||||||
FROM token
|
FROM token
|
||||||
LEFT JOIN application
|
LEFT JOIN application
|
||||||
ON token.app_id = application.id
|
ON token.app_id = application.id
|
||||||
LEFT JOIN service
|
LEFT JOIN application_group
|
||||||
ON application.service_id = service.id
|
ON application.application_group_id = service.id
|
||||||
LEFT JOIN domain
|
LEFT JOIN domain
|
||||||
ON service.domain_id = domain.id
|
ON application_group.domain_id = domain.id
|
||||||
WHERE token = $1
|
WHERE token = $1
|
||||||
`
|
`
|
||||||
result := entity.AuthData{}
|
result := entity.AuthData{}
|
||||||
|
|||||||
+38
-11
@@ -1,20 +1,21 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/integration-system/isp-kit/cluster"
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
"github.com/integration-system/isp-kit/grpc"
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
"github.com/integration-system/isp-kit/grpc/endpoint"
|
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||||
"github.com/integration-system/isp-kit/grpc/isp"
|
"github.com/txix-open/isp-kit/grpc/isp"
|
||||||
"isp-system-service/controller"
|
"isp-system-service/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Controllers struct {
|
type Controllers struct {
|
||||||
AccessList controller.AccessList
|
AccessList controller.AccessList
|
||||||
Domain controller.Domain
|
Domain controller.Domain
|
||||||
Service controller.Service
|
Service controller.Service
|
||||||
Application controller.Application
|
ApplicationGroup controller.ApplicationGroup
|
||||||
Token controller.Token
|
Application controller.Application
|
||||||
Secure controller.Secure
|
Token controller.Token
|
||||||
|
Secure controller.Secure
|
||||||
}
|
}
|
||||||
|
|
||||||
func EndpointDescriptors() []cluster.EndpointDescriptor {
|
func EndpointDescriptors() []cluster.EndpointDescriptor {
|
||||||
@@ -35,6 +36,7 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
|||||||
accessListCluster(c),
|
accessListCluster(c),
|
||||||
domainCluster(c),
|
domainCluster(c),
|
||||||
serviceCluster(c),
|
serviceCluster(c),
|
||||||
|
applicationGroupCluster(c),
|
||||||
applicationCluster(c),
|
applicationCluster(c),
|
||||||
tokenCluster(c),
|
tokenCluster(c),
|
||||||
})
|
})
|
||||||
@@ -130,6 +132,31 @@ func serviceCluster(c Controllers) []cluster.EndpointDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applicationGroupCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||||
|
return []cluster.EndpointDescriptor{
|
||||||
|
{
|
||||||
|
Path: "system/application_group/get_group",
|
||||||
|
Inner: true,
|
||||||
|
Handler: c.ApplicationGroup.Get,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "system/application_group/create_update_group",
|
||||||
|
Inner: true,
|
||||||
|
Handler: c.ApplicationGroup.CreateUpdate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "system/application_group/get_group_by_id",
|
||||||
|
Inner: true,
|
||||||
|
Handler: c.ApplicationGroup.GetById,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "system/application_group/delete_group",
|
||||||
|
Inner: true,
|
||||||
|
Handler: c.ApplicationGroup.Delete,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func applicationCluster(c Controllers) []cluster.EndpointDescriptor {
|
func applicationCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||||
return []cluster.EndpointDescriptor{
|
return []cluster.EndpointDescriptor{
|
||||||
{
|
{
|
||||||
@@ -140,7 +167,7 @@ func applicationCluster(c Controllers) []cluster.EndpointDescriptor {
|
|||||||
{
|
{
|
||||||
Path: "system/application/get_applications_by_service_id",
|
Path: "system/application/get_applications_by_service_id",
|
||||||
Inner: true,
|
Inner: true,
|
||||||
Handler: c.Application.GetByServiceId,
|
Handler: c.Application.GetByApplicationGroupId,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Path: "system/application/create_update_application",
|
Path: "system/application/create_update_application",
|
||||||
|
|||||||
+51
-51
@@ -11,8 +11,8 @@ import (
|
|||||||
type IApplicationApplicationRep interface {
|
type IApplicationApplicationRep interface {
|
||||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||||
GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error)
|
GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error)
|
||||||
GetApplicationByServiceIdList(ctx context.Context, serviceIdList []int) ([]entity.Application, error)
|
GetApplicationByApplicationGroupIdList(ctx context.Context, serviceIdList []int) ([]entity.Application, error)
|
||||||
GetApplicationByNameAndServiceId(ctx context.Context, name string, serviceId int) (*entity.Application, error)
|
GetApplicationByNameAndApplicationGroupId(ctx context.Context, name string, serviceId int) (*entity.Application, error)
|
||||||
CreateApplication(ctx context.Context, name string, desc string, serviceId int, appType string) (*entity.Application, error)
|
CreateApplication(ctx context.Context, name string, desc string, serviceId int, appType string) (*entity.Application, error)
|
||||||
UpdateApplication(ctx context.Context, id int, name string, description string) (*entity.Application, error)
|
UpdateApplication(ctx context.Context, id int, name string, description string) (*entity.Application, error)
|
||||||
}
|
}
|
||||||
@@ -22,8 +22,8 @@ type IApplicationTokenRep interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IApplicationServiceRep interface {
|
type IApplicationServiceRep interface {
|
||||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
GetApplicationGroupById(ctx context.Context, id int) (*entity.ApplicationGroup, error)
|
||||||
GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error)
|
GetApplicationGroupByDomainId(ctx context.Context, domainIdList []int) ([]entity.ApplicationGroup, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type IApplicationDomainRep interface {
|
type IApplicationDomainRep interface {
|
||||||
@@ -42,7 +42,7 @@ type Application struct {
|
|||||||
tx IApplicationTxRunner
|
tx IApplicationTxRunner
|
||||||
applicationRep IApplicationApplicationRep
|
applicationRep IApplicationApplicationRep
|
||||||
domainRep IApplicationDomainRep
|
domainRep IApplicationDomainRep
|
||||||
serviceRep IApplicationServiceRep
|
groupRep IApplicationServiceRep
|
||||||
tokenRep IApplicationTokenRep
|
tokenRep IApplicationTokenRep
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,14 +50,14 @@ func NewApplication(
|
|||||||
tx IApplicationTxRunner,
|
tx IApplicationTxRunner,
|
||||||
applicationRep IApplicationApplicationRep,
|
applicationRep IApplicationApplicationRep,
|
||||||
domainRep IApplicationDomainRep,
|
domainRep IApplicationDomainRep,
|
||||||
serviceRep IApplicationServiceRep,
|
groupRep IApplicationServiceRep,
|
||||||
tokenRep IApplicationTokenRep,
|
tokenRep IApplicationTokenRep,
|
||||||
) Application {
|
) Application {
|
||||||
return Application{
|
return Application{
|
||||||
tx: tx,
|
tx: tx,
|
||||||
applicationRep: applicationRep,
|
applicationRep: applicationRep,
|
||||||
domainRep: domainRep,
|
domainRep: domainRep,
|
||||||
serviceRep: serviceRep,
|
groupRep: groupRep,
|
||||||
tokenRep: tokenRep,
|
tokenRep: tokenRep,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,26 +85,26 @@ func (s Application) GetByIdList(ctx context.Context, idList []int) ([]*domain.A
|
|||||||
return s.EnrichWithTokens(ctx, res)
|
return s.EnrichWithTokens(ctx, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Application) GetByServiceId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error) {
|
func (s Application) GetByApplicationGroupId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error) {
|
||||||
arr, err := s.applicationRep.GetApplicationByServiceIdList(ctx, []int{id})
|
arr, err := s.applicationRep.GetApplicationByApplicationGroupIdList(ctx, []int{id})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get application by service_id")
|
return nil, errors.WithMessage(err, "get application by application_group_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.EnrichWithTokens(ctx, arr)
|
return s.EnrichWithTokens(ctx, arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithService, error) {
|
func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithApplicationGroup, error) {
|
||||||
domainEntityList, err := s.domainRep.GetDomainBySystemId(ctx, systemId)
|
domainEntityList, err := s.domainRep.GetDomainBySystemId(ctx, systemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get domains by system_id")
|
return nil, errors.WithMessage(err, "get domains by system_id")
|
||||||
}
|
}
|
||||||
if len(domainEntityList) == 0 {
|
if len(domainEntityList) == 0 {
|
||||||
return []*domain.DomainWithService{}, nil
|
return []*domain.DomainWithApplicationGroup{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]*domain.DomainWithService, len(domainEntityList))
|
result := make([]*domain.DomainWithApplicationGroup, len(domainEntityList))
|
||||||
resultByDomainId := make(map[int]*domain.DomainWithService, len(domainEntityList))
|
resultByDomainId := make(map[int]*domain.DomainWithApplicationGroup, len(domainEntityList))
|
||||||
domainIdList := make([]int, len(domainEntityList))
|
domainIdList := make([]int, len(domainEntityList))
|
||||||
for i, domainEntity := range domainEntityList {
|
for i, domainEntity := range domainEntityList {
|
||||||
domainIdList[i] = domainEntity.Id
|
domainIdList[i] = domainEntity.Id
|
||||||
@@ -112,52 +112,52 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do
|
|||||||
if domainEntity.Description != nil {
|
if domainEntity.Description != nil {
|
||||||
description = *domainEntity.Description
|
description = *domainEntity.Description
|
||||||
}
|
}
|
||||||
r := &domain.DomainWithService{
|
r := &domain.DomainWithApplicationGroup{
|
||||||
Id: domainEntity.Id,
|
Id: domainEntity.Id,
|
||||||
Name: domainEntity.Name,
|
Name: domainEntity.Name,
|
||||||
Description: description,
|
Description: description,
|
||||||
Services: make([]*domain.ServiceWithApps, 0),
|
ApplicationGroup: make([]*domain.ApplicationGroupWithApps, 0),
|
||||||
}
|
}
|
||||||
resultByDomainId[domainEntity.Id] = r
|
resultByDomainId[domainEntity.Id] = r
|
||||||
result[i] = r
|
result[i] = r
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceEntityList, err := s.serviceRep.GetServiceByDomainId(ctx, domainIdList)
|
applicationGroupEntityList, err := s.groupRep.GetApplicationGroupByDomainId(ctx, domainIdList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get service by domain_id")
|
return nil, errors.WithMessage(err, "get application group by domain_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceIdList := make([]int, len(serviceEntityList))
|
applicationGroupIdList := make([]int, len(applicationGroupEntityList))
|
||||||
resultServiceByServiceId := make(map[int]*domain.ServiceWithApps, len(serviceEntityList))
|
resultApplicationGroupById := make(map[int]*domain.ApplicationGroupWithApps, len(applicationGroupEntityList))
|
||||||
for i, serviceEntity := range serviceEntityList {
|
for i, applicationGroupEntity := range applicationGroupEntityList {
|
||||||
serviceIdList[i] = serviceEntity.Id
|
applicationGroupIdList[i] = applicationGroupEntity.Id
|
||||||
description := ""
|
description := ""
|
||||||
if serviceEntity.Description != nil {
|
if applicationGroupEntity.Description != nil {
|
||||||
description = *serviceEntity.Description
|
description = *applicationGroupEntity.Description
|
||||||
}
|
}
|
||||||
resultService := &domain.ServiceWithApps{
|
resultApplicationGroup := &domain.ApplicationGroupWithApps{
|
||||||
Id: serviceEntity.Id,
|
Id: applicationGroupEntity.Id,
|
||||||
Name: serviceEntity.Name,
|
Name: applicationGroupEntity.Name,
|
||||||
Description: description,
|
Description: description,
|
||||||
Apps: make([]*domain.ApplicationSimple, 0),
|
Apps: make([]*domain.ApplicationSimple, 0),
|
||||||
}
|
}
|
||||||
r := resultByDomainId[serviceEntity.DomainId]
|
r := resultByDomainId[applicationGroupEntity.DomainId]
|
||||||
r.Services = append(r.Services, resultService)
|
r.ApplicationGroup = append(r.ApplicationGroup, resultApplicationGroup)
|
||||||
resultServiceByServiceId[serviceEntity.Id] = resultService
|
resultApplicationGroupById[applicationGroupEntity.Id] = resultApplicationGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationEntityList, err := s.applicationRep.GetApplicationByServiceIdList(ctx, serviceIdList)
|
applicationEntityList, err := s.applicationRep.GetApplicationByApplicationGroupIdList(ctx, applicationGroupIdList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "get application by service_id")
|
return nil, errors.WithMessagef(err, "get application by application_group_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, applicationEntity := range applicationEntityList {
|
for _, applicationEntity := range applicationEntityList {
|
||||||
resultService := resultServiceByServiceId[applicationEntity.ServiceId]
|
resultApplicationGroup := resultApplicationGroupById[applicationEntity.ApplicationGroupId]
|
||||||
description := ""
|
description := ""
|
||||||
if applicationEntity.Description != nil {
|
if applicationEntity.Description != nil {
|
||||||
description = *applicationEntity.Description
|
description = *applicationEntity.Description
|
||||||
}
|
}
|
||||||
resultService.Apps = append(resultService.Apps, &domain.ApplicationSimple{
|
resultApplicationGroup.Apps = append(resultApplicationGroup.Apps, &domain.ApplicationSimple{
|
||||||
Id: applicationEntity.Id,
|
Id: applicationEntity.Id,
|
||||||
Name: applicationEntity.Name,
|
Name: applicationEntity.Name,
|
||||||
Type: applicationEntity.Type,
|
Type: applicationEntity.Type,
|
||||||
@@ -170,16 +170,16 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
||||||
existed, err := s.applicationRep.GetApplicationByNameAndServiceId(ctx, req.Name, req.ServiceId)
|
existed, err := s.applicationRep.GetApplicationByNameAndApplicationGroupId(ctx, req.Name, req.ApplicationGroupId)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, errors.WithMessage(err, "get application by name and service_id")
|
return nil, errors.WithMessage(err, "get application by name and application_group_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.serviceRep.GetServiceById(ctx, req.ServiceId)
|
_, err = s.groupRep.GetApplicationGroupById(ctx, req.ApplicationGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get service by id")
|
return nil, errors.WithMessage(err, "get application group by id")
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Id == 0 {
|
if req.Id == 0 {
|
||||||
@@ -187,12 +187,12 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
|||||||
return nil, domain.ErrApplicationDuplicateName
|
return nil, domain.ErrApplicationDuplicateName
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.applicationRep.GetApplicationByNameAndServiceId(ctx, req.Name, req.ServiceId)
|
_, err = s.applicationRep.GetApplicationByNameAndApplicationGroupId(ctx, req.Name, req.ApplicationGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get application by name and service_id")
|
return nil, errors.WithMessage(err, "get application by name and application_group_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
app, err := s.applicationRep.CreateApplication(ctx, req.Name, req.Description, req.ServiceId, req.Type)
|
app, err := s.applicationRep.CreateApplication(ctx, req.Name, req.Description, req.ApplicationGroupId, req.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "create application")
|
return nil, errors.WithMessage(err, "create application")
|
||||||
}
|
}
|
||||||
@@ -283,12 +283,12 @@ func (s Application) convertApplication(req entity.Application) domain.Applicati
|
|||||||
}
|
}
|
||||||
|
|
||||||
return domain.Application{
|
return domain.Application{
|
||||||
Id: req.Id,
|
Id: req.Id,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
ServiceId: req.ServiceId,
|
ApplicationGroupId: req.ApplicationGroupId,
|
||||||
Type: req.Type,
|
Type: req.Type,
|
||||||
CreatedAt: req.CreatedAt,
|
CreatedAt: req.CreatedAt,
|
||||||
UpdatedAt: req.UpdatedAt,
|
UpdatedAt: req.UpdatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"isp-system-service/domain"
|
||||||
|
"isp-system-service/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IApplicationGroupRep interface {
|
||||||
|
GetApplicationGroupById(ctx context.Context, id int) (*entity.ApplicationGroup, error)
|
||||||
|
GetApplicationGroupByIdList(ctx context.Context, idList []int) ([]entity.ApplicationGroup, error)
|
||||||
|
GetApplicationGroupByDomainId(ctx context.Context, domainIdList []int) ([]entity.ApplicationGroup, error)
|
||||||
|
GetSApplicationGroupByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.ApplicationGroup, error)
|
||||||
|
CreateApplicationGroup(ctx context.Context, name string, desc string, domainId int) (*entity.ApplicationGroup, error)
|
||||||
|
UpdateApplicationGroup(ctx context.Context, id int, name string, description string) (*entity.ApplicationGroup, error)
|
||||||
|
DeleteApplicationGroup(ctx context.Context, idList []int) (int, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type IApplicationGroupDomainRep interface {
|
||||||
|
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApplicationGroup struct {
|
||||||
|
domainRep IApplicationGroupDomainRep
|
||||||
|
groupRep IApplicationGroupRep
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApplicationGroup(
|
||||||
|
domainRep IApplicationGroupDomainRep,
|
||||||
|
groupRep IApplicationGroupRep,
|
||||||
|
) ApplicationGroup {
|
||||||
|
return ApplicationGroup{
|
||||||
|
domainRep: domainRep,
|
||||||
|
groupRep: groupRep,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ApplicationGroup) GetById(ctx context.Context, id int) (*domain.ApplicationGroup, error) {
|
||||||
|
applicationGroupEntity, err := s.groupRep.GetApplicationGroupById(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessagef(err, "get application group by id")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := s.convertApplicationGroup(*applicationGroupEntity)
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ApplicationGroup) GetByIdList(ctx context.Context, idList []int) ([]domain.ApplicationGroup, error) {
|
||||||
|
applicationGroupEntity, err := s.groupRep.GetApplicationGroupByIdList(ctx, idList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get system by id list")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]domain.ApplicationGroup, len(applicationGroupEntity))
|
||||||
|
for i := range applicationGroupEntity {
|
||||||
|
result[i] = s.convertApplicationGroup(applicationGroupEntity[i])
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ApplicationGroup) GetByDomainId(ctx context.Context, domainId int) ([]domain.ApplicationGroup, error) {
|
||||||
|
applicationGroupEntity, err := s.groupRep.GetApplicationGroupByDomainId(ctx, []int{domainId})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get system by id list")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]domain.ApplicationGroup, len(applicationGroupEntity))
|
||||||
|
for i := range applicationGroupEntity {
|
||||||
|
result[i] = s.convertApplicationGroup(applicationGroupEntity[i])
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ApplicationGroup) CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error) {
|
||||||
|
req.DomainId = 1 // Хардкодом проставляем domainId = 1
|
||||||
|
|
||||||
|
existed, err := s.groupRep.GetSApplicationGroupByNameAndDomainId(ctx, req.Name, req.DomainId)
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||||
|
case err != nil:
|
||||||
|
return nil, errors.WithMessage(err, "get application group by name and domain_id")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = s.domainRep.GetDomainById(ctx, req.DomainId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get domain by id")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Id == 0 {
|
||||||
|
if existed != nil {
|
||||||
|
return nil, domain.ErrDomainDuplicateName
|
||||||
|
}
|
||||||
|
|
||||||
|
applicationGroupEntity, err := s.groupRep.CreateApplicationGroup(ctx, req.Name, req.Description, req.DomainId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "create application group")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := s.convertApplicationGroup(*applicationGroupEntity)
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if existed != nil && existed.Id != req.Id {
|
||||||
|
return nil, domain.ErrDomainDuplicateName
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = s.groupRep.GetApplicationGroupById(ctx, req.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get application group by id")
|
||||||
|
}
|
||||||
|
|
||||||
|
applicationGroupEntity, err := s.groupRep.UpdateApplicationGroup(ctx, req.Id, req.Name, req.Description)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "update application group")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := s.convertApplicationGroup(*applicationGroupEntity)
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ApplicationGroup) Delete(ctx context.Context, idList []int) (int, error) {
|
||||||
|
result, err := s.groupRep.DeleteApplicationGroup(ctx, idList)
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.WithMessage(err, "delete application group")
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ApplicationGroup) convertApplicationGroup(req entity.ApplicationGroup) domain.ApplicationGroup {
|
||||||
|
desc := ""
|
||||||
|
if req.Description != nil {
|
||||||
|
desc = *req.Description
|
||||||
|
}
|
||||||
|
result := domain.ApplicationGroup{
|
||||||
|
Id: req.Id,
|
||||||
|
Name: req.Name,
|
||||||
|
Description: desc,
|
||||||
|
DomainId: req.DomainId,
|
||||||
|
CreatedAt: req.CreatedAt,
|
||||||
|
UpdatedAt: req.UpdatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
@@ -17,22 +17,22 @@ type AccessListRep interface {
|
|||||||
GetAccessListByAppIdAndMethod(ctx context.Context, appId int, method string) (*entity.AccessList, error)
|
GetAccessListByAppIdAndMethod(ctx context.Context, appId int, method string) (*entity.AccessList, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type ApplicationGroup struct {
|
||||||
tokenRep TokenRep
|
tokenRep TokenRep
|
||||||
accessListRep AccessListRep
|
accessListRep AccessListRep
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(
|
func NewApplicationGroup(
|
||||||
tokenRep TokenRep,
|
tokenRep TokenRep,
|
||||||
accessListRep AccessListRep,
|
accessListRep AccessListRep,
|
||||||
) Service {
|
) ApplicationGroup {
|
||||||
return Service{
|
return ApplicationGroup{
|
||||||
tokenRep: tokenRep,
|
tokenRep: tokenRep,
|
||||||
accessListRep: accessListRep,
|
accessListRep: accessListRep,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) Authenticate(ctx context.Context, token string) (*domain.AuthData, error) {
|
func (s ApplicationGroup) Authenticate(ctx context.Context, token string) (*domain.AuthData, error) {
|
||||||
authData, err := s.tokenRep.AuthDataByToken(ctx, token)
|
authData, err := s.tokenRep.AuthDataByToken(ctx, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get auth data by token")
|
return nil, errors.WithMessage(err, "get auth data by token")
|
||||||
@@ -44,14 +44,14 @@ func (s Service) Authenticate(ctx context.Context, token string) (*domain.AuthDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &domain.AuthData{
|
return &domain.AuthData{
|
||||||
SystemId: authData.SystemId,
|
SystemId: authData.SystemId,
|
||||||
DomainId: authData.DomainId,
|
DomainId: authData.DomainId,
|
||||||
ServiceId: authData.ServiceId,
|
ApplicationGroupId: authData.ApplicationGroupIdId,
|
||||||
ApplicationId: authData.AppId,
|
ApplicationId: authData.AppId,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) Authorize(ctx context.Context, appId int, endpoint string) (bool, error) {
|
func (s ApplicationGroup) Authorize(ctx context.Context, appId int, endpoint string) (bool, error) {
|
||||||
accessList, err := s.accessListRep.GetAccessListByAppIdAndMethod(ctx, appId, endpoint)
|
accessList, err := s.accessListRep.GetAccessListByAppIdAndMethod(ctx, appId, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.WithMessage(err, "get access list by app_id and method")
|
return false, errors.WithMessage(err, "get access list by app_id and method")
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"isp-system-service/domain"
|
|
||||||
"isp-system-service/entity"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IServiceServiceRep interface {
|
|
||||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
|
||||||
GetServiceByIdList(ctx context.Context, idList []int) ([]entity.Service, error)
|
|
||||||
GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error)
|
|
||||||
GetServiceByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.Service, error)
|
|
||||||
CreateService(ctx context.Context, name string, desc string, domainId int) (*entity.Service, error)
|
|
||||||
UpdateService(ctx context.Context, id int, name string, description string) (*entity.Service, error)
|
|
||||||
DeleteService(ctx context.Context, idList []int) (int, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type IServiceDomainRep interface {
|
|
||||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Service struct {
|
|
||||||
domainRep IServiceDomainRep
|
|
||||||
serviceRep IServiceServiceRep
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewService(
|
|
||||||
domainRep IServiceDomainRep,
|
|
||||||
serviceRep IServiceServiceRep,
|
|
||||||
) Service {
|
|
||||||
return Service{
|
|
||||||
domainRep: domainRep,
|
|
||||||
serviceRep: serviceRep,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Service) GetById(ctx context.Context, id int) (*domain.Service, error) {
|
|
||||||
serviceEntity, err := s.serviceRep.GetServiceById(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessagef(err, "get service by id")
|
|
||||||
}
|
|
||||||
|
|
||||||
result := s.convertService(*serviceEntity)
|
|
||||||
return &result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Service) GetByIdList(ctx context.Context, idList []int) ([]domain.Service, error) {
|
|
||||||
serviceEntity, err := s.serviceRep.GetServiceByIdList(ctx, idList)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessage(err, "get system by id list")
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make([]domain.Service, len(serviceEntity))
|
|
||||||
for i := range serviceEntity {
|
|
||||||
result[i] = s.convertService(serviceEntity[i])
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Service) GetByDomainId(ctx context.Context, domainId int) ([]domain.Service, error) {
|
|
||||||
serviceEntity, err := s.serviceRep.GetServiceByDomainId(ctx, []int{domainId})
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessage(err, "get system by id list")
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make([]domain.Service, len(serviceEntity))
|
|
||||||
for i := range serviceEntity {
|
|
||||||
result[i] = s.convertService(serviceEntity[i])
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) {
|
|
||||||
existed, err := s.serviceRep.GetServiceByNameAndDomainId(ctx, req.Name, req.DomainId)
|
|
||||||
switch {
|
|
||||||
case errors.Is(err, domain.ErrServiceNotFound):
|
|
||||||
case err != nil:
|
|
||||||
return nil, errors.WithMessage(err, "get service by name and domain_id")
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = s.domainRep.GetDomainById(ctx, req.DomainId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessage(err, "get domain by id")
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Id == 0 {
|
|
||||||
if existed != nil {
|
|
||||||
return nil, domain.ErrDomainDuplicateName
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceEntity, err := s.serviceRep.CreateService(ctx, req.Name, req.Description, req.DomainId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessage(err, "create service")
|
|
||||||
}
|
|
||||||
|
|
||||||
result := s.convertService(*serviceEntity)
|
|
||||||
return &result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if existed != nil && existed.Id != req.Id {
|
|
||||||
return nil, domain.ErrDomainDuplicateName
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = s.serviceRep.GetServiceById(ctx, req.Id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessage(err, "get service by id")
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceEntity, err := s.serviceRep.UpdateService(ctx, req.Id, req.Name, req.Description)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessage(err, "update service")
|
|
||||||
}
|
|
||||||
|
|
||||||
result := s.convertService(*serviceEntity)
|
|
||||||
return &result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Service) Delete(ctx context.Context, idList []int) (int, error) {
|
|
||||||
result, err := s.serviceRep.DeleteService(ctx, idList)
|
|
||||||
if err != nil {
|
|
||||||
return 0, errors.WithMessage(err, "delete service")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Service) convertService(req entity.Service) domain.Service {
|
|
||||||
desc := ""
|
|
||||||
if req.Description != nil {
|
|
||||||
desc = *req.Description
|
|
||||||
}
|
|
||||||
result := domain.Service{
|
|
||||||
Id: req.Id,
|
|
||||||
Name: req.Name,
|
|
||||||
Description: desc,
|
|
||||||
DomainId: req.DomainId,
|
|
||||||
CreatedAt: req.CreatedAt,
|
|
||||||
UpdatedAt: req.UpdatedAt,
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
+19
-19
@@ -21,7 +21,7 @@ type ITokenApplicationRep interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ITokenServiceRep interface {
|
type ITokenServiceRep interface {
|
||||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
GetApplicationGroupById(ctx context.Context, id int) (*entity.ApplicationGroup, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ITokenDomainRep interface {
|
type ITokenDomainRep interface {
|
||||||
@@ -46,13 +46,13 @@ type ITokenTxRunner interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Token struct {
|
type Token struct {
|
||||||
jwt ITokenSource
|
jwt ITokenSource
|
||||||
appEnrich ITokenAppEnrich
|
appEnrich ITokenAppEnrich
|
||||||
tx ITokenTxRunner
|
tx ITokenTxRunner
|
||||||
appRep ITokenApplicationRep
|
appRep ITokenApplicationRep
|
||||||
domainRep ITokenDomainRep
|
domainRep ITokenDomainRep
|
||||||
serviceRep ITokenServiceRep
|
groupRep ITokenServiceRep
|
||||||
tokenRep ITokenTokenRep
|
tokenRep ITokenTokenRep
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewToken(
|
func NewToken(
|
||||||
@@ -61,17 +61,17 @@ func NewToken(
|
|||||||
tx ITokenTxRunner,
|
tx ITokenTxRunner,
|
||||||
appRep ITokenApplicationRep,
|
appRep ITokenApplicationRep,
|
||||||
domainRep ITokenDomainRep,
|
domainRep ITokenDomainRep,
|
||||||
serviceRep ITokenServiceRep,
|
groupRep ITokenServiceRep,
|
||||||
tokenRep ITokenTokenRep,
|
tokenRep ITokenTokenRep,
|
||||||
) Token {
|
) Token {
|
||||||
return Token{
|
return Token{
|
||||||
appEnrich: appEnrich,
|
appEnrich: appEnrich,
|
||||||
jwt: jwtGenerate,
|
jwt: jwtGenerate,
|
||||||
tx: tx,
|
tx: tx,
|
||||||
appRep: appRep,
|
appRep: appRep,
|
||||||
domainRep: domainRep,
|
domainRep: domainRep,
|
||||||
serviceRep: serviceRep,
|
groupRep: groupRep,
|
||||||
tokenRep: tokenRep,
|
tokenRep: tokenRep,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,12 +95,12 @@ func (s Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
|||||||
return nil, errors.WithMessagef(err, "get application by id")
|
return nil, errors.WithMessagef(err, "get application by id")
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceEntity, err := s.serviceRep.GetServiceById(ctx, applicationEntity.ServiceId)
|
applicationGroupIdEntity, err := s.groupRep.GetApplicationGroupById(ctx, applicationEntity.ApplicationGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "get service by id")
|
return nil, errors.WithMessagef(err, "get application groupId by id")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.domainRep.GetDomainById(ctx, serviceEntity.DomainId)
|
_, err = s.domainRep.GetDomainById(ctx, applicationGroupIdEntity.DomainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "get domain by id")
|
return nil, errors.WithMessagef(err, "get domain by id")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/integration-system/isp-kit/test/dbt"
|
"github.com/txix-open/isp-kit/test/dbt"
|
||||||
"isp-system-service/entity"
|
"isp-system-service/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,9 +15,9 @@ func InsertDomain(db *dbt.TestDb, value entity.Domain) {
|
|||||||
db.Must().ExecNamed(q, value)
|
db.Must().ExecNamed(q, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func InsertService(db *dbt.TestDb, value entity.Service) {
|
func InsertApplicationGroup(db *dbt.TestDb, value entity.ApplicationGroup) {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO service
|
INSERT INTO application_group
|
||||||
(id, name, description, domain_id, created_at, updated_at)
|
(id, name, description, domain_id, created_at, updated_at)
|
||||||
VALUES
|
VALUES
|
||||||
(:id, :name, :description, :domain_id, :created_at, :updated_at)
|
(:id, :name, :description, :domain_id, :created_at, :updated_at)
|
||||||
@@ -28,7 +28,7 @@ func InsertService(db *dbt.TestDb, value entity.Service) {
|
|||||||
func InsertApplication(db *dbt.TestDb, value entity.Application) {
|
func InsertApplication(db *dbt.TestDb, value entity.Application) {
|
||||||
q := `
|
q := `
|
||||||
INSERT INTO application
|
INSERT INTO application
|
||||||
(id, name, description, service_id, created_at, updated_at)
|
(id, name, description, application_group_id, created_at, updated_at)
|
||||||
VALUES
|
VALUES
|
||||||
(:id, :name, :description, :service_id, :created_at, :updated_at)
|
(:id, :name, :description, :service_id, :created_at, :updated_at)
|
||||||
`
|
`
|
||||||
|
|||||||
+27
-24
@@ -2,16 +2,16 @@ package tests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/txix-open/isp-kit/dbx/migration"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/integration-system/isp-kit/dbx/migration"
|
|
||||||
"github.com/integration-system/isp-kit/grpc/client"
|
|
||||||
"github.com/integration-system/isp-kit/test"
|
|
||||||
"github.com/integration-system/isp-kit/test/dbt"
|
|
||||||
"github.com/integration-system/isp-kit/test/grpct"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"github.com/txix-open/isp-kit/test"
|
||||||
|
"github.com/txix-open/isp-kit/test/dbt"
|
||||||
|
"github.com/txix-open/isp-kit/test/grpct"
|
||||||
"isp-system-service/assembly"
|
"isp-system-service/assembly"
|
||||||
"isp-system-service/conf"
|
"isp-system-service/conf"
|
||||||
"isp-system-service/domain"
|
"isp-system-service/domain"
|
||||||
@@ -40,7 +40,10 @@ func (s *SecureSuite) SetupSuite() {
|
|||||||
db, err := s.testDb.DB()
|
db, err := s.testDb.DB()
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
|
|
||||||
err = migration.NewRunner(db.DB.DB, "../migrations").Run()
|
logger := s.test.Logger()
|
||||||
|
|
||||||
|
err = migration.NewRunner(migration.DialectPostgreSQL, "../migrations", logger).Run(context.Background(), db.DB.DB)
|
||||||
|
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
|
|
||||||
locator := assembly.NewLocator(s.testDb, s.test.Logger())
|
locator := assembly.NewLocator(s.testDb, s.test.Logger())
|
||||||
@@ -51,11 +54,11 @@ func (s *SecureSuite) SetupSuite() {
|
|||||||
InsertDomain(s.testDb, entity.Domain{
|
InsertDomain(s.testDb, entity.Domain{
|
||||||
Id: 3, Name: "test_domain", SystemId: 1, CreatedAt: createdTime, UpdatedAt: createdTime,
|
Id: 3, Name: "test_domain", SystemId: 1, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||||
})
|
})
|
||||||
InsertService(s.testDb, entity.Service{
|
InsertApplicationGroup(s.testDb, entity.ApplicationGroup{
|
||||||
Id: 5, Name: "test_service", DomainId: 3, CreatedAt: createdTime, UpdatedAt: createdTime,
|
Id: 5, Name: "test_application_group", DomainId: 3, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||||
})
|
})
|
||||||
InsertApplication(s.testDb, entity.Application{
|
InsertApplication(s.testDb, entity.Application{
|
||||||
Id: 7, Name: "test_application", ServiceId: 5, CreatedAt: createdTime, UpdatedAt: createdTime,
|
Id: 7, Name: "test_application", ApplicationGroupId: 5, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,17 +72,17 @@ func (s *SecureSuite) TestAuthenticate_Success() {
|
|||||||
JsonRequestBody(domain.AuthenticateRequest{
|
JsonRequestBody(domain.AuthenticateRequest{
|
||||||
Token: "test_token_success",
|
Token: "test_token_success",
|
||||||
}).
|
}).
|
||||||
ReadJsonResponse(&result).
|
JsonResponseBody(&result).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
s.require.Equal(domain.AuthenticateResponse{
|
s.require.Equal(domain.AuthenticateResponse{
|
||||||
Authenticated: true,
|
Authenticated: true,
|
||||||
ErrorReason: "",
|
ErrorReason: "",
|
||||||
AuthData: &domain.AuthData{
|
AuthData: &domain.AuthData{
|
||||||
SystemId: 1,
|
SystemId: 1,
|
||||||
DomainId: 3,
|
DomainId: 3,
|
||||||
ServiceId: 5,
|
ApplicationGroupId: 5,
|
||||||
ApplicationId: 7,
|
ApplicationId: 7,
|
||||||
},
|
},
|
||||||
}, result)
|
}, result)
|
||||||
}
|
}
|
||||||
@@ -90,7 +93,7 @@ func (s *SecureSuite) TestAuthenticate_NotFound() {
|
|||||||
JsonRequestBody(domain.AuthenticateRequest{
|
JsonRequestBody(domain.AuthenticateRequest{
|
||||||
Token: "test_token_not_found",
|
Token: "test_token_not_found",
|
||||||
}).
|
}).
|
||||||
ReadJsonResponse(&result).
|
JsonResponseBody(&result).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
s.require.Equal(domain.AuthenticateResponse{
|
s.require.Equal(domain.AuthenticateResponse{
|
||||||
@@ -110,17 +113,17 @@ func (s *SecureSuite) TestAuthenticate_NotExpired() {
|
|||||||
JsonRequestBody(domain.AuthenticateRequest{
|
JsonRequestBody(domain.AuthenticateRequest{
|
||||||
Token: "test_token_not_expired",
|
Token: "test_token_not_expired",
|
||||||
}).
|
}).
|
||||||
ReadJsonResponse(&result).
|
JsonResponseBody(&result).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
s.require.Equal(domain.AuthenticateResponse{
|
s.require.Equal(domain.AuthenticateResponse{
|
||||||
Authenticated: true,
|
Authenticated: true,
|
||||||
ErrorReason: "",
|
ErrorReason: "",
|
||||||
AuthData: &domain.AuthData{
|
AuthData: &domain.AuthData{
|
||||||
SystemId: 1,
|
SystemId: 1,
|
||||||
DomainId: 3,
|
DomainId: 3,
|
||||||
ServiceId: 5,
|
ApplicationGroupId: 5,
|
||||||
ApplicationId: 7,
|
ApplicationId: 7,
|
||||||
},
|
},
|
||||||
}, result)
|
}, result)
|
||||||
}
|
}
|
||||||
@@ -135,7 +138,7 @@ func (s *SecureSuite) TestAuthenticate_Expired() {
|
|||||||
JsonRequestBody(domain.AuthenticateRequest{
|
JsonRequestBody(domain.AuthenticateRequest{
|
||||||
Token: "test_token_expired",
|
Token: "test_token_expired",
|
||||||
}).
|
}).
|
||||||
ReadJsonResponse(&result).
|
JsonResponseBody(&result).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
s.require.Equal(domain.AuthenticateResponse{
|
s.require.Equal(domain.AuthenticateResponse{
|
||||||
@@ -158,7 +161,7 @@ func (s *SecureSuite) TestAuthorize_Success_True() {
|
|||||||
ApplicationId: 7,
|
ApplicationId: 7,
|
||||||
Endpoint: "endpoint/available",
|
Endpoint: "endpoint/available",
|
||||||
}).
|
}).
|
||||||
ReadJsonResponse(&result).
|
JsonResponseBody(&result).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
s.require.Equal(domain.AuthorizeResponse{
|
s.require.Equal(domain.AuthorizeResponse{
|
||||||
@@ -179,7 +182,7 @@ func (s *SecureSuite) TestAuthorize_Success_False() {
|
|||||||
ApplicationId: 7,
|
ApplicationId: 7,
|
||||||
Endpoint: "endpoint/not_available",
|
Endpoint: "endpoint/not_available",
|
||||||
}).
|
}).
|
||||||
ReadJsonResponse(&result).
|
JsonResponseBody(&result).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
s.require.Equal(domain.AuthorizeResponse{
|
s.require.Equal(domain.AuthorizeResponse{
|
||||||
@@ -194,7 +197,7 @@ func (s *SecureSuite) TestAuthorize_NotFound() {
|
|||||||
ApplicationId: 7,
|
ApplicationId: 7,
|
||||||
Endpoint: "endpoint/not_found",
|
Endpoint: "endpoint/not_found",
|
||||||
}).
|
}).
|
||||||
ReadJsonResponse(&result).
|
JsonResponseBody(&result).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.require.NoError(err)
|
s.require.NoError(err)
|
||||||
s.require.Equal(domain.AuthorizeResponse{
|
s.require.Equal(domain.AuthorizeResponse{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package transaction
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/integration-system/isp-kit/db"
|
"github.com/txix-open/isp-kit/db"
|
||||||
"isp-system-service/repository"
|
"isp-system-service/repository"
|
||||||
"isp-system-service/service"
|
"isp-system-service/service"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user