Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e701501dbb | ||
|
|
ad505b8f3c | ||
|
|
9600f7ef1e | ||
|
|
0db03de171 | ||
|
|
d8a0db34ef |
No files matched your search
+84
@@ -0,0 +1,84 @@
|
|||||||
|
|
||||||
|
# Created by .ignore support plugin (hsz.mobi)
|
||||||
|
### JetBrains template
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
*.iml
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
### Go template
|
||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
vendor
|
||||||
|
|
||||||
|
# Test binary, build with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
docker-compose.yml
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
conf/config_dev.yml
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
include:
|
||||||
|
- project: '$CI_PROJECT_PATH'
|
||||||
|
file: '/ci-isp-go-service.yml'
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
run:
|
||||||
|
allow-parallel-runners: true
|
||||||
|
issues:
|
||||||
|
exclude-rules:
|
||||||
|
- path: controller #достаточное кол-во контекса на уровне контроллеров
|
||||||
|
linters:
|
||||||
|
- wrapcheck
|
||||||
|
- path: transaction #транзакции прозрачны
|
||||||
|
linters:
|
||||||
|
- wrapcheck
|
||||||
|
linters:
|
||||||
|
enable-all: true
|
||||||
|
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:
|
||||||
|
rules:
|
||||||
|
- name: var-naming #отключаем Id -> ID
|
||||||
|
disabled: true
|
||||||
|
stylecheck:
|
||||||
|
checks: #отключаем Id -> ID
|
||||||
|
- "-ST1000"
|
||||||
|
- "-ST1016"
|
||||||
|
- "-ST1020"
|
||||||
|
- "-ST1021"
|
||||||
|
- "-ST1022"
|
||||||
|
testifylint:
|
||||||
|
disable:
|
||||||
|
- compares
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
### v3.1.4
|
||||||
|
* обновлены зависимости
|
||||||
|
### v3.1.3
|
||||||
|
* Замена в конфигурации одного массива скриптов на кастомные и остальные
|
||||||
|
* Добавлена новая ошибка с дупликатами id
|
||||||
|
### v3.1.1
|
||||||
|
* Обновлены зависимости
|
||||||
|
* Замена `integration-system` на `txix-open`
|
||||||
|
* Обновление линтера
|
||||||
|
* Добавлено логирование запросов
|
||||||
|
### v3.1.0
|
||||||
|
* обновлены зависимости
|
||||||
|
### v3.0.2
|
||||||
|
* обновлены зависимости
|
||||||
|
* исправлен вызов внутренних методов через `external.invoke`
|
||||||
|
### v3.0.1
|
||||||
|
* Название ручек сервиса изменены для обеспечения обратной совместимости
|
||||||
|
### v3.0.0
|
||||||
|
* миграция сервиса на isp-kit
|
||||||
|
* миграция на версию GO 1.19.1
|
||||||
|
* обновлен формат логов в json
|
||||||
|
* обновлена библиотека goja, добавлена поддержка ES6 синтаксиса
|
||||||
|
### v2.5.8
|
||||||
|
* updated dependencies
|
||||||
|
* migrated to common local config
|
||||||
|
### v2.5.7
|
||||||
|
* fix receiving new configuration
|
||||||
|
### v2.5.6
|
||||||
|
* updated dependencies
|
||||||
|
### v2.5.5
|
||||||
|
* add new functions for scripts: sha256, sha512, generate UUIDv4
|
||||||
|
### v2.5.4
|
||||||
|
* fix: added missing "invoke" function to scripts
|
||||||
|
### v2.5.3
|
||||||
|
* added "invalid script configuration" error instead of "404:Not Found" error when invalid script was requested.
|
||||||
|
### v2.5.2
|
||||||
|
* updated isp-lib
|
||||||
|
### v2.5.1
|
||||||
|
* updated isp-lib
|
||||||
|
* updated isp-lib-test
|
||||||
|
### v2.5.0
|
||||||
|
* migrate from inbuilt wrapping of goja to new isp-lib/scripts package
|
||||||
|
### v2.4.1
|
||||||
|
* updated isp-lib
|
||||||
|
* updated isp-event-lib
|
||||||
|
### V2.4.0
|
||||||
|
* added swagger docs
|
||||||
|
* updated to new isp-lib (v2.6.1)
|
||||||
|
* added golanci support
|
||||||
|
### V2.3.0
|
||||||
|
* additional batch method
|
||||||
|
### V2.2.0
|
||||||
|
* add batch execution
|
||||||
|
### V2.1.1
|
||||||
|
* update script engine
|
||||||
|
### v2.1.0
|
||||||
|
* update to go mod
|
||||||
|
### v2.0.3
|
||||||
|
* up script engine version and others dependencies
|
||||||
|
### v2.0.2
|
||||||
|
* add metrics
|
||||||
|
### v2.0.0
|
||||||
|
* update to new isp-lib & config service
|
||||||
|
* fix max body request/response sizing
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
FROM dockerhub.mos.ru/mosos/arbat:15.5 as builder
|
||||||
|
RUN zypper --no-gpg-checks update -y && zypper --no-gpg-checks install -y go1.24 git
|
||||||
|
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/mosos/arbat:15.5
|
||||||
|
|
||||||
|
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
||||||
|
RUN echo "Europe/Moscow" > /etc/timezone
|
||||||
|
|
||||||
|
ARG UID=10001
|
||||||
|
RUN useradd \
|
||||||
|
--home "/nonexistent" \
|
||||||
|
--shell "/sbin/nologin" \
|
||||||
|
--no-create-home \
|
||||||
|
--uid "${UID}" \
|
||||||
|
--user-group \
|
||||||
|
appuser
|
||||||
|
|
||||||
|
RUN mkdir -p /app/data
|
||||||
|
RUN chown appuser:appuser /app/data
|
||||||
|
VOLUME /app/data
|
||||||
|
|
||||||
|
USER appuser
|
||||||
|
|
||||||
|
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
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// nolint:wrapcheck
|
||||||
|
package assembly
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/app"
|
||||||
|
"github.com/txix-open/isp-kit/bootstrap"
|
||||||
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"isp-script-service/conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Assembly struct {
|
||||||
|
boot *bootstrap.Bootstrap
|
||||||
|
server *grpc.Server
|
||||||
|
logger *log.Adapter
|
||||||
|
router *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
||||||
|
server := grpc.DefaultServer()
|
||||||
|
router, err := client.Default()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "create repository client")
|
||||||
|
}
|
||||||
|
return &Assembly{
|
||||||
|
boot: boot,
|
||||||
|
server: server,
|
||||||
|
logger: boot.App.Logger(),
|
||||||
|
router: router,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error {
|
||||||
|
var (
|
||||||
|
newCfg conf.Remote
|
||||||
|
prevCfg conf.Remote
|
||||||
|
)
|
||||||
|
err := a.boot.RemoteConfig.Upgrade(remoteConfig, &newCfg, &prevCfg)
|
||||||
|
if err != nil {
|
||||||
|
a.logger.Fatal(ctx, errors.WithMessage(err, "upgrade remote config"))
|
||||||
|
}
|
||||||
|
|
||||||
|
a.logger.SetLevel(newCfg.LogLevel)
|
||||||
|
|
||||||
|
locator := NewLocator(a.logger, a.router)
|
||||||
|
handler, err := locator.Handler(newCfg)
|
||||||
|
if err != nil {
|
||||||
|
a.logger.Fatal(ctx, errors.WithMessage(err, "new handler"))
|
||||||
|
}
|
||||||
|
|
||||||
|
a.server.Upgrade(handler)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Assembly) Runners() []app.Runner {
|
||||||
|
eventHandler := cluster.NewEventHandler().
|
||||||
|
RequireModule("router", a.router).
|
||||||
|
RemoteConfigReceiver(a)
|
||||||
|
return []app.Runner{
|
||||||
|
app.RunnerFunc(func(ctx context.Context) error {
|
||||||
|
return a.server.ListenAndServe(a.boot.BindingAddress)
|
||||||
|
}),
|
||||||
|
app.RunnerFunc(func(ctx context.Context) error {
|
||||||
|
return a.boot.ClusterCli.Run(ctx, eventHandler)
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Assembly) Closers() []app.Closer {
|
||||||
|
return []app.Closer{
|
||||||
|
a.boot.ClusterCli,
|
||||||
|
app.CloserFunc(func() error {
|
||||||
|
a.server.Shutdown()
|
||||||
|
return nil
|
||||||
|
}),
|
||||||
|
a.router,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
// nolint:ireturn
|
||||||
|
package assembly
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/endpoint/grpclog"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"isp-script-service/conf"
|
||||||
|
"isp-script-service/controller"
|
||||||
|
"isp-script-service/domain"
|
||||||
|
"isp-script-service/repository"
|
||||||
|
"isp-script-service/routes"
|
||||||
|
"isp-script-service/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Locator struct {
|
||||||
|
logger log.Logger
|
||||||
|
grpcCli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLocator(logger log.Logger, grpcCli *client.Client) Locator {
|
||||||
|
return Locator{
|
||||||
|
logger: logger,
|
||||||
|
grpcCli: grpcCli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l Locator) Handler(cfg conf.Remote) (*grpc.Mux, error) {
|
||||||
|
scripts, err := MergeScripts(cfg.Scripts, cfg.CustomScripts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "merge scripts")
|
||||||
|
}
|
||||||
|
|
||||||
|
router := repository.NewRouter(l.grpcCli)
|
||||||
|
scriptService := service.NewScript(router, l.logger, scripts, cfg.SharedScript, cfg.ScriptExecutionTimeoutMs)
|
||||||
|
scriptController := controller.NewScript(scriptService)
|
||||||
|
|
||||||
|
c := routes.Controllers{
|
||||||
|
Script: scriptController,
|
||||||
|
}
|
||||||
|
mapper := endpoint.DefaultWrapper(l.logger, grpclog.Log(l.logger, true))
|
||||||
|
handler := routes.Handler(mapper, c)
|
||||||
|
return handler, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func MergeScripts(scripts []conf.ScriptDefinition, customScripts []conf.ScriptDefinition) ([]conf.ScriptDefinition, error) {
|
||||||
|
uniqueScripts := make(map[string]conf.ScriptDefinition)
|
||||||
|
|
||||||
|
for _, script := range scripts {
|
||||||
|
if _, exists := uniqueScripts[script.Id]; exists {
|
||||||
|
return nil, domain.ErrDuplicateScriptId
|
||||||
|
}
|
||||||
|
uniqueScripts[script.Id] = script
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, customScript := range customScripts {
|
||||||
|
if _, exists := uniqueScripts[customScript.Id]; exists {
|
||||||
|
return nil, domain.ErrDuplicateScriptId
|
||||||
|
}
|
||||||
|
uniqueScripts[customScript.Id] = customScript
|
||||||
|
}
|
||||||
|
|
||||||
|
mergedScripts := make([]conf.ScriptDefinition, 0, len(uniqueScripts))
|
||||||
|
for _, script := range uniqueScripts {
|
||||||
|
mergedScripts = append(mergedScripts, script)
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergedScripts, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
configServiceAddress:
|
||||||
|
ip: 127.0.0.1
|
||||||
|
port: 9001
|
||||||
|
grpcOuterAddress:
|
||||||
|
# ip: 127.0.0.1
|
||||||
|
port: 9024
|
||||||
|
grpcInnerAddress:
|
||||||
|
ip: 0.0.0.0
|
||||||
|
port: 9024
|
||||||
|
moduleName: script
|
||||||
|
infraServerPort: 9574
|
||||||
|
|
||||||
|
logfile:
|
||||||
|
path: /var/log/isp-script-service/runtime.log
|
||||||
|
maxSizeMb: 512
|
||||||
|
maxBackups: 4
|
||||||
|
compress: true
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"logLevel": "debug",
|
||||||
|
"scripts": [],
|
||||||
|
"customScripts": [],
|
||||||
|
"sharedScript": "",
|
||||||
|
"scriptExecutionTimeoutMs": 1000
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package conf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"github.com/txix-open/isp-kit/rc/schema"
|
||||||
|
"github.com/txix-open/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
// nolint:gochecknoinits
|
||||||
|
func init() {
|
||||||
|
schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, t *jsonschema.Schema) {
|
||||||
|
t.Type = "string"
|
||||||
|
t.Enum = []interface{}{"debug", "info", "error", "fatal"}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type Remote struct {
|
||||||
|
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||||
|
Scripts []ScriptDefinition `schema:"Скрипты"`
|
||||||
|
CustomScripts []ScriptDefinition `schema:"Кастомные скрипты"`
|
||||||
|
SharedScript string `schema:"Общий скрипт"`
|
||||||
|
ScriptExecutionTimeoutMs int `validate:"required" schema:"Время выполнения скрипта"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ScriptDefinition struct {
|
||||||
|
Id string `validate:"required"`
|
||||||
|
Script string `validate:"required"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package conf_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/test/rct"
|
||||||
|
"isp-script-service/conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultRemoteConfig(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
rct.Test(t, "default_remote_config.json", conf.Remote{})
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
"isp-script-service/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type scriptService interface {
|
||||||
|
Execute(req domain.ExecuteRequest) *domain.ScriptResp
|
||||||
|
ExecuteById(req domain.ExecuteByIdRequest) (*domain.ScriptResp, error)
|
||||||
|
BatchExecute(req []domain.ExecuteByIdRequest) []domain.ScriptResp
|
||||||
|
BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type Script struct {
|
||||||
|
service scriptService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScript(service scriptService) Script {
|
||||||
|
return Script{service: service}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecuteById
|
||||||
|
// @Tags script
|
||||||
|
// @Summary Выполнить скрипт под конкретным ID
|
||||||
|
// @Description Возвращает результат выполнения скрипта и ошибку (если есть)
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body domain.ExecuteByIdRequest true "идентификатор скрипта"
|
||||||
|
// @Success 200 {object} domain.ScriptResp
|
||||||
|
// @Failure 404 {object} domain.GrpcError
|
||||||
|
// @Router /script/execute_by_id [POST].
|
||||||
|
func (c Script) ExecuteById(req domain.ExecuteByIdRequest) (*domain.ScriptResp, error) {
|
||||||
|
data, err := c.service.ExecuteById(req)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, domain.ErrScriptNotFound):
|
||||||
|
return nil, status.Errorf(codes.NotFound, "not defined script for id %s", req.Id)
|
||||||
|
case err != nil:
|
||||||
|
return nil, err
|
||||||
|
default:
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
// @Tags script
|
||||||
|
// @Summary Выполнить скрипт без учёта идентификатора
|
||||||
|
// @Description Возвращает результат выполнения скрипта и ошибку (если есть)
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body domain.ExecuteRequest true "Скрипт необходимый к выполнению"
|
||||||
|
// @Success 200 {object} domain.ScriptResp
|
||||||
|
// @Router /script/execute [POST].
|
||||||
|
func (c Script) Execute(req domain.ExecuteRequest) *domain.ScriptResp {
|
||||||
|
return c.service.Execute(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchExecute
|
||||||
|
// @Tags script
|
||||||
|
// @Summary Выполнить набор скриптов под конкретными ID
|
||||||
|
// @Description Возвращает результат выполнения скриптов и ошибок (если есть)
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body []domain.ExecuteByIdRequest true "Набор идентификаторов и аргументов"
|
||||||
|
// @Success 200 {array} domain.ScriptResp
|
||||||
|
// @Router /script/batch_execute [POST].
|
||||||
|
func (c Script) BatchExecute(req []domain.ExecuteByIdRequest) []domain.ScriptResp {
|
||||||
|
return c.service.BatchExecute(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchExecuteById
|
||||||
|
// @Tags script
|
||||||
|
// @Summary Выполнить набор скриптов под конкретными ID с идентичным аргументом для всех
|
||||||
|
// @Description Возвращает результат выполнения скриптов и ошибок (если есть)
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body domain.BatchExecuteByIdsRequest true "Набор идентификаторов и единый аргумент"
|
||||||
|
// @Success 200 {array} domain.ScriptResp
|
||||||
|
// @Router /script/batch_execute_by_ids [POST].
|
||||||
|
func (c Script) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
|
||||||
|
return c.service.BatchExecuteById(req)
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
basePath: /api/script
|
||||||
|
definitions:
|
||||||
|
domain.BatchExecuteByIdsRequest:
|
||||||
|
properties:
|
||||||
|
arg:
|
||||||
|
type: object
|
||||||
|
ids:
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
required:
|
||||||
|
- ids
|
||||||
|
type: object
|
||||||
|
domain.Error:
|
||||||
|
properties:
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
domain.ExecuteByIdRequest:
|
||||||
|
properties:
|
||||||
|
arg:
|
||||||
|
type: object
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
type: object
|
||||||
|
domain.ExecuteRequest:
|
||||||
|
properties:
|
||||||
|
arg:
|
||||||
|
type: object
|
||||||
|
script:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- script
|
||||||
|
type: object
|
||||||
|
domain.GrpcError:
|
||||||
|
properties:
|
||||||
|
details:
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
type: array
|
||||||
|
errorCode:
|
||||||
|
type: string
|
||||||
|
errorMessage:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
domain.ScriptResp:
|
||||||
|
properties:
|
||||||
|
error:
|
||||||
|
$ref: '#/definitions/domain.Error'
|
||||||
|
result:
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
host: localhost:9000
|
||||||
|
info:
|
||||||
|
contact: {}
|
||||||
|
description: Сервис для обработки и выполнения JavaScript скриптов
|
||||||
|
license:
|
||||||
|
name: GNU GPL v3.0
|
||||||
|
title: isp-script-service
|
||||||
|
version: 1.0.0
|
||||||
|
paths:
|
||||||
|
/script/batch_execute:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Возвращает результат выполнения скриптов и ошибок (если есть)
|
||||||
|
parameters:
|
||||||
|
- description: Набор идентификаторов и аргументов
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/domain.ExecuteByIdRequest'
|
||||||
|
type: array
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/domain.ScriptResp'
|
||||||
|
type: array
|
||||||
|
summary: Выполнить набор скриптов под конкретными ID
|
||||||
|
tags:
|
||||||
|
- script
|
||||||
|
/script/batch_execute_by_ids:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Возвращает результат выполнения скриптов и ошибок (если есть)
|
||||||
|
parameters:
|
||||||
|
- description: Набор идентификаторов и единый аргумент
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.BatchExecuteByIdsRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/domain.ScriptResp'
|
||||||
|
type: array
|
||||||
|
summary: Выполнить набор скриптов под конкретными ID с идентичным аргументом
|
||||||
|
для всех
|
||||||
|
tags:
|
||||||
|
- script
|
||||||
|
/script/execute:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Возвращает результат выполнения скрипта и ошибку (если есть)
|
||||||
|
parameters:
|
||||||
|
- description: Скрипт необходимый к выполнению
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.ExecuteRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.ScriptResp'
|
||||||
|
summary: Выполнить скрипт без учёта идентификатора
|
||||||
|
tags:
|
||||||
|
- script
|
||||||
|
/script/execute_by_id:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Возвращает результат выполнения скрипта и ошибку (если есть)
|
||||||
|
parameters:
|
||||||
|
- description: идентификатор скрипта
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.ExecuteByIdRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.ScriptResp'
|
||||||
|
"404":
|
||||||
|
description: Not Found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.GrpcError'
|
||||||
|
summary: Выполнить скрипт под конкретным ID
|
||||||
|
tags:
|
||||||
|
- script
|
||||||
|
swagger: "2.0"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrScriptNotFound = errors.New("script not found")
|
||||||
|
ErrDuplicateScriptId = errors.New("duplicate script id")
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
type GrpcError struct {
|
||||||
|
ErrorMessage string
|
||||||
|
ErrorCode string
|
||||||
|
Details []interface{}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
type ExecuteByIdRequest struct {
|
||||||
|
Id string `validate:"required"`
|
||||||
|
Arg interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExecuteRequest struct {
|
||||||
|
Script string `validate:"required"`
|
||||||
|
Arg interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type BatchExecuteByIdsRequest struct {
|
||||||
|
Ids []string `validate:"required"`
|
||||||
|
Arg interface{}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
const (
|
||||||
|
ErrorCompile = "Compilation"
|
||||||
|
ErrorRunTime = "Runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ScriptResp struct {
|
||||||
|
Result interface{}
|
||||||
|
Error *Error
|
||||||
|
}
|
||||||
|
|
||||||
|
type Error struct {
|
||||||
|
Type string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
module isp-script-service
|
||||||
|
|
||||||
|
go 1.24
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
|
github.com/robertkrimen/otto v0.5.1
|
||||||
|
github.com/stretchr/testify v1.10.0
|
||||||
|
github.com/txix-open/isp-kit v1.46.0
|
||||||
|
github.com/txix-open/isp-script v1.3.0
|
||||||
|
github.com/txix-open/jsonschema v1.2.0
|
||||||
|
github.com/yuin/gopher-lua v1.1.1
|
||||||
|
google.golang.org/grpc v1.71.1
|
||||||
|
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf
|
||||||
|
)
|
||||||
|
|
||||||
|
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/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/coder/websocket v1.8.13 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||||
|
github.com/dop251/goja_nodejs v0.0.0-20240221231712-27eeffc9c235 // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||||
|
github.com/getsentry/sentry-go v0.31.1 // indirect
|
||||||
|
github.com/go-logr/logr v1.4.2 // 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/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
||||||
|
github.com/google/pprof v0.0.0-20240327155427-868f304927ed // indirect
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
|
github.com/mailru/easyjson v0.9.0 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/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/prometheus/client_golang v1.21.1 // indirect
|
||||||
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
|
github.com/prometheus/common v0.63.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.16.0 // indirect
|
||||||
|
github.com/txix-open/bellows v1.2.0 // indirect
|
||||||
|
github.com/txix-open/etp/v4 v4.0.1 // indirect
|
||||||
|
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 // 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/auto/sdk v1.1.0 // indirect
|
||||||
|
go.opentelemetry.io/otel v1.35.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/metric v1.35.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/trace v1.35.0 // indirect
|
||||||
|
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
||||||
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
|
golang.org/x/crypto v0.36.0 // indirect
|
||||||
|
golang.org/x/net v0.38.0 // indirect
|
||||||
|
golang.org/x/sys v0.31.0 // indirect
|
||||||
|
golang.org/x/text v0.23.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
|
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||||
|
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
||||||
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||||
|
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
|
||||||
|
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
|
||||||
|
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/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.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
|
||||||
|
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
||||||
|
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/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
|
||||||
|
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||||
|
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c h1:mxWGS0YyquJ/ikZOjSrRjjFIbUqIP9ojyYQ+QZTU3Rg=
|
||||||
|
github.com/dop251/goja v0.0.0-20250309171923-bcd7cc6bf64c/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
|
||||||
|
github.com/dop251/goja_nodejs v0.0.0-20240221231712-27eeffc9c235 h1:5870ijWGCGCw7Ty4IGCquT6EfTck6f5zriYzFpPwOJ0=
|
||||||
|
github.com/dop251/goja_nodejs v0.0.0-20240221231712-27eeffc9c235/go.mod h1:bhGPmCgCCTSRfiMYWjpS46IDo9EUZXlsuUaPXSWGbv0=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||||
|
github.com/getsentry/sentry-go v0.31.1 h1:ELVc0h7gwyhnXHDouXkhqTFSO5oslsRDk0++eyE0KJ4=
|
||||||
|
github.com/getsentry/sentry-go v0.31.1/go.mod h1:CYNcMMz73YigoHljQRG+qPF+eMq8gG72XcGN/p71BAY=
|
||||||
|
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-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/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=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
|
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-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TCYl6lbukKPc7b5x0n1s6Q=
|
||||||
|
github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
||||||
|
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/pprof v0.0.0-20240327155427-868f304927ed h1:n8QtJTrwsv3P7dNxPaMeNkMcxvUpqocsHLr8iDLGlQI=
|
||||||
|
github.com/google/pprof v0.0.0-20240327155427-868f304927ed/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
|
||||||
|
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.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo=
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI=
|
||||||
|
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/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/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
|
||||||
|
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
|
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||||
|
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||||
|
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/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk=
|
||||||
|
github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg=
|
||||||
|
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.63.0 h1:YR/EIY1o3mEFP/kZCD7iDMnLPlGyuU2Gb3HIcXnA98k=
|
||||||
|
github.com/prometheus/common v0.63.0/go.mod h1:VVFF/fBIoToEnWRVkYoXEkq3R3paCoxG9PXP74SnV18=
|
||||||
|
github.com/prometheus/procfs v0.16.0 h1:xh6oHhKwnOJKMYiYBDWmkHqQPyiY40sny36Cmx2bbsM=
|
||||||
|
github.com/prometheus/procfs v0.16.0/go.mod h1:8veyXUu3nGP7oaCxhX6yeaM5u4stL2FeMXnCqhDthZg=
|
||||||
|
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/robertkrimen/otto v0.5.1 h1:avDI4ToRk8k1hppLdYFTuuzND41n37vPGJU7547dGf0=
|
||||||
|
github.com/robertkrimen/otto v0.5.1/go.mod h1:bS433I4Q9p+E5pZLu7r17vP6FkE6/wLxBdmKjoqJXF8=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
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/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
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/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.7.0 h1:nwenrlxEjXpK0EBCa/WbIxK+y0mF2pZxNKbheFjQVsI=
|
||||||
|
github.com/txix-open/grmq v1.7.0/go.mod h1:DAfbV4jLyxQBLG8OYJVy8kCbhucdlu/C/wl+nUDc9p8=
|
||||||
|
github.com/txix-open/isp-kit v1.46.0 h1:Rqw5X+501vEwMv6oGvC6sYU1++1XiTvxt6Ja/CD7lRw=
|
||||||
|
github.com/txix-open/isp-kit v1.46.0/go.mod h1:tWz/RGhRHx+JQZa5j1srR9kzL5YkIed3350SQ+FV1Wc=
|
||||||
|
github.com/txix-open/isp-script v1.3.0 h1:hQ29e+aAwlLxgjKpMheo4Sici9t87V/9VQkKwYvJoag=
|
||||||
|
github.com/txix-open/isp-script v1.3.0/go.mod h1:DjQ6T6yAjdWCR6SxAN63fE6mS37+NLUKUDS85GTAhlQ=
|
||||||
|
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/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=
|
||||||
|
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
|
||||||
|
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||||
|
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
|
||||||
|
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=
|
||||||
|
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
||||||
|
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.60.0 h1:0tY123n7CdWMem7MOVdKOt0YfshufLCwfE5Bob+hQuM=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.60.0/go.mod h1:CosX/aS4eHnG9D7nESYpV753l4j9q5j3SL/PUYd2lR8=
|
||||||
|
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
|
||||||
|
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 h1:1fTNlAIJZGWLP5FVu0fikVry1IsiUnXjf7QFvoNN3Xw=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0/go.mod h1:zjPK58DtkqQFn+YUMbx0M2XV3QgKU0gS9LeGohREyK4=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 h1:xJ2qHD0C1BeYVTLLR9sX12+Qb95kfeD/byKj6Ky1pXg=
|
||||||
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0/go.mod h1:u5BF1xyjstDowA1R5QAO9JHzqK+ublenEW/dyqTjBVk=
|
||||||
|
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
|
||||||
|
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
|
||||||
|
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
|
||||||
|
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
|
||||||
|
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
|
||||||
|
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
|
||||||
|
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.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
||||||
|
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
||||||
|
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
|
||||||
|
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||||
|
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||||
|
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
|
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||||
|
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 h1:hE3bRWtU6uceqlh4fhrSnUyjKHMKB9KrTLLG+bc0ddM=
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463/go.mod h1:U90ffi8eUL9MwPcrJylN5+Mk2v3vuPDptd5yyNUiRR8=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 h1:e0AIkUUhxyBKh6ssZNrAMeqhA7RKUj42346d1y02i2g=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
|
||||||
|
google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI=
|
||||||
|
google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
|
||||||
|
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||||
|
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||||
|
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=
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||||
|
gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI=
|
||||||
|
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
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=
|
||||||
|
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf h1:rRz0YsF7VXj9fXRF6yQgFI7DzST+hsI3TeFSGupntu0=
|
||||||
|
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf/go.mod h1:ivKkcY8Zxw5ba0jldhZCYYQfGdb2K6u9tbYK1AwMIBc=
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/txix-open/isp-kit/bootstrap"
|
||||||
|
"github.com/txix-open/isp-kit/shutdown"
|
||||||
|
"isp-script-service/assembly"
|
||||||
|
"isp-script-service/conf"
|
||||||
|
"isp-script-service/routes"
|
||||||
|
)
|
||||||
|
|
||||||
|
var version = "1.0.0"
|
||||||
|
|
||||||
|
// @title isp-script-service
|
||||||
|
// @version 1.0.0
|
||||||
|
// @description Сервис для обработки и выполнения JavaScript скриптов
|
||||||
|
|
||||||
|
// @license.name GNU GPL v3.0
|
||||||
|
|
||||||
|
// @host localhost:9000
|
||||||
|
// @BasePath /api/script
|
||||||
|
|
||||||
|
//go:generate swag init --parseDependency
|
||||||
|
//go:generate rm -f docs/swagger.json
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
boot := bootstrap.New(version, conf.Remote{}, routes.EndpointDescriptors())
|
||||||
|
app := boot.App
|
||||||
|
logger := app.Logger()
|
||||||
|
|
||||||
|
assembly, err := assembly.New(boot)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatal(app.Context(), err)
|
||||||
|
}
|
||||||
|
app.AddRunners(assembly.Runners()...)
|
||||||
|
app.AddClosers(assembly.Closers()...)
|
||||||
|
|
||||||
|
shutdown.On(func() {
|
||||||
|
logger.Info(app.Context(), "starting shutdown")
|
||||||
|
app.Shutdown()
|
||||||
|
logger.Info(app.Context(), "shutdown completed")
|
||||||
|
})
|
||||||
|
|
||||||
|
err = app.Run()
|
||||||
|
if err != nil {
|
||||||
|
app.Shutdown()
|
||||||
|
logger.Fatal(app.Context(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
md "google.golang.org/grpc/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Router struct {
|
||||||
|
cli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRouter(cli *client.Client) Router {
|
||||||
|
return Router{
|
||||||
|
cli: cli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Router) Invoke(methodPath string, request interface{}, metadata map[string]interface{}) (interface{}, error) {
|
||||||
|
ctx := context.Background()
|
||||||
|
newMd := md.New(nil)
|
||||||
|
for key, val := range metadata {
|
||||||
|
newMd.Set(key, fmt.Sprint(val))
|
||||||
|
}
|
||||||
|
ctx = md.NewOutgoingContext(ctx, newMd)
|
||||||
|
|
||||||
|
var response interface{}
|
||||||
|
|
||||||
|
err := i.cli.Invoke(methodPath).JsonRequestBody(request).JsonResponseBody(&response).Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "invoke")
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// nolint:ireturn
|
||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||||
|
"isp-script-service/controller"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Controllers struct {
|
||||||
|
Script controller.Script
|
||||||
|
}
|
||||||
|
|
||||||
|
func EndpointDescriptors() []cluster.EndpointDescriptor {
|
||||||
|
return endpointDescriptors(Controllers{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Handler(wrapper endpoint.Wrapper, c Controllers) *grpc.Mux {
|
||||||
|
muxer := grpc.NewMux()
|
||||||
|
for _, descriptor := range endpointDescriptors(c) {
|
||||||
|
muxer.Handle(descriptor.Path, wrapper.Endpoint(descriptor.Handler))
|
||||||
|
}
|
||||||
|
return muxer
|
||||||
|
}
|
||||||
|
|
||||||
|
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||||
|
return []cluster.EndpointDescriptor{
|
||||||
|
{
|
||||||
|
Path: "script/script/execute",
|
||||||
|
Inner: true,
|
||||||
|
UserAuthRequired: false,
|
||||||
|
Handler: c.Script.Execute,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "script/script/batch_execute",
|
||||||
|
Inner: true,
|
||||||
|
UserAuthRequired: false,
|
||||||
|
Handler: c.Script.BatchExecute,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "script/script/execute_by_id",
|
||||||
|
Inner: true,
|
||||||
|
UserAuthRequired: false,
|
||||||
|
Handler: c.Script.ExecuteById,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: "script/script/batch_execute_by_ids",
|
||||||
|
Inner: true,
|
||||||
|
UserAuthRequired: false,
|
||||||
|
Handler: c.Script.BatchExecuteById,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
// nolint:wrapcheck
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/hex"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"github.com/txix-open/isp-script"
|
||||||
|
"isp-script-service/conf"
|
||||||
|
"isp-script-service/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type scriptServiceCfg struct {
|
||||||
|
Scripts map[string]CompiledScript
|
||||||
|
ExecutionTimeout time.Duration
|
||||||
|
SharedScript string
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompiledScript struct {
|
||||||
|
scripts.Script
|
||||||
|
Compiled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Router interface {
|
||||||
|
Invoke(methodPath string, request interface{}, metadata map[string]interface{}) (interface{}, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Script struct {
|
||||||
|
store scriptServiceCfg
|
||||||
|
scriptEngine *scripts.Engine
|
||||||
|
logger log.Logger
|
||||||
|
router Router
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScript(invoker Router, logger log.Logger, sd []conf.ScriptDefinition, shared string, timeout int) *Script {
|
||||||
|
scr := scriptsFromConfig(context.Background(), logger, sd, shared, timeout)
|
||||||
|
scriptInstance := Script{
|
||||||
|
store: scr,
|
||||||
|
scriptEngine: scripts.NewEngine(),
|
||||||
|
logger: logger,
|
||||||
|
router: invoker,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &scriptInstance
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Script) Execute(req domain.ExecuteRequest) *domain.ScriptResp {
|
||||||
|
cfg := s.store
|
||||||
|
scr, err := createScript(req.Script, cfg.SharedScript)
|
||||||
|
if err != nil {
|
||||||
|
return s.respError(err, domain.ErrorCompile)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.executeScript(CompiledScript{scr, true}, req.Arg, cfg.ExecutionTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Script) ExecuteById(req domain.ExecuteByIdRequest) (*domain.ScriptResp, error) {
|
||||||
|
cfg := s.store
|
||||||
|
scr, ok := cfg.Scripts[req.Id]
|
||||||
|
if !ok {
|
||||||
|
return nil, domain.ErrScriptNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.executeScript(scr, req.Arg, cfg.ExecutionTimeout), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Script) BatchExecute(req []domain.ExecuteByIdRequest) []domain.ScriptResp {
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
cfg := s.store
|
||||||
|
response := make([]domain.ScriptResp, len(req))
|
||||||
|
for i := range req {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(i int) {
|
||||||
|
defer wg.Done()
|
||||||
|
if scr, ok := cfg.Scripts[req[i].Id]; !ok {
|
||||||
|
response[i] = *s.respError(errors.Errorf("not defined script for id %s", req[i].Id), domain.ErrorCompile)
|
||||||
|
} else {
|
||||||
|
response[i] = *s.executeScript(scr, req[i].Arg, cfg.ExecutionTimeout)
|
||||||
|
}
|
||||||
|
}(i)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Script) BatchExecuteById(req domain.BatchExecuteByIdsRequest) []domain.ScriptResp {
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
cfg := s.store
|
||||||
|
response := make([]domain.ScriptResp, len(req.Ids))
|
||||||
|
for i := range req.Ids {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(i int) {
|
||||||
|
defer wg.Done()
|
||||||
|
if scr, ok := cfg.Scripts[req.Ids[i]]; !ok {
|
||||||
|
response[i] = *s.respError(errors.Errorf("not defined script for id %s", req.Ids[i]), domain.ErrorCompile)
|
||||||
|
} else {
|
||||||
|
response[i] = *s.executeScript(scr, req.Arg, cfg.ExecutionTimeout)
|
||||||
|
}
|
||||||
|
}(i)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
var errEmpty = errors.New("empty answer, maybe lost return")
|
||||||
|
|
||||||
|
func (s *Script) executeScript(scr CompiledScript, arg interface{}, timeout time.Duration) *domain.ScriptResp {
|
||||||
|
if !scr.Compiled {
|
||||||
|
return s.respError(errors.New("invalid script configuration"), domain.ErrorCompile)
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := s.scriptEngine.Execute(scr.Script, arg,
|
||||||
|
scripts.WithTimeout(timeout),
|
||||||
|
scripts.WithDefaultToolkit(),
|
||||||
|
scripts.WithSet("external", map[string]interface{}{
|
||||||
|
"invoke": s.router.Invoke,
|
||||||
|
"hashSha256": Sha256,
|
||||||
|
"hashSha512": Sha512,
|
||||||
|
"generateUUIDv4": UUIDv4,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return s.respError(err, domain.ErrorRunTime)
|
||||||
|
}
|
||||||
|
if response == nil {
|
||||||
|
return s.respError(errEmpty, domain.ErrorRunTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &domain.ScriptResp{
|
||||||
|
Result: response,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Script) respError(err error, errorType string) *domain.ScriptResp {
|
||||||
|
respError := domain.Error{
|
||||||
|
Type: errorType,
|
||||||
|
Description: err.Error(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &domain.ScriptResp{
|
||||||
|
Error: &respError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sha256(value string) string {
|
||||||
|
sum := sha256.Sum256([]byte(value))
|
||||||
|
return hex.EncodeToString(sum[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sha512(value string) string {
|
||||||
|
sum := sha512.Sum512([]byte(value))
|
||||||
|
return hex.EncodeToString(sum[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func UUIDv4() string {
|
||||||
|
randomUUID, err := uuid.NewRandom()
|
||||||
|
if err != nil {
|
||||||
|
// will be handled as exception in js
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return randomUUID.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func scriptsFromConfig(
|
||||||
|
ctx context.Context,
|
||||||
|
logger log.Logger,
|
||||||
|
scriptDef []conf.ScriptDefinition,
|
||||||
|
sharedScript string,
|
||||||
|
executionTimeoutMs int,
|
||||||
|
) scriptServiceCfg {
|
||||||
|
var compiled bool
|
||||||
|
cfg := scriptServiceCfg{
|
||||||
|
Scripts: make(map[string]CompiledScript),
|
||||||
|
ExecutionTimeout: time.Duration(executionTimeoutMs) * time.Millisecond,
|
||||||
|
SharedScript: sharedScript,
|
||||||
|
}
|
||||||
|
for _, value := range scriptDef {
|
||||||
|
compiled = true
|
||||||
|
scr, err := createScript(value.Script, sharedScript)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(ctx, errors.WithMessage(err, "create script from config"),
|
||||||
|
log.String("scriptId", value.Id))
|
||||||
|
compiled = false
|
||||||
|
}
|
||||||
|
cfg.Scripts[value.Id] = CompiledScript{scr, compiled}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
func createScript(script, sharedScript string) (scripts.Script, error) {
|
||||||
|
return scripts.NewScript([]byte(sharedScript),
|
||||||
|
[]byte("(function() {\n"), []byte(script), []byte("\n})();"))
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
package tests_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"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/grpct"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
"isp-script-service/assembly"
|
||||||
|
"isp-script-service/conf"
|
||||||
|
"isp-script-service/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestApiScriptTestSuite(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
suite.Run(t, &ApiScript{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApiScript struct {
|
||||||
|
suite.Suite
|
||||||
|
test *test.Test
|
||||||
|
require *require.Assertions
|
||||||
|
apiCli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) SetupSuite() {
|
||||||
|
s.test, s.require = test.New(s.T())
|
||||||
|
|
||||||
|
cli := s.initMockServer()
|
||||||
|
|
||||||
|
cfg := conf.Remote{
|
||||||
|
ScriptExecutionTimeoutMs: 10000,
|
||||||
|
Scripts: []conf.ScriptDefinition{
|
||||||
|
{
|
||||||
|
Id: "1",
|
||||||
|
Script: "return true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "2",
|
||||||
|
Script: "return false",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CustomScripts: []conf.ScriptDefinition{},
|
||||||
|
}
|
||||||
|
|
||||||
|
locator := assembly.NewLocator(s.test.Logger(), cli)
|
||||||
|
handler, _ := locator.Handler(cfg)
|
||||||
|
|
||||||
|
_, s.apiCli = grpct.TestServer(s.test, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) TestExternalInvoke() {
|
||||||
|
req := domain.ExecuteRequest{
|
||||||
|
Script: "return external.invoke('mock', true, {})",
|
||||||
|
Arg: struct{}{},
|
||||||
|
}
|
||||||
|
res := domain.ScriptResp{}
|
||||||
|
err := s.apiCli.Invoke("script/script/execute").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&res).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(true, res.Result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) TestExecuteHappyPath() {
|
||||||
|
req := domain.ExecuteRequest{
|
||||||
|
Script: "return arg.a",
|
||||||
|
Arg: map[string]bool{
|
||||||
|
"a": true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
res := domain.ScriptResp{}
|
||||||
|
err := s.apiCli.Invoke("script/script/execute").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&res).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(true, res.Result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) TestExecuteByIdHappyPath() {
|
||||||
|
req := domain.ExecuteByIdRequest{
|
||||||
|
Id: "1",
|
||||||
|
Arg: struct{}{},
|
||||||
|
}
|
||||||
|
res := domain.ScriptResp{}
|
||||||
|
err := s.apiCli.Invoke("script/script/execute_by_id").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&res).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(true, res.Result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) TestExecuteByIdNotFound() {
|
||||||
|
req := domain.ExecuteByIdRequest{
|
||||||
|
Id: "unknown",
|
||||||
|
Arg: struct{}{},
|
||||||
|
}
|
||||||
|
res := domain.ScriptResp{}
|
||||||
|
err := s.apiCli.Invoke("script/script/execute_by_id").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&res).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().Error(err)
|
||||||
|
st, ok := status.FromError(err)
|
||||||
|
s.Require().True(ok)
|
||||||
|
s.Require().Equal(codes.NotFound, st.Code())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) TestBatchExecuteHappyPath() {
|
||||||
|
req := []domain.ExecuteByIdRequest{
|
||||||
|
{
|
||||||
|
Id: "1",
|
||||||
|
Arg: struct{}{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "2",
|
||||||
|
Arg: struct{}{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
res := make([]domain.ScriptResp, 0)
|
||||||
|
err := s.apiCli.Invoke("script/script/batch_execute").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&res).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
expected := []domain.ScriptResp{
|
||||||
|
{Result: true, Error: nil},
|
||||||
|
{Result: false, Error: nil},
|
||||||
|
}
|
||||||
|
s.Require().ElementsMatch(expected, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) TestBatchExecuteMixedNotFound() {
|
||||||
|
req := []domain.ExecuteByIdRequest{
|
||||||
|
{
|
||||||
|
Id: "1",
|
||||||
|
Arg: struct{}{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "unknown",
|
||||||
|
Arg: struct{}{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
res := make([]domain.ScriptResp, 0)
|
||||||
|
err := s.apiCli.Invoke("script/script/batch_execute").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&res).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
expected := []domain.ScriptResp{
|
||||||
|
{Result: true, Error: nil},
|
||||||
|
{Result: nil, Error: &domain.Error{
|
||||||
|
Type: domain.ErrorCompile,
|
||||||
|
Description: "not defined script for id unknown",
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
s.Require().ElementsMatch(expected, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) TestBatchExecuteByIdHappyPath() {
|
||||||
|
req := domain.BatchExecuteByIdsRequest{
|
||||||
|
Ids: []string{"1", "2"},
|
||||||
|
Arg: struct{}{},
|
||||||
|
}
|
||||||
|
res := make([]domain.ScriptResp, 0)
|
||||||
|
err := s.apiCli.Invoke("script/script/batch_execute_by_ids").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&res).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
expected := []domain.ScriptResp{
|
||||||
|
{Result: true, Error: nil},
|
||||||
|
{Result: false, Error: nil},
|
||||||
|
}
|
||||||
|
s.Require().ElementsMatch(expected, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ApiScript) initMockServer() *client.Client {
|
||||||
|
server, cli := grpct.NewMock(s.test)
|
||||||
|
server.Mock("mock", func(req bool) bool {
|
||||||
|
return req
|
||||||
|
})
|
||||||
|
|
||||||
|
return cli
|
||||||
|
}
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
// nolint:gochecknoglobals
|
||||||
|
package tests_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
json2 "github.com/txix-open/isp-kit/json"
|
||||||
|
|
||||||
|
"github.com/dop251/goja"
|
||||||
|
"github.com/robertkrimen/otto"
|
||||||
|
"github.com/robertkrimen/otto/parser"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
lua "github.com/yuin/gopher-lua"
|
||||||
|
"github.com/yuin/gopher-lua/parse"
|
||||||
|
json "layeh.com/gopher-json"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
jsScript = `
|
||||||
|
var a = {};
|
||||||
|
for (i=0; i<b.length; i++) {
|
||||||
|
a[b[i]["id_tp_cd"]] = b[i]
|
||||||
|
}
|
||||||
|
`
|
||||||
|
luaScript = `
|
||||||
|
dst = {}
|
||||||
|
for k,v in pairs(src) do
|
||||||
|
dst[v.id_tp_cd] = v
|
||||||
|
end
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
recordsExample = []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"ref_num": "IIИК778068",
|
||||||
|
"id_tp_cd": "1000017",
|
||||||
|
"start_dt": "2006-10-10 00:00:00.000",
|
||||||
|
"etalon_id": "7d53bf34-0aa6-11e9-9799-87ba01ce01e5",
|
||||||
|
"ext_upd_date": "2018-01-11 17:52:01.000",
|
||||||
|
"last_update_dt": "2018-09-13 23:41:35.324",
|
||||||
|
"identification_issuer": "Красногорским Управлением ЗАГС Главного Управления ЗАГС Московской области",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref_num": "18605520974",
|
||||||
|
"id_tp_cd": "1000015",
|
||||||
|
"start_dt": "2018-09-13 00:00:00.000",
|
||||||
|
"etalon_id": "7d57dde9-0aa6-11e9-9799-87ba01ce01e5",
|
||||||
|
"ext_upd_date": "2018-01-11 17:52:01.000",
|
||||||
|
"last_update_dt": "2018-09-13 23:41:35.330",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ref_num": "5090399778001137",
|
||||||
|
"id_tp_cd": "1000014",
|
||||||
|
"start_dt": "2018-09-13 23:41:35.327",
|
||||||
|
"etalon_id": "7d58a13e-0aa6-11e9-9799-87ba01ce01e5",
|
||||||
|
"ext_upd_date": "2018-01-11 17:52:01.000",
|
||||||
|
"last_update_dt": "2018-09-13 23:41:35.327",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
srcString []byte
|
||||||
|
expecting = make(map[string]interface{})
|
||||||
|
)
|
||||||
|
|
||||||
|
// nolint:gochecknoinits
|
||||||
|
func init() {
|
||||||
|
for _, v := range recordsExample {
|
||||||
|
expecting[v["id_tp_cd"].(string)] = v // nolint:forcetypeassert
|
||||||
|
}
|
||||||
|
if bytes, err := json2.Marshal(recordsExample); err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else {
|
||||||
|
srcString = bytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOtto(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
prog, err := parser.ParseFile(nil, "example", jsScript, 0)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
runTime := otto.New()
|
||||||
|
err = runTime.Set("b", recordsExample)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
_, err = runTime.Run(prog)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
res, err := runTime.Get("a")
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
_, err = res.Export()
|
||||||
|
require.NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoja(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
prog := goja.MustCompile("test.js", jsScript, false)
|
||||||
|
|
||||||
|
runTime := goja.New()
|
||||||
|
err := runTime.Set("b", recordsExample)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
_, err = runTime.RunProgram(prog)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
a := runTime.Get("a")
|
||||||
|
_ = a.Export()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGopherLua(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
l := lua.NewState()
|
||||||
|
defer l.Close()
|
||||||
|
|
||||||
|
b, err := json2.Marshal(recordsExample)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
val, err := json.Decode(l, b)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
l.SetGlobal("src", val)
|
||||||
|
|
||||||
|
err = l.DoString(luaScript)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
dst := l.GetGlobal("dst")
|
||||||
|
b, err = json.Encode(dst)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
m := make(map[string]interface{})
|
||||||
|
err = json2.Unmarshal(b, &m)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
require.EqualValues(expecting, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkOtto(b *testing.B) {
|
||||||
|
prog, err := parser.ParseFile(nil, "example", jsScript, 0)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for range b.N {
|
||||||
|
runTime := otto.New()
|
||||||
|
err = runTime.Set("b", recordsExample)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = runTime.Run(prog)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := runTime.Get("a")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = res.Export()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkGoja(b *testing.B) {
|
||||||
|
prog := goja.MustCompile("test.js", jsScript, false)
|
||||||
|
|
||||||
|
for range b.N {
|
||||||
|
runTime := goja.New()
|
||||||
|
err := runTime.Set("b", recordsExample)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = runTime.RunProgram(prog)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
a := runTime.Get("a")
|
||||||
|
_ = a.Export()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkGopherLua(b *testing.B) {
|
||||||
|
chunk, err := parse.Parse(strings.NewReader(luaScript), "test")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
proto, err := lua.Compile(chunk, "test")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for range b.N {
|
||||||
|
l := lua.NewState()
|
||||||
|
|
||||||
|
val, err := json.Decode(l, srcString)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
l.SetGlobal("src", val)
|
||||||
|
|
||||||
|
prog := l.NewFunctionFromProto(proto)
|
||||||
|
l.Push(prog)
|
||||||
|
err = l.PCall(0, lua.MultRet, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dst := l.GetGlobal("dst")
|
||||||
|
c, err := json.Encode(dst)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
m := make(map[string]interface{})
|
||||||
|
err = json2.Unmarshal(c, &m)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
l.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package tests_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"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/grpct"
|
||||||
|
"isp-script-service/assembly"
|
||||||
|
"isp-script-service/conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMergeScriptTestSuite(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
suite.Run(t, &MergeScript{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type MergeScript struct {
|
||||||
|
suite.Suite
|
||||||
|
test *test.Test
|
||||||
|
require *require.Assertions
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MergeScript) TestMergeScriptsDuplicateId() {
|
||||||
|
s.test, s.require = test.New(s.T())
|
||||||
|
|
||||||
|
cli := s.initMockServer()
|
||||||
|
|
||||||
|
cfg := conf.Remote{
|
||||||
|
ScriptExecutionTimeoutMs: 10000,
|
||||||
|
Scripts: []conf.ScriptDefinition{
|
||||||
|
{
|
||||||
|
Id: "1",
|
||||||
|
Script: "return true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CustomScripts: []conf.ScriptDefinition{
|
||||||
|
{
|
||||||
|
Id: "1",
|
||||||
|
Script: "return false",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
locator := assembly.NewLocator(s.test.Logger(), cli)
|
||||||
|
_, err := locator.Handler(cfg)
|
||||||
|
|
||||||
|
s.Require().Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MergeScript) TestMergeScriptsHappyPath() {
|
||||||
|
s.test, s.require = test.New(s.T())
|
||||||
|
|
||||||
|
cli := s.initMockServer()
|
||||||
|
|
||||||
|
cfg := conf.Remote{
|
||||||
|
ScriptExecutionTimeoutMs: 10000,
|
||||||
|
Scripts: []conf.ScriptDefinition{
|
||||||
|
{
|
||||||
|
Id: "1",
|
||||||
|
Script: "return true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Id: "2",
|
||||||
|
Script: "return true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CustomScripts: []conf.ScriptDefinition{
|
||||||
|
{
|
||||||
|
Id: "3",
|
||||||
|
Script: "return false",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
locator := assembly.NewLocator(s.test.Logger(), cli)
|
||||||
|
_, err := locator.Handler(cfg)
|
||||||
|
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MergeScript) initMockServer() *client.Client {
|
||||||
|
server, cli := grpct.NewMock(s.test)
|
||||||
|
server.Mock("mock", func(req bool) bool {
|
||||||
|
return req
|
||||||
|
})
|
||||||
|
|
||||||
|
return cli
|
||||||
|
}
|
||||||
Reference in new issue
Block a user