Merge branch 'MSP-634' into 'master'
Resolve MSP-634 Closes MSP-634 See merge request integration-system/isp-system-service!8
This commit is contained in:
commit
7ca053a733
40 files changed
+1011
-630
No files matched your search
@@ -1,3 +1,11 @@
|
||||
### v4.0.0
|
||||
* Удален `InstanceUuid`
|
||||
* Удалена интеграция с Redis
|
||||
* Генерация токенов теперь использует обычный crypto/rand вместо JWT
|
||||
* Убран из конфига defaultTokenExpireTime
|
||||
* Добавлены методы проверки подлинности токенов и прав у приложений
|
||||
* system/secure/authenticate
|
||||
* system/secure/authorize
|
||||
### v3.0.2
|
||||
* исправлена ошибка при обновлении имени или описании у созданного application
|
||||
### v3.0.1
|
||||
|
||||
+10
-33
@@ -10,46 +10,27 @@ import (
|
||||
"github.com/integration-system/isp-kit/dbx"
|
||||
"github.com/integration-system/isp-kit/grpc"
|
||||
"github.com/integration-system/isp-kit/log"
|
||||
rd "github.com/integration-system/isp-lib/v2/redis"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/migrations"
|
||||
"isp-system-service/redis"
|
||||
)
|
||||
|
||||
type Assembly struct {
|
||||
boot *bootstrap.Bootstrap
|
||||
db *dbrx.Client
|
||||
redis *rd.RxClient
|
||||
server *grpc.Server
|
||||
logger *log.Adapter
|
||||
instanceUuid string
|
||||
boot *bootstrap.Bootstrap
|
||||
db *dbrx.Client
|
||||
server *grpc.Server
|
||||
logger *log.Adapter
|
||||
}
|
||||
|
||||
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
||||
dbCli := dbrx.New(dbx.WithMigration(boot.MigrationsDir))
|
||||
server := grpc.NewServer()
|
||||
|
||||
localConfig := conf.Local{}
|
||||
err := boot.App.Config().Read(&localConfig)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "read local config")
|
||||
}
|
||||
|
||||
redisCli := rd.NewRxClient(
|
||||
rd.WithInitHandler(func(c *rd.Client, err error) {
|
||||
if err != nil {
|
||||
boot.App.Logger().Fatal(c.Context(), "redis init", log.Any("err", err))
|
||||
}
|
||||
}))
|
||||
|
||||
return &Assembly{
|
||||
boot: boot,
|
||||
db: dbCli,
|
||||
redis: redisCli,
|
||||
server: server,
|
||||
logger: boot.App.Logger(),
|
||||
instanceUuid: localConfig.InstanceUuid,
|
||||
boot: boot,
|
||||
db: dbCli,
|
||||
server: server,
|
||||
logger: boot.App.Logger(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -63,10 +44,7 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error
|
||||
a.logger.Fatal(ctx, errors.WithMessage(err, "upgrade remote config"))
|
||||
}
|
||||
|
||||
a.redis.ReceiveConfiguration(newCfg.Redis)
|
||||
redisCli := redis.NewClient(a.instanceUuid, a.redis)
|
||||
|
||||
migrations.Initialize.SetParams(redisCli, a.boot.MigrationsDir, newCfg.Database.Schema)
|
||||
migrations.Initialize.SetParams(a.boot.MigrationsDir, newCfg.Database.Schema)
|
||||
|
||||
a.logger.SetLevel(newCfg.LogLevel)
|
||||
|
||||
@@ -75,7 +53,7 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error
|
||||
a.logger.Fatal(ctx, errors.WithMessage(err, "upgrade db client"), log.Any("config", newCfg.Database))
|
||||
}
|
||||
|
||||
locator := NewLocator(a.db, redisCli, a.logger)
|
||||
locator := NewLocator(a.db, a.logger)
|
||||
handler := locator.Handler(newCfg)
|
||||
a.server.Upgrade(handler)
|
||||
|
||||
@@ -102,7 +80,6 @@ func (a *Assembly) Closers() []app.Closer {
|
||||
a.server.Shutdown()
|
||||
return nil
|
||||
}),
|
||||
a.redis,
|
||||
a.db,
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/integration-system/isp-kit/log"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/controller"
|
||||
"isp-system-service/redis"
|
||||
"isp-system-service/repository"
|
||||
"isp-system-service/routes"
|
||||
"isp-system-service/service"
|
||||
"isp-system-service/service/secure"
|
||||
"isp-system-service/transaction"
|
||||
)
|
||||
|
||||
@@ -21,14 +21,12 @@ type DB interface {
|
||||
|
||||
type Locator struct {
|
||||
db DB
|
||||
redis redis.Client
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewLocator(db DB, redisCli redis.Client, logger log.Logger) Locator {
|
||||
func NewLocator(db DB, logger log.Logger) Locator {
|
||||
return Locator{
|
||||
db: db,
|
||||
redis: redisCli,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
@@ -41,16 +39,18 @@ func (l Locator) Handler(cfg conf.Remote) isp.BackendServiceServer {
|
||||
serviceRep := repository.NewService(l.db)
|
||||
tokenRep := repository.NewToken(l.db)
|
||||
|
||||
accessListService := service.NewAccessList(l.redis, txManager, accessListRep, applicationRep)
|
||||
applicationService := service.NewApplication(l.redis, txManager, applicationRep, domainRep, serviceRep, tokenRep)
|
||||
secureService := secure.NewService(tokenRep, accessListRep)
|
||||
accessListService := service.NewAccessList(txManager, accessListRep, applicationRep)
|
||||
applicationService := service.NewApplication(txManager, applicationRep, domainRep, serviceRep, tokenRep)
|
||||
domainService := service.NewDomain(domainRep)
|
||||
serviceService := service.NewService(domainRep, serviceRep)
|
||||
|
||||
jwtService := service.NewJwt(cfg.ApplicationSecret)
|
||||
tokenService := service.NewToken(l.redis, cfg.DefaultTokenExpireTime, jwtService, applicationService, txManager,
|
||||
jwtService := service.NewTokenSource()
|
||||
tokenService := service.NewToken(jwtService, applicationService, txManager,
|
||||
applicationRep, domainRep, serviceRep, tokenRep,
|
||||
)
|
||||
|
||||
secureController := controller.NewSecure(secureService)
|
||||
accessListController := controller.NewAccessList(accessListService)
|
||||
applicationController := controller.NewApplication(applicationService)
|
||||
domainController := controller.NewDomain(domainService)
|
||||
@@ -58,6 +58,7 @@ func (l Locator) Handler(cfg conf.Remote) isp.BackendServiceServer {
|
||||
tokenController := controller.NewToken(tokenService)
|
||||
|
||||
c := routes.Controllers{
|
||||
Secure: secureController,
|
||||
AccessList: accessListController,
|
||||
Domain: domainController,
|
||||
Service: serviceController,
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ grpcInnerAddress:
|
||||
ip: 0.0.0.0
|
||||
port: 9005
|
||||
moduleName: isp-system-service
|
||||
instanceUuid: 3f4faf30-8482-48ef-931a-b15575a3af1d
|
||||
|
||||
infraServerPort: 9555
|
||||
|
||||
logfile:
|
||||
path: /var/log/isp-system-service/runtime.log
|
||||
|
||||
@@ -7,14 +7,5 @@
|
||||
"username": "{{ msp_pgsql_user }}",
|
||||
"host": "{{ msp_pgsql_address }}",
|
||||
"port": 5432
|
||||
},
|
||||
"redis": {
|
||||
"address": {
|
||||
"ip": "{{ msp_redis_address }}",
|
||||
"port": "{{ msp_redis_port }}"
|
||||
},
|
||||
"defaultDB": 0,
|
||||
"password": "{{ msp_redis_password }}"
|
||||
},
|
||||
"applicationSecret": "{{ msp_app_secret }}"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-kit/bootstrap"
|
||||
)
|
||||
|
||||
type Local struct {
|
||||
*bootstrap.LocalConfig
|
||||
InstanceUuid string `valid:"required"`
|
||||
}
|
||||
+2
-6
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/integration-system/isp-kit/dbx"
|
||||
"github.com/integration-system/isp-kit/log"
|
||||
"github.com/integration-system/isp-kit/rc/schema"
|
||||
"github.com/integration-system/isp-lib/v2/structure"
|
||||
"github.com/integration-system/jsonschema"
|
||||
)
|
||||
|
||||
@@ -18,9 +17,6 @@ func init() {
|
||||
}
|
||||
|
||||
type Remote struct {
|
||||
Database dbx.Config `schema:"Настройка базы данных"`
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||
Redis structure.RedisConfiguration `schema:"Настройка Redis" valid:"required~Required"`
|
||||
DefaultTokenExpireTime int `schema:"Время жизни токена по умолчанию,время жизни токена в миллисекундах с момента его создания. если = -1 - время жизни неограниченно"`
|
||||
ApplicationSecret string `schema:"Ключ для подписи application токенов" valid:"required~Required"`
|
||||
Database dbx.Config `schema:"Настройка базы данных"`
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||
}
|
||||
@@ -33,8 +33,8 @@ func NewAccessList(service AccessListService) AccessList {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity false "идентификатор приложения"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /access_list/get_by_id [POST]
|
||||
func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.MethodInfo, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
@@ -56,8 +56,8 @@ func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetOneRequest false "объект для настройки доступа"
|
||||
// @Success 200 {object} domain.AccessListSetOneResponse "количество измененных строк"
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /access_list/set_one [POST]
|
||||
func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error) {
|
||||
result, err := c.service.SetOne(ctx, req)
|
||||
@@ -79,8 +79,8 @@ func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneReque
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetListRequest false "объект настройки доступа"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /access_list/set_list [POST]
|
||||
func (c AccessList) SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error) {
|
||||
result, err := c.service.SetList(ctx, req)
|
||||
|
||||
+12
-12
@@ -36,9 +36,9 @@ func NewApplication(service ApplicationService) Application {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_application_by_id [POST]
|
||||
func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
@@ -60,7 +60,7 @@ func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_applications [POST]
|
||||
func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.ApplicationWithTokens, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
@@ -74,7 +74,7 @@ func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.Appl
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_applications_by_service_id [POST]
|
||||
func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) {
|
||||
return c.service.GetByServiceId(ctx, req.Id)
|
||||
@@ -87,7 +87,7 @@ func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.DomainWithService
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_system_tree [POST]
|
||||
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithService, error) {
|
||||
return c.service.SystemTree(ctx, domain.DefaultSystemId)
|
||||
@@ -101,10 +101,10 @@ func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithSer
|
||||
// @Produce json
|
||||
// @Param body body domain.ApplicationCreateUpdateRequest true "Объект приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/create_update_application [POST]
|
||||
func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req)
|
||||
@@ -130,8 +130,8 @@ func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/delete_applications [POST]
|
||||
func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
if len(req) == 0 {
|
||||
|
||||
@@ -34,8 +34,8 @@ func NewDomain(service DomainService) Domain {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/get_domain_by_id [POST]
|
||||
func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domain, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
@@ -57,7 +57,7 @@ func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domai
|
||||
// @Produce json
|
||||
// @Param body body integer false "Идентификатор системы"
|
||||
// @Success 200 {array} domain.Domain
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/get_domains_by_system_id [POST]
|
||||
func (c Domain) GetBySystemId(ctx context.Context) ([]domain.Domain, error) {
|
||||
return c.service.GetBySystemId(ctx, domain.DefaultSystemId)
|
||||
@@ -71,7 +71,7 @@ func (c Domain) GetBySystemId(ctx context.Context) ([]domain.Domain, error) {
|
||||
// @Produce json
|
||||
// @Param body body domain.DomainCreateUpdateRequest true "Объект домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/create_update_domain [POST]
|
||||
func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateRequest) (*domain.Domain, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req, domain.DefaultSystemId)
|
||||
@@ -97,8 +97,8 @@ func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов доменов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/delete_domains [POST]
|
||||
func (c Domain) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
if len(req) == 0 {
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type SecureService interface {
|
||||
Authenticate(ctx context.Context, token string) (*domain.AuthData, error)
|
||||
Authorize(ctx context.Context, appId int, endpoint string) (bool, error)
|
||||
}
|
||||
|
||||
type Secure struct {
|
||||
service SecureService
|
||||
}
|
||||
|
||||
func NewSecure(service SecureService) Secure {
|
||||
return Secure{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// Authenticate godoc
|
||||
// @Tags secure
|
||||
// @Summary Метод аутентификации токена
|
||||
// @Description Проверяет наличие токена в системе,
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AuthenticateRequest true "Тело запроса"
|
||||
// @Success 200 {array} domain.AuthenticateResponse
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /secure/authenticate [POST]
|
||||
func (c Secure) Authenticate(ctx context.Context, req domain.AuthenticateRequest) (*domain.AuthenticateResponse, error) {
|
||||
result, err := c.service.Authenticate(ctx, req.Token)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrTokenNotFound):
|
||||
return &domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenNotFound.Error(),
|
||||
}, nil
|
||||
case errors.Is(err, domain.ErrTokenExpired):
|
||||
return &domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenExpired.Error(),
|
||||
}, nil
|
||||
case err != nil:
|
||||
return nil, errors.WithMessage(err, "authenticate")
|
||||
default:
|
||||
return &domain.AuthenticateResponse{
|
||||
Authenticated: true,
|
||||
AuthData: result,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Authorize godoc
|
||||
// @Tags secure
|
||||
// @Summary Метод авторизации приложения
|
||||
// @Description Проверяет доступ приложения к запрашиваемому ендпоинту
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AuthorizeRequest true "Тело запрос"
|
||||
// @Success 200 {array} domain.AuthorizeResponse
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /secure/authorize [POST]
|
||||
func (c Secure) Authorize(ctx context.Context, req domain.AuthorizeRequest) (*domain.AuthorizeResponse, error) {
|
||||
result, err := c.service.Authorize(ctx, req.ApplicationId, req.Endpoint)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrAccessListNotFound):
|
||||
return &domain.AuthorizeResponse{
|
||||
Authorized: false,
|
||||
}, nil
|
||||
case err != nil:
|
||||
return nil, errors.WithMessage(err, "authorize")
|
||||
default:
|
||||
return &domain.AuthorizeResponse{
|
||||
Authorized: result,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -35,8 +35,8 @@ func NewService(service ServiceService) Service {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_service_by_id [POST]
|
||||
func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Service, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
@@ -58,7 +58,7 @@ func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Serv
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов сервисов"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_service [POST]
|
||||
func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
@@ -72,7 +72,7 @@ func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_services_by_domain_id [POST]
|
||||
func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.Service, error) {
|
||||
return c.service.GetByDomainId(ctx, req.Id)
|
||||
@@ -86,10 +86,10 @@ func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]doma
|
||||
// @Produce json
|
||||
// @Param body body domain.ServiceCreateUpdateRequest true "Объект сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/create_update_service [POST]
|
||||
func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req)
|
||||
@@ -115,8 +115,8 @@ func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdat
|
||||
// @Produce json
|
||||
// @Param body body []integer true "Массив идентификаторов сервисов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/delete_service [POST]
|
||||
func (c Service) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
if len(req) == 0 {
|
||||
|
||||
+4
-4
@@ -34,7 +34,7 @@ func NewToken(service ITokenService) Token {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {array} entity.Token
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/get_tokens_by_app_id [POST]
|
||||
func (c Token) GetByAppId(ctx context.Context, req domain.Identity) ([]domain.Token, error) {
|
||||
return c.service.GetByAppId(ctx, req.Id)
|
||||
@@ -48,7 +48,7 @@ func (c Token) GetByAppId(ctx context.Context, req domain.Identity) ([]domain.To
|
||||
// @Produce json
|
||||
// @Param body body domain.TokenCreateRequest true "Объект создания токена"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/create_token [POST]
|
||||
func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.Create(ctx, req)
|
||||
@@ -74,7 +74,7 @@ func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
// @Produce json
|
||||
// @Param body body domain.TokenRevokeRequest true "Объект отзыва токенов"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/revoke_tokens [POST]
|
||||
func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error) {
|
||||
return c.service.Revoke(ctx, req)
|
||||
@@ -88,7 +88,7 @@ func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*doma
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/revoke_tokens_for_app [POST]
|
||||
func (c Token) RevokeForApp(ctx context.Context, req domain.Identity) (*domain.DeleteResponse, error) {
|
||||
return c.service.RevokeByAppId(ctx, req.Id)
|
||||
|
||||
+206
-55
@@ -55,13 +55,13 @@ var doc = `{
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,13 +103,13 @@ var doc = `{
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,13 +148,13 @@ var doc = `{
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,25 +194,25 @@ var doc = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"409": {
|
||||
"description": "Conflict",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,13 +254,13 @@ var doc = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,19 +300,19 @@ var doc = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,7 +357,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,7 +400,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -432,7 +432,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,7 +472,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,13 +514,13 @@ var doc = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -560,13 +560,13 @@ var doc = `{
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -608,7 +608,93 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/secure/authenticate": {
|
||||
"post": {
|
||||
"description": "Проверяет наличие токена в системе,",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"secure"
|
||||
],
|
||||
"summary": "Метод аутентификации токена",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Тело запроса",
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.AuthenticateRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/domain.AuthenticateResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/secure/authorize": {
|
||||
"post": {
|
||||
"description": "Проверяет доступ приложения к запрашиваемому ендпоинту",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"secure"
|
||||
],
|
||||
"summary": "Метод авторизации приложения",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Тело запрос",
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.AuthorizeRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/domain.AuthorizeResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -648,25 +734,25 @@ var doc = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"409": {
|
||||
"description": "Conflict",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,13 +795,13 @@ var doc = `{
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -760,7 +846,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -800,13 +886,13 @@ var doc = `{
|
||||
"404": {
|
||||
"description": "Not Found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -849,7 +935,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -889,7 +975,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -932,7 +1018,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -972,7 +1058,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1012,7 +1098,7 @@ var doc = `{
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/structure.GrpcError"
|
||||
"$ref": "#/definitions/domain.GrpcError"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1158,6 +1244,71 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.AuthData": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"applicationId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"domainId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"serviceId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"systemId": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.AuthenticateRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"token"
|
||||
],
|
||||
"properties": {
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.AuthenticateResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"authData": {
|
||||
"$ref": "#/definitions/domain.AuthData"
|
||||
},
|
||||
"authenticated": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"errorReason": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.AuthorizeRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"applicationId",
|
||||
"endpoint"
|
||||
],
|
||||
"properties": {
|
||||
"applicationId": {
|
||||
"type": "integer"
|
||||
},
|
||||
"endpoint": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.AuthorizeResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"authorized": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.DeleteResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1226,6 +1377,23 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.GrpcError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"errorCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.Identity": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -1376,23 +1544,6 @@ var doc = `{
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"structure.GrpcError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"errorCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
+147
-49
@@ -91,6 +91,48 @@ definitions:
|
||||
$ref: '#/definitions/domain.Token'
|
||||
type: array
|
||||
type: object
|
||||
domain.AuthData:
|
||||
properties:
|
||||
applicationId:
|
||||
type: integer
|
||||
domainId:
|
||||
type: integer
|
||||
serviceId:
|
||||
type: integer
|
||||
systemId:
|
||||
type: integer
|
||||
type: object
|
||||
domain.AuthenticateRequest:
|
||||
properties:
|
||||
token:
|
||||
type: string
|
||||
required:
|
||||
- token
|
||||
type: object
|
||||
domain.AuthenticateResponse:
|
||||
properties:
|
||||
authData:
|
||||
$ref: '#/definitions/domain.AuthData'
|
||||
authenticated:
|
||||
type: boolean
|
||||
errorReason:
|
||||
type: string
|
||||
type: object
|
||||
domain.AuthorizeRequest:
|
||||
properties:
|
||||
applicationId:
|
||||
type: integer
|
||||
endpoint:
|
||||
type: string
|
||||
required:
|
||||
- applicationId
|
||||
- endpoint
|
||||
type: object
|
||||
domain.AuthorizeResponse:
|
||||
properties:
|
||||
authorized:
|
||||
type: boolean
|
||||
type: object
|
||||
domain.DeleteResponse:
|
||||
properties:
|
||||
deleted:
|
||||
@@ -135,6 +177,17 @@ definitions:
|
||||
$ref: '#/definitions/domain.ServiceWithApps'
|
||||
type: array
|
||||
type: object
|
||||
domain.GrpcError:
|
||||
properties:
|
||||
details:
|
||||
items:
|
||||
type: object
|
||||
type: array
|
||||
errorCode:
|
||||
type: string
|
||||
errorMessage:
|
||||
type: string
|
||||
type: object
|
||||
domain.Identity:
|
||||
properties:
|
||||
id:
|
||||
@@ -233,17 +286,6 @@ definitions:
|
||||
token:
|
||||
type: string
|
||||
type: object
|
||||
structure.GrpcError:
|
||||
properties:
|
||||
details:
|
||||
items:
|
||||
type: object
|
||||
type: array
|
||||
errorCode:
|
||||
type: string
|
||||
errorMessage:
|
||||
type: string
|
||||
type: object
|
||||
host: localhost:9000
|
||||
info:
|
||||
contact: {}
|
||||
@@ -277,11 +319,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить список доступности методов для приложения
|
||||
tags:
|
||||
- accessList
|
||||
@@ -309,11 +351,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Настроить доступность списка методов для приложения
|
||||
tags:
|
||||
- accessList
|
||||
@@ -338,11 +380,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Настроить доступность метода для приложения
|
||||
tags:
|
||||
- accessList
|
||||
@@ -369,19 +411,19 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Создать/обновить приложение
|
||||
tags:
|
||||
- application
|
||||
@@ -409,11 +451,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Удалить приложения
|
||||
tags:
|
||||
- application
|
||||
@@ -439,15 +481,15 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить приложение по идентификатору
|
||||
tags:
|
||||
- application
|
||||
@@ -476,7 +518,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить список приложений
|
||||
tags:
|
||||
- application
|
||||
@@ -504,7 +546,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить список приложений по идентификатору сервиса
|
||||
tags:
|
||||
- application
|
||||
@@ -525,7 +567,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Метод получения системного дерева
|
||||
tags:
|
||||
- application
|
||||
@@ -552,7 +594,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Создать/обновить домен
|
||||
tags:
|
||||
- domain
|
||||
@@ -580,11 +622,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Удаление доменов
|
||||
tags:
|
||||
- domain
|
||||
@@ -610,11 +652,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить домен по идентификатору
|
||||
tags:
|
||||
- domain
|
||||
@@ -641,10 +683,66 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить домены по идентификатору системы
|
||||
tags:
|
||||
- domain
|
||||
/secure/authenticate:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Проверяет наличие токена в системе,
|
||||
parameters:
|
||||
- description: Тело запроса
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.AuthenticateRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.AuthenticateResponse'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Метод аутентификации токена
|
||||
tags:
|
||||
- secure
|
||||
/secure/authorize:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Проверяет доступ приложения к запрашиваемому ендпоинту
|
||||
parameters:
|
||||
- description: Тело запрос
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.AuthorizeRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.AuthorizeResponse'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Метод авторизации приложения
|
||||
tags:
|
||||
- secure
|
||||
/service/create_update_service:
|
||||
post:
|
||||
consumes:
|
||||
@@ -668,19 +766,19 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Создать/обновить сервис
|
||||
tags:
|
||||
- service
|
||||
@@ -709,11 +807,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Удалить сервисы
|
||||
tags:
|
||||
- service
|
||||
@@ -742,7 +840,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить список сервисов
|
||||
tags:
|
||||
- service
|
||||
@@ -768,11 +866,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить сервис по идентификатору
|
||||
tags:
|
||||
- service
|
||||
@@ -800,7 +898,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить список сервисов по идентификатору домена
|
||||
tags:
|
||||
- service
|
||||
@@ -826,7 +924,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Создать токен
|
||||
tags:
|
||||
- token
|
||||
@@ -854,7 +952,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Получить токены по идентификатору приложения
|
||||
tags:
|
||||
- token
|
||||
@@ -880,7 +978,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Отозвать токены
|
||||
tags:
|
||||
- token
|
||||
@@ -907,7 +1005,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
summary: Отозвать токены для приложения
|
||||
tags:
|
||||
- token
|
||||
|
||||
@@ -15,4 +15,9 @@ var (
|
||||
|
||||
ErrApplicationNotFound = errors.New("application not found")
|
||||
ErrApplicationDuplicateName = errors.New("application name already exist")
|
||||
|
||||
ErrTokenNotFound = errors.New("token not found")
|
||||
ErrTokenExpired = errors.New("token is expired")
|
||||
|
||||
ErrAccessListNotFound = errors.New("access_list not found")
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package domain
|
||||
|
||||
type GrpcError struct {
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
ErrorCode string `json:"errorCode"`
|
||||
Details []interface{} `json:"details"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package domain
|
||||
|
||||
type AuthenticateRequest struct {
|
||||
Token string `valid:"required~Required"`
|
||||
}
|
||||
|
||||
type AuthenticateResponse struct {
|
||||
Authenticated bool
|
||||
ErrorReason string
|
||||
AuthData *AuthData
|
||||
}
|
||||
|
||||
type AuthData struct {
|
||||
SystemId int
|
||||
DomainId int
|
||||
ServiceId int
|
||||
ApplicationId int
|
||||
}
|
||||
|
||||
type AuthorizeRequest struct {
|
||||
ApplicationId int `valid:"required~Required"`
|
||||
Endpoint string `valid:"required~Required"`
|
||||
}
|
||||
|
||||
type AuthorizeResponse struct {
|
||||
Authorized bool
|
||||
}
|
||||
+1
-1
@@ -18,5 +18,5 @@ type TokenRevokeRequest struct {
|
||||
|
||||
type TokenCreateRequest struct {
|
||||
AppId int `valid:"required~Required"`
|
||||
ExpireTimeMs int
|
||||
ExpireTimeMs int `valid:"required~Required"`
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package entity
|
||||
|
||||
type RedisSetToken struct {
|
||||
Token string
|
||||
ExpireTime int
|
||||
DomainIdentity int
|
||||
ServiceIdentity int
|
||||
ApplicationIdentity int
|
||||
}
|
||||
|
||||
type RedisApplicationPermission struct {
|
||||
AppId int
|
||||
Method string
|
||||
Value bool
|
||||
}
|
||||
@@ -10,3 +10,12 @@ type Token struct {
|
||||
ExpireTime int
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type AuthData struct {
|
||||
SystemId int
|
||||
DomainId int
|
||||
ServiceId int
|
||||
AppId int
|
||||
ExpireTime int
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -3,25 +3,33 @@ module isp-system-service
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/integration-system/isp-kit v1.10.0
|
||||
github.com/Masterminds/squirrel v1.5.3
|
||||
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/pressly/goose v2.7.0+incompatible
|
||||
github.com/stretchr/testify v1.8.0
|
||||
google.golang.org/grpc v1.48.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.1.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/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.0 // indirect
|
||||
github.com/go-openapi/spec v0.20.5 // indirect
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/iancoleman/strcase v0.2.0 // indirect
|
||||
github.com/integration-system/bellows v1.0.1 // indirect
|
||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f // 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
|
||||
@@ -39,6 +47,7 @@ require (
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
@@ -46,6 +55,7 @@ require (
|
||||
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/prometheus/client_golang v1.12.2 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.36.0 // indirect
|
||||
@@ -57,9 +67,6 @@ require (
|
||||
github.com/spf13/viper v1.12.0 // indirect
|
||||
github.com/subosito/gotenv v1.4.0 // indirect
|
||||
github.com/swaggo/swag v1.7.0 // indirect
|
||||
go.opentelemetry.io/otel v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.19.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v0.19.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/zap v1.21.0 // indirect
|
||||
@@ -68,6 +75,7 @@ require (
|
||||
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
|
||||
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.10 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220713161829-9c7dac0a6568 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/ini.v1 v1.66.6 // indirect
|
||||
@@ -76,18 +84,3 @@ require (
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
nhooyr.io/websocket v1.8.7 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.1.0 // indirect
|
||||
github.com/Masterminds/squirrel v1.5.3
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/go-openapi/spec v0.20.5 // indirect
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-redis/redis/v8 v8.8.2
|
||||
github.com/integration-system/isp-lib/v2 v2.10.0
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/pressly/goose v2.7.0+incompatible
|
||||
golang.org/x/tools v0.1.10 // indirect
|
||||
google.golang.org/grpc v1.48.0
|
||||
)
|
||||
@@ -136,10 +136,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
|
||||
@@ -210,7 +207,6 @@ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/go-playground/validator/v10 v10.9.0 h1:NgTtmN58D0m8+UuxtYmGztBJB7VnPgjj221I1QHci2A=
|
||||
github.com/go-playground/validator/v10 v10.9.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
|
||||
github.com/go-redis/redis/v8 v8.8.2 h1:O/NcHqobw7SEptA0yA6up6spZVFtwE06SXM8rgLtsP8=
|
||||
github.com/go-redis/redis/v8 v8.8.2/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y=
|
||||
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
|
||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
||||
@@ -362,15 +358,14 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
|
||||
github.com/integration-system/bellows v1.0.1 h1:7g1lhD/6EcvsSo9iuiFqw98XGS78Sko6kUKPzfte/SY=
|
||||
github.com/integration-system/bellows v1.0.1/go.mod h1:qHPg1ptN3AHHr0f/wvoicfA2LOCprOyrbXnIa5QIRe0=
|
||||
github.com/integration-system/bgjob v1.2.0/go.mod h1:KYaolHZc3OYhtY+lPN71M0y+1DJXEzRanaya1MU0KvU=
|
||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f h1:52UOJguw5yqe1y2JjmyVxGcZf3kv2BQeUodR363MkiQ=
|
||||
github.com/integration-system/go-cmp v0.0.0-20190131081942-ac5582987a2f/go.mod h1:w+dmaWojuIwNujSYg6qt1wKHhSdorLOivCEl/XuLzbM=
|
||||
github.com/integration-system/gowsdl v1.0.0/go.mod h1:ZwTCE+Av5aQLnPj2/3PIop6mzCs1FY7jXrcWDvSjrBA=
|
||||
github.com/integration-system/grmq v1.1.1 h1:qd3n0rvNsJCO6V8qdRRttBGIJ7gwOAerEInWcqJudsw=
|
||||
github.com/integration-system/grmq v1.1.1/go.mod h1:8DkjaJB8s2onDia1qFgVNKA6gFVBr2WRaTkGuDlW00k=
|
||||
github.com/integration-system/isp-etp-go/v2 v2.1.3 h1:vcHP/PE7p1G3rxqoVKrKtXzoSxFA4ryxigd+zPkAb3w=
|
||||
github.com/integration-system/isp-etp-go/v2 v2.1.3/go.mod h1:ZpB+FIH3hy7md+f8ylVSQx5zwZVjczhkc45f1B2z9nw=
|
||||
github.com/integration-system/isp-kit v1.10.0 h1:7rdGtvZltg3g+66I1HZTaD/MT8THRyyaIOxmDNAqSZc=
|
||||
github.com/integration-system/isp-kit v1.10.0/go.mod h1:e4OdOcoCvqop3k0UY+n/DA5IC+NbjUUp55YneA1qRxc=
|
||||
github.com/integration-system/isp-kit v1.10.4 h1:yDaOYT/4/8DAX2B7R/Mx9su2a9WRGwbeoWUvU8u/IYE=
|
||||
github.com/integration-system/isp-kit v1.10.4/go.mod h1:e4OdOcoCvqop3k0UY+n/DA5IC+NbjUUp55YneA1qRxc=
|
||||
github.com/integration-system/isp-lib/v2 v2.10.0 h1:rMOVfMYndEmX1hf6Y10aMGhSzzC7/FxlEkGQ+3iNKUE=
|
||||
github.com/integration-system/isp-lib/v2 v2.10.0/go.mod h1:Uz79/zcx4BNq4LpTBY2GoJR83WJDy2TZhYrmQAY0R+k=
|
||||
github.com/integration-system/isp-log v1.1.8/go.mod h1:xSYA6TY/N45lFYSDwhoOW96Q/4it0nufG0yQDA2BNy8=
|
||||
@@ -535,17 +530,14 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4=
|
||||
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
|
||||
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
@@ -710,13 +702,9 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
||||
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
|
||||
go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng=
|
||||
go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg=
|
||||
go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg=
|
||||
go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc=
|
||||
go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q=
|
||||
go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA=
|
||||
go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc=
|
||||
go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
@@ -1284,7 +1272,6 @@ gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI=
|
||||
gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- +goose Up
|
||||
INSERT INTO system (id, name) VALUES (1, 'rootSystem');
|
||||
SELECT setval('system_service.system_id_seq' :: regclass, 1);
|
||||
SELECT setval(concat(current_schema(), '.system_id_seq') :: regclass, 1);
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM system
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -11,7 +10,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pressly/goose"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,14 +27,9 @@ func init() {
|
||||
goose.AddMigration(Initialize.Up, Initialize.Down)
|
||||
}
|
||||
|
||||
type IRedis interface {
|
||||
SetApplicationToken(ctx context.Context, req entity.RedisSetToken) error
|
||||
}
|
||||
|
||||
var Initialize = &initializeMigration{}
|
||||
|
||||
type initializeMigration struct {
|
||||
redis IRedis
|
||||
migrationDir string
|
||||
schema string
|
||||
}
|
||||
@@ -47,8 +40,7 @@ type identity struct {
|
||||
serviceId int
|
||||
}
|
||||
|
||||
func (i *initializeMigration) SetParams(redis IRedis, migrationDir string, schema string) {
|
||||
i.redis = redis
|
||||
func (i *initializeMigration) SetParams(migrationDir string, schema string) {
|
||||
i.migrationDir = migrationDir
|
||||
i.schema = schema
|
||||
}
|
||||
@@ -132,17 +124,6 @@ func (i *initializeMigration) insert(tx *sql.Tx, domainInfo domain.DomainWithSer
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "insert token")
|
||||
}
|
||||
|
||||
err = i.redis.SetApplicationToken(context.Background(), entity.RedisSetToken{
|
||||
Token: t.Token,
|
||||
ExpireTime: t.ExpireTime,
|
||||
DomainIdentity: domainId,
|
||||
ServiceIdentity: serviceId,
|
||||
ApplicationIdentity: appId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "redis set token")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- +goose Up
|
||||
insert into access_list (app_id, method, value)
|
||||
values (1, 'admin/auth/login', true)
|
||||
on conflict (app_id, method) do update set value = true;
|
||||
|
||||
-- +goose Down
|
||||
|
||||
-164
@@ -1,164 +0,0 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
rd "github.com/go-redis/redis/v8"
|
||||
"github.com/integration-system/isp-lib/v2/redis"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
const (
|
||||
systemIdentityFieldInDb = "1"
|
||||
domainIdentityFieldInDb = "2"
|
||||
serviceIdentityFieldInDb = "3"
|
||||
applicationIdentityFieldInDb = "4"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
instanceUuid string
|
||||
cli *redis.RxClient
|
||||
}
|
||||
|
||||
func NewClient(instanceUuid string, cli *redis.RxClient) Client {
|
||||
return Client{
|
||||
cli: cli,
|
||||
instanceUuid: instanceUuid,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Client) SetApplicationToken(ctx context.Context, req entity.RedisSetToken) error {
|
||||
_, err := r.cli.UseDbTx(redis.ApplicationTokenDb, func(pipeline rd.Pipeliner) error {
|
||||
idMap := map[string]interface{}{
|
||||
systemIdentityFieldInDb: domain.DefaultSystemId,
|
||||
domainIdentityFieldInDb: req.DomainIdentity,
|
||||
serviceIdentityFieldInDb: req.ServiceIdentity,
|
||||
applicationIdentityFieldInDb: req.ApplicationIdentity,
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%s|%s", req.Token, r.instanceUuid)
|
||||
stat := pipeline.HMSet(ctx, key, idMap)
|
||||
err := stat.Err()
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "pipeline hmset")
|
||||
}
|
||||
|
||||
if req.ExpireTime > 0 {
|
||||
err = pipeline.Expire(ctx, req.Token, time.Duration(req.ExpireTime)*time.Millisecond).Err()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline expire token")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_token transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) UpdateApplicationPermission(ctx context.Context, req entity.RedisApplicationPermission) error {
|
||||
_, err := r.cli.UseDb(redis.ApplicationPermissionDb, func(pipeline rd.Pipeliner) error {
|
||||
key := fmt.Sprintf("%d|%s", req.AppId, req.Method)
|
||||
_, err := pipeline.Set(ctx, key, req.Value, 0).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline set")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_permission transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) UpdateApplicationPermissionList(ctx context.Context, removed []string, added []interface{}) error {
|
||||
_, err := r.cli.UseDb(redis.ApplicationPermissionDb, func(pipeline rd.Pipeliner) error {
|
||||
if len(removed) > 0 {
|
||||
_, err := pipeline.Del(ctx, removed...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline del")
|
||||
}
|
||||
}
|
||||
|
||||
if len(added) > 0 {
|
||||
_, err := pipeline.MSet(ctx, added...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline mset")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_permission transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) DeleteApplication(ctx context.Context, appTokens []string, applicationPermissionList []string) error {
|
||||
keys := make([]string, len(appTokens))
|
||||
for i, token := range appTokens {
|
||||
keys[i] = fmt.Sprintf("%s|%s", token, r.instanceUuid)
|
||||
}
|
||||
|
||||
_, err := r.cli.UseDbTx(redis.ApplicationTokenDb, func(pipeline rd.Pipeliner) error {
|
||||
if len(appTokens) > 0 {
|
||||
_, err := pipeline.Del(ctx, keys...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline del")
|
||||
}
|
||||
}
|
||||
|
||||
if len(applicationPermissionList) > 0 {
|
||||
_, err := r.cli.UseDb(redis.ApplicationPermissionDb, func(pipeliner rd.Pipeliner) error {
|
||||
_, err := pipeliner.Del(ctx, applicationPermissionList...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "pipeline del")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_permission transaction")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_token transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Client) DeleteToken(ctx context.Context, tokens []string) error {
|
||||
keys := make([]string, len(tokens))
|
||||
for i, token := range tokens {
|
||||
keys[i] = fmt.Sprintf("%s|%s", token, r.instanceUuid)
|
||||
}
|
||||
|
||||
_, err := r.cli.UseDbTx(redis.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
_, err := p.Del(ctx, keys...).Result()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "del keys")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "application_token transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -2,11 +2,13 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/integration-system/isp-kit/db"
|
||||
"github.com/integration-system/isp-kit/db/query"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
@@ -20,6 +22,24 @@ func NewAccessList(db db.DB) AccessList {
|
||||
}
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppIdAndMethod(ctx context.Context, appId int, method string) (*entity.AccessList, error) {
|
||||
q := `
|
||||
SELECT app_id, method, value
|
||||
FROM access_list
|
||||
WHERE app_id = $1 AND method = $2
|
||||
`
|
||||
result := entity.AccessList{}
|
||||
err := r.db.SelectRow(ctx, &result, q, appId, method)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, domain.ErrAccessListNotFound
|
||||
}
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error) {
|
||||
q := `
|
||||
SELECT app_id, method, value
|
||||
|
||||
@@ -2,11 +2,13 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/integration-system/isp-kit/db"
|
||||
"github.com/integration-system/isp-kit/db/query"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
@@ -92,3 +94,27 @@ func (r Token) DeleteToken(ctx context.Context, tokens []string) (int, error) {
|
||||
|
||||
return int(rowsAffected), nil
|
||||
}
|
||||
|
||||
func (r Token) AuthDataByToken(ctx context.Context, token string) (*entity.AuthData, error) {
|
||||
q := `
|
||||
SELECT system_id, domain_id, service_id, app_id, token.expire_time, token.created_at
|
||||
FROM token
|
||||
LEFT JOIN application
|
||||
ON token.app_id = application.id
|
||||
LEFT JOIN service
|
||||
ON application.service_id = service.id
|
||||
LEFT JOIN domain
|
||||
ON service.domain_id = domain.id
|
||||
WHERE token = $1
|
||||
`
|
||||
result := entity.AuthData{}
|
||||
err := r.db.SelectRow(ctx, &result, q, token)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, domain.ErrTokenNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
@@ -14,6 +14,7 @@ type Controllers struct {
|
||||
Service controller.Service
|
||||
Application controller.Application
|
||||
Token controller.Token
|
||||
Secure controller.Secure
|
||||
}
|
||||
|
||||
func EndpointDescriptors() []cluster.EndpointDescriptor {
|
||||
@@ -30,6 +31,7 @@ func Handler(wrapper endpoint.Wrapper, c Controllers) isp.BackendServiceServer {
|
||||
|
||||
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||
return concatCluster([][]cluster.EndpointDescriptor{
|
||||
secureCluster(c),
|
||||
accessListCluster(c),
|
||||
domainCluster(c),
|
||||
serviceCluster(c),
|
||||
@@ -38,6 +40,21 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||
})
|
||||
}
|
||||
|
||||
func secureCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
return []cluster.EndpointDescriptor{
|
||||
{
|
||||
Path: "system/secure/authenticate",
|
||||
Inner: true,
|
||||
Handler: c.Secure.Authenticate,
|
||||
},
|
||||
{
|
||||
Path: "system/secure/authorize",
|
||||
Inner: true,
|
||||
Handler: c.Secure.Authorize,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func accessListCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
return []cluster.EndpointDescriptor{
|
||||
{
|
||||
|
||||
+1
-32
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
@@ -33,26 +32,18 @@ type IAccessListTxRunner interface {
|
||||
AccessListSetListTx(ctx context.Context, tx func(ctx context.Context, tx IAccessListSetListTx) error) error
|
||||
}
|
||||
|
||||
type IAccessListRedis interface {
|
||||
UpdateApplicationPermission(ctx context.Context, req entity.RedisApplicationPermission) error
|
||||
UpdateApplicationPermissionList(ctx context.Context, removed []string, added []interface{}) error
|
||||
}
|
||||
|
||||
type AccessList struct {
|
||||
redis IAccessListRedis
|
||||
tx IAccessListTxRunner
|
||||
accessListRep IAccessListAccessListRep
|
||||
applicationRep IAccessListApplicationRep
|
||||
}
|
||||
|
||||
func NewAccessList(
|
||||
redis IAccessListRedis,
|
||||
tx IAccessListTxRunner,
|
||||
accessListRep IAccessListAccessListRep,
|
||||
applicationRep IAccessListApplicationRep,
|
||||
) AccessList {
|
||||
return AccessList{
|
||||
redis: redis,
|
||||
tx: tx,
|
||||
accessListRep: accessListRep,
|
||||
applicationRep: applicationRep,
|
||||
@@ -98,15 +89,6 @@ func (s AccessList) SetOne(ctx context.Context, request domain.AccessListSetOneR
|
||||
return errors.WithMessagef(err, "upsert access list")
|
||||
}
|
||||
|
||||
err = s.redis.UpdateApplicationPermission(ctx, entity.RedisApplicationPermission{
|
||||
AppId: request.AppId,
|
||||
Method: request.Method,
|
||||
Value: request.Value,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "redis update application permission")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -125,9 +107,8 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
}
|
||||
|
||||
err = s.tx.AccessListSetListTx(ctx, func(ctx context.Context, tx IAccessListSetListTx) error {
|
||||
oldAccessList := make([]entity.AccessList, 0)
|
||||
if req.RemoveOld {
|
||||
oldAccessList, err = tx.DeleteAccessListByAppId(ctx, req.AppId)
|
||||
_, err = tx.DeleteAccessListByAppId(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete access list by app_id")
|
||||
}
|
||||
@@ -135,7 +116,6 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
|
||||
newAccessList := make([]entity.AccessList, len(req.Methods))
|
||||
updateMethods := make([]string, len(req.Methods))
|
||||
redisMsetRequest := make([]interface{}, 0)
|
||||
for i, m := range req.Methods {
|
||||
updateMethods[i] = m.Method
|
||||
newAccessList[i] = entity.AccessList{
|
||||
@@ -143,12 +123,6 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
Method: m.Method,
|
||||
Value: m.Value,
|
||||
}
|
||||
redisMsetRequest = append(redisMsetRequest, fmt.Sprintf("%d|%s", req.AppId, m.Method), m.Value)
|
||||
}
|
||||
|
||||
redisDelRequest := make([]string, len(oldAccessList))
|
||||
for i, access := range oldAccessList {
|
||||
redisDelRequest[i] = fmt.Sprintf("%d|%s", req.AppId, access.Method)
|
||||
}
|
||||
|
||||
if len(newAccessList) > 0 {
|
||||
@@ -163,11 +137,6 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
}
|
||||
}
|
||||
|
||||
err = s.redis.UpdateApplicationPermissionList(ctx, redisDelRequest, redisMsetRequest)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis update application permission list")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
@@ -32,8 +31,6 @@ type IApplicationDomainRep interface {
|
||||
}
|
||||
|
||||
type IApplicationDeleteTx interface {
|
||||
GetAccessListByAppIdList(ctx context.Context, appIdList []int) ([]entity.AccessList, error)
|
||||
GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error)
|
||||
DeleteApplicationByIdList(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
@@ -41,12 +38,7 @@ type IApplicationTxRunner interface {
|
||||
ApplicationDeleteTx(ctx context.Context, tx func(ctx context.Context, tx IApplicationDeleteTx) error) error
|
||||
}
|
||||
|
||||
type IApplicationRedis interface {
|
||||
DeleteApplication(ctx context.Context, appTokens []string, applicationPermissionList []string) error
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
redis IApplicationRedis
|
||||
tx IApplicationTxRunner
|
||||
applicationRep IApplicationApplicationRep
|
||||
domainRep IApplicationDomainRep
|
||||
@@ -55,7 +47,6 @@ type Application struct {
|
||||
}
|
||||
|
||||
func NewApplication(
|
||||
redis IApplicationRedis,
|
||||
tx IApplicationTxRunner,
|
||||
applicationRep IApplicationApplicationRep,
|
||||
domainRep IApplicationDomainRep,
|
||||
@@ -63,7 +54,6 @@ func NewApplication(
|
||||
tokenRep IApplicationTokenRep,
|
||||
) Application {
|
||||
return Application{
|
||||
redis: redis,
|
||||
tx: tx,
|
||||
applicationRep: applicationRep,
|
||||
domainRep: domainRep,
|
||||
@@ -240,36 +230,11 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
||||
func (s Application) Delete(ctx context.Context, idList []int) (int, error) {
|
||||
count := 0
|
||||
err := s.tx.ApplicationDeleteTx(ctx, func(ctx context.Context, tx IApplicationDeleteTx) error {
|
||||
accessList, err := tx.GetAccessListByAppIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get access list by app_id list")
|
||||
}
|
||||
|
||||
permissionDeleteList := make([]string, 0)
|
||||
for _, access := range accessList {
|
||||
permissionDeleteList = append(permissionDeleteList, fmt.Sprintf("%d|%s", access.AppId, access.Method))
|
||||
}
|
||||
|
||||
tokens, err := tx.GetTokenByAppIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get token by app_id list")
|
||||
}
|
||||
|
||||
tokenIdList := make([]string, len(tokens))
|
||||
for i, t := range tokens {
|
||||
tokenIdList[i] = t.Token
|
||||
}
|
||||
|
||||
deletedApp, err := tx.DeleteApplicationByIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete application by id list")
|
||||
}
|
||||
|
||||
err = s.redis.DeleteApplication(ctx, tokenIdList, permissionDeleteList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis delete application")
|
||||
}
|
||||
|
||||
count = deletedApp
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Jwt struct {
|
||||
secret string
|
||||
}
|
||||
|
||||
func NewJwt(secret string) Jwt {
|
||||
return Jwt{
|
||||
secret: secret,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Jwt) CreateApplicationToken(appId int, expireTime int) (string, error) {
|
||||
random, err := s.generateSalt()
|
||||
if err != nil {
|
||||
return "", errors.WithMessage(err, "generate salt")
|
||||
}
|
||||
|
||||
created := time.Now().UTC()
|
||||
claims := jwt.MapClaims{
|
||||
"appId": appId,
|
||||
"iat": created.Unix(),
|
||||
"salt": random,
|
||||
}
|
||||
if expireTime > 0 {
|
||||
claims["exp"] = created.Add(time.Millisecond * time.Duration(expireTime)).Unix()
|
||||
}
|
||||
|
||||
token, err := jwt.NewWithClaims(jwt.SigningMethodHS512, claims).
|
||||
SignedString([]byte(s.secret))
|
||||
if err != nil {
|
||||
return "", errors.WithMessage(err, "signed token")
|
||||
}
|
||||
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (Jwt) generateSalt() (string, error) {
|
||||
cryptoRand := make([]byte, 16) //nolint:gomnd
|
||||
_, err := rand.Read(cryptoRand)
|
||||
if err != nil {
|
||||
return "", errors.WithMessage(err, "crypto/rand read")
|
||||
}
|
||||
random := hex.EncodeToString(cryptoRand)
|
||||
|
||||
return random, nil
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package secure
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type TokenRep interface {
|
||||
AuthDataByToken(ctx context.Context, token string) (*entity.AuthData, error)
|
||||
}
|
||||
|
||||
type AccessListRep interface {
|
||||
GetAccessListByAppIdAndMethod(ctx context.Context, appId int, method string) (*entity.AccessList, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
tokenRep TokenRep
|
||||
accessListRep AccessListRep
|
||||
}
|
||||
|
||||
func NewService(
|
||||
tokenRep TokenRep,
|
||||
accessListRep AccessListRep,
|
||||
) Service {
|
||||
return Service{
|
||||
tokenRep: tokenRep,
|
||||
accessListRep: accessListRep,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Service) Authenticate(ctx context.Context, token string) (*domain.AuthData, error) {
|
||||
authData, err := s.tokenRep.AuthDataByToken(ctx, token)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get auth data by token")
|
||||
}
|
||||
|
||||
if authData.ExpireTime != -1 &&
|
||||
authData.CreatedAt.Add(time.Millisecond*time.Duration(authData.ExpireTime)).Before(time.Now().UTC()) {
|
||||
return nil, domain.ErrTokenExpired
|
||||
}
|
||||
|
||||
return &domain.AuthData{
|
||||
SystemId: authData.SystemId,
|
||||
DomainId: authData.DomainId,
|
||||
ServiceId: authData.ServiceId,
|
||||
ApplicationId: authData.AppId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s Service) Authorize(ctx context.Context, appId int, endpoint string) (bool, error) {
|
||||
accessList, err := s.accessListRep.GetAccessListByAppIdAndMethod(ctx, appId, endpoint)
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "get access list by app_id and method")
|
||||
}
|
||||
|
||||
return accessList.Value, nil
|
||||
}
|
||||
+21
-53
@@ -8,8 +8,8 @@ import (
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type ITokenJwt interface {
|
||||
CreateApplicationToken(appId int, expireTime int) (string, error)
|
||||
type ITokenSource interface {
|
||||
CreateApplicationToken() (string, error)
|
||||
}
|
||||
|
||||
type ITokenAppEnrich interface {
|
||||
@@ -45,27 +45,18 @@ type ITokenTxRunner interface {
|
||||
TokenRevokeTx(ctx context.Context, tx func(ctx context.Context, tx ITokenRevokeTx) error) error
|
||||
}
|
||||
|
||||
type ITokenRedis interface {
|
||||
SetApplicationToken(ctx context.Context, req entity.RedisSetToken) error
|
||||
DeleteToken(ctx context.Context, tokens []string) error
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
redisRep ITokenRedis
|
||||
defaultExpireTime int
|
||||
jwt ITokenJwt
|
||||
appEnrich ITokenAppEnrich
|
||||
tx ITokenTxRunner
|
||||
appRep ITokenApplicationRep
|
||||
domainRep ITokenDomainRep
|
||||
serviceRep ITokenServiceRep
|
||||
tokenRep ITokenTokenRep
|
||||
jwt ITokenSource
|
||||
appEnrich ITokenAppEnrich
|
||||
tx ITokenTxRunner
|
||||
appRep ITokenApplicationRep
|
||||
domainRep ITokenDomainRep
|
||||
serviceRep ITokenServiceRep
|
||||
tokenRep ITokenTokenRep
|
||||
}
|
||||
|
||||
func NewToken(
|
||||
redisRep ITokenRedis,
|
||||
defaultExpireTime int,
|
||||
jwtGenerate ITokenJwt,
|
||||
jwtGenerate ITokenSource,
|
||||
appEnrich ITokenAppEnrich,
|
||||
tx ITokenTxRunner,
|
||||
appRep ITokenApplicationRep,
|
||||
@@ -74,15 +65,13 @@ func NewToken(
|
||||
tokenRep ITokenTokenRep,
|
||||
) Token {
|
||||
return Token{
|
||||
redisRep: redisRep,
|
||||
defaultExpireTime: defaultExpireTime,
|
||||
appEnrich: appEnrich,
|
||||
jwt: jwtGenerate,
|
||||
tx: tx,
|
||||
appRep: appRep,
|
||||
domainRep: domainRep,
|
||||
serviceRep: serviceRep,
|
||||
tokenRep: tokenRep,
|
||||
appEnrich: appEnrich,
|
||||
jwt: jwtGenerate,
|
||||
tx: tx,
|
||||
appRep: appRep,
|
||||
domainRep: domainRep,
|
||||
serviceRep: serviceRep,
|
||||
tokenRep: tokenRep,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,38 +100,22 @@ func (s Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
return nil, errors.WithMessagef(err, "get service by id")
|
||||
}
|
||||
|
||||
domainEntity, err := s.domainRep.GetDomainById(ctx, serviceEntity.DomainId)
|
||||
_, err = s.domainRep.GetDomainById(ctx, serviceEntity.DomainId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get domain by id")
|
||||
}
|
||||
|
||||
expTime := req.ExpireTimeMs
|
||||
if expTime == 0 {
|
||||
expTime = s.defaultExpireTime
|
||||
}
|
||||
|
||||
token, err := s.jwt.CreateApplicationToken(req.AppId, expTime)
|
||||
token, err := s.jwt.CreateApplicationToken()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "jwt create application token")
|
||||
return nil, errors.WithMessagef(err, "create application token")
|
||||
}
|
||||
|
||||
err = s.tx.TokenCreateTx(ctx, func(ctx context.Context, tx ITokenCreateTx) error {
|
||||
tokenEntity, err := tx.SaveToken(ctx, token, req.AppId, expTime)
|
||||
_, err = tx.SaveToken(ctx, token, req.AppId, req.ExpireTimeMs)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "tx save token")
|
||||
}
|
||||
|
||||
err = s.redisRep.SetApplicationToken(ctx, entity.RedisSetToken{
|
||||
Token: tokenEntity.Token,
|
||||
ExpireTime: tokenEntity.ExpireTime,
|
||||
DomainIdentity: domainEntity.Id,
|
||||
ServiceIdentity: serviceEntity.Id,
|
||||
ApplicationIdentity: applicationEntity.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis set token")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -202,11 +175,6 @@ func (s Token) revokeTokens(ctx context.Context, tokens []string) (*domain.Delet
|
||||
return errors.WithMessagef(err, "tx delete token")
|
||||
}
|
||||
|
||||
err = s.redisRep.DeleteToken(ctx, tokens)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "redis delete token")
|
||||
}
|
||||
|
||||
count = deleted
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type TokenSource struct {
|
||||
}
|
||||
|
||||
func NewTokenSource() TokenSource {
|
||||
return TokenSource{}
|
||||
}
|
||||
|
||||
func (s TokenSource) CreateApplicationToken() (string, error) {
|
||||
cryptoRand := make([]byte, 128) //nolint:gomnd
|
||||
_, err := rand.Read(cryptoRand)
|
||||
if err != nil {
|
||||
return "", errors.WithMessage(err, "crypto/rand read")
|
||||
}
|
||||
random := hex.EncodeToString(cryptoRand)
|
||||
|
||||
return random, nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-kit/test/dbt"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
func InsertDomain(db *dbt.TestDb, value entity.Domain) {
|
||||
q := `
|
||||
INSERT INTO domain
|
||||
(id, name, description, system_id, created_at, updated_at)
|
||||
VALUES
|
||||
(:id, :name, :description, 1, :created_at, :updated_at)
|
||||
`
|
||||
db.Must().ExecNamed(q, value)
|
||||
}
|
||||
|
||||
func InsertService(db *dbt.TestDb, value entity.Service) {
|
||||
q := `
|
||||
INSERT INTO service
|
||||
(id, name, description, domain_id, created_at, updated_at)
|
||||
VALUES
|
||||
(:id, :name, :description, :domain_id, :created_at, :updated_at)
|
||||
`
|
||||
db.Must().ExecNamed(q, value)
|
||||
}
|
||||
|
||||
func InsertApplication(db *dbt.TestDb, value entity.Application) {
|
||||
q := `
|
||||
INSERT INTO application
|
||||
(id, name, description, service_id, created_at, updated_at)
|
||||
VALUES
|
||||
(:id, :name, :description, :service_id, :created_at, :updated_at)
|
||||
`
|
||||
db.Must().ExecNamed(q, value)
|
||||
}
|
||||
|
||||
func InsertToken(db *dbt.TestDb, value entity.Token) {
|
||||
q := `
|
||||
INSERT INTO token
|
||||
(token, created_at, app_id, expire_time)
|
||||
VALUES
|
||||
(:token, :created_at, :app_id, :expire_time)
|
||||
`
|
||||
db.Must().ExecNamed(q, value)
|
||||
}
|
||||
|
||||
func InsertAccessList(db *dbt.TestDb, value entity.AccessList) {
|
||||
q := `
|
||||
INSERT INTO access_list
|
||||
(app_id, method, value)
|
||||
VALUES
|
||||
(:app_id, :method, :value)
|
||||
`
|
||||
db.Must().ExecNamed(q, value)
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"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/suite"
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/migrations"
|
||||
)
|
||||
|
||||
func TestSecureSuite(t *testing.T) {
|
||||
suite.Run(t, &SecureSuite{})
|
||||
}
|
||||
|
||||
type SecureSuite struct {
|
||||
suite.Suite
|
||||
test *test.Test
|
||||
require *require.Assertions
|
||||
testDb *dbt.TestDb
|
||||
api *client.Client
|
||||
}
|
||||
|
||||
func (s *SecureSuite) SetupSuite() {
|
||||
s.test, s.require = test.New(s.T())
|
||||
|
||||
s.testDb = dbt.New(s.test)
|
||||
migrations.Initialize.SetParams("../migrations", s.testDb.Schema())
|
||||
|
||||
db, err := s.testDb.DB()
|
||||
s.require.NoError(err)
|
||||
|
||||
err = migration.NewRunner(db.DB.DB, "../migrations").Run()
|
||||
s.require.NoError(err)
|
||||
|
||||
locator := assembly.NewLocator(s.testDb, s.test.Logger())
|
||||
handler := locator.Handler(conf.Remote{})
|
||||
_, s.api = grpct.TestServer(s.test, handler)
|
||||
|
||||
createdTime := time.Now().UTC()
|
||||
InsertDomain(s.testDb, entity.Domain{
|
||||
Id: 3, Name: "test_domain", SystemId: 1, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||
})
|
||||
InsertService(s.testDb, entity.Service{
|
||||
Id: 5, Name: "test_service", DomainId: 3, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||
})
|
||||
InsertApplication(s.testDb, entity.Application{
|
||||
Id: 7, Name: "test_application", ServiceId: 5, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SecureSuite) TestAuthenticate_Success() {
|
||||
InsertToken(s.testDb, entity.Token{
|
||||
Token: "test_token_success", AppId: 7, ExpireTime: -1, CreatedAt: time.Now().UTC(),
|
||||
})
|
||||
|
||||
result := domain.AuthenticateResponse{}
|
||||
err := s.api.Invoke("system/secure/authenticate").
|
||||
JsonRequestBody(domain.AuthenticateRequest{
|
||||
Token: "test_token_success",
|
||||
}).
|
||||
ReadJsonResponse(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Authenticated: true,
|
||||
ErrorReason: "",
|
||||
AuthData: &domain.AuthData{
|
||||
SystemId: 1,
|
||||
DomainId: 3,
|
||||
ServiceId: 5,
|
||||
ApplicationId: 7,
|
||||
},
|
||||
}, result)
|
||||
}
|
||||
|
||||
func (s *SecureSuite) TestAuthenticate_NotFound() {
|
||||
result := domain.AuthenticateResponse{}
|
||||
err := s.api.Invoke("system/secure/authenticate").
|
||||
JsonRequestBody(domain.AuthenticateRequest{
|
||||
Token: "test_token_not_found",
|
||||
}).
|
||||
ReadJsonResponse(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenNotFound.Error(),
|
||||
AuthData: nil,
|
||||
}, result)
|
||||
}
|
||||
|
||||
func (s *SecureSuite) TestAuthenticate_NotExpired() {
|
||||
InsertToken(s.testDb, entity.Token{
|
||||
Token: "test_token_not_expired", AppId: 7, ExpireTime: int((time.Hour).Milliseconds()), CreatedAt: time.Now().UTC(),
|
||||
})
|
||||
|
||||
result := domain.AuthenticateResponse{}
|
||||
err := s.api.Invoke("system/secure/authenticate").
|
||||
JsonRequestBody(domain.AuthenticateRequest{
|
||||
Token: "test_token_not_expired",
|
||||
}).
|
||||
ReadJsonResponse(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Authenticated: true,
|
||||
ErrorReason: "",
|
||||
AuthData: &domain.AuthData{
|
||||
SystemId: 1,
|
||||
DomainId: 3,
|
||||
ServiceId: 5,
|
||||
ApplicationId: 7,
|
||||
},
|
||||
}, result)
|
||||
}
|
||||
|
||||
func (s *SecureSuite) TestAuthenticate_Expired() {
|
||||
InsertToken(s.testDb, entity.Token{
|
||||
Token: "test_token_expired", AppId: 7, ExpireTime: 0, CreatedAt: time.Now().UTC(),
|
||||
})
|
||||
|
||||
result := domain.AuthenticateResponse{}
|
||||
err := s.api.Invoke("system/secure/authenticate").
|
||||
JsonRequestBody(domain.AuthenticateRequest{
|
||||
Token: "test_token_expired",
|
||||
}).
|
||||
ReadJsonResponse(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenExpired.Error(),
|
||||
AuthData: nil,
|
||||
}, result)
|
||||
}
|
||||
|
||||
func (s *SecureSuite) TestAuthorize_Success_True() {
|
||||
InsertAccessList(s.testDb, entity.AccessList{
|
||||
AppId: 7,
|
||||
Method: "endpoint/available",
|
||||
Value: true,
|
||||
})
|
||||
|
||||
result := domain.AuthorizeResponse{}
|
||||
err := s.api.Invoke("system/secure/authorize").
|
||||
JsonRequestBody(domain.AuthorizeRequest{
|
||||
ApplicationId: 7,
|
||||
Endpoint: "endpoint/available",
|
||||
}).
|
||||
ReadJsonResponse(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
Authorized: true,
|
||||
}, result)
|
||||
}
|
||||
|
||||
func (s *SecureSuite) TestAuthorize_Success_False() {
|
||||
InsertAccessList(s.testDb, entity.AccessList{
|
||||
AppId: 7,
|
||||
Method: "endpoint/not_available",
|
||||
Value: false,
|
||||
})
|
||||
|
||||
result := domain.AuthorizeResponse{}
|
||||
err := s.api.Invoke("system/secure/authorize").
|
||||
JsonRequestBody(domain.AuthorizeRequest{
|
||||
ApplicationId: 7,
|
||||
Endpoint: "endpoint/not_available",
|
||||
}).
|
||||
ReadJsonResponse(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
Authorized: false,
|
||||
}, result)
|
||||
}
|
||||
|
||||
func (s *SecureSuite) TestAuthorize_NotFound() {
|
||||
result := domain.AuthorizeResponse{}
|
||||
err := s.api.Invoke("system/secure/authorize").
|
||||
JsonRequestBody(domain.AuthorizeRequest{
|
||||
ApplicationId: 7,
|
||||
Endpoint: "endpoint/not_found",
|
||||
}).
|
||||
ReadJsonResponse(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
Authorized: false,
|
||||
}, result)
|
||||
}
|
||||
@@ -45,20 +45,14 @@ func (m Manager) AccessListSetListTx(ctx context.Context, msgTx func(ctx context
|
||||
}
|
||||
|
||||
type applicationDeleteTx struct {
|
||||
repository.AccessList
|
||||
repository.Application
|
||||
repository.Token
|
||||
}
|
||||
|
||||
func (m Manager) ApplicationDeleteTx(ctx context.Context, msgTx func(ctx context.Context, tx service.IApplicationDeleteTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
accessListRep := repository.NewAccessList(tx)
|
||||
applicationRep := repository.NewApplication(tx)
|
||||
tokenRep := repository.NewToken(tx)
|
||||
return msgTx(ctx, applicationDeleteTx{
|
||||
AccessList: accessListRep,
|
||||
Application: applicationRep,
|
||||
Token: tokenRep,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user