Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1651a1fc3c | ||
|
|
882e5c67a7 | ||
|
|
d7a7e4ee0d | ||
|
|
ec0f1a02d1 | ||
|
|
65cfb65f8e | ||
|
|
c0687a264e | ||
|
|
c5b82152e0 | ||
|
|
a648f4f9a7 | ||
|
|
454526d047 | ||
|
|
6d3e1cbccd | ||
|
|
b9dcfec926 | ||
|
|
dff580b252 | ||
|
|
24e21beee2 | ||
|
|
c11d09b992 |
No files matched your search
@@ -0,0 +1,60 @@
|
||||
name: Create and publish a Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
APP_NAME: ${{ github.event.repository.name }}
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Get version from tag
|
||||
id: version_reader
|
||||
run: |
|
||||
VERSION=${GITHUB_REF_NAME#v}
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: docker-container
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and push Docker image
|
||||
id: push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_reader.outputs.version }}
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
labels: |
|
||||
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
|
||||
org.opencontainers.image.version=${{ steps.version_reader.outputs.version }}
|
||||
build-args: |
|
||||
app_name=${{ env.APP_NAME }}
|
||||
version=${{ steps.version_reader.outputs.version }}
|
||||
- name: Generate artifact attestation
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
|
||||
subject-digest: ${{ steps.push.outputs.digest }}
|
||||
push-to-registry: true
|
||||
+3
-29
@@ -1,29 +1,3 @@
|
||||
docker-build:
|
||||
image: docker:latest
|
||||
stage: build
|
||||
services:
|
||||
- docker:dind
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
script:
|
||||
- set
|
||||
- docker build -f Dockerfile.dit --force-rm --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
|
||||
- |
|
||||
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
|
||||
tag=""
|
||||
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = ':latest'"
|
||||
#docker pull "$CI_REGISTRY_IMAGE${tag}"
|
||||
#docker tag "$CI_REGISTRY_IMAGE${tag}" "$CI_REGISTRY_IMAGE:pre"
|
||||
#docker rmi "$CI_REGISTRY_IMAGE${tag}"
|
||||
#docker push "$CI_REGISTRY_IMAGE:pre"
|
||||
#docker rmi -f "$CI_REGISTRY_IMAGE:pre"
|
||||
docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" "$CI_REGISTRY_IMAGE${tag}"
|
||||
docker rmi "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
|
||||
docker push "$CI_REGISTRY_IMAGE${tag}"
|
||||
docker rmi -f "$CI_REGISTRY_IMAGE${tag}"
|
||||
else
|
||||
tag=":$CI_COMMIT_BRANCH"
|
||||
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
|
||||
fi
|
||||
after_script:
|
||||
- docker logout $CI_REGISTRY
|
||||
include:
|
||||
- project: '$CI_PROJECT_PATH'
|
||||
file: '/ci-isp-go-service.yml'
|
||||
+64
-51
@@ -1,56 +1,69 @@
|
||||
version: "2"
|
||||
run:
|
||||
allow-parallel-runners: true
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: controller #достаточное кол-во контекса на уровне контроллеров
|
||||
linters:
|
||||
- wrapcheck
|
||||
- path: transaction #транзакции прозрачны
|
||||
linters:
|
||||
- wrapcheck
|
||||
linters:
|
||||
enable-all: true
|
||||
default: all
|
||||
disable:
|
||||
- goimports #у нас собственные правила форматирования импортов
|
||||
- wsl #расставление пробелов очень индивидуально
|
||||
- exhaustivestruct #не имеет смысла
|
||||
- varnamelen #очень индивидуально (db)
|
||||
- exhaustruct #не имеет смысла
|
||||
- golint #устарел
|
||||
- contextcheck #не имеет смысла
|
||||
- gci #у нас собственные правила форматирования импортов
|
||||
- gofumpt #у нас собственные правила форматирования импортов
|
||||
- nolintlint #Goland все равно форматирует с отступом
|
||||
- nlreturn #не всегда имеет смысл
|
||||
- godot #не актуально для свагера
|
||||
- ifshort #приняли решение, что мы так не пишем if err := ...; err != nil {}
|
||||
- godox #не позволяет оставлять todo
|
||||
- maligned #аллокацией памяти для структур конфликтует с удобством их чтения
|
||||
- nosnakecase #не позволяет заводить пакеты используя snake_case
|
||||
- depguard #не всегда имеет смысл
|
||||
- dupword #не имеет смысла
|
||||
- tagalign #не всегда имеет смысл
|
||||
- musttag #у нас собственные правило: не используем теги, если работаем с пакетом isp-kit/json и с внутренними структурами(между нашими сервисами), при этом теги обязательный для всех внених для нас структур
|
||||
- perfsprint #мнимая производительность в угоду читаемости
|
||||
- gomnd #устарел
|
||||
linters-settings:
|
||||
funlen:
|
||||
lines: 80
|
||||
lll:
|
||||
line-length: 150
|
||||
cyclop:
|
||||
max-complexity: 15 #по умолчанию 10 мало
|
||||
revive:
|
||||
- contextcheck # не имеет смысла
|
||||
- depguard # не всегда имеет смысл
|
||||
- dupword # не имеет смысла
|
||||
- exhaustruct # не имеет смысла
|
||||
- godot # не актуально для swagger
|
||||
- godox # не позволяет оставлять todo
|
||||
- musttag # у нас собственное правило: не используем теги, если работаем с пакетом isp-kit/json и с внутренними структурами(между нашими сервисами), при этом теги обязательный для всех внешних для нас структур
|
||||
- nlreturn # не всегда имеет смысл
|
||||
- nolintlint # Goland все равно форматирует с отступом
|
||||
- perfsprint # мнимая производительность в угоду читаемости
|
||||
- tagalign # не всегда имеет смысл
|
||||
- varnamelen # очень индивидуально (db)
|
||||
- wsl # расставление пробелов очень индивидуально
|
||||
- wsl_v5 # расставление пробелов очень индивидуально
|
||||
settings:
|
||||
cyclop:
|
||||
max-complexity: 15 # по умолчанию 10 мало
|
||||
funlen:
|
||||
lines: 80
|
||||
lll:
|
||||
line-length: 150
|
||||
revive:
|
||||
rules:
|
||||
- name: var-naming # отключаем Id -> ID
|
||||
disabled: true
|
||||
staticcheck:
|
||||
checks: # отключаем Id -> ID
|
||||
- -ST1000
|
||||
- -ST1016
|
||||
- -ST1020
|
||||
- -ST1021
|
||||
- -ST1022
|
||||
testifylint:
|
||||
disable:
|
||||
- compares
|
||||
- equal-values
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
rules:
|
||||
- name: var-naming #отключаем Id -> ID
|
||||
disabled: true
|
||||
stylecheck:
|
||||
checks: #отключаем Id -> ID
|
||||
- "-ST1000"
|
||||
- "-ST1016"
|
||||
- "-ST1020"
|
||||
- "-ST1021"
|
||||
- "-ST1022"
|
||||
testifylint:
|
||||
disable:
|
||||
- compares
|
||||
- linters:
|
||||
- wrapcheck
|
||||
path: controller # достаточное кол-во контекста на уровне контроллеров
|
||||
- linters:
|
||||
- wrapcheck
|
||||
path: transaction # транзакции прозрачны
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
@@ -1,3 +1,27 @@
|
||||
### v5.6.0
|
||||
* Для endpoint'а `system/secure/authenticate` в ответ добавлено поле `appName` (название приложения)
|
||||
* Обновлена версия `go` до `1.25`
|
||||
* Обновлены зависимости
|
||||
### v5.5.0
|
||||
* Обновлены зависимости
|
||||
### v5.4.0
|
||||
* Добавлен новый endpoint: `/access_list/delete_list` для удаления методов из списка доступов у приложений
|
||||
### v5.3.1
|
||||
* добавлен `Dockerfile` и скрипт для сборки и публикации образа в `GitHub Contaier Registry`
|
||||
* обновлены зависимости
|
||||
### v5.3.0
|
||||
* Добавлен новый endpoint: `/application/get_application_by_token`
|
||||
### v5.2.1
|
||||
* обновлены зависимости
|
||||
### v5.2.0
|
||||
* Обновлены зависимости
|
||||
* Добавлены новые endpoint'ы: `/application/update_application`, `/application/create_application`, `/application_group/create`, `/application_group/update`, `/application_group/delete_list`, `/application_group/get_by_id_list`, `/application_group/get_all`
|
||||
### v5.1.1
|
||||
* обновлены зависимости
|
||||
### v5.1.0
|
||||
* все сервисы (группы приложений) перенесены в домен с id = 1
|
||||
* при создании/изменении сервисов (групп приложений) будет использоваться только домен с id = 1
|
||||
|
||||
### v5.0.0
|
||||
* изменен механизм инициализации токена панели администратора
|
||||
* для механизма инициализации используется поле `baseline.initialAdminUiToken` в конфигурации
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
FROM dockerhub.mos.ru/golang:1.19-alpine3.16 as builder
|
||||
WORKDIR /build
|
||||
ARG version
|
||||
ENV version_env=$version
|
||||
ARG app_name
|
||||
ENV app_name_env=$app_name
|
||||
COPY . .
|
||||
ENV GOPROXY=https://repo-mirror.mos.ru/repository/go-public
|
||||
RUN go build -ldflags="-X 'main.version=$version_env'" -o /main .
|
||||
|
||||
FROM dockerhub.mos.ru/alpine:3.16.0
|
||||
WORKDIR /app
|
||||
ARG app_name
|
||||
ENV app_name_env=$app_name
|
||||
COPY --from=builder main /app/$app_name_env
|
||||
COPY /conf/config.yml /app/config.yml
|
||||
COPY /conf/default_remote_config.json* /app/default_remote_config.json
|
||||
COPY /migrations /app/migrations
|
||||
ENTRYPOINT /app/$app_name_env
|
||||
@@ -2,8 +2,11 @@ package assembly
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/txix-open/isp-kit/rc"
|
||||
|
||||
"isp-system-service/conf"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/app"
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
@@ -12,7 +15,6 @@ import (
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-system-service/conf"
|
||||
)
|
||||
|
||||
type Assembly struct {
|
||||
@@ -23,13 +25,14 @@ type Assembly struct {
|
||||
}
|
||||
|
||||
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
||||
dbCli := dbrx.New(dbx.WithMigrationRunner(boot.MigrationsDir, boot.App.Logger()))
|
||||
logger := boot.App.Logger()
|
||||
dbCli := dbrx.New(logger, dbx.WithMigrationRunner(boot.MigrationsDir, logger))
|
||||
server := grpc.NewServer()
|
||||
return &Assembly{
|
||||
boot: boot,
|
||||
db: dbCli,
|
||||
server: server,
|
||||
logger: boot.App.Logger(),
|
||||
logger: logger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
+14
-9
@@ -1,10 +1,6 @@
|
||||
package assembly
|
||||
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/controller"
|
||||
"isp-system-service/repository"
|
||||
@@ -13,6 +9,12 @@ import (
|
||||
"isp-system-service/service/baseline"
|
||||
"isp-system-service/service/secure"
|
||||
"isp-system-service/transaction"
|
||||
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint/grpclog"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
)
|
||||
|
||||
type DB interface {
|
||||
@@ -42,18 +44,18 @@ func (l Locator) Config(cfg conf.Remote) Config {
|
||||
accessListRep := repository.NewAccessList(l.db)
|
||||
applicationRep := repository.NewApplication(l.db)
|
||||
domainRep := repository.NewDomain(l.db)
|
||||
serviceRep := repository.NewService(l.db)
|
||||
appGroupRep := repository.NewAppGroup(l.db)
|
||||
tokenRep := repository.NewToken(l.db)
|
||||
|
||||
secureService := secure.NewService(tokenRep, accessListRep)
|
||||
accessListService := service.NewAccessList(txManager, accessListRep, applicationRep)
|
||||
applicationService := service.NewApplication(txManager, applicationRep, domainRep, serviceRep, tokenRep)
|
||||
applicationService := service.NewApplication(txManager, applicationRep, domainRep, appGroupRep, tokenRep)
|
||||
domainService := service.NewDomain(domainRep)
|
||||
serviceService := service.NewService(domainRep, serviceRep)
|
||||
serviceService := service.NewService(domainRep, appGroupRep)
|
||||
|
||||
jwtService := service.NewTokenSource()
|
||||
tokenService := service.NewToken(jwtService, applicationService, txManager,
|
||||
applicationRep, domainRep, serviceRep, tokenRep,
|
||||
applicationRep, domainRep, appGroupRep, tokenRep,
|
||||
)
|
||||
|
||||
secureController := controller.NewSecure(secureService)
|
||||
@@ -63,6 +65,8 @@ func (l Locator) Config(cfg conf.Remote) Config {
|
||||
serviceController := controller.NewService(serviceService)
|
||||
tokenController := controller.NewToken(tokenService)
|
||||
|
||||
appGroupService := service.NewAppGroup(appGroupRep)
|
||||
appGroupController := controller.NewAppGroup(appGroupService)
|
||||
c := routes.Controllers{
|
||||
Secure: secureController,
|
||||
AccessList: accessListController,
|
||||
@@ -70,8 +74,9 @@ func (l Locator) Config(cfg conf.Remote) Config {
|
||||
Service: serviceController,
|
||||
Application: applicationController,
|
||||
Token: tokenController,
|
||||
AppGroup: appGroupController,
|
||||
}
|
||||
mapper := endpoint.DefaultWrapper(l.logger, endpoint.BodyLogger(l.logger))
|
||||
mapper := endpoint.DefaultWrapper(l.logger, grpclog.Log(l.logger, true))
|
||||
server := routes.Handler(mapper, c)
|
||||
|
||||
baselineService := baseline.NewService(cfg.Baseline, txManager, l.logger)
|
||||
|
||||
+83
-35
@@ -2,17 +2,20 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type AccessListService interface {
|
||||
GetById(ctx context.Context, appId int) ([]domain.MethodInfo, error)
|
||||
SetOne(ctx context.Context, request domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error)
|
||||
SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error)
|
||||
DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error
|
||||
}
|
||||
|
||||
type AccessList struct {
|
||||
@@ -26,21 +29,27 @@ func NewAccessList(service AccessListService) AccessList {
|
||||
}
|
||||
|
||||
// GetById godoc
|
||||
// @Tags accessList
|
||||
// @Summary Получить список доступности методов для приложения
|
||||
// @Description Возвращает список методов для приложения, для которых заданы настройки доступа
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity false "идентификатор приложения"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /access_list/get_by_id [POST]
|
||||
//
|
||||
// @Tags accessList
|
||||
// @Summary Получить список доступности методов для приложения
|
||||
// @Description Возвращает список методов для приложения, для которых заданы настройки доступа
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity false "идентификатор приложения"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application not found")
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -49,21 +58,27 @@ func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.
|
||||
}
|
||||
|
||||
// SetOne godoc
|
||||
// @Tags accessList
|
||||
// @Summary Настроить доступность метода для приложения
|
||||
// @Description Возвращает количество измененных строк
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetOneRequest false "объект для настройки доступа"
|
||||
// @Success 200 {object} domain.AccessListSetOneResponse "количество измененных строк"
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /access_list/set_one [POST]
|
||||
//
|
||||
// @Tags accessList
|
||||
// @Summary Настроить доступность метода для приложения
|
||||
// @Description Возвращает количество измененных строк
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetOneRequest false "объект для настройки доступа"
|
||||
// @Success 200 {object} domain.AccessListSetOneResponse "количество измененных строк"
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application not found")
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.AppId),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -72,24 +87,57 @@ func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneReque
|
||||
}
|
||||
|
||||
// SetList godoc
|
||||
// @Tags accessList
|
||||
// @Summary Настроить доступность списка методов для приложения
|
||||
// @Description Возвращает список методов для приложения, для которых заданы настройки доступа
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetListRequest false "объект настройки доступа"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /access_list/set_list [POST]
|
||||
//
|
||||
// @Tags accessList
|
||||
// @Summary Настроить доступность списка методов для приложения
|
||||
// @Description Возвращает список методов для приложения, для которых заданы настройки доступа
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetListRequest false "объект настройки доступа"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application not found")
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.AppId),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteList godoc
|
||||
//
|
||||
// @Tags accessList
|
||||
// @Summary Удалить список доступных методов для приложения
|
||||
// @Description Удаляет заданный список методов для приложения
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListDeleteListRequest false "тело запроса"
|
||||
// @Success 200 {object} any
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /access_list/delete_list [POST]
|
||||
func (c AccessList) DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error {
|
||||
err := c.service.DeleteList(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.AppId),
|
||||
err,
|
||||
)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
type AppGroupService interface {
|
||||
Create(ctx context.Context, req domain.CreateAppGroupRequest) (*domain.AppGroup, error)
|
||||
Update(ctx context.Context, req domain.UpdateAppGroupRequest) (*domain.AppGroup, error)
|
||||
DeleteList(ctx context.Context, req domain.IdListRequest) (*domain.DeleteResponse, error)
|
||||
GetByIdList(ctx context.Context, idList []int) ([]domain.AppGroup, error)
|
||||
GetAll(ctx context.Context) ([]domain.AppGroup, error)
|
||||
}
|
||||
|
||||
type AppGroup struct {
|
||||
service AppGroupService
|
||||
}
|
||||
|
||||
func NewAppGroup(service AppGroupService) AppGroup {
|
||||
return AppGroup{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// Create godoc
|
||||
//
|
||||
// @Tags application_group
|
||||
// @Summary Создать группу приложений
|
||||
// @Description Если группа приложений таким именем существует, возвращает ошибку
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.CreateAppGroupRequest true "Объект группы приложений"
|
||||
// @Success 200 {object} domain.AppGroup
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/create [POST]
|
||||
func (c AppGroup) Create(ctx context.Context, req domain.CreateAppGroupRequest) (*domain.AppGroup, error) {
|
||||
result, err := c.service.Create(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrAppGroupDuplicateName):
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeAppGroupDuplicateName,
|
||||
fmt.Sprintf("application group with name %s already exists", req.Name),
|
||||
err,
|
||||
)
|
||||
default:
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
// Update godoc
|
||||
//
|
||||
// @Tags application_group
|
||||
// @Summary Обновить группу приложений
|
||||
// @Description Если группа приложений таким именем существует или группы приложений с указанным id не существует, возвращает ошибку
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.UpdateAppGroupRequest true "Объект группы приложений"
|
||||
// @Success 200 {object} domain.AppGroup
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/update [POST]
|
||||
func (c AppGroup) Update(ctx context.Context, req domain.UpdateAppGroupRequest) (*domain.AppGroup, error) {
|
||||
result, err := c.service.Update(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrAppGroupDuplicateName):
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeAppGroupDuplicateName,
|
||||
fmt.Sprintf("application group with name %s already exists", req.Name),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrAppGroupNotFound):
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeAppGroupNotFound,
|
||||
fmt.Sprintf("application group with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
default:
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteList godoc
|
||||
//
|
||||
// @Tags application_group
|
||||
// @Summary Удалить группы приложений
|
||||
// @Description Удаляет группы приложений по списку их идентификаторов, возвращает количество удаленных групп приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.IdListRequest true "список идентификаторов групп приложений"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/delete_list [POST]
|
||||
func (c AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*domain.DeleteResponse, error) {
|
||||
return c.service.DeleteList(ctx, req)
|
||||
}
|
||||
|
||||
// GetByIdList godoc
|
||||
//
|
||||
// @Tags application_group
|
||||
// @Summary Получить группы приложений по списку идентификаторов
|
||||
// @Description Возвращает группы приложений с указанными идентификаторами
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.IdListRequest true "список идентификаторов групп приложений"
|
||||
// @Success 200 {array} domain.AppGroup
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/get_by_id_list [POST]
|
||||
func (c AppGroup) GetByIdList(ctx context.Context, req domain.IdListRequest) ([]domain.AppGroup, error) {
|
||||
return c.service.GetByIdList(ctx, req.IdList)
|
||||
}
|
||||
|
||||
// GetAll godoc
|
||||
//
|
||||
// @Tags application_group
|
||||
// @Summary Получить группы приложений
|
||||
// @Description Возвращает все группы приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.AppGroup
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/get_all [POST]
|
||||
func (c AppGroup) GetAll(ctx context.Context) ([]domain.AppGroup, error) {
|
||||
return c.service.GetAll(ctx)
|
||||
}
|
||||
+243
-67
@@ -2,20 +2,28 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
// nolint:interfacebloat
|
||||
type ApplicationService interface {
|
||||
GetById(ctx context.Context, appId int) (*domain.ApplicationWithTokens, error)
|
||||
GetByToken(ctx context.Context, token string) (*domain.GetApplicationByTokenResponse, error)
|
||||
GetByIdList(ctx context.Context, idList []int) ([]*domain.ApplicationWithTokens, error)
|
||||
GetByServiceId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error)
|
||||
SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithService, error)
|
||||
CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error)
|
||||
Delete(ctx context.Context, idList []int) (int, error)
|
||||
NextId(ctx context.Context) (int, error)
|
||||
GetAll(ctx context.Context) ([]domain.Application, error)
|
||||
Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error)
|
||||
Update(ctx context.Context, req domain.UpdateApplicationRequest) (*domain.ApplicationWithTokens, error)
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
@@ -29,22 +37,58 @@ func NewApplication(service ApplicationService) Application {
|
||||
}
|
||||
|
||||
// GetById godoc
|
||||
// @Tags application
|
||||
// @Summary Получить приложение по идентификатору
|
||||
// @Description Возвращает описание приложения по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_application_by_id [POST]
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Получить приложение по идентификатору
|
||||
// @Description Возвращает описание приложения по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.Id)
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetByToken godoc
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Получить идентификатор приложения и группы по токену
|
||||
// @Description Возвращает идентификатор приложения и группы по токену
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.GetApplicationByTokenRequest true "Тело запроса"
|
||||
// @Success 200 {object} domain.GetApplicationByTokenResponse
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_application_by_token [POST]
|
||||
func (c Application) GetByToken(ctx context.Context, req domain.GetApplicationByTokenRequest) (*domain.GetApplicationByTokenResponse, error) {
|
||||
result, err := c.service.GetByToken(ctx, req.Token)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with token '%s' not found", req.Token),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -53,68 +97,86 @@ func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.
|
||||
}
|
||||
|
||||
// GetByIdList godoc
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений
|
||||
// @Description Возвращает массив приложений с токенами по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_applications [POST]
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений
|
||||
// @Description Возвращает массив приложений с токенами по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_applications [POST]
|
||||
func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.ApplicationWithTokens, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
}
|
||||
|
||||
// GetByServiceId godoc
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений по идентификатору сервиса
|
||||
// @Description Возвращает список приложений по запрошенному идентификатору сервиса
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_applications_by_service_id [POST]
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений по идентификатору сервиса
|
||||
// @Description Возвращает список приложений по запрошенному идентификатору сервиса
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
}
|
||||
|
||||
// GetSystemTree godoc
|
||||
// @Tags application
|
||||
// @Summary Метод получения системного дерева
|
||||
// @Description Возвращает описание взаимосвязей сервисов и приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.DomainWithService
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_system_tree [POST]
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Метод получения системного дерева
|
||||
// @Description Возвращает описание взаимосвязей сервисов и приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.DomainWithService
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_system_tree [POST]
|
||||
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithService, error) {
|
||||
return c.service.SystemTree(ctx, domain.DefaultSystemId)
|
||||
}
|
||||
|
||||
// CreateUpdate godoc
|
||||
// @Tags application
|
||||
// @Summary Создать/обновить приложение
|
||||
// @Description Если приложение с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ApplicationCreateUpdateRequest true "Объект приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @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]
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Создать/обновить приложение
|
||||
// @Description Если приложение с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ApplicationCreateUpdateRequest true "Объект приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "service with id %d not found", req.ServiceId)
|
||||
case errors.Is(err, domain.ErrAppGroupNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrCodeAppGroupNotFound,
|
||||
fmt.Sprintf("service with id %d not found", req.ServiceId),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrApplicationDuplicateName):
|
||||
return nil, status.Errorf(codes.AlreadyExists, "application with name %s already exists", req.Name)
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeApplicationDuplicateName,
|
||||
fmt.Sprintf("application with name %s already exists", req.Name),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "Application with id %d not found", req.Id)
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -123,19 +185,21 @@ func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
||||
}
|
||||
|
||||
// Delete godoc
|
||||
// @Tags application
|
||||
// @Summary Удалить приложения
|
||||
// @Description Удаляет приложения по списку их идентификаторов, возвращает количество удаленных приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/delete_applications [POST]
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Удалить приложения
|
||||
// @Description Удаляет приложения по списку их идентификаторов, возвращает количество удаленных приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/delete_applications [POST]
|
||||
func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
if len(req) == 0 {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
return nil, apierrors.NewBusinessError(domain.ErrCodeInvalidRequest,
|
||||
"At least one id are required", errors.New("invalid id count"))
|
||||
}
|
||||
|
||||
result, err := c.service.Delete(ctx, req)
|
||||
@@ -147,3 +211,115 @@ func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteRespo
|
||||
Deleted: result,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NextId godoc
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Получить следующий идентификатор приложения
|
||||
// @Description Возвращает следующий идентификатор приложения
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} integer
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/next_id [POST]
|
||||
func (c Application) NextId(ctx context.Context) (int, error) {
|
||||
return c.service.NextId(ctx)
|
||||
}
|
||||
|
||||
// GetAll godoc
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений
|
||||
// @Description Возвращает список приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.Application
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_all [POST]
|
||||
func (c Application) GetAll(ctx context.Context) ([]domain.Application, error) {
|
||||
return c.service.GetAll(ctx)
|
||||
}
|
||||
|
||||
// Create godoc
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Создать приложение
|
||||
// @Description Если приложение с такими идентификатором или связкой `applicationGroupId`-`name` существует, то возвращает ошибку
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.CreateApplicationRequest true "Объект приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/create_application [POST]
|
||||
func (c Application) Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.Create(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrAppGroupNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrCodeAppGroupNotFound,
|
||||
fmt.Sprintf("application group with id %d not found", req.ApplicationGroupId),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrApplicationDuplicateName):
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeApplicationDuplicateName,
|
||||
fmt.Sprintf("application with name %s already exists", req.Name),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrApplicationDuplicateId):
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeApplicationDuplicateId,
|
||||
fmt.Sprintf("application with id %d already exists", req.Id),
|
||||
err,
|
||||
)
|
||||
default:
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
|
||||
// Update godoc
|
||||
//
|
||||
// @Tags application
|
||||
// @Summary Обновить приложение
|
||||
// @Description Если приложение с связкой `applicationGroupId`-`name` существует или приложение не найдено, то возвращает ошибку
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.UpdateApplicationRequest true "Объект приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/update_application [POST]
|
||||
func (c Application) Update(ctx context.Context, req domain.UpdateApplicationRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.Update(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.OldId),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrApplicationDuplicateName):
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeApplicationDuplicateName,
|
||||
fmt.Sprintf("application with name %s already exists", req.Name),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrApplicationDuplicateId):
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeApplicationDuplicateId,
|
||||
fmt.Sprintf("application with id %d already exists", req.NewId),
|
||||
err,
|
||||
)
|
||||
default:
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
+71
-45
@@ -2,11 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type DomainService interface {
|
||||
@@ -27,21 +29,27 @@ func NewDomain(service DomainService) Domain {
|
||||
}
|
||||
|
||||
// GetById godoc
|
||||
// @Tags domain
|
||||
// @Summary Получить домен по идентификатору
|
||||
// @Description Возвращает описание домена по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/get_domain_by_id [POST]
|
||||
//
|
||||
// @Tags domain
|
||||
// @Summary Получить домен по идентификатору
|
||||
// @Description Возвращает описание домена по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "domain with id %d not found", req.Id)
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeDomainNotFound,
|
||||
fmt.Sprintf("domain with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -50,38 +58,54 @@ func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domai
|
||||
}
|
||||
|
||||
// GetBySystemId godoc
|
||||
// @Tags domain
|
||||
// @Summary Получить домены по идентификатору системы
|
||||
// @Description Возвращает список доменов по системному идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body integer false "Идентификатор системы"
|
||||
// @Success 200 {array} domain.Domain
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/get_domains_by_system_id [POST]
|
||||
//
|
||||
// @Tags domain
|
||||
// @Summary Получить домены по идентификатору системы
|
||||
// @Description Возвращает список доменов по системному идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body integer false "Идентификатор системы"
|
||||
// @Success 200 {array} domain.Domain
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
}
|
||||
|
||||
// CreateUpdate godoc
|
||||
// @Tags domain
|
||||
// @Summary Создать/обновить домен
|
||||
// @Description Если домен с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.DomainCreateUpdateRequest true "Объект домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/create_update_domain [POST]
|
||||
//
|
||||
// @Tags domain
|
||||
// @Summary Создать/обновить домен
|
||||
// @Description Если домен с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.DomainCreateUpdateRequest true "Объект домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrSystemNotFound):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "system with id %d not found", domain.DefaultSystemId)
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrCodeSystemNotFound,
|
||||
fmt.Sprintf("system with id %d not found", domain.DefaultSystemId),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "domain with id %d not found", req.Id)
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeDomainNotFound,
|
||||
fmt.Sprintf("domain with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrDomainDuplicateName):
|
||||
return nil, status.Errorf(codes.AlreadyExists, "domain with name %s already exists", req.Name)
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeDomainDuplicateName,
|
||||
fmt.Sprintf("domain with name %s already exists", req.Name),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -90,19 +114,21 @@ func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
}
|
||||
|
||||
// Delete godoc
|
||||
// @Tags domain
|
||||
// @Summary Удаление доменов
|
||||
// @Description Удаляет домены по списку их идентификаторов, возвращает количество удаленных доменов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов доменов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /domain/delete_domains [POST]
|
||||
//
|
||||
// @Tags domain
|
||||
// @Summary Удаление доменов
|
||||
// @Description Удаляет домены по списку их идентификаторов, возвращает количество удаленных доменов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов доменов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /domain/delete_domains [POST]
|
||||
func (c Domain) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
if len(req) == 0 {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "at least one id are required")
|
||||
return nil, apierrors.NewBusinessError(domain.ErrCodeInvalidRequest,
|
||||
"At least one id are required", errors.New("invalid id count"))
|
||||
}
|
||||
|
||||
result, err := c.service.Delete(ctx, req)
|
||||
|
||||
+22
-19
@@ -3,8 +3,9 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SecureService interface {
|
||||
@@ -23,15 +24,16 @@ func NewSecure(service SecureService) Secure {
|
||||
}
|
||||
|
||||
// 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]
|
||||
//
|
||||
// @Tags secure
|
||||
// @Summary Метод аутентификации токена
|
||||
// @Description Проверяет наличие токена в системе,
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AuthenticateRequest true "Тело запроса"
|
||||
// @Success 200 {array} domain.AuthenticateResponse
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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 {
|
||||
@@ -56,15 +58,16 @@ func (c Secure) Authenticate(ctx context.Context, req domain.AuthenticateRequest
|
||||
}
|
||||
|
||||
// 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]
|
||||
//
|
||||
// @Tags secure
|
||||
// @Summary Метод авторизации приложения
|
||||
// @Description Проверяет доступ приложения к запрашиваемому ендпоинту
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.AuthorizeRequest true "Тело запрос"
|
||||
// @Success 200 {array} domain.AuthorizeResponse
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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 {
|
||||
|
||||
+87
-60
@@ -2,11 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type ServiceService interface {
|
||||
@@ -28,21 +30,27 @@ func NewService(service ServiceService) Service {
|
||||
}
|
||||
|
||||
// GetById godoc
|
||||
// @Tags service
|
||||
// @Summary Получить сервис по идентификатору
|
||||
// @Description Возвращает описание сервиса по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_service_by_id [POST]
|
||||
//
|
||||
// @Tags service
|
||||
// @Summary Получить сервис по идентификатору
|
||||
// @Description Возвращает описание сервиса по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
||||
case errors.Is(err, domain.ErrAppGroupNotFound):
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeAppGroupNotFound,
|
||||
fmt.Sprintf("service with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -51,55 +59,72 @@ func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Serv
|
||||
}
|
||||
|
||||
// Get godoc
|
||||
// @Tags service
|
||||
// @Summary Получить список сервисов
|
||||
// @Description Возвращает список сервисов по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов сервисов"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_service [POST]
|
||||
//
|
||||
// @Tags service
|
||||
// @Summary Получить список сервисов
|
||||
// @Description Возвращает список сервисов по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов сервисов"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /service/get_service [POST]
|
||||
func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
}
|
||||
|
||||
// GetByDomainId godoc
|
||||
// @Tags service
|
||||
// @Summary Получить список сервисов по идентификатору домена
|
||||
// @Description Возвращает список сервисов по идентификатору домена
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_services_by_domain_id [POST]
|
||||
//
|
||||
// @Tags service
|
||||
// @Summary Получить список сервисов по идентификатору домена
|
||||
// @Description Возвращает список сервисов по идентификатору домена
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
}
|
||||
|
||||
// CreateUpdate godoc
|
||||
// @Tags service
|
||||
// @Summary Создать/обновить сервис
|
||||
// @Description Если сервис с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ServiceCreateUpdateRequest true "Объект сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @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]
|
||||
//
|
||||
// @Tags service
|
||||
// @Summary Создать/обновить сервис
|
||||
// @Description Если сервис с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ServiceCreateUpdateRequest true "Объект сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "domain with id %d not found", req.DomainId)
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
||||
case errors.Is(err, domain.ErrServiceDuplicateName):
|
||||
return nil, status.Errorf(codes.AlreadyExists, "service with name %s already exists", req.Name)
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrCodeDomainNotFound,
|
||||
fmt.Sprintf("domain with id %d not found", req.DomainId),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrAppGroupNotFound):
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeAppGroupNotFound,
|
||||
fmt.Sprintf("service with id %d not found", req.Id),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrAppGroupDuplicateName):
|
||||
return nil, apierrors.New(
|
||||
codes.AlreadyExists,
|
||||
domain.ErrCodeAppGroupNotFound,
|
||||
fmt.Sprintf("service with name %s already exists", req.Name),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -108,19 +133,21 @@ func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdat
|
||||
}
|
||||
|
||||
// Delete godoc
|
||||
// @Tags service
|
||||
// @Summary Удалить сервисы
|
||||
// @Description Удаляет сервисов по списку их идентификаторов, возвращает количество удаленных сервисов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer true "Массив идентификаторов сервисов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/delete_service [POST]
|
||||
//
|
||||
// @Tags service
|
||||
// @Summary Удалить сервисы
|
||||
// @Description Удаляет сервисов по списку их идентификаторов, возвращает количество удаленных сервисов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer true "Массив идентификаторов сервисов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /service/delete_service [POST]
|
||||
func (c Service) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
if len(req) == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "at least one id are required")
|
||||
return nil, apierrors.NewBusinessError(domain.ErrCodeInvalidRequest,
|
||||
"At least one id are required", errors.New("invalid id count"))
|
||||
}
|
||||
|
||||
result, err := c.service.Delete(ctx, req)
|
||||
|
||||
+66
-45
@@ -2,14 +2,16 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type ITokenService interface {
|
||||
type TokenService interface {
|
||||
GetByAppId(ctx context.Context, appId int) ([]domain.Token, error)
|
||||
Create(ctx context.Context, req domain.TokenCreateRequest) (*domain.ApplicationWithTokens, error)
|
||||
Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error)
|
||||
@@ -17,48 +19,65 @@ type ITokenService interface {
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
service ITokenService
|
||||
service TokenService
|
||||
}
|
||||
|
||||
func NewToken(service ITokenService) Token {
|
||||
func NewToken(service TokenService) Token {
|
||||
return Token{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// GetByAppId godoc
|
||||
// @Tags token
|
||||
// @Summary Получить токены по идентификатору приложения
|
||||
// @Description Возвращает список токенов, привязанных к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {array} entity.Token
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/get_tokens_by_app_id [POST]
|
||||
//
|
||||
// @Tags token
|
||||
// @Summary Получить токены по идентификатору приложения
|
||||
// @Description Возвращает список токенов, привязанных к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {array} entity.Token
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
}
|
||||
|
||||
// Create godoc
|
||||
// @Tags token
|
||||
// @Summary Создать токен
|
||||
// @Description Создает токен и привязывает его к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.TokenCreateRequest true "Объект создания токена"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/create_token [POST]
|
||||
//
|
||||
// @Tags token
|
||||
// @Summary Создать токен
|
||||
// @Description Создает токен и привязывает его к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.TokenCreateRequest true "Объект создания токена"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.AppId)
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "service for app_id id %d not found", req.AppId)
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeApplicationNotFound,
|
||||
fmt.Sprintf("application with id %d not found", req.AppId),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrAppGroupNotFound):
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeAppGroupNotFound,
|
||||
fmt.Sprintf("service for app_id id %d not found", req.AppId),
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "domain for app_id %d not found", req.AppId)
|
||||
return nil, apierrors.New(
|
||||
codes.NotFound,
|
||||
domain.ErrCodeDomainNotFound,
|
||||
fmt.Sprintf("domain for app_id id %d not found", req.AppId),
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -67,29 +86,31 @@ func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
}
|
||||
|
||||
// Revoke godoc
|
||||
// @Tags token
|
||||
// @Summary Отозвать токены
|
||||
// @Description Отвязывает токены от приложений и удаляет их
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.TokenRevokeRequest true "Объект отзыва токенов"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/revoke_tokens [POST]
|
||||
//
|
||||
// @Tags token
|
||||
// @Summary Отозвать токены
|
||||
// @Description Отвязывает токены от приложений и удаляет их
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.TokenRevokeRequest true "Объект отзыва токенов"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /token/revoke_tokens [POST]
|
||||
func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error) {
|
||||
return c.service.Revoke(ctx, req)
|
||||
}
|
||||
|
||||
// RevokeForApp godoc
|
||||
// @Tags token
|
||||
// @Summary Отозвать токены для приложения
|
||||
// @Description Отвязывает токены от приложений и удаляет их по идентификатору приложения
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /token/revoke_tokens_for_app [POST]
|
||||
//
|
||||
// @Tags token
|
||||
// @Summary Отозвать токены для приложения
|
||||
// @Description Отвязывает токены от приложений и удаляет их по идентификатору приложения
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @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)
|
||||
}
|
||||
+489
-47
@@ -1,5 +1,28 @@
|
||||
basePath: /api/system
|
||||
definitions:
|
||||
apierrors.Error:
|
||||
properties:
|
||||
details:
|
||||
additionalProperties: {}
|
||||
type: object
|
||||
errorCode:
|
||||
type: integer
|
||||
errorMessage:
|
||||
type: string
|
||||
type: object
|
||||
domain.AccessListDeleteListRequest:
|
||||
properties:
|
||||
appId:
|
||||
type: integer
|
||||
methods:
|
||||
items:
|
||||
type: string
|
||||
minItems: 1
|
||||
type: array
|
||||
required:
|
||||
- appId
|
||||
- methods
|
||||
type: object
|
||||
domain.AccessListSetListRequest:
|
||||
properties:
|
||||
appId:
|
||||
@@ -30,6 +53,19 @@ definitions:
|
||||
count:
|
||||
type: integer
|
||||
type: object
|
||||
domain.AppGroup:
|
||||
properties:
|
||||
createdAt:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
||||
updatedAt:
|
||||
type: string
|
||||
type: object
|
||||
domain.Application:
|
||||
properties:
|
||||
createdAt:
|
||||
@@ -93,6 +129,8 @@ definitions:
|
||||
type: object
|
||||
domain.AuthData:
|
||||
properties:
|
||||
appName:
|
||||
type: string
|
||||
applicationId:
|
||||
type: integer
|
||||
domainId:
|
||||
@@ -133,6 +171,36 @@ definitions:
|
||||
authorized:
|
||||
type: boolean
|
||||
type: object
|
||||
domain.CreateAppGroupRequest:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
required:
|
||||
- name
|
||||
type: object
|
||||
domain.CreateApplicationRequest:
|
||||
properties:
|
||||
applicationGroupId:
|
||||
type: integer
|
||||
description:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
||||
type:
|
||||
enum:
|
||||
- SYSTEM
|
||||
- MOBILE
|
||||
type: string
|
||||
required:
|
||||
- applicationGroupId
|
||||
- id
|
||||
- name
|
||||
- type
|
||||
type: object
|
||||
domain.DeleteResponse:
|
||||
properties:
|
||||
deleted:
|
||||
@@ -177,15 +245,29 @@ definitions:
|
||||
$ref: '#/definitions/domain.ServiceWithApps'
|
||||
type: array
|
||||
type: object
|
||||
domain.GrpcError:
|
||||
domain.GetApplicationByTokenRequest:
|
||||
properties:
|
||||
details:
|
||||
items: {}
|
||||
token:
|
||||
type: string
|
||||
required:
|
||||
- token
|
||||
type: object
|
||||
domain.GetApplicationByTokenResponse:
|
||||
properties:
|
||||
applicationGroupId:
|
||||
type: integer
|
||||
applicationId:
|
||||
type: integer
|
||||
type: object
|
||||
domain.IdListRequest:
|
||||
properties:
|
||||
idList:
|
||||
items:
|
||||
type: integer
|
||||
minItems: 1
|
||||
type: array
|
||||
errorCode:
|
||||
type: string
|
||||
errorMessage:
|
||||
type: string
|
||||
required:
|
||||
- idList
|
||||
type: object
|
||||
domain.Identity:
|
||||
properties:
|
||||
@@ -275,6 +357,33 @@ definitions:
|
||||
required:
|
||||
- appId
|
||||
type: object
|
||||
domain.UpdateAppGroupRequest:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
type: object
|
||||
domain.UpdateApplicationRequest:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
newId:
|
||||
type: integer
|
||||
oldId:
|
||||
type: integer
|
||||
required:
|
||||
- name
|
||||
- newId
|
||||
- oldId
|
||||
type: object
|
||||
entity.Token:
|
||||
properties:
|
||||
appId:
|
||||
@@ -295,6 +404,34 @@ info:
|
||||
title: isp-system-service
|
||||
version: 1.0.0
|
||||
paths:
|
||||
/access_list/delete_list:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Удаляет заданный список методов для приложения
|
||||
parameters:
|
||||
- description: тело запроса
|
||||
in: body
|
||||
name: body
|
||||
schema:
|
||||
$ref: '#/definitions/domain.AccessListDeleteListRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema: {}
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Удалить список доступных методов для приложения
|
||||
tags:
|
||||
- accessList
|
||||
/access_list/get_by_id:
|
||||
post:
|
||||
consumes:
|
||||
@@ -319,11 +456,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить список доступности методов для приложения
|
||||
tags:
|
||||
- accessList
|
||||
@@ -351,11 +488,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Настроить доступность списка методов для приложения
|
||||
tags:
|
||||
- accessList
|
||||
@@ -380,14 +517,49 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Настроить доступность метода для приложения
|
||||
tags:
|
||||
- accessList
|
||||
/application/create_application:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Если приложение с такими идентификатором или связкой `applicationGroupId`-`name`
|
||||
существует, то возвращает ошибку
|
||||
parameters:
|
||||
- description: Объект приложения
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.CreateApplicationRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ApplicationWithTokens'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Создать приложение
|
||||
tags:
|
||||
- application
|
||||
/application/create_update_application:
|
||||
post:
|
||||
consumes:
|
||||
@@ -411,19 +583,19 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Создать/обновить приложение
|
||||
tags:
|
||||
- application
|
||||
@@ -451,14 +623,35 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Удалить приложения
|
||||
tags:
|
||||
- application
|
||||
/application/get_all:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает список приложений
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.Application'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить список приложений
|
||||
tags:
|
||||
- application
|
||||
/application/get_application_by_id:
|
||||
post:
|
||||
consumes:
|
||||
@@ -481,18 +674,52 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить приложение по идентификатору
|
||||
tags:
|
||||
- application
|
||||
/application/get_application_by_token:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает идентификатор приложения и группы по токену
|
||||
parameters:
|
||||
- description: Тело запроса
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GetApplicationByTokenRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GetApplicationByTokenResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить идентификатор приложения и группы по токену
|
||||
tags:
|
||||
- application
|
||||
/application/get_applications:
|
||||
post:
|
||||
consumes:
|
||||
@@ -518,7 +745,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить список приложений
|
||||
tags:
|
||||
- application
|
||||
@@ -546,7 +773,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить список приложений по идентификатору сервиса
|
||||
tags:
|
||||
- application
|
||||
@@ -567,10 +794,225 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Метод получения системного дерева
|
||||
tags:
|
||||
- application
|
||||
/application/next_id:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает следующий идентификатор приложения
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
type: integer
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить следующий идентификатор приложения
|
||||
tags:
|
||||
- application
|
||||
/application/update_application:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Если приложение с связкой `applicationGroupId`-`name` существует
|
||||
или приложение не найдено, то возвращает ошибку
|
||||
parameters:
|
||||
- description: Объект приложения
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.UpdateApplicationRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ApplicationWithTokens'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Обновить приложение
|
||||
tags:
|
||||
- application
|
||||
/application_group/create:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Если группа приложений таким именем существует, возвращает ошибку
|
||||
parameters:
|
||||
- description: Объект группы приложений
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.CreateAppGroupRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.AppGroup'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Создать группу приложений
|
||||
tags:
|
||||
- application_group
|
||||
/application_group/delete_list:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Удаляет группы приложений по списку их идентификаторов, возвращает
|
||||
количество удаленных групп приложений
|
||||
parameters:
|
||||
- description: список идентификаторов групп приложений
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.IdListRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Удалить группы приложений
|
||||
tags:
|
||||
- application_group
|
||||
/application_group/get_all:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает все группы приложений
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.AppGroup'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить группы приложений
|
||||
tags:
|
||||
- application_group
|
||||
/application_group/get_by_id_list:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает группы приложений с указанными идентификаторами
|
||||
parameters:
|
||||
- description: список идентификаторов групп приложений
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.IdListRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.AppGroup'
|
||||
type: array
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить группы приложений по списку идентификаторов
|
||||
tags:
|
||||
- application_group
|
||||
/application_group/update:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Если группа приложений таким именем существует или группы приложений
|
||||
с указанным id не существует, возвращает ошибку
|
||||
parameters:
|
||||
- description: Объект группы приложений
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.UpdateAppGroupRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.AppGroup'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Обновить группу приложений
|
||||
tags:
|
||||
- application_group
|
||||
/domain/create_update_domain:
|
||||
post:
|
||||
consumes:
|
||||
@@ -594,7 +1036,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Создать/обновить домен
|
||||
tags:
|
||||
- domain
|
||||
@@ -622,11 +1064,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Удаление доменов
|
||||
tags:
|
||||
- domain
|
||||
@@ -652,11 +1094,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить домен по идентификатору
|
||||
tags:
|
||||
- domain
|
||||
@@ -683,7 +1125,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить домены по идентификатору системы
|
||||
tags:
|
||||
- domain
|
||||
@@ -711,7 +1153,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Метод аутентификации токена
|
||||
tags:
|
||||
- secure
|
||||
@@ -739,7 +1181,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Метод авторизации приложения
|
||||
tags:
|
||||
- secure
|
||||
@@ -766,19 +1208,19 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"409":
|
||||
description: Conflict
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Создать/обновить сервис
|
||||
tags:
|
||||
- service
|
||||
@@ -807,11 +1249,11 @@ paths:
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Удалить сервисы
|
||||
tags:
|
||||
- service
|
||||
@@ -840,7 +1282,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить список сервисов
|
||||
tags:
|
||||
- service
|
||||
@@ -866,11 +1308,11 @@ paths:
|
||||
"404":
|
||||
description: Not Found
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить сервис по идентификатору
|
||||
tags:
|
||||
- service
|
||||
@@ -898,7 +1340,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить список сервисов по идентификатору домена
|
||||
tags:
|
||||
- service
|
||||
@@ -924,7 +1366,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Создать токен
|
||||
tags:
|
||||
- token
|
||||
@@ -952,7 +1394,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Получить токены по идентификатору приложения
|
||||
tags:
|
||||
- token
|
||||
@@ -978,7 +1420,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Отозвать токены
|
||||
tags:
|
||||
- token
|
||||
@@ -1005,7 +1447,7 @@ paths:
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GrpcError'
|
||||
$ref: '#/definitions/apierrors.Error'
|
||||
summary: Отозвать токены для приложения
|
||||
tags:
|
||||
- token
|
||||
|
||||
@@ -20,3 +20,8 @@ type MethodInfo struct {
|
||||
Method string
|
||||
Value bool
|
||||
}
|
||||
|
||||
type AccessListDeleteListRequest struct {
|
||||
AppId int `validate:"required"`
|
||||
Methods []string `validate:"required,min=1"`
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type AppGroup struct {
|
||||
Id int
|
||||
Name string
|
||||
Description string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type CreateAppGroupRequest struct {
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
}
|
||||
|
||||
type UpdateAppGroupRequest struct {
|
||||
Id int `validate:"required"`
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
}
|
||||
|
||||
type IdListRequest struct {
|
||||
IdList []int `validate:"required,min=1"`
|
||||
}
|
||||
@@ -4,6 +4,11 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ApplicationSystemType = "SYSTEM"
|
||||
ApplicationMobileType = "MOBILE"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
Id int
|
||||
Name string
|
||||
@@ -34,3 +39,27 @@ type ApplicationSimple struct {
|
||||
Type string
|
||||
Tokens []Token
|
||||
}
|
||||
|
||||
type CreateApplicationRequest struct {
|
||||
Id int `validate:"required"`
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
ApplicationGroupId int `validate:"required"`
|
||||
Type string `validate:"required,oneof=SYSTEM MOBILE"`
|
||||
}
|
||||
|
||||
type UpdateApplicationRequest struct {
|
||||
OldId int `validate:"required"`
|
||||
NewId int `validate:"required"`
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
}
|
||||
|
||||
type GetApplicationByTokenRequest struct {
|
||||
Token string `validate:"required"`
|
||||
}
|
||||
|
||||
type GetApplicationByTokenResponse struct {
|
||||
ApplicationId int
|
||||
ApplicationGroupId int
|
||||
}
|
||||
+18
-2
@@ -4,17 +4,33 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrCodeInvalidRequest = 600
|
||||
|
||||
ErrCodeApplicationNotFound = 602
|
||||
ErrCodeApplicationDuplicateName = 603
|
||||
ErrCodeApplicationDuplicateId = 604
|
||||
|
||||
ErrCodeAppGroupNotFound = 605
|
||||
ErrCodeAppGroupDuplicateName = 606
|
||||
|
||||
ErrCodeSystemNotFound = 607
|
||||
ErrCodeDomainNotFound = 608
|
||||
ErrCodeDomainDuplicateName = 609
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDomainNotFound = errors.New("domain not found")
|
||||
ErrDomainDuplicateName = errors.New("domain name already exist")
|
||||
|
||||
ErrServiceNotFound = errors.New("service not found")
|
||||
ErrServiceDuplicateName = errors.New("service name already exist")
|
||||
ErrAppGroupNotFound = errors.New("application group not found")
|
||||
ErrAppGroupDuplicateName = errors.New("application group name already exist")
|
||||
|
||||
ErrSystemNotFound = errors.New("system not found")
|
||||
|
||||
ErrApplicationNotFound = errors.New("application not found")
|
||||
ErrApplicationDuplicateName = errors.New("application name already exist")
|
||||
ErrApplicationDuplicateId = errors.New("application id already exist")
|
||||
|
||||
ErrTokenNotFound = errors.New("token not found")
|
||||
ErrTokenExpired = errors.New("token is expired")
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package domain
|
||||
|
||||
type GrpcError struct {
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
ErrorCode string `json:"errorCode"`
|
||||
Details []interface{} `json:"details"`
|
||||
}
|
||||
@@ -11,6 +11,7 @@ type AuthenticateResponse struct {
|
||||
}
|
||||
|
||||
type AuthData struct {
|
||||
AppName string
|
||||
SystemId int
|
||||
DomainId int
|
||||
ServiceId int
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
type AppGroup struct {
|
||||
Id int
|
||||
Name string
|
||||
Description *string
|
||||
Description sql.NullString
|
||||
DomainId int
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
@@ -1,15 +1,16 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
Id int
|
||||
Name string
|
||||
Description *string
|
||||
ServiceId int
|
||||
Type string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Id int
|
||||
Name string
|
||||
Description sql.NullString
|
||||
ApplicationGroupId int
|
||||
Type string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
+7
-6
@@ -12,10 +12,11 @@ type Token struct {
|
||||
}
|
||||
|
||||
type AuthData struct {
|
||||
SystemId int
|
||||
DomainId int
|
||||
ServiceId int
|
||||
AppId int
|
||||
ExpireTime int
|
||||
CreatedAt time.Time
|
||||
AppName string
|
||||
SystemId int
|
||||
DomainId int
|
||||
ApplicationGroupId int
|
||||
AppId int
|
||||
ExpireTime int
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -1,80 +1,82 @@
|
||||
module isp-system-service
|
||||
|
||||
go 1.22
|
||||
go 1.25
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.5.4
|
||||
github.com/jackc/pgx/v5 v5.7.6
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/txix-open/isp-kit v1.38.1
|
||||
github.com/txix-open/jsonschema v1.2.0
|
||||
google.golang.org/grpc v1.66.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/txix-open/isp-kit v1.62.0
|
||||
github.com/txix-open/jsonschema v1.3.0
|
||||
google.golang.org/grpc v1.75.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bahlo/generic-list-go v0.2.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/coder/websocket v1.8.12 // indirect
|
||||
github.com/coder/websocket v1.8.14 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
||||
github.com/getsentry/sentry-go v0.28.1 // indirect
|
||||
github.com/go-faker/faker/v4 v4.4.2 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
|
||||
github.com/getsentry/sentry-go v0.35.2 // indirect
|
||||
github.com/go-faker/faker/v4 v4.6.1 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
|
||||
github.com/iancoleman/strcase v0.3.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jmoiron/sqlx v1.4.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mailru/easyjson v0.9.0 // indirect
|
||||
github.com/mfridman/interpolate v0.0.2 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/pressly/goose/v3 v3.21.1 // indirect
|
||||
github.com/prometheus/client_golang v1.19.1 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.55.0 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/pressly/goose/v3 v3.25.0 // indirect
|
||||
github.com/prometheus/client_golang v1.23.2 // indirect
|
||||
github.com/prometheus/client_model v0.6.2 // indirect
|
||||
github.com/prometheus/common v0.66.1 // indirect
|
||||
github.com/prometheus/procfs v0.17.0 // indirect
|
||||
github.com/sethvargo/go-retry v0.3.0 // indirect
|
||||
github.com/txix-open/bellows v1.2.0 // indirect
|
||||
github.com/txix-open/etp/v3 v3.2.0 // indirect
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 // indirect
|
||||
github.com/txix-open/etp/v4 v4.0.1 // indirect
|
||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb // indirect
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||
go.opentelemetry.io/otel v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.28.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.0 // indirect
|
||||
go.opentelemetry.io/otel v1.38.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.38.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.38.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.8.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/crypto v0.26.0 // indirect
|
||||
golang.org/x/net v0.28.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.24.0 // indirect
|
||||
golang.org/x/text v0.17.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||
golang.org/x/crypto v0.42.0 // indirect
|
||||
golang.org/x/net v0.44.0 // indirect
|
||||
golang.org/x/sync v0.17.0 // indirect
|
||||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.29.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 // indirect
|
||||
google.golang.org/protobuf v1.36.9 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
@@ -10,28 +10,28 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
|
||||
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
|
||||
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
||||
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
|
||||
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
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/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
|
||||
github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k=
|
||||
github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
|
||||
github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||
github.com/getsentry/sentry-go v0.35.2 h1:jKuujpRwa8FFRYMIwwZpu83Xh0voll9bmvyc6310WBM=
|
||||
github.com/getsentry/sentry-go v0.35.2/go.mod h1:mdL49ixwT2yi57k5eh7mpnDyPybixPzlzEJFu0Z76QA=
|
||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||
github.com/go-faker/faker/v4 v4.4.2 h1:96WeU9QKEqRUVYdjHquY2/5bAqmVM0IfGKHV5mbfqmQ=
|
||||
github.com/go-faker/faker/v4 v4.4.2/go.mod h1:4K3v4AbKXYNHMQNaREMc9/kRB9j5JJzpFo6KHRvrcIw=
|
||||
github.com/go-faker/faker/v4 v4.6.1 h1:xUyVpAjEtB04l6XFY0V/29oR332rOSPWV4lU8RwDt4k=
|
||||
github.com/go-faker/faker/v4 v4.6.1/go.mod h1:arSdxNCSt7mOhdk8tEolvHeIJ7eX4OX80wXjKKvkKBY=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
@@ -40,36 +40,42 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
|
||||
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 h1:CWyXh/jylQWp2dtiV33mY4iSSp6yf4lmn+c7/tN+ObI=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0/go.mod h1:nCLIt0w3Ept2NwF8ThLmrppXsfT07oC8k0XNDxd8sVU=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
|
||||
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
||||
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
||||
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
||||
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
|
||||
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
|
||||
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
|
||||
@@ -78,8 +84,8 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
|
||||
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
@@ -103,22 +109,22 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pressly/goose/v3 v3.21.1 h1:5SSAKKWej8LVVzNLuT6KIvP1eFDuPvxa+B6H0w78buQ=
|
||||
github.com/pressly/goose/v3 v3.21.1/go.mod h1:sqthmzV8PitchEkjecFJII//l43dLOCzfWh8pHEe+vE=
|
||||
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
|
||||
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
|
||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
|
||||
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
|
||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||
github.com/pressly/goose/v3 v3.25.0 h1:6WeYhMWGRCzpyd89SpODFnCBCKz41KrVbRT58nVjGng=
|
||||
github.com/pressly/goose/v3 v3.25.0/go.mod h1:4hC1KrritdCxtuFsqgs1R4AU5bWtTAf+cnWvfhf2DNY=
|
||||
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
|
||||
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
|
||||
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
||||
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
|
||||
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
|
||||
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
|
||||
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
|
||||
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
|
||||
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
|
||||
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
|
||||
github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
@@ -131,20 +137,21 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
|
||||
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
|
||||
github.com/txix-open/etp/v3 v3.2.0 h1:EgTchT8VtCYV1iEo/y4jII3/NybrXiQDE0y6pmS350M=
|
||||
github.com/txix-open/etp/v3 v3.2.0/go.mod h1:lgen0TJmiturgBhvlxH1/PQ7iLL/OebKbxPAQYkuKI0=
|
||||
github.com/txix-open/grmq v1.6.0 h1:V4QRb0sI2CMfdMaMsFGvGvUIDGad5vr3khNU7A3LlP8=
|
||||
github.com/txix-open/grmq v1.6.0/go.mod h1:s+NNNv42+32yLpjvl2tpqtyBbMB9e7kKFee3lfa/dyo=
|
||||
github.com/txix-open/isp-kit v1.38.1 h1:IYsiW2xc06//xQsWcHX9A1GXCGTXQRXbUqotcxa6eDY=
|
||||
github.com/txix-open/isp-kit v1.38.1/go.mod h1:uVn5y71Rg8jlFjFK3+QCh9uw1O7mcK+1grCNFZRWhME=
|
||||
github.com/txix-open/jsonschema v1.2.0 h1:B8TrdSsPhDvYv67oi/LVqf7/+PuqFlMsNwUzGeHfl1s=
|
||||
github.com/txix-open/jsonschema v1.2.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 h1:Z0Sqf+U+Sc6hfIXtRCIZlbJprkCjwMFbS4ZbEPQ44To=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99/go.mod h1:pA0NYmhL0uEkkxj55S+S7MZU4e2QIt46x9XSrzrWc3c=
|
||||
github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA=
|
||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
||||
github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM=
|
||||
github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
|
||||
github.com/txix-open/isp-kit v1.62.0 h1:SfY8x5/3yYEicr5phGTJBaUwFvgktSIsD/NubrKYbg4=
|
||||
github.com/txix-open/isp-kit v1.62.0/go.mod h1:hyCFmWF0qoVY2loTLyHJx8QPZJuULntG0JfthqFCdsA=
|
||||
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
|
||||
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb/go.mod h1:0biAFE0bgbcKeBBAwgEDhbZz6uT1vuSETCrFQlv2RiA=
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
@@ -154,44 +161,56 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
|
||||
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03ymgYhPKmeXGk5Zu+cIZOlVzd9Zv7QIiyItjFBU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk=
|
||||
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
|
||||
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
|
||||
go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE=
|
||||
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
|
||||
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
|
||||
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
go.opentelemetry.io/auto/sdk v1.2.0 h1:YpRtUFjvhSymycLS2T81lT6IGhcUP+LUPtv0iv1N8bM=
|
||||
go.opentelemetry.io/auto/sdk v1.2.0/go.mod h1:1deq2zL7rwjwC8mR7XgY2N+tlIl6pjmEUoLDENMEzwk=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.63.0 h1:2pn7OzMewmYRiNtv1doZnLo3gONcnMHlFnmOR8Vgt+8=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.63.0/go.mod h1:rjbQTDEPQymPE0YnRQp9/NuPwwtL0sesz/fnqRW/v84=
|
||||
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
|
||||
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 h1:GqRJVj7UmLjCVyVJ3ZFLdPRmhDUp2zFmQe3RHIOsw24=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0/go.mod h1:ri3aaHSmCTVYu2AWv44YMauwAQc0aqI9gHKIcSbI1pU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 h1:aTL7F04bJHUlztTsNGJ2l+6he8c+y/b//eR0jjjemT4=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0/go.mod h1:kldtb7jDTeol0l3ewcmd8SDvx3EmIE7lyvqbasU3QC4=
|
||||
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
|
||||
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
|
||||
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
|
||||
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
|
||||
go.opentelemetry.io/proto/otlp v1.8.0 h1:fRAZQDcAFHySxpJ1TwlA1cJ4tvcrw7nXl9xWWC8N5CE=
|
||||
go.opentelemetry.io/proto/otlp v1.8.0/go.mod h1:tIeYOeNBU4cvmPqpaji1P+KbB4Oloai8wN4rWzRrFF0=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 h1:+/tmTy5zAieooKIXfzDm9KiA3Bv6JBwriRN9LY+yayk=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988/go.mod h1:4+X6GvPs+25wZKbQq9qyAXrwIRExv7w0Ea6MgZLZiDM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 h1:V71AcdLZr2p8dC9dbOIMCpqi4EmRl8wUwnJzXXLmbmc=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
|
||||
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c=
|
||||
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
|
||||
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
|
||||
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
||||
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
||||
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
|
||||
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
|
||||
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
|
||||
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
||||
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
|
||||
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090 h1:d8Nakh1G+ur7+P3GcMjpRDEkoLUcLW2iU92XVqR+XMQ=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090/go.mod h1:U8EXRNSd8sUYyDfs/It7KVWodQr+Hf9xtxyxWudSwEw=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 h1:/OQuEa4YWtDt7uQWHd3q3sUMb+QOLQUg1xa8CEsRv5w=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090/go.mod h1:GmFNa4BdJZ2a8G+wCe9Bg3wwThLrJun751XstdJt5Og=
|
||||
google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
|
||||
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
|
||||
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
|
||||
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
@@ -200,17 +219,11 @@ gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYs
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/libc v1.41.0 h1:g9YAc6BkKlgORsUWj+JwqoB1wU3o4DE3bM3yvA3k+Gk=
|
||||
modernc.org/libc v1.41.0/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
|
||||
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
|
||||
modernc.org/sqlite v1.29.6 h1:0lOXGrycJPptfHDuohfYgNqoe4hu+gYuN/pKgY5XjS4=
|
||||
modernc.org/sqlite v1.29.6/go.mod h1:S02dvcmm7TnTRvGhv8IGYyLnIt7AS2KPaB1F/71p75U=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
modernc.org/libc v1.66.3 h1:cfCbjTUcdsKyyZZfEUKfoHcP3S0Wkvz3jgSzByEWVCQ=
|
||||
modernc.org/libc v1.66.3/go.mod h1:XD9zO8kt59cANKvHPXpx7yS2ELPheAey0vjIuZOhOU8=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/sqlite v1.38.2 h1:Aclu7+tgjgcQVShZqim41Bbw9Cho0y/7WzYptXqkEek=
|
||||
modernc.org/sqlite v1.38.2/go.mod h1:cPTJYSlgg3Sfg046yBShXENNtPrWrDX8bsbAQBzgQ5E=
|
||||
@@ -1,28 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
"github.com/txix-open/isp-kit/shutdown"
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/routes"
|
||||
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
"github.com/txix-open/isp-kit/shutdown"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "1.0.0"
|
||||
)
|
||||
|
||||
// @title isp-system-service
|
||||
// @version 1.0.0
|
||||
// @description Сервис управления реестром внешних приложений и токенами аутентификации
|
||||
// @title isp-system-service
|
||||
// @version 1.0.0
|
||||
// @description Сервис управления реестром внешних приложений и токенами аутентификации
|
||||
|
||||
// @license.name GNU GPL v3.0
|
||||
// @license.name GNU GPL v3.0
|
||||
|
||||
// @host localhost:9000
|
||||
// @BasePath /api/system
|
||||
// @host localhost:9000
|
||||
// @BasePath /api/system
|
||||
|
||||
//go:generate swag init --parseDependency
|
||||
//go:generate rm -f docs/swagger.json
|
||||
//go:generate rm -f docs/swagger.json docs/docs.go
|
||||
func main() {
|
||||
boot := bootstrap.New(version, conf.Remote{}, routes.EndpointDescriptors())
|
||||
app := boot.App
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- +goose Up
|
||||
update service set domain_id = 1, updated_at = now();
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE application ALTER COLUMN id DROP DEFAULT;
|
||||
|
||||
DROP SEQUENCE application_id_seq;
|
||||
|
||||
ALTER TABLE service RENAME TO application_group;
|
||||
|
||||
ALTER TABLE application
|
||||
RENAME COLUMN service_id TO application_group_id;
|
||||
|
||||
ALTER INDEX uq_name_service_id
|
||||
RENAME TO uq_name_application_group_id;
|
||||
|
||||
ALTER TABLE application
|
||||
RENAME CONSTRAINT "fk_service_id__domain_id" TO "fk_application_group_id";
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE application
|
||||
RENAME CONSTRAINT "fk_application_group_id" TO "fk_service_id__domain_id";
|
||||
|
||||
ALTER INDEX uq_name_application_group_id
|
||||
RENAME TO uq_name_service_id;
|
||||
|
||||
ALTER TABLE application
|
||||
RENAME COLUMN application_group_id TO service_id;
|
||||
|
||||
ALTER TABLE application_group RENAME TO service;
|
||||
|
||||
CREATE SEQUENCE application_id_seq;
|
||||
|
||||
SELECT setval(
|
||||
'application_id_seq', COALESCE(
|
||||
(
|
||||
SELECT MAX(id)
|
||||
FROM isp_system_service.application
|
||||
), 1
|
||||
)
|
||||
);
|
||||
|
||||
ALTER TABLE application
|
||||
ALTER COLUMN id
|
||||
SET DEFAULT nextval('application_id_seq');
|
||||
+14
-13
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type AccessList struct {
|
||||
@@ -30,14 +31,14 @@ func (r AccessList) GetAccessListByAppIdAndMethod(ctx context.Context, appId int
|
||||
`
|
||||
result := entity.AccessList{}
|
||||
err := r.db.SelectRow(ctx, &result, q, appId, method)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrAccessListNotFound
|
||||
}
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrAccessListNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error) {
|
||||
@@ -68,7 +69,7 @@ func (r AccessList) GetAccessListByAppIdList(ctx context.Context, appIdList []in
|
||||
result := make([]entity.AccessList, 0)
|
||||
err = r.db.Select(ctx, &result, q, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -88,7 +89,7 @@ func (r AccessList) InsertArrayAccessList(ctx context.Context, entity []entity.A
|
||||
|
||||
_, err = r.db.Exec(ctx, q, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "exec db")
|
||||
return errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -105,7 +106,7 @@ func (r AccessList) UpsertAccessList(ctx context.Context, e entity.AccessList) (
|
||||
`
|
||||
result, err := r.db.Exec(ctx, q, e.AppId, e.Method, e.Value)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "exec db")
|
||||
return 0, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
@@ -146,7 +147,7 @@ func (r AccessList) DeleteAccessListByAppId(ctx context.Context, appId int) ([]e
|
||||
result := make([]entity.AccessList, 0)
|
||||
err := r.db.Select(ctx, &result, q, appId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
)
|
||||
|
||||
type AppGroup struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewAppGroup(db db.DB) AppGroup {
|
||||
return AppGroup{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupById(ctx context.Context, id int) (*entity.AppGroup, error) {
|
||||
q := `
|
||||
SELECT id, name, description, domain_id, created_at, updated_at
|
||||
FROM application_group
|
||||
WHERE id = $1
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id)
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrAppGroupNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupByIdList(ctx context.Context, idList []int) ([]entity.AppGroup, error) {
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("application_group").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
OrderBy("created_at DESC").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.AppGroup, 0)
|
||||
err = r.db.Select(ctx, &result, q, arg...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupByDomainId(ctx context.Context, domainIdList []int) ([]entity.AppGroup, error) {
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("application_group").
|
||||
Where(squirrel.Eq{"domain_id": domainIdList}).
|
||||
OrderBy("created_at DESC").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.AppGroup, 0)
|
||||
err = r.db.Select(ctx, &result, q, arg...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.AppGroup, error) {
|
||||
q := `
|
||||
SELECT id, name, description, domain_id, created_at, updated_at
|
||||
FROM application_group
|
||||
WHERE name = $1 AND domain_id = $2
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, domainId)
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrAppGroupNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r AppGroup) CreateAppGroup(ctx context.Context, name string, desc string, domainId int) (*entity.AppGroup, error) {
|
||||
q := `
|
||||
INSERT INTO application_group
|
||||
(name, description, domain_id)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (name, domain_id) DO NOTHING
|
||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, desc, domainId)
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrAppGroupDuplicateName
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r AppGroup) UpdateAppGroup(ctx context.Context, id int, name string, description string) (*entity.AppGroup, error) {
|
||||
q := `
|
||||
UPDATE application_group
|
||||
SET name = $1, description = $2
|
||||
WHERE id = $3
|
||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, description, id)
|
||||
var pgErr *pgconn.PgError
|
||||
switch {
|
||||
case errors.As(err, &pgErr) && pgErr.ConstraintName == applicationGroupUniqueNameConstraint:
|
||||
return nil, domain.ErrAppGroupDuplicateName
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrAppGroupNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r AppGroup) DeleteAppGroup(ctx context.Context, idList []int) (int, error) {
|
||||
q, args, err := query.New().
|
||||
Delete("application_group").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "build query")
|
||||
}
|
||||
|
||||
result, err := r.db.Exec(ctx, q, args...)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "get rows affected")
|
||||
}
|
||||
|
||||
return int(rowsAffected), nil
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAllAppGroups(ctx context.Context) ([]entity.AppGroup, error) {
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("application_group").
|
||||
OrderBy("created_at DESC").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.AppGroup, 0)
|
||||
err = r.db.Select(ctx, &result, q, arg...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
+130
-37
@@ -4,12 +4,14 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
@@ -24,25 +26,25 @@ func NewApplication(db db.DB) Application {
|
||||
|
||||
func (r Application) GetApplicationById(ctx context.Context, id int) (*entity.Application, error) {
|
||||
q := `
|
||||
SELECT id, name, description, service_id, type, created_at, updated_at
|
||||
SELECT id, name, description, application_group_id, type, created_at, updated_at
|
||||
FROM application
|
||||
WHERE id = $1
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrApplicationNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrApplicationNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Application) GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error) {
|
||||
q, args, err := query.New().
|
||||
Select("id", "name", "description", "service_id", "type", "created_at", "updated_at").
|
||||
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||
From("application").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
OrderBy("created_at DESC").
|
||||
@@ -54,81 +56,107 @@ func (r Application) GetApplicationByIdList(ctx context.Context, idList []int) (
|
||||
result := make([]entity.Application, 0)
|
||||
err = r.db.Select(ctx, &result, q, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Application) GetApplicationByServiceIdList(ctx context.Context, serviceIdList []int) ([]entity.Application, error) {
|
||||
func (r Application) GetApplicationByAppGroupIdList(ctx context.Context, appGroupIdList []int) ([]entity.Application, error) {
|
||||
q, args, err := query.New().
|
||||
Select("id", "name", "description", "service_id", "type", "created_at", "updated_at").
|
||||
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||
From("application").
|
||||
Where(squirrel.Eq{"service_id": serviceIdList}).
|
||||
Where(squirrel.Eq{"application_group_id": appGroupIdList}).
|
||||
OrderBy("created_at DESC").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
result := make([]entity.Application, 0)
|
||||
err = r.db.Select(ctx, &result, q, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Application) GetApplicationByNameAndServiceId(ctx context.Context, name string, serviceId int) (*entity.Application, error) {
|
||||
func (r Application) GetApplicationByNameAndAppGroupId(ctx context.Context, name string, serviceId int) (*entity.Application, error) {
|
||||
q := `
|
||||
SELECT id, name, description, service_id, type, created_at, updated_at
|
||||
SELECT id, name, description, application_group_id, type, created_at, updated_at
|
||||
FROM application
|
||||
WHERE name = $1 AND service_id = $2
|
||||
WHERE name = $1 AND application_group_id = $2
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, serviceId)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
return nil, errors.WithMessagef(err, "select row db")
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, nil // nolint:nilnil
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Application) CreateApplication(ctx context.Context, name string, desc string, serviceId int, appType string) (
|
||||
func (r Application) CreateApplication(ctx context.Context, id int, name string, desc string, appGroupId int, appType string) (
|
||||
*entity.Application, error) {
|
||||
q := `
|
||||
INSERT INTO application
|
||||
(name, description, service_id, type)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, name, description, service_id, type, created_at, updated_at
|
||||
(id, name, description, application_group_id, type)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, desc, serviceId, appType)
|
||||
err := r.db.SelectRow(ctx, &result, q, id, name, desc, appGroupId, appType)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select row db")
|
||||
return nil, r.handleCreateError(err, q)
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Application) UpdateApplication(ctx context.Context, id int, name string, description string) (*entity.Application, error) {
|
||||
func (r Application) UpdateApplication(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
name string,
|
||||
description string,
|
||||
) (*entity.Application, error) {
|
||||
q := `
|
||||
UPDATE application
|
||||
SET name = $2,
|
||||
description = $3
|
||||
WHERE id = $1
|
||||
RETURNING id, name, description, service_id, type, created_at, updated_at
|
||||
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id, name, description)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select row db")
|
||||
return nil, r.handleUpdateError(err, q)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Application) UpdateApplicationWithNewId(
|
||||
ctx context.Context,
|
||||
oldId int,
|
||||
newId int,
|
||||
name string,
|
||||
description string,
|
||||
) (*entity.Application, error) {
|
||||
q := `
|
||||
UPDATE application
|
||||
SET id = $2,
|
||||
name = $3,
|
||||
description = $4
|
||||
WHERE id = $1
|
||||
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, oldId, newId, name, description)
|
||||
if err != nil {
|
||||
return nil, r.handleUpdateError(err, q)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
@@ -153,3 +181,68 @@ func (r Application) DeleteApplicationByIdList(ctx context.Context, idList []int
|
||||
|
||||
return int(rowsAffected), nil
|
||||
}
|
||||
|
||||
func (r Application) NextApplicationId(ctx context.Context) (int, error) {
|
||||
q := `SELECT COALESCE(MAX(id)+1, 1) FROM application;`
|
||||
nextAppId := 0
|
||||
err := r.db.SelectRow(ctx, &nextAppId, q)
|
||||
if err != nil {
|
||||
return -1, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
return nextAppId, nil
|
||||
}
|
||||
|
||||
func (r Application) GetAllApplications(ctx context.Context) ([]entity.Application, error) {
|
||||
q, args, err := query.New().
|
||||
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||
From("application").
|
||||
OrderBy("created_at DESC").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
result := make([]entity.Application, 0)
|
||||
err = r.db.Select(ctx, &result, q, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Application) handleCreateError(err error, q string) error {
|
||||
var pgErr *pgconn.PgError
|
||||
if !errors.As(err, &pgErr) {
|
||||
return errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
switch pgErr.ConstraintName {
|
||||
case applicationPkConstraintName:
|
||||
return domain.ErrApplicationDuplicateId
|
||||
case applicationUniqueNameConstraintName:
|
||||
return domain.ErrApplicationDuplicateName
|
||||
case applicationFkAppGroupConstraintName:
|
||||
return domain.ErrAppGroupNotFound
|
||||
}
|
||||
return errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
func (r Application) handleUpdateError(err error, q string) error {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return domain.ErrApplicationNotFound
|
||||
}
|
||||
|
||||
var pgErr *pgconn.PgError
|
||||
if !errors.As(err, &pgErr) {
|
||||
return errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
switch pgErr.ConstraintName {
|
||||
case applicationPkConstraintName:
|
||||
return domain.ErrApplicationDuplicateId
|
||||
case applicationUniqueNameConstraintName:
|
||||
return domain.ErrApplicationDuplicateName
|
||||
default:
|
||||
return errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package repository
|
||||
|
||||
const (
|
||||
applicationPkConstraintName = "application_pkey"
|
||||
applicationUniqueNameConstraintName = "uq_name_application_group_id"
|
||||
applicationFkAppGroupConstraintName = "fk_application_group_id"
|
||||
|
||||
applicationGroupUniqueNameConstraint = "uq_name_domain_name"
|
||||
)
|
||||
+27
-29
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
@@ -30,14 +31,14 @@ func (r Domain) GetDomainById(ctx context.Context, id int) (*entity.Domain, erro
|
||||
`
|
||||
result := entity.Domain{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrDomainNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrDomainNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Domain) GetDomainByIdList(ctx context.Context, idList []int) ([]entity.Domain, error) {
|
||||
@@ -69,7 +70,7 @@ func (r Domain) GetDomainBySystemId(ctx context.Context, systemId int) ([]entity
|
||||
result := make([]entity.Domain, 0)
|
||||
err := r.db.Select(ctx, &result, q, systemId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "select db")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -83,14 +84,14 @@ func (r Domain) GetDomainByNameAndSystemId(ctx context.Context, name string, sys
|
||||
`
|
||||
result := entity.Domain{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, systemId)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrDomainNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrDomainNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Domain) CreateDomain(ctx context.Context, name string, desc string, systemId int) (*entity.Domain, error) {
|
||||
@@ -103,12 +104,8 @@ func (r Domain) CreateDomain(ctx context.Context, name string, desc string, syst
|
||||
result := entity.Domain{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, desc, systemId)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrDomainNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
@@ -121,13 +118,14 @@ func (r Domain) UpdateDomain(ctx context.Context, id int, name string, descripti
|
||||
`
|
||||
result := entity.Domain{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, description, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrDomainNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrDomainNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Domain) DeleteDomain(ctx context.Context, idList []int) (int, error) {
|
||||
@@ -141,7 +139,7 @@ func (r Domain) DeleteDomain(ctx context.Context, idList []int) (int, error) {
|
||||
|
||||
result, err := r.db.Exec(ctx, q, args...)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec db")
|
||||
return 0, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewService(db db.DB) Service {
|
||||
return Service{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Service) GetServiceById(ctx context.Context, id int) (*entity.Service, error) {
|
||||
q := `
|
||||
SELECT id, name, description, domain_id, created_at, updated_at
|
||||
FROM service
|
||||
WHERE id = $1
|
||||
`
|
||||
result := entity.Service{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrServiceNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Service) GetServiceByIdList(ctx context.Context, idList []int) ([]entity.Service, error) {
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("service").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
OrderBy("created_at DESC").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Service, 0)
|
||||
err = r.db.Select(ctx, &result, q, arg...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Service) GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error) {
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("service").
|
||||
Where(squirrel.Eq{"domain_id": domainIdList}).
|
||||
OrderBy("created_at DESC").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Service, 0)
|
||||
err = r.db.Select(ctx, &result, q, arg...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Service) GetServiceByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.Service, error) {
|
||||
q := `
|
||||
SELECT id, name, description, domain_id, created_at, updated_at
|
||||
FROM service
|
||||
WHERE name = $1 AND domain_id = $2
|
||||
`
|
||||
result := entity.Service{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, domainId)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrServiceNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Service) CreateService(ctx context.Context, name string, desc string, domainId int) (*entity.Service, error) {
|
||||
q := `
|
||||
INSERT INTO service
|
||||
(name, description, domain_id)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||
`
|
||||
result := entity.Service{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, desc, domainId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Service) UpdateService(ctx context.Context, id int, name string, description string) (*entity.Service, error) {
|
||||
q := `
|
||||
UPDATE service
|
||||
SET name = $1, description = $2
|
||||
WHERE id = $3
|
||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||
`
|
||||
result := entity.Service{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, description, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrServiceNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Service) DeleteService(ctx context.Context, idList []int) (int, error) {
|
||||
q, args, err := query.New().
|
||||
Delete("service").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "build query")
|
||||
}
|
||||
|
||||
result, err := r.db.Exec(ctx, q, args...)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec db")
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "get rows affected")
|
||||
}
|
||||
|
||||
return int(rowsAffected), nil
|
||||
}
|
||||
+22
-21
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
@@ -46,14 +47,14 @@ func (r Token) GetTokenById(ctx context.Context, token string) (*entity.Token, e
|
||||
`
|
||||
result := entity.Token{}
|
||||
err := r.db.SelectRow(ctx, &result, q, token)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, nil //nolint:nilnil
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r Token) GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error) {
|
||||
@@ -70,7 +71,7 @@ func (r Token) GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]enti
|
||||
result := make([]entity.Token, 0)
|
||||
err = r.db.Select(ctx, &result, q, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select db")
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -87,7 +88,7 @@ func (r Token) DeleteToken(ctx context.Context, tokens []string) (int, error) {
|
||||
|
||||
result, err := r.db.Exec(ctx, q, args...)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec db")
|
||||
return 0, errors.WithMessagef(err, "exec query %s", q)
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
@@ -100,24 +101,24 @@ func (r Token) DeleteToken(ctx context.Context, tokens []string) (int, error) {
|
||||
|
||||
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
|
||||
SELECT system_id, domain_id, application_group_id, app_id, application.name AS app_name , 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 application_group
|
||||
ON application.application_group_id = application_group.id
|
||||
LEFT JOIN domain
|
||||
ON service.domain_id = domain.id
|
||||
ON application_group.domain_id = domain.id
|
||||
WHERE token = $1
|
||||
`
|
||||
result := entity.AuthData{}
|
||||
err := r.db.SelectRow(ctx, &result, q, token)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, domain.ErrTokenNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
return nil, domain.ErrTokenNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "exec query %s", q)
|
||||
default:
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
+63
-4
@@ -1,10 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"isp-system-service/controller"
|
||||
|
||||
"github.com/txix-open/isp-kit/cluster"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||
"isp-system-service/controller"
|
||||
)
|
||||
|
||||
type Controllers struct {
|
||||
@@ -12,6 +13,7 @@ type Controllers struct {
|
||||
Domain controller.Domain
|
||||
Service controller.Service
|
||||
Application controller.Application
|
||||
AppGroup controller.AppGroup
|
||||
Token controller.Token
|
||||
Secure controller.Secure
|
||||
}
|
||||
@@ -29,14 +31,15 @@ func Handler(wrapper endpoint.Wrapper, c Controllers) *grpc.Mux {
|
||||
}
|
||||
|
||||
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||
return concatCluster([][]cluster.EndpointDescriptor{
|
||||
return concatCluster(
|
||||
secureCluster(c),
|
||||
accessListCluster(c),
|
||||
domainCluster(c),
|
||||
serviceCluster(c),
|
||||
applicationCluster(c),
|
||||
tokenCluster(c),
|
||||
})
|
||||
applicationGroupCluster(c),
|
||||
)
|
||||
}
|
||||
|
||||
func secureCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
@@ -71,6 +74,11 @@ func accessListCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
Inner: true,
|
||||
Handler: c.AccessList.SetList,
|
||||
},
|
||||
{
|
||||
Path: "system/access_list/delete_list",
|
||||
Inner: true,
|
||||
Handler: c.AccessList.DeleteList,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +107,7 @@ func domainCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func serviceCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
return []cluster.EndpointDescriptor{
|
||||
{
|
||||
@@ -151,6 +160,11 @@ func applicationCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
Inner: true,
|
||||
Handler: c.Application.GetById,
|
||||
},
|
||||
{
|
||||
Path: "system/application/get_application_by_token",
|
||||
Inner: true,
|
||||
Handler: c.Application.GetByToken,
|
||||
},
|
||||
{
|
||||
Path: "system/application/delete_applications",
|
||||
Inner: true,
|
||||
@@ -161,6 +175,25 @@ func applicationCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
Inner: true,
|
||||
Handler: c.Application.GetSystemTree,
|
||||
},
|
||||
{
|
||||
Path: "system/application/next_id",
|
||||
Inner: true,
|
||||
Handler: c.Application.NextId,
|
||||
},
|
||||
{
|
||||
Path: "system/application/get_all",
|
||||
Inner: true,
|
||||
Handler: c.Application.GetAll,
|
||||
},
|
||||
{
|
||||
Path: "system/application/create_application",
|
||||
Inner: true,
|
||||
Handler: c.Application.Create,
|
||||
}, {
|
||||
Path: "system/application/update_application",
|
||||
Inner: true,
|
||||
Handler: c.Application.Update,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +222,33 @@ func tokenCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
func concatCluster(clusters [][]cluster.EndpointDescriptor) []cluster.EndpointDescriptor {
|
||||
func applicationGroupCluster(c Controllers) []cluster.EndpointDescriptor {
|
||||
return []cluster.EndpointDescriptor{
|
||||
{
|
||||
Path: "system/application_group/create",
|
||||
Inner: true,
|
||||
Handler: c.AppGroup.Create,
|
||||
}, {
|
||||
Path: "system/application_group/update",
|
||||
Inner: true,
|
||||
Handler: c.AppGroup.Update,
|
||||
}, {
|
||||
Path: "system/application_group/delete_list",
|
||||
Inner: true,
|
||||
Handler: c.AppGroup.DeleteList,
|
||||
}, {
|
||||
Path: "system/application_group/get_by_id_list",
|
||||
Inner: true,
|
||||
Handler: c.AppGroup.GetByIdList,
|
||||
}, {
|
||||
Path: "system/application_group/get_all",
|
||||
Inner: true,
|
||||
Handler: c.AppGroup.GetAll,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func concatCluster(clusters ...[]cluster.EndpointDescriptor) []cluster.EndpointDescriptor {
|
||||
var result []cluster.EndpointDescriptor
|
||||
for _, c := range clusters {
|
||||
result = append(result, c...)
|
||||
|
||||
+39
-29
@@ -3,62 +3,60 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type IAccessListAccessListRep interface {
|
||||
type AccessListRepo interface {
|
||||
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []string) error
|
||||
}
|
||||
|
||||
type IAccessListApplicationRep interface {
|
||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||
}
|
||||
|
||||
type IAccessListSetOneTx interface {
|
||||
type AccessListSetOneTx interface {
|
||||
UpsertAccessList(ctx context.Context, e entity.AccessList) (int, error)
|
||||
}
|
||||
|
||||
type IAccessListSetListTx interface {
|
||||
type AccessListSetListTx interface {
|
||||
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
InsertArrayAccessList(ctx context.Context, entity []entity.AccessList) error
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []string) error
|
||||
DeleteAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
}
|
||||
|
||||
type IAccessListTxRunner interface {
|
||||
AccessListSetOneTx(ctx context.Context, tx func(ctx context.Context, tx IAccessListSetOneTx) error) error
|
||||
AccessListSetListTx(ctx context.Context, tx func(ctx context.Context, tx IAccessListSetListTx) error) error
|
||||
type AccessListTxRunner interface {
|
||||
AccessListSetOneTx(ctx context.Context, tx func(ctx context.Context, tx AccessListSetOneTx) error) error
|
||||
AccessListSetListTx(ctx context.Context, tx func(ctx context.Context, tx AccessListSetListTx) error) error
|
||||
}
|
||||
|
||||
type AccessList struct {
|
||||
tx IAccessListTxRunner
|
||||
accessListRep IAccessListAccessListRep
|
||||
applicationRep IAccessListApplicationRep
|
||||
tx AccessListTxRunner
|
||||
accessListRepo AccessListRepo
|
||||
appRepo ApplicationRepo
|
||||
}
|
||||
|
||||
func NewAccessList(
|
||||
tx IAccessListTxRunner,
|
||||
accessListRep IAccessListAccessListRep,
|
||||
applicationRep IAccessListApplicationRep,
|
||||
tx AccessListTxRunner,
|
||||
accessListRepo AccessListRepo,
|
||||
appRepo ApplicationRepo,
|
||||
) AccessList {
|
||||
return AccessList{
|
||||
tx: tx,
|
||||
accessListRep: accessListRep,
|
||||
applicationRep: applicationRep,
|
||||
accessListRepo: accessListRepo,
|
||||
appRepo: appRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s AccessList) GetById(ctx context.Context, appId int) ([]domain.MethodInfo, error) {
|
||||
_, err := s.applicationRep.GetApplicationById(ctx, appId)
|
||||
_, err := s.appRepo.GetApplicationById(ctx, appId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
|
||||
accessList, err := s.accessListRep.GetAccessListByAppId(ctx, appId)
|
||||
accessList, err := s.accessListRepo.GetAccessListByAppId(ctx, appId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get access list by app_id")
|
||||
return nil, errors.WithMessage(err, "get access list by app_id")
|
||||
}
|
||||
|
||||
methodInfos := make([]domain.MethodInfo, len(accessList))
|
||||
@@ -73,20 +71,20 @@ func (s AccessList) GetById(ctx context.Context, appId int) ([]domain.MethodInfo
|
||||
}
|
||||
|
||||
func (s AccessList) SetOne(ctx context.Context, request domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error) {
|
||||
_, err := s.applicationRep.GetApplicationById(ctx, request.AppId)
|
||||
_, err := s.appRepo.GetApplicationById(ctx, request.AppId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
|
||||
var resp int
|
||||
err = s.tx.AccessListSetOneTx(ctx, func(ctx context.Context, tx IAccessListSetOneTx) error {
|
||||
err = s.tx.AccessListSetOneTx(ctx, func(ctx context.Context, tx AccessListSetOneTx) error {
|
||||
resp, err = tx.UpsertAccessList(ctx, entity.AccessList{
|
||||
AppId: request.AppId,
|
||||
Method: request.Method,
|
||||
Value: request.Value,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "upsert access list")
|
||||
return errors.WithMessage(err, "upsert access list")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -101,12 +99,12 @@ func (s AccessList) SetOne(ctx context.Context, request domain.AccessListSetOneR
|
||||
}
|
||||
|
||||
func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error) {
|
||||
_, err := s.applicationRep.GetApplicationById(ctx, req.AppId)
|
||||
_, err := s.appRepo.GetApplicationById(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
|
||||
err = s.tx.AccessListSetListTx(ctx, func(ctx context.Context, tx IAccessListSetListTx) error {
|
||||
err = s.tx.AccessListSetListTx(ctx, func(ctx context.Context, tx AccessListSetListTx) error {
|
||||
if req.RemoveOld {
|
||||
_, err = tx.DeleteAccessListByAppId(ctx, req.AppId)
|
||||
if err != nil {
|
||||
@@ -143,9 +141,9 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
return nil, errors.WithMessage(err, "transaction access list set list")
|
||||
}
|
||||
|
||||
accessList, err := s.accessListRep.GetAccessListByAppId(ctx, req.AppId)
|
||||
accessList, err := s.accessListRepo.GetAccessListByAppId(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get access list by app_id")
|
||||
return nil, errors.WithMessage(err, "get access list by app_id")
|
||||
}
|
||||
|
||||
methodInfos := make([]domain.MethodInfo, len(accessList))
|
||||
@@ -158,3 +156,15 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
|
||||
return methodInfos, nil
|
||||
}
|
||||
|
||||
func (s AccessList) DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error {
|
||||
_, err := s.appRepo.GetApplicationById(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
err = s.accessListRepo.DeleteAccessList(ctx, req.AppId, req.Methods)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete access_list")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type AppGroup struct {
|
||||
repo AppGroupRepo
|
||||
}
|
||||
|
||||
func NewAppGroup(repo AppGroupRepo) AppGroup {
|
||||
return AppGroup{
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s AppGroup) Create(ctx context.Context, req domain.CreateAppGroupRequest) (*domain.AppGroup, error) {
|
||||
appGroup, err := s.repo.CreateAppGroup(ctx, req.Name, req.Description, 1)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "create appGroup")
|
||||
}
|
||||
converted := s.convertAppGroup(*appGroup)
|
||||
return &converted, nil
|
||||
}
|
||||
|
||||
func (s AppGroup) Update(ctx context.Context, req domain.UpdateAppGroupRequest) (*domain.AppGroup, error) {
|
||||
appGroup, err := s.repo.UpdateAppGroup(ctx, req.Id, req.Name, req.Description)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "update appGroup")
|
||||
}
|
||||
converted := s.convertAppGroup(*appGroup)
|
||||
return &converted, nil
|
||||
}
|
||||
|
||||
func (s AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*domain.DeleteResponse, error) {
|
||||
deleted, err := s.repo.DeleteAppGroup(ctx, req.IdList)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "delete appGroup")
|
||||
}
|
||||
return &domain.DeleteResponse{
|
||||
Deleted: deleted,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s AppGroup) GetByIdList(ctx context.Context, idList []int) ([]domain.AppGroup, error) {
|
||||
appGroups, err := s.repo.GetAppGroupByIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get appGroups by id list")
|
||||
}
|
||||
result := make([]domain.AppGroup, 0, len(appGroups))
|
||||
for _, appGroup := range appGroups {
|
||||
result = append(result, s.convertAppGroup(appGroup))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s AppGroup) GetAll(ctx context.Context) ([]domain.AppGroup, error) {
|
||||
appGroups, err := s.repo.GetAllAppGroups(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get all appGroups")
|
||||
}
|
||||
result := make([]domain.AppGroup, 0, len(appGroups))
|
||||
for _, appGroup := range appGroups {
|
||||
result = append(result, s.convertAppGroup(appGroup))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s AppGroup) convertAppGroup(appGroup entity.AppGroup) domain.AppGroup {
|
||||
return domain.AppGroup{
|
||||
Id: appGroup.Id,
|
||||
Name: appGroup.Name,
|
||||
Description: appGroup.Description.String,
|
||||
CreatedAt: appGroup.CreatedAt,
|
||||
UpdatedAt: appGroup.UpdatedAt,
|
||||
}
|
||||
}
|
||||
+108
-96
@@ -3,67 +3,46 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type IApplicationApplicationRep interface {
|
||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||
GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error)
|
||||
GetApplicationByServiceIdList(ctx context.Context, serviceIdList []int) ([]entity.Application, error)
|
||||
GetApplicationByNameAndServiceId(ctx context.Context, name string, serviceId int) (*entity.Application, error)
|
||||
CreateApplication(ctx context.Context, name string, desc string, serviceId int, appType string) (*entity.Application, error)
|
||||
UpdateApplication(ctx context.Context, id int, name string, description string) (*entity.Application, error)
|
||||
}
|
||||
|
||||
type IApplicationTokenRep interface {
|
||||
GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error)
|
||||
}
|
||||
|
||||
type IApplicationServiceRep interface {
|
||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
||||
GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error)
|
||||
}
|
||||
|
||||
type IApplicationDomainRep interface {
|
||||
GetDomainBySystemId(ctx context.Context, systemId int) ([]entity.Domain, error)
|
||||
}
|
||||
|
||||
type IApplicationDeleteTx interface {
|
||||
type ApplicationDeleteTx interface {
|
||||
DeleteApplicationByIdList(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
type IApplicationTxRunner interface {
|
||||
ApplicationDeleteTx(ctx context.Context, tx func(ctx context.Context, tx IApplicationDeleteTx) error) error
|
||||
type ApplicationTxRunner interface {
|
||||
ApplicationDeleteTx(ctx context.Context, tx func(ctx context.Context, tx ApplicationDeleteTx) error) error
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
tx IApplicationTxRunner
|
||||
applicationRep IApplicationApplicationRep
|
||||
domainRep IApplicationDomainRep
|
||||
serviceRep IApplicationServiceRep
|
||||
tokenRep IApplicationTokenRep
|
||||
txRunner ApplicationTxRunner
|
||||
appRepo ApplicationRepo
|
||||
domainRepo DomainRepo
|
||||
serviceRepo AppGroupRepo
|
||||
tokenRepo TokenRepo
|
||||
}
|
||||
|
||||
func NewApplication(
|
||||
tx IApplicationTxRunner,
|
||||
applicationRep IApplicationApplicationRep,
|
||||
domainRep IApplicationDomainRep,
|
||||
serviceRep IApplicationServiceRep,
|
||||
tokenRep IApplicationTokenRep,
|
||||
txRunner ApplicationTxRunner,
|
||||
applicationRepo ApplicationRepo,
|
||||
domainRepo DomainRepo,
|
||||
appGroupRepo AppGroupRepo,
|
||||
tokenRepo TokenRepo,
|
||||
) Application {
|
||||
return Application{
|
||||
tx: tx,
|
||||
applicationRep: applicationRep,
|
||||
domainRep: domainRep,
|
||||
serviceRep: serviceRep,
|
||||
tokenRep: tokenRep,
|
||||
txRunner: txRunner,
|
||||
appRepo: applicationRepo,
|
||||
domainRepo: domainRepo,
|
||||
serviceRepo: appGroupRepo,
|
||||
tokenRepo: tokenRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Application) GetById(ctx context.Context, appId int) (*domain.ApplicationWithTokens, error) {
|
||||
application, err := s.applicationRep.GetApplicationById(ctx, appId)
|
||||
application, err := s.appRepo.GetApplicationById(ctx, appId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
@@ -76,8 +55,27 @@ func (s Application) GetById(ctx context.Context, appId int) (*domain.Applicatio
|
||||
return arr[0], nil
|
||||
}
|
||||
|
||||
func (s Application) GetByToken(ctx context.Context, tokenStr string) (*domain.GetApplicationByTokenResponse, error) {
|
||||
token, err := s.tokenRepo.GetTokenById(ctx, tokenStr)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get token by id")
|
||||
}
|
||||
if token == nil {
|
||||
return nil, domain.ErrApplicationNotFound
|
||||
}
|
||||
|
||||
app, err := s.appRepo.GetApplicationById(ctx, token.AppId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get app by id")
|
||||
}
|
||||
return &domain.GetApplicationByTokenResponse{
|
||||
ApplicationId: app.Id,
|
||||
ApplicationGroupId: app.ApplicationGroupId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s Application) GetByIdList(ctx context.Context, idList []int) ([]*domain.ApplicationWithTokens, error) {
|
||||
res, err := s.applicationRep.GetApplicationByIdList(ctx, idList)
|
||||
res, err := s.appRepo.GetApplicationByIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by id list")
|
||||
}
|
||||
@@ -86,16 +84,16 @@ func (s Application) GetByIdList(ctx context.Context, idList []int) ([]*domain.A
|
||||
}
|
||||
|
||||
func (s Application) GetByServiceId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error) {
|
||||
arr, err := s.applicationRep.GetApplicationByServiceIdList(ctx, []int{id})
|
||||
arr, err := s.appRepo.GetApplicationByAppGroupIdList(ctx, []int{id})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by service_id")
|
||||
return nil, errors.WithMessage(err, "get application by app_group_id")
|
||||
}
|
||||
|
||||
return s.EnrichWithTokens(ctx, arr)
|
||||
}
|
||||
|
||||
func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithService, error) {
|
||||
domainEntityList, err := s.domainRep.GetDomainBySystemId(ctx, systemId)
|
||||
domainEntityList, err := s.domainRepo.GetDomainBySystemId(ctx, systemId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domains by system_id")
|
||||
}
|
||||
@@ -122,7 +120,7 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do
|
||||
result[i] = r
|
||||
}
|
||||
|
||||
serviceEntityList, err := s.serviceRep.GetServiceByDomainId(ctx, domainIdList)
|
||||
serviceEntityList, err := s.serviceRepo.GetAppGroupByDomainId(ctx, domainIdList)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get service by domain_id")
|
||||
}
|
||||
@@ -131,14 +129,10 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do
|
||||
resultServiceByServiceId := make(map[int]*domain.ServiceWithApps, len(serviceEntityList))
|
||||
for i, serviceEntity := range serviceEntityList {
|
||||
serviceIdList[i] = serviceEntity.Id
|
||||
description := ""
|
||||
if serviceEntity.Description != nil {
|
||||
description = *serviceEntity.Description
|
||||
}
|
||||
resultService := &domain.ServiceWithApps{
|
||||
Id: serviceEntity.Id,
|
||||
Name: serviceEntity.Name,
|
||||
Description: description,
|
||||
Description: serviceEntity.Description.String,
|
||||
Apps: make([]*domain.ApplicationSimple, 0),
|
||||
}
|
||||
r := resultByDomainId[serviceEntity.DomainId]
|
||||
@@ -146,22 +140,18 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do
|
||||
resultServiceByServiceId[serviceEntity.Id] = resultService
|
||||
}
|
||||
|
||||
applicationEntityList, err := s.applicationRep.GetApplicationByServiceIdList(ctx, serviceIdList)
|
||||
applicationEntityList, err := s.appRepo.GetApplicationByAppGroupIdList(ctx, serviceIdList)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get application by service_id")
|
||||
return nil, errors.WithMessage(err, "get application by service_id")
|
||||
}
|
||||
|
||||
for _, applicationEntity := range applicationEntityList {
|
||||
resultService := resultServiceByServiceId[applicationEntity.ServiceId]
|
||||
description := ""
|
||||
if applicationEntity.Description != nil {
|
||||
description = *applicationEntity.Description
|
||||
}
|
||||
resultService := resultServiceByServiceId[applicationEntity.ApplicationGroupId]
|
||||
resultService.Apps = append(resultService.Apps, &domain.ApplicationSimple{
|
||||
Id: applicationEntity.Id,
|
||||
Name: applicationEntity.Name,
|
||||
Type: applicationEntity.Type,
|
||||
Description: description,
|
||||
Description: applicationEntity.Description.String,
|
||||
Tokens: make([]domain.Token, 0),
|
||||
})
|
||||
}
|
||||
@@ -170,29 +160,18 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do
|
||||
}
|
||||
|
||||
func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
||||
existed, err := s.applicationRep.GetApplicationByNameAndServiceId(ctx, req.Name, req.ServiceId)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
case err != nil:
|
||||
return nil, errors.WithMessage(err, "get application by name and service_id")
|
||||
}
|
||||
|
||||
_, err = s.serviceRep.GetServiceById(ctx, req.ServiceId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get service by id")
|
||||
}
|
||||
|
||||
if req.Id == 0 {
|
||||
if existed != nil {
|
||||
return nil, domain.ErrApplicationDuplicateName
|
||||
}
|
||||
|
||||
_, err = s.applicationRep.GetApplicationByNameAndServiceId(ctx, req.Name, req.ServiceId)
|
||||
_, err := s.appRepo.GetApplicationByNameAndAppGroupId(ctx, req.Name, req.ServiceId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by name and service_id")
|
||||
}
|
||||
|
||||
app, err := s.applicationRep.CreateApplication(ctx, req.Name, req.Description, req.ServiceId, req.Type)
|
||||
appId, err := s.appRepo.NextApplicationId(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "next app id")
|
||||
}
|
||||
|
||||
app, err := s.appRepo.CreateApplication(ctx, appId, req.Name, req.Description, req.ServiceId, req.Type)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "create application")
|
||||
}
|
||||
@@ -205,16 +184,7 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
||||
return result[0], nil
|
||||
}
|
||||
|
||||
if existed != nil && existed.Id != req.Id {
|
||||
return nil, domain.ErrApplicationDuplicateName
|
||||
}
|
||||
|
||||
_, err = s.applicationRep.GetApplicationById(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
|
||||
app, err := s.applicationRep.UpdateApplication(ctx, req.Id, req.Name, req.Description)
|
||||
app, err := s.appRepo.UpdateApplication(ctx, req.Id, req.Name, req.Description)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "update application")
|
||||
}
|
||||
@@ -229,7 +199,7 @@ 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 {
|
||||
err := s.txRunner.ApplicationDeleteTx(ctx, func(ctx context.Context, tx ApplicationDeleteTx) error {
|
||||
deletedApp, err := tx.DeleteApplicationByIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete application by id list")
|
||||
@@ -263,7 +233,7 @@ func (s Application) EnrichWithTokens(ctx context.Context, apps []entity.Applica
|
||||
result[i] = awt
|
||||
}
|
||||
|
||||
tokens, err := s.tokenRep.GetTokenByAppIdList(ctx, appIdList)
|
||||
tokens, err := s.tokenRepo.GetTokenByAppIdList(ctx, appIdList)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get token by app_id list")
|
||||
}
|
||||
@@ -276,17 +246,59 @@ func (s Application) EnrichWithTokens(ctx context.Context, apps []entity.Applica
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s Application) convertApplication(req entity.Application) domain.Application {
|
||||
desc := ""
|
||||
if req.Description != nil {
|
||||
desc = *req.Description
|
||||
func (s Application) NextId(ctx context.Context) (int, error) {
|
||||
nextId, err := s.appRepo.NextApplicationId(ctx)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "get next application id")
|
||||
}
|
||||
return nextId, nil
|
||||
}
|
||||
|
||||
func (s Application) GetAll(ctx context.Context) ([]domain.Application, error) {
|
||||
apps, err := s.appRepo.GetAllApplications(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get applications list")
|
||||
}
|
||||
|
||||
result := make([]domain.Application, 0, len(apps))
|
||||
for _, app := range apps {
|
||||
result = append(result, s.convertApplication(app))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s Application) Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error) {
|
||||
app, err := s.appRepo.CreateApplication(ctx, req.Id, req.Name, req.Description, req.ApplicationGroupId, req.Type)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "create application")
|
||||
}
|
||||
|
||||
return &domain.ApplicationWithTokens{
|
||||
App: s.convertApplication(*app),
|
||||
Tokens: make([]domain.Token, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s Application) Update(ctx context.Context, req domain.UpdateApplicationRequest) (*domain.ApplicationWithTokens, error) {
|
||||
app, err := s.appRepo.UpdateApplicationWithNewId(ctx, req.OldId, req.NewId, req.Name, req.Description)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "update application")
|
||||
}
|
||||
|
||||
result, err := s.EnrichWithTokens(ctx, []entity.Application{*app})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "enrich application with tokens")
|
||||
}
|
||||
|
||||
return result[0], nil
|
||||
}
|
||||
|
||||
func (s Application) convertApplication(req entity.Application) domain.Application {
|
||||
return domain.Application{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Description: desc,
|
||||
ServiceId: req.ServiceId,
|
||||
Description: req.Description.String,
|
||||
ServiceId: req.ApplicationGroupId,
|
||||
Type: req.Type,
|
||||
CreatedAt: req.CreatedAt,
|
||||
UpdatedAt: req.UpdatedAt,
|
||||
|
||||
@@ -2,16 +2,19 @@ package baseline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
)
|
||||
|
||||
const adminAppId = 1
|
||||
|
||||
type Transaction interface {
|
||||
CreateDomain(ctx context.Context, name string, desc string, systemId int) (*entity.Domain, error)
|
||||
CreateService(ctx context.Context, name string, desc string, domainId int) (*entity.Service, error)
|
||||
CreateApplication(ctx context.Context, name string, desc string, serviceId int, appType string) (*entity.Application, error)
|
||||
CreateAppGroup(ctx context.Context, name string, desc string, domainId int) (*entity.AppGroup, error)
|
||||
CreateApplication(ctx context.Context, id int, name string, desc string, appGroupId int, appType string) (*entity.Application, error)
|
||||
UpsertAccessList(ctx context.Context, e entity.AccessList) (int, error)
|
||||
SaveToken(ctx context.Context, token string, appId int, expireTime int) (*entity.Token, error)
|
||||
GetTokenById(ctx context.Context, token string) (*entity.Token, error)
|
||||
@@ -77,12 +80,12 @@ func (s Service) transaction(ctx context.Context, tx Transaction) error {
|
||||
return errors.WithMessage(err, "create domain")
|
||||
}
|
||||
|
||||
service, err := tx.CreateService(ctx, "rootService", "", domain.Id)
|
||||
service, err := tx.CreateAppGroup(ctx, "rootService", "", domain.Id)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "create service")
|
||||
}
|
||||
|
||||
app, err := tx.CreateApplication(ctx, "admin", "", service.Id, "SYSTEM")
|
||||
app, err := tx.CreateApplication(ctx, adminAppId, "admin", "", service.Id, "SYSTEM")
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "create application")
|
||||
}
|
||||
|
||||
+13
-23
@@ -3,34 +3,24 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type IDomainDomainRep interface {
|
||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||
GetDomainBySystemId(ctx context.Context, systemId int) ([]entity.Domain, error)
|
||||
GetDomainByNameAndSystemId(ctx context.Context, name string, systemId int) (*entity.Domain, error)
|
||||
CreateDomain(ctx context.Context, name string, desc string, systemId int) (*entity.Domain, error)
|
||||
UpdateDomain(ctx context.Context, id int, name string, description string) (*entity.Domain, error)
|
||||
DeleteDomain(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
domainRep IDomainDomainRep
|
||||
repo DomainRepo
|
||||
}
|
||||
|
||||
func NewDomain(
|
||||
domainRep IDomainDomainRep,
|
||||
) Domain {
|
||||
func NewDomain(repo DomainRepo) Domain {
|
||||
return Domain{
|
||||
domainRep: domainRep,
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Domain) GetById(ctx context.Context, id int) (*domain.Domain, error) {
|
||||
domainEntity, err := s.domainRep.GetDomainById(ctx, id)
|
||||
domainEntity, err := s.repo.GetDomainById(ctx, id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domain by id")
|
||||
}
|
||||
@@ -40,7 +30,7 @@ func (s Domain) GetById(ctx context.Context, id int) (*domain.Domain, error) {
|
||||
}
|
||||
|
||||
func (s Domain) GetBySystemId(ctx context.Context, systemId int) ([]domain.Domain, error) {
|
||||
domainEntity, err := s.domainRep.GetDomainBySystemId(ctx, systemId)
|
||||
domainEntity, err := s.repo.GetDomainBySystemId(ctx, systemId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domain by system_id")
|
||||
}
|
||||
@@ -53,7 +43,7 @@ func (s Domain) GetBySystemId(ctx context.Context, systemId int) ([]domain.Domai
|
||||
}
|
||||
|
||||
func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateRequest, systemId int) (*domain.Domain, error) {
|
||||
existed, err := s.domainRep.GetDomainByNameAndSystemId(ctx, req.Name, systemId)
|
||||
existed, err := s.repo.GetDomainByNameAndSystemId(ctx, req.Name, systemId)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
case err != nil:
|
||||
@@ -65,9 +55,9 @@ func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
return nil, domain.ErrDomainDuplicateName
|
||||
}
|
||||
|
||||
domainEntity, err := s.domainRep.CreateDomain(ctx, req.Name, req.Description, systemId)
|
||||
domainEntity, err := s.repo.CreateDomain(ctx, req.Name, req.Description, systemId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "create domain")
|
||||
return nil, errors.WithMessage(err, "create domain")
|
||||
}
|
||||
|
||||
result := s.convertDomain(*domainEntity)
|
||||
@@ -78,12 +68,12 @@ func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
return nil, domain.ErrDomainDuplicateName
|
||||
}
|
||||
|
||||
_, err = s.domainRep.GetDomainById(ctx, req.Id)
|
||||
_, err = s.repo.GetDomainById(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domain by id")
|
||||
}
|
||||
|
||||
domainEntity, err := s.domainRep.UpdateDomain(ctx, req.Id, req.Name, req.Description)
|
||||
domainEntity, err := s.repo.UpdateDomain(ctx, req.Id, req.Name, req.Description)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "update domain")
|
||||
}
|
||||
@@ -93,7 +83,7 @@ func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
}
|
||||
|
||||
func (s Domain) Delete(ctx context.Context, idList []int) (int, error) {
|
||||
result, err := s.domainRep.DeleteDomain(ctx, idList)
|
||||
result, err := s.repo.DeleteDomain(ctx, idList)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "delete domain")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type TokenRepo interface {
|
||||
GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error)
|
||||
GetTokenById(ctx context.Context, token string) (*entity.Token, error)
|
||||
}
|
||||
|
||||
type DomainRepo interface {
|
||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||
GetDomainBySystemId(ctx context.Context, systemId int) ([]entity.Domain, error)
|
||||
GetDomainByNameAndSystemId(ctx context.Context, name string, systemId int) (*entity.Domain, error)
|
||||
CreateDomain(ctx context.Context, name string, desc string, systemId int) (*entity.Domain, error)
|
||||
UpdateDomain(ctx context.Context, id int, name string, description string) (*entity.Domain, error)
|
||||
DeleteDomain(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
type ApplicationRepo interface {
|
||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||
GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error)
|
||||
GetApplicationByAppGroupIdList(ctx context.Context, appGroupIdList []int) ([]entity.Application, error)
|
||||
GetApplicationByNameAndAppGroupId(ctx context.Context, name string, appGroupId int) (*entity.Application, error)
|
||||
CreateApplication(ctx context.Context, id int, name string, desc string, appGroupId int, appType string) (*entity.Application, error)
|
||||
UpdateApplication(ctx context.Context, id int, name string, description string) (*entity.Application, error)
|
||||
UpdateApplicationWithNewId(ctx context.Context, oldId int, newId int, name string, description string) (*entity.Application, error)
|
||||
NextApplicationId(ctx context.Context) (int, error)
|
||||
GetAllApplications(ctx context.Context) ([]entity.Application, error)
|
||||
}
|
||||
|
||||
type AppGroupRepo interface {
|
||||
GetAppGroupById(ctx context.Context, id int) (*entity.AppGroup, error)
|
||||
GetAppGroupByIdList(ctx context.Context, idList []int) ([]entity.AppGroup, error)
|
||||
GetAppGroupByDomainId(ctx context.Context, domainIdList []int) ([]entity.AppGroup, error)
|
||||
GetAllAppGroups(ctx context.Context) ([]entity.AppGroup, error)
|
||||
GetAppGroupByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.AppGroup, error)
|
||||
CreateAppGroup(ctx context.Context, name string, desc string, domainId int) (*entity.AppGroup, error)
|
||||
UpdateAppGroup(ctx context.Context, id int, name string, description string) (*entity.AppGroup, error)
|
||||
DeleteAppGroup(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type TokenRep interface {
|
||||
@@ -44,9 +45,10 @@ func (s Service) Authenticate(ctx context.Context, token string) (*domain.AuthDa
|
||||
}
|
||||
|
||||
return &domain.AuthData{
|
||||
AppName: authData.AppName,
|
||||
SystemId: authData.SystemId,
|
||||
DomainId: authData.DomainId,
|
||||
ServiceId: authData.ServiceId,
|
||||
ServiceId: authData.ApplicationGroupId,
|
||||
ApplicationId: authData.AppId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
+20
-50
@@ -3,44 +3,31 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type IServiceServiceRep interface {
|
||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
||||
GetServiceByIdList(ctx context.Context, idList []int) ([]entity.Service, error)
|
||||
GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error)
|
||||
GetServiceByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.Service, error)
|
||||
CreateService(ctx context.Context, name string, desc string, domainId int) (*entity.Service, error)
|
||||
UpdateService(ctx context.Context, id int, name string, description string) (*entity.Service, error)
|
||||
DeleteService(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
type IServiceDomainRep interface {
|
||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
domainRep IServiceDomainRep
|
||||
serviceRep IServiceServiceRep
|
||||
domainRepo DomainRepo
|
||||
serviceRepo AppGroupRepo
|
||||
}
|
||||
|
||||
func NewService(
|
||||
domainRep IServiceDomainRep,
|
||||
serviceRep IServiceServiceRep,
|
||||
domainRepo DomainRepo,
|
||||
serviceRepo AppGroupRepo,
|
||||
) Service {
|
||||
return Service{
|
||||
domainRep: domainRep,
|
||||
serviceRep: serviceRep,
|
||||
domainRepo: domainRepo,
|
||||
serviceRepo: serviceRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Service) GetById(ctx context.Context, id int) (*domain.Service, error) {
|
||||
serviceEntity, err := s.serviceRep.GetServiceById(ctx, id)
|
||||
serviceEntity, err := s.serviceRepo.GetAppGroupById(ctx, id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get service by id")
|
||||
return nil, errors.WithMessage(err, "get service by id")
|
||||
}
|
||||
|
||||
result := s.convertService(*serviceEntity)
|
||||
@@ -48,7 +35,7 @@ func (s Service) GetById(ctx context.Context, id int) (*domain.Service, error) {
|
||||
}
|
||||
|
||||
func (s Service) GetByIdList(ctx context.Context, idList []int) ([]domain.Service, error) {
|
||||
serviceEntity, err := s.serviceRep.GetServiceByIdList(ctx, idList)
|
||||
serviceEntity, err := s.serviceRepo.GetAppGroupByIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get system by id list")
|
||||
}
|
||||
@@ -61,7 +48,7 @@ func (s Service) GetByIdList(ctx context.Context, idList []int) ([]domain.Servic
|
||||
}
|
||||
|
||||
func (s Service) GetByDomainId(ctx context.Context, domainId int) ([]domain.Service, error) {
|
||||
serviceEntity, err := s.serviceRep.GetServiceByDomainId(ctx, []int{domainId})
|
||||
serviceEntity, err := s.serviceRepo.GetAppGroupByDomainId(ctx, []int{domainId})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get system by id list")
|
||||
}
|
||||
@@ -74,24 +61,15 @@ func (s Service) GetByDomainId(ctx context.Context, domainId int) ([]domain.Serv
|
||||
}
|
||||
|
||||
func (s Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) {
|
||||
existed, err := s.serviceRep.GetServiceByNameAndDomainId(ctx, req.Name, req.DomainId)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
case err != nil:
|
||||
return nil, errors.WithMessage(err, "get service by name and domain_id")
|
||||
}
|
||||
req.DomainId = 1 // temporary use only 1 domain, soon domain entity will be removed
|
||||
|
||||
_, err = s.domainRep.GetDomainById(ctx, req.DomainId)
|
||||
_, err := s.domainRepo.GetDomainById(ctx, req.DomainId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domain by id")
|
||||
}
|
||||
|
||||
if req.Id == 0 {
|
||||
if existed != nil {
|
||||
return nil, domain.ErrDomainDuplicateName
|
||||
}
|
||||
|
||||
serviceEntity, err := s.serviceRep.CreateService(ctx, req.Name, req.Description, req.DomainId)
|
||||
serviceEntity, err := s.serviceRepo.CreateAppGroup(ctx, req.Name, req.Description, req.DomainId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "create service")
|
||||
}
|
||||
@@ -100,16 +78,12 @@ func (s Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdat
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
if existed != nil && existed.Id != req.Id {
|
||||
return nil, domain.ErrDomainDuplicateName
|
||||
}
|
||||
|
||||
_, err = s.serviceRep.GetServiceById(ctx, req.Id)
|
||||
_, err = s.serviceRepo.GetAppGroupById(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get service by id")
|
||||
}
|
||||
|
||||
serviceEntity, err := s.serviceRep.UpdateService(ctx, req.Id, req.Name, req.Description)
|
||||
serviceEntity, err := s.serviceRepo.UpdateAppGroup(ctx, req.Id, req.Name, req.Description)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "update service")
|
||||
}
|
||||
@@ -119,7 +93,7 @@ func (s Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdat
|
||||
}
|
||||
|
||||
func (s Service) Delete(ctx context.Context, idList []int) (int, error) {
|
||||
result, err := s.serviceRep.DeleteService(ctx, idList)
|
||||
result, err := s.serviceRepo.DeleteAppGroup(ctx, idList)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "delete service")
|
||||
}
|
||||
@@ -127,15 +101,11 @@ func (s Service) Delete(ctx context.Context, idList []int) (int, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s Service) convertService(req entity.Service) domain.Service {
|
||||
desc := ""
|
||||
if req.Description != nil {
|
||||
desc = *req.Description
|
||||
}
|
||||
func (s Service) convertService(req entity.AppGroup) domain.Service {
|
||||
result := domain.Service{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Description: desc,
|
||||
Description: req.Description.String,
|
||||
DomainId: req.DomainId,
|
||||
CreatedAt: req.CreatedAt,
|
||||
UpdatedAt: req.UpdatedAt,
|
||||
|
||||
+50
-65
@@ -3,80 +3,65 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type ITokenSource interface {
|
||||
type ApplicationTokenCreator interface {
|
||||
CreateApplicationToken() (string, error)
|
||||
}
|
||||
|
||||
type ITokenAppEnrich interface {
|
||||
type AppEnricher interface {
|
||||
EnrichWithTokens(ctx context.Context, apps []entity.Application) ([]*domain.ApplicationWithTokens, error)
|
||||
}
|
||||
|
||||
type ITokenApplicationRep interface {
|
||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||
}
|
||||
|
||||
type ITokenServiceRep interface {
|
||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
||||
}
|
||||
|
||||
type ITokenDomainRep interface {
|
||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||
}
|
||||
|
||||
type ITokenTokenRep interface {
|
||||
GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error)
|
||||
}
|
||||
|
||||
type ITokenCreateTx interface {
|
||||
type TokenCreateTx interface {
|
||||
SaveToken(ctx context.Context, token string, appId int, expireTime int) (*entity.Token, error)
|
||||
}
|
||||
|
||||
type ITokenRevokeTx interface {
|
||||
type TokenRevokeTx interface {
|
||||
DeleteToken(ctx context.Context, tokens []string) (int, error)
|
||||
}
|
||||
|
||||
type ITokenTxRunner interface {
|
||||
TokenCreateTx(ctx context.Context, tx func(ctx context.Context, tx ITokenCreateTx) error) error
|
||||
TokenRevokeTx(ctx context.Context, tx func(ctx context.Context, tx ITokenRevokeTx) error) error
|
||||
type TokenTxRunner interface {
|
||||
TokenCreateTx(ctx context.Context, tx func(ctx context.Context, tx TokenCreateTx) error) error
|
||||
TokenRevokeTx(ctx context.Context, tx func(ctx context.Context, tx TokenRevokeTx) error) error
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
jwt ITokenSource
|
||||
appEnrich ITokenAppEnrich
|
||||
tx ITokenTxRunner
|
||||
appRep ITokenApplicationRep
|
||||
domainRep ITokenDomainRep
|
||||
serviceRep ITokenServiceRep
|
||||
tokenRep ITokenTokenRep
|
||||
jwt ApplicationTokenCreator
|
||||
appEnricher AppEnricher
|
||||
tx TokenTxRunner
|
||||
appRepo ApplicationRepo
|
||||
domainRepo DomainRepo
|
||||
serviceRepo AppGroupRepo
|
||||
tokenRepo TokenRepo
|
||||
}
|
||||
|
||||
func NewToken(
|
||||
jwtGenerate ITokenSource,
|
||||
appEnrich ITokenAppEnrich,
|
||||
tx ITokenTxRunner,
|
||||
appRep ITokenApplicationRep,
|
||||
domainRep ITokenDomainRep,
|
||||
serviceRep ITokenServiceRep,
|
||||
tokenRep ITokenTokenRep,
|
||||
jwtGenerate ApplicationTokenCreator,
|
||||
appEnricher AppEnricher,
|
||||
tx TokenTxRunner,
|
||||
appRepo ApplicationRepo,
|
||||
domainRepo DomainRepo,
|
||||
appGroupRepo AppGroupRepo,
|
||||
tokenRepo TokenRepo,
|
||||
) Token {
|
||||
return Token{
|
||||
appEnrich: appEnrich,
|
||||
jwt: jwtGenerate,
|
||||
tx: tx,
|
||||
appRep: appRep,
|
||||
domainRep: domainRep,
|
||||
serviceRep: serviceRep,
|
||||
tokenRep: tokenRep,
|
||||
appEnricher: appEnricher,
|
||||
jwt: jwtGenerate,
|
||||
tx: tx,
|
||||
appRepo: appRepo,
|
||||
domainRepo: domainRepo,
|
||||
serviceRepo: appGroupRepo,
|
||||
tokenRepo: tokenRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Token) GetByAppId(ctx context.Context, appId int) ([]domain.Token, error) {
|
||||
tokenEntity, err := s.tokenRep.GetTokenByAppIdList(ctx, []int{appId})
|
||||
tokenEntity, err := s.tokenRepo.GetTokenByAppIdList(ctx, []int{appId})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get token by app_id list")
|
||||
}
|
||||
@@ -90,30 +75,30 @@ func (s Token) GetByAppId(ctx context.Context, appId int) ([]domain.Token, error
|
||||
}
|
||||
|
||||
func (s Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*domain.ApplicationWithTokens, error) {
|
||||
applicationEntity, err := s.appRep.GetApplicationById(ctx, req.AppId)
|
||||
applicationEntity, err := s.appRepo.GetApplicationById(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get application by id")
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
|
||||
serviceEntity, err := s.serviceRep.GetServiceById(ctx, applicationEntity.ServiceId)
|
||||
serviceEntity, err := s.serviceRepo.GetAppGroupById(ctx, applicationEntity.ApplicationGroupId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get service by id")
|
||||
return nil, errors.WithMessage(err, "get service by id")
|
||||
}
|
||||
|
||||
_, err = s.domainRep.GetDomainById(ctx, serviceEntity.DomainId)
|
||||
_, err = s.domainRepo.GetDomainById(ctx, serviceEntity.DomainId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get domain by id")
|
||||
return nil, errors.WithMessage(err, "get domain by id")
|
||||
}
|
||||
|
||||
token, err := s.jwt.CreateApplicationToken()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "create application token")
|
||||
return nil, errors.WithMessage(err, "create application token")
|
||||
}
|
||||
|
||||
err = s.tx.TokenCreateTx(ctx, func(ctx context.Context, tx ITokenCreateTx) error {
|
||||
err = s.tx.TokenCreateTx(ctx, func(ctx context.Context, tx TokenCreateTx) error {
|
||||
_, err = tx.SaveToken(ctx, token, req.AppId, req.ExpireTimeMs)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "tx save token")
|
||||
return errors.WithMessage(err, "tx save token")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -122,35 +107,35 @@ func (s Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
return nil, errors.WithMessage(err, "token create transaction")
|
||||
}
|
||||
|
||||
arr, err := s.appEnrich.EnrichWithTokens(ctx, []entity.Application{*applicationEntity})
|
||||
arr, err := s.appEnricher.EnrichWithTokens(ctx, []entity.Application{*applicationEntity})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "application enrich with tokens")
|
||||
return nil, errors.WithMessage(err, "application enrich with tokens")
|
||||
}
|
||||
|
||||
return arr[0], nil
|
||||
}
|
||||
|
||||
func (s Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error) {
|
||||
app, err := s.appRep.GetApplicationById(ctx, req.AppId)
|
||||
app, err := s.appRepo.GetApplicationById(ctx, req.AppId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "get application by id")
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
|
||||
_, err = s.revokeTokens(ctx, req.Tokens)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "reboke tokens")
|
||||
return nil, errors.WithMessage(err, "revoke tokens")
|
||||
}
|
||||
|
||||
res, err := s.appEnrich.EnrichWithTokens(ctx, []entity.Application{*app})
|
||||
res, err := s.appEnricher.EnrichWithTokens(ctx, []entity.Application{*app})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "application enrich")
|
||||
return nil, errors.WithMessage(err, "application enrich")
|
||||
}
|
||||
|
||||
return res[0], nil
|
||||
}
|
||||
|
||||
func (s Token) RevokeByAppId(ctx context.Context, appId int) (*domain.DeleteResponse, error) {
|
||||
tokens, err := s.tokenRep.GetTokenByAppIdList(ctx, []int{appId})
|
||||
tokens, err := s.tokenRepo.GetTokenByAppIdList(ctx, []int{appId})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get token by app_id list")
|
||||
}
|
||||
@@ -169,10 +154,10 @@ func (s Token) revokeTokens(ctx context.Context, tokens []string) (*domain.Delet
|
||||
}
|
||||
|
||||
var count int
|
||||
err := s.tx.TokenRevokeTx(ctx, func(ctx context.Context, tx ITokenRevokeTx) error {
|
||||
err := s.tx.TokenRevokeTx(ctx, func(ctx context.Context, tx TokenRevokeTx) error {
|
||||
deleted, err := tx.DeleteToken(ctx, tokens)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "tx delete token")
|
||||
return errors.WithMessage(err, "tx delete token")
|
||||
}
|
||||
|
||||
count = deleted
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type TokenSource struct {
|
||||
}
|
||||
type TokenSource struct{}
|
||||
|
||||
func NewTokenSource() TokenSource {
|
||||
return TokenSource{}
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/repository"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
"github.com/txix-open/isp-kit/test/fake"
|
||||
"github.com/txix-open/isp-kit/test/grpct"
|
||||
)
|
||||
|
||||
func TestAccessListSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &AccessListSuite{})
|
||||
}
|
||||
|
||||
type AccessListSuite struct {
|
||||
suite.Suite
|
||||
|
||||
test *test.Test
|
||||
testDb *dbt.TestDb
|
||||
api *client.Client
|
||||
accessListRepo repository.AccessList
|
||||
appId int
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) SetupTest() {
|
||||
s.test, _ = test.New(s.T())
|
||||
|
||||
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
|
||||
|
||||
locator := assembly.NewLocator(s.testDb, s.test.Logger())
|
||||
config := locator.Config(conf.Remote{})
|
||||
_, s.api = grpct.TestServer(s.test, config.Handler)
|
||||
s.accessListRepo = repository.NewAccessList(s.testDb)
|
||||
|
||||
createdDomain, err := repository.NewDomain(s.testDb).CreateDomain(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
1,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
appGroup, err := repository.NewAppGroup(s.testDb).CreateAppGroup(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
createdDomain.Id,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.appId = fake.It[int]()
|
||||
|
||||
_, err = repository.NewApplication(s.testDb).CreateApplication(
|
||||
s.T().Context(),
|
||||
s.appId,
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
appGroup.Id,
|
||||
domain.ApplicationSystemType,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestGetById_HappyPath() {
|
||||
expectedAccessList := []entity.AccessList{
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: false,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
}
|
||||
|
||||
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), expectedAccessList)
|
||||
s.Require().NoError(err)
|
||||
|
||||
req := domain.Identity{
|
||||
Id: s.appId,
|
||||
}
|
||||
var accessList []domain.MethodInfo
|
||||
err = s.api.Invoke("system/access_list/get_by_id").
|
||||
JsonRequestBody(&req).
|
||||
JsonResponseBody(&accessList).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(accessList, len(expectedAccessList))
|
||||
|
||||
actualAccessList := s.convertAccessList(accessList)
|
||||
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestSetOne_HappyPath() {
|
||||
expectedAccessList := []entity.AccessList{
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: false,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
}
|
||||
|
||||
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), expectedAccessList)
|
||||
s.Require().NoError(err)
|
||||
|
||||
req := domain.AccessListSetOneRequest{
|
||||
AppId: s.appId,
|
||||
Method: expectedAccessList[0].Method,
|
||||
Value: true,
|
||||
}
|
||||
err = s.api.Invoke("system/access_list/set_one").
|
||||
JsonRequestBody(&req).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
|
||||
s.Require().NoError(err)
|
||||
|
||||
for i := range expectedAccessList {
|
||||
expectedAccessList[i].Value = true
|
||||
}
|
||||
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestSetList_HappyPath() {
|
||||
req := domain.AccessListSetListRequest{
|
||||
AppId: s.appId,
|
||||
Methods: []domain.MethodInfo{
|
||||
{
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/access_list/set_list").
|
||||
JsonRequestBody(&req).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(actualAccessList, len(req.Methods))
|
||||
|
||||
expectedAccessList := s.convertAccessList(req.Methods)
|
||||
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) TestDeleteList_HappyPath() {
|
||||
accessList := []entity.AccessList{
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: false,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
AppId: s.appId,
|
||||
Method: fake.It[string](),
|
||||
Value: true,
|
||||
},
|
||||
}
|
||||
|
||||
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), accessList)
|
||||
s.Require().NoError(err)
|
||||
|
||||
req := domain.AccessListDeleteListRequest{
|
||||
AppId: s.appId,
|
||||
Methods: []string{
|
||||
accessList[0].Method,
|
||||
accessList[1].Method,
|
||||
},
|
||||
}
|
||||
err = s.api.Invoke("system/access_list/delete_list").
|
||||
JsonRequestBody(&req).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(actualAccessList, 1)
|
||||
s.Require().Equal(accessList[2], actualAccessList[0])
|
||||
}
|
||||
|
||||
func (s *AccessListSuite) convertAccessList(methods []domain.MethodInfo) []entity.AccessList {
|
||||
converted := make([]entity.AccessList, 0, len(methods))
|
||||
for _, method := range methods {
|
||||
converted = append(converted, entity.AccessList{
|
||||
AppId: s.appId,
|
||||
Method: method.Method,
|
||||
Value: method.Value,
|
||||
})
|
||||
}
|
||||
return converted
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/repository"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
"github.com/txix-open/isp-kit/test/fake"
|
||||
"github.com/txix-open/isp-kit/test/grpct"
|
||||
)
|
||||
|
||||
func TestApplicationGroupSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &AppGroupSuite{})
|
||||
}
|
||||
|
||||
type AppGroupSuite struct {
|
||||
suite.Suite
|
||||
|
||||
test *test.Test
|
||||
testDb *dbt.TestDb
|
||||
domainRepo repository.Domain
|
||||
appGroupRepo repository.AppGroup
|
||||
api *client.Client
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) SetupTest() {
|
||||
s.test, _ = test.New(s.T())
|
||||
|
||||
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
|
||||
|
||||
locator := assembly.NewLocator(s.testDb, s.test.Logger())
|
||||
config := locator.Config(conf.Remote{})
|
||||
_, s.api = grpct.TestServer(s.test, config.Handler)
|
||||
s.domainRepo = repository.NewDomain(s.testDb)
|
||||
s.appGroupRepo = repository.NewAppGroup(s.testDb)
|
||||
|
||||
q := `
|
||||
INSERT INTO domain
|
||||
(id, name, description, system_id)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, name, description, system_id, created_at, updated_at
|
||||
`
|
||||
_, err := s.testDb.Exec(s.T().Context(), q, 1, fake.It[string](), fake.It[string](), 1)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestGetByIdList() {
|
||||
toGenerate := 10
|
||||
appGroups := make([]domain.AppGroup, 0, toGenerate)
|
||||
ids := make([]int, 0, toGenerate)
|
||||
for range 10 {
|
||||
appGroup := s.createAppGroup()
|
||||
appGroups = append(appGroups, domain.AppGroup{
|
||||
Id: appGroup.Id,
|
||||
Name: appGroup.Name,
|
||||
Description: appGroup.Description.String,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
})
|
||||
ids = append(ids, appGroup.Id)
|
||||
}
|
||||
result := []domain.AppGroup{}
|
||||
apiReq := domain.IdListRequest{IdList: ids}
|
||||
err := s.api.Invoke("system/application_group/get_by_id_list").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
for i := range result {
|
||||
s.Require().NotEmpty(result[i].CreatedAt)
|
||||
result[i].CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(result[i].UpdatedAt)
|
||||
result[i].UpdatedAt = time.Time{}
|
||||
}
|
||||
s.Require().ElementsMatch(appGroups, result)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestGetByIdList_EmptyDescription() {
|
||||
toGenerate := 10
|
||||
appGroups := make([]domain.AppGroup, 0, toGenerate)
|
||||
ids := make([]int, 0, toGenerate)
|
||||
for range 10 {
|
||||
appGroup, err := s.appGroupRepo.CreateAppGroup(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
"",
|
||||
1,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
appGroups = append(appGroups, domain.AppGroup{
|
||||
Id: appGroup.Id,
|
||||
Name: appGroup.Name,
|
||||
Description: "",
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
})
|
||||
ids = append(ids, appGroup.Id)
|
||||
}
|
||||
result := []domain.AppGroup{}
|
||||
apiReq := domain.IdListRequest{IdList: ids}
|
||||
err := s.api.Invoke("system/application_group/get_by_id_list").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
for i := range result {
|
||||
s.Require().NotEmpty(result[i].CreatedAt)
|
||||
result[i].CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(result[i].UpdatedAt)
|
||||
result[i].UpdatedAt = time.Time{}
|
||||
}
|
||||
s.Require().ElementsMatch(appGroups, result)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestGetByIdList_NotFoundAppGroups() {
|
||||
appGroup := s.createAppGroup()
|
||||
result := []domain.AppGroup{}
|
||||
|
||||
apiReq := domain.IdListRequest{IdList: []int{appGroup.Id + 1}}
|
||||
err := s.api.Invoke("system/application_group/get_by_id_list").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Empty(result)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestCreate_HappyPath() {
|
||||
apiReq := domain.CreateAppGroupRequest{
|
||||
Name: fake.It[string](),
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
var result domain.AppGroup
|
||||
err := s.api.Invoke("system/application_group/create").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().Equal(apiReq.Name, result.Name)
|
||||
s.Require().Equal(apiReq.Description, result.Description)
|
||||
|
||||
appGroup, err := s.appGroupRepo.GetAppGroupById(s.T().Context(), result.Id)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(apiReq.Name, appGroup.Name)
|
||||
s.Require().Equal(apiReq.Description, appGroup.Description.String)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestCreate_AppGroupNameNotUnique() {
|
||||
appGroup := s.createAppGroup()
|
||||
|
||||
apiReq := domain.CreateAppGroupRequest{
|
||||
Name: appGroup.Name,
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
var result domain.AppGroup
|
||||
err := s.api.Invoke("system/application_group/create").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeAppGroupDuplicateName, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestUpdate_HappyPath() {
|
||||
appGroupToUpdate := s.createAppGroup()
|
||||
|
||||
apiReq := domain.UpdateAppGroupRequest{
|
||||
Id: appGroupToUpdate.Id,
|
||||
Name: fake.It[string](),
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
var result domain.AppGroup
|
||||
err := s.api.Invoke("system/application_group/update").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().Equal(apiReq.Name, result.Name)
|
||||
s.Require().Equal(apiReq.Description, result.Description)
|
||||
|
||||
appGroup, err := s.appGroupRepo.GetAppGroupById(s.T().Context(), apiReq.Id)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(apiReq.Name, appGroup.Name)
|
||||
s.Require().Equal(apiReq.Description, appGroup.Description.String)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestUpdate_AppGroupNameNotUnique() {
|
||||
appGroupToUpdate := s.createAppGroup()
|
||||
appGroup := s.createAppGroup()
|
||||
|
||||
apiReq := domain.UpdateAppGroupRequest{
|
||||
Id: appGroupToUpdate.Id,
|
||||
Name: appGroup.Name,
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
err := s.api.Invoke("system/application_group/update").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeAppGroupDuplicateName, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestUpdate_AppGroupNotFound() {
|
||||
apiReq := domain.UpdateAppGroupRequest{
|
||||
Id: fake.It[int](),
|
||||
Name: fake.It[string](),
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
err := s.api.Invoke("system/application_group/update").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeAppGroupNotFound, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestDeleteList() {
|
||||
appGroupToDelete := s.createAppGroup()
|
||||
appGroup := s.createAppGroup()
|
||||
|
||||
var result domain.DeleteResponse
|
||||
apiReq := domain.IdListRequest{IdList: []int{appGroupToDelete.Id}}
|
||||
err := s.api.Invoke("system/application_group/delete_list").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(1, result.Deleted)
|
||||
|
||||
_, err = s.appGroupRepo.GetAppGroupById(s.T().Context(), appGroup.Id)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) TestGetAll() {
|
||||
toGenerate := 10
|
||||
appGroups := make([]domain.AppGroup, 0, toGenerate)
|
||||
for range 10 {
|
||||
appGroup := s.createAppGroup()
|
||||
appGroups = append(appGroups, domain.AppGroup{
|
||||
Id: appGroup.Id,
|
||||
Name: appGroup.Name,
|
||||
Description: appGroup.Description.String,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
})
|
||||
}
|
||||
result := []domain.AppGroup{}
|
||||
err := s.api.Invoke("system/application_group/get_all").
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
for i := range result {
|
||||
s.Require().NotEmpty(result[i].CreatedAt)
|
||||
result[i].CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(result[i].UpdatedAt)
|
||||
result[i].UpdatedAt = time.Time{}
|
||||
}
|
||||
s.Require().ElementsMatch(appGroups, result)
|
||||
}
|
||||
|
||||
func (s *AppGroupSuite) createAppGroup() *entity.AppGroup {
|
||||
appGroup, err := s.appGroupRepo.CreateAppGroup(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
1,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
return appGroup
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/repository"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
"github.com/txix-open/isp-kit/test/fake"
|
||||
"github.com/txix-open/isp-kit/test/grpct"
|
||||
)
|
||||
|
||||
func TestApplicationSuite(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &ApplicationSuite{})
|
||||
}
|
||||
|
||||
type ApplicationSuite struct {
|
||||
suite.Suite
|
||||
|
||||
test *test.Test
|
||||
testDb *dbt.TestDb
|
||||
domainRepo repository.Domain
|
||||
appRepo repository.Application
|
||||
appGroupRepo repository.AppGroup
|
||||
tokenRepo repository.Token
|
||||
api *client.Client
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) SetupTest() {
|
||||
s.test, _ = test.New(s.T())
|
||||
|
||||
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
|
||||
|
||||
locator := assembly.NewLocator(s.testDb, s.test.Logger())
|
||||
config := locator.Config(conf.Remote{})
|
||||
_, s.api = grpct.TestServer(s.test, config.Handler)
|
||||
s.domainRepo = repository.NewDomain(s.testDb)
|
||||
s.appRepo = repository.NewApplication(s.testDb)
|
||||
s.appGroupRepo = repository.NewAppGroup(s.testDb)
|
||||
s.tokenRepo = repository.NewToken(s.testDb)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestGetAllApplications() {
|
||||
expectedApps := s.insertApps(2)
|
||||
|
||||
result := []domain.Application{}
|
||||
err := s.api.Invoke("system/application/get_all").
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
for i := range result {
|
||||
s.Require().NotEmpty(result[i].CreatedAt)
|
||||
result[i].CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(result[i].UpdatedAt)
|
||||
result[i].UpdatedAt = time.Time{}
|
||||
}
|
||||
s.Require().ElementsMatch(expectedApps, result)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestCreate_HappyPath() {
|
||||
result := domain.ApplicationWithTokens{}
|
||||
appGroup := s.createAppGroup()
|
||||
|
||||
apiReq := domain.CreateApplicationRequest{
|
||||
Id: 1,
|
||||
Name: fake.It[string](),
|
||||
Type: domain.ApplicationSystemType,
|
||||
ApplicationGroupId: appGroup.Id,
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/application/create_application").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NotEmpty(result.App.CreatedAt)
|
||||
result.App.CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(result.App.UpdatedAt)
|
||||
result.App.UpdatedAt = time.Time{}
|
||||
|
||||
expectedApp := domain.Application{
|
||||
Id: apiReq.Id,
|
||||
Name: apiReq.Name,
|
||||
Description: apiReq.Description,
|
||||
Type: apiReq.Type,
|
||||
ServiceId: apiReq.ApplicationGroupId,
|
||||
}
|
||||
s.Require().Equal(expectedApp, result.App)
|
||||
s.Require().Empty(result.Tokens)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestCreate_AppGroupNotFound() {
|
||||
apiReq := domain.CreateApplicationRequest{
|
||||
Id: 1,
|
||||
Name: fake.It[string](),
|
||||
Type: domain.ApplicationSystemType,
|
||||
ApplicationGroupId: 1,
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/application/create_application").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeAppGroupNotFound, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestCreate_ApplicationNameNotUniqueInAppGroup() {
|
||||
inserted := s.insertApps(1)
|
||||
|
||||
apiReq := domain.CreateApplicationRequest{
|
||||
Id: inserted[0].Id + 1,
|
||||
Name: inserted[0].Name,
|
||||
Type: domain.ApplicationSystemType,
|
||||
ApplicationGroupId: inserted[0].ServiceId,
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/application/create_application").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeApplicationDuplicateName, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestCreate_ApplicationIdNotUnique() {
|
||||
inserted := s.insertApps(1)
|
||||
|
||||
apiReq := domain.CreateApplicationRequest{
|
||||
Id: inserted[0].Id,
|
||||
Name: inserted[0].Name,
|
||||
Type: domain.ApplicationSystemType,
|
||||
ApplicationGroupId: inserted[0].ServiceId,
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/application/create_application").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeApplicationDuplicateId, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestUpdate_HappyPath() {
|
||||
inserted := s.insertApps(2)
|
||||
apiReq := domain.UpdateApplicationRequest{
|
||||
OldId: inserted[0].Id,
|
||||
NewId: fake.It[int](),
|
||||
Name: fake.It[string](),
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
|
||||
var result domain.ApplicationWithTokens
|
||||
err := s.api.Invoke("system/application/update_application").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NotEmpty(result.App.CreatedAt)
|
||||
result.App.CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(result.App.UpdatedAt)
|
||||
result.App.UpdatedAt = time.Time{}
|
||||
|
||||
expectedApp := domain.Application{
|
||||
Id: apiReq.NewId,
|
||||
Name: apiReq.Name,
|
||||
Description: apiReq.Description,
|
||||
Type: inserted[0].Type,
|
||||
ServiceId: inserted[0].ServiceId,
|
||||
}
|
||||
s.Require().Equal(expectedApp, result.App)
|
||||
s.Require().Empty(result.Tokens)
|
||||
|
||||
app, err := s.appRepo.GetApplicationById(s.T().Context(), apiReq.NewId)
|
||||
s.Require().NoError(err)
|
||||
|
||||
expectedDbApp := entity.Application{
|
||||
Id: apiReq.NewId,
|
||||
Name: apiReq.Name,
|
||||
Description: app.Description,
|
||||
Type: inserted[0].Type,
|
||||
ApplicationGroupId: inserted[0].ServiceId,
|
||||
}
|
||||
|
||||
s.Require().NotEmpty(app.CreatedAt)
|
||||
app.CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(app.UpdatedAt)
|
||||
app.UpdatedAt = time.Time{}
|
||||
s.Require().Equal(expectedDbApp, *app)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestUpdate_ApplicationNameNotUniqueInAppGroup() {
|
||||
inserted := s.insertApps(2)
|
||||
apiReq := domain.UpdateApplicationRequest{
|
||||
NewId: inserted[0].Id,
|
||||
OldId: inserted[0].Id,
|
||||
Name: inserted[1].Name,
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/application/update_application").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeApplicationDuplicateName, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestUpdate_AppIdNotUnique() {
|
||||
inserted := s.insertApps(2)
|
||||
apiReq := domain.UpdateApplicationRequest{
|
||||
OldId: inserted[0].Id,
|
||||
NewId: inserted[1].Id,
|
||||
Name: fake.It[string](),
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/application/update_application").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeApplicationDuplicateId, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestUpdate_AppNotFound() {
|
||||
apiReq := domain.UpdateApplicationRequest{
|
||||
OldId: fake.It[int](),
|
||||
NewId: fake.It[int](),
|
||||
Name: fake.It[string](),
|
||||
Description: fake.It[string](),
|
||||
}
|
||||
|
||||
err := s.api.Invoke("system/application/update_application").
|
||||
JsonRequestBody(apiReq).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeApplicationNotFound, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestGetByToken() {
|
||||
insertedApps := s.insertApps(2)
|
||||
|
||||
token := fake.It[string]()
|
||||
expectedApp := domain.GetApplicationByTokenResponse{
|
||||
ApplicationId: insertedApps[0].Id,
|
||||
ApplicationGroupId: insertedApps[0].ServiceId,
|
||||
}
|
||||
_, err := s.tokenRepo.SaveToken(s.T().Context(), token, expectedApp.ApplicationId, fake.It[int]())
|
||||
s.Require().NoError(err)
|
||||
|
||||
result := domain.GetApplicationByTokenResponse{}
|
||||
err = s.api.Invoke("system/application/get_application_by_token").
|
||||
JsonRequestBody(domain.GetApplicationByTokenRequest{Token: token}).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(expectedApp, result)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestGetByToken_NotFound() {
|
||||
s.insertApps(2)
|
||||
|
||||
result := domain.GetApplicationByTokenResponse{}
|
||||
err := s.api.Invoke("system/application/get_application_by_token").
|
||||
JsonRequestBody(domain.GetApplicationByTokenRequest{Token: fake.It[string]()}).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
apiError := apierrors.FromError(err)
|
||||
s.Require().NotNil(apiError)
|
||||
s.Require().Equal(domain.ErrCodeApplicationNotFound, apiError.ErrorCode)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) createAppGroup() *entity.AppGroup {
|
||||
createdDomain, err := s.domainRepo.CreateDomain(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
1,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
appGroup, err := s.appGroupRepo.CreateAppGroup(
|
||||
s.T().Context(),
|
||||
fake.It[string](),
|
||||
fake.It[string](),
|
||||
createdDomain.Id,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
return appGroup
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) insertApps(appsCount uint) []domain.Application {
|
||||
toInsert := fake.It[[]domain.Application](fake.MinSliceSize(appsCount), fake.MaxSliceSize(appsCount))
|
||||
|
||||
appGroup := s.createAppGroup()
|
||||
toExpect := make([]domain.Application, 0, len(toInsert))
|
||||
for _, app := range toInsert {
|
||||
appId, err := s.appRepo.NextApplicationId(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
createdApp, err := s.appRepo.CreateApplication(
|
||||
s.T().Context(),
|
||||
appId,
|
||||
app.Name,
|
||||
app.Description,
|
||||
appGroup.Id,
|
||||
app.Type,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotEmpty(createdApp.CreatedAt)
|
||||
s.Require().NotEmpty(createdApp.UpdatedAt)
|
||||
|
||||
toExpect = append(toExpect, domain.Application{
|
||||
Id: createdApp.Id,
|
||||
Name: createdApp.Name,
|
||||
Description: createdApp.Description.String,
|
||||
ServiceId: createdApp.ApplicationGroupId,
|
||||
Type: createdApp.Type,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
})
|
||||
}
|
||||
return toExpect
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
@@ -22,6 +21,7 @@ func TestBaselineSuite(t *testing.T) {
|
||||
|
||||
type BaselineSuite struct {
|
||||
suite.Suite
|
||||
|
||||
test *test.Test
|
||||
testDb *dbt.TestDb
|
||||
baseline baseline.Service
|
||||
@@ -44,9 +44,9 @@ func (s *BaselineSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
func (s *BaselineSuite) TestBaselineSuccess() {
|
||||
err := s.baseline.Do(context.Background())
|
||||
err := s.baseline.Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = s.baseline.Do(context.Background())
|
||||
err = s.baseline.Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
)
|
||||
|
||||
func InsertDomain(db *dbt.TestDb, value entity.Domain) {
|
||||
@@ -15,9 +16,9 @@ func InsertDomain(db *dbt.TestDb, value entity.Domain) {
|
||||
db.Must().ExecNamed(q, value)
|
||||
}
|
||||
|
||||
func InsertService(db *dbt.TestDb, value entity.Service) {
|
||||
func InsertAppGroup(db *dbt.TestDb, value entity.AppGroup) {
|
||||
q := `
|
||||
INSERT INTO service
|
||||
INSERT INTO application_group
|
||||
(id, name, description, domain_id, created_at, updated_at)
|
||||
VALUES
|
||||
(:id, :name, :description, :domain_id, :created_at, :updated_at)
|
||||
@@ -28,9 +29,9 @@ func InsertService(db *dbt.TestDb, value entity.Service) {
|
||||
func InsertApplication(db *dbt.TestDb, value entity.Application) {
|
||||
q := `
|
||||
INSERT INTO application
|
||||
(id, name, description, service_id, created_at, updated_at)
|
||||
(id, name, description, application_group_id, created_at, updated_at)
|
||||
VALUES
|
||||
(:id, :name, :description, :service_id, :created_at, :updated_at)
|
||||
(:id, :name, :description, :application_group_id, :created_at, :updated_at)
|
||||
`
|
||||
db.Must().ExecNamed(q, value)
|
||||
}
|
||||
|
||||
+38
-36
@@ -1,21 +1,21 @@
|
||||
package tests_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"github.com/txix-open/isp-kit/test"
|
||||
"github.com/txix-open/isp-kit/test/dbt"
|
||||
"github.com/txix-open/isp-kit/test/grpct"
|
||||
"isp-system-service/assembly"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
func TestSecureSuite(t *testing.T) {
|
||||
@@ -25,14 +25,14 @@ func TestSecureSuite(t *testing.T) {
|
||||
|
||||
type SecureSuite struct {
|
||||
suite.Suite
|
||||
test *test.Test
|
||||
require *require.Assertions
|
||||
testDb *dbt.TestDb
|
||||
api *client.Client
|
||||
|
||||
test *test.Test
|
||||
testDb *dbt.TestDb
|
||||
api *client.Client
|
||||
}
|
||||
|
||||
func (s *SecureSuite) SetupSuite() {
|
||||
s.test, s.require = test.New(s.T())
|
||||
s.test, _ = test.New(s.T())
|
||||
|
||||
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
|
||||
|
||||
@@ -44,11 +44,11 @@ func (s *SecureSuite) SetupSuite() {
|
||||
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,
|
||||
InsertAppGroup(s.testDb, entity.AppGroup{
|
||||
Id: 5, Name: "test_application_group", DomainId: 3, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||
})
|
||||
InsertApplication(s.testDb, entity.Application{
|
||||
Id: 7, Name: "test_application", ServiceId: 5, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||
Id: 7, Name: "test_application", ApplicationGroupId: 5, CreatedAt: createdTime, UpdatedAt: createdTime,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,12 +63,13 @@ func (s *SecureSuite) TestAuthenticate_Success() {
|
||||
Token: "test_token_success",
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: true,
|
||||
ErrorReason: "",
|
||||
AuthData: &domain.AuthData{
|
||||
AppName: "test_application",
|
||||
SystemId: 1,
|
||||
DomainId: 3,
|
||||
ServiceId: 5,
|
||||
@@ -84,9 +85,9 @@ func (s *SecureSuite) TestAuthenticate_NotFound() {
|
||||
Token: "test_token_not_found",
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenNotFound.Error(),
|
||||
AuthData: nil,
|
||||
@@ -104,12 +105,13 @@ func (s *SecureSuite) TestAuthenticate_NotExpired() {
|
||||
Token: "test_token_not_expired",
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: true,
|
||||
ErrorReason: "",
|
||||
AuthData: &domain.AuthData{
|
||||
AppName: "test_application",
|
||||
SystemId: 1,
|
||||
DomainId: 3,
|
||||
ServiceId: 5,
|
||||
@@ -129,9 +131,9 @@ func (s *SecureSuite) TestAuthenticate_Expired() {
|
||||
Token: "test_token_expired",
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthenticateResponse{
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthenticateResponse{
|
||||
Authenticated: false,
|
||||
ErrorReason: domain.ErrTokenExpired.Error(),
|
||||
AuthData: nil,
|
||||
@@ -152,9 +154,9 @@ func (s *SecureSuite) TestAuthorize_Success_True() {
|
||||
Endpoint: "endpoint/available",
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthorizeResponse{
|
||||
Authorized: true,
|
||||
}, result)
|
||||
}
|
||||
@@ -173,9 +175,9 @@ func (s *SecureSuite) TestAuthorize_Success_False() {
|
||||
Endpoint: "endpoint/not_available",
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthorizeResponse{
|
||||
Authorized: false,
|
||||
}, result)
|
||||
}
|
||||
@@ -188,9 +190,9 @@ func (s *SecureSuite) TestAuthorize_NotFound() {
|
||||
Endpoint: "endpoint/not_found",
|
||||
}).
|
||||
JsonResponseBody(&result).
|
||||
Do(context.Background())
|
||||
s.require.NoError(err)
|
||||
s.require.Equal(domain.AuthorizeResponse{
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(domain.AuthorizeResponse{
|
||||
Authorized: false,
|
||||
}, result)
|
||||
}
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"isp-system-service/service/baseline"
|
||||
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"isp-system-service/repository"
|
||||
"isp-system-service/service"
|
||||
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
@@ -23,7 +24,7 @@ type accessListSetOneTx struct {
|
||||
repository.AccessList
|
||||
}
|
||||
|
||||
func (m Manager) AccessListSetOneTx(ctx context.Context, msgTx func(ctx context.Context, tx service.IAccessListSetOneTx) error) error {
|
||||
func (m Manager) AccessListSetOneTx(ctx context.Context, msgTx func(ctx context.Context, tx service.AccessListSetOneTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
accessListRepository := repository.NewAccessList(tx)
|
||||
return msgTx(ctx, accessListSetOneTx{
|
||||
@@ -36,7 +37,7 @@ type accessListSetListTx struct {
|
||||
repository.AccessList
|
||||
}
|
||||
|
||||
func (m Manager) AccessListSetListTx(ctx context.Context, msgTx func(ctx context.Context, tx service.IAccessListSetListTx) error) error {
|
||||
func (m Manager) AccessListSetListTx(ctx context.Context, msgTx func(ctx context.Context, tx service.AccessListSetListTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
accessListRep := repository.NewAccessList(tx)
|
||||
return msgTx(ctx, accessListSetListTx{
|
||||
@@ -49,7 +50,7 @@ type applicationDeleteTx struct {
|
||||
repository.Application
|
||||
}
|
||||
|
||||
func (m Manager) ApplicationDeleteTx(ctx context.Context, msgTx func(ctx context.Context, tx service.IApplicationDeleteTx) error) error {
|
||||
func (m Manager) ApplicationDeleteTx(ctx context.Context, msgTx func(ctx context.Context, tx service.ApplicationDeleteTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
applicationRep := repository.NewApplication(tx)
|
||||
return msgTx(ctx, applicationDeleteTx{
|
||||
@@ -62,7 +63,7 @@ type tokenCreateTx struct {
|
||||
repository.Token
|
||||
}
|
||||
|
||||
func (m Manager) TokenCreateTx(ctx context.Context, msgTx func(ctx context.Context, tx service.ITokenCreateTx) error) error {
|
||||
func (m Manager) TokenCreateTx(ctx context.Context, msgTx func(ctx context.Context, tx service.TokenCreateTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
tokenRep := repository.NewToken(tx)
|
||||
return msgTx(ctx, tokenCreateTx{
|
||||
@@ -75,7 +76,7 @@ type tokenRevokeTx struct {
|
||||
repository.Token
|
||||
}
|
||||
|
||||
func (m Manager) TokenRevokeTx(ctx context.Context, msgTx func(ctx context.Context, tx service.ITokenRevokeTx) error) error {
|
||||
func (m Manager) TokenRevokeTx(ctx context.Context, msgTx func(ctx context.Context, tx service.TokenRevokeTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
tokenRep := repository.NewToken(tx)
|
||||
return msgTx(ctx, tokenRevokeTx{
|
||||
@@ -87,7 +88,7 @@ func (m Manager) TokenRevokeTx(ctx context.Context, msgTx func(ctx context.Conte
|
||||
type baselineTx struct {
|
||||
repository.Locker
|
||||
repository.Domain
|
||||
repository.Service
|
||||
repository.AppGroup
|
||||
repository.Application
|
||||
repository.AccessList
|
||||
repository.Token
|
||||
@@ -98,7 +99,7 @@ func (m Manager) BaselineTx(ctx context.Context, txTx func(ctx context.Context,
|
||||
return txTx(ctx, baselineTx{
|
||||
Locker: repository.NewLocker(tx),
|
||||
Domain: repository.NewDomain(tx),
|
||||
Service: repository.NewService(tx),
|
||||
AppGroup: repository.NewAppGroup(tx),
|
||||
Application: repository.NewApplication(tx),
|
||||
AccessList: repository.NewAccessList(tx),
|
||||
Token: repository.NewToken(tx),
|
||||
|
||||
Reference in new issue
Block a user