Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b18fe7351 | ||
|
|
f3c801e4a4 | ||
|
|
ee13991d87 | ||
|
|
d4846359e4 | ||
|
|
13cf0075f6 | ||
|
|
135e551473 | ||
|
|
689f730a3e | ||
|
|
a30582fa38 | ||
|
|
5b1ce14467 | ||
|
|
264b438cdb | ||
|
|
f699aefa58 | ||
|
|
8d40e76637 | ||
|
|
e2b4becfd6 | ||
|
|
e4ef2d8645 | ||
|
|
bfc28503d5 | ||
|
|
d759f883f4 | ||
|
|
64373fdf3c | ||
|
|
1dd566593e | ||
|
|
560c1f22c4 | ||
|
|
171b85f627 | ||
|
|
734b83b2b8 | ||
|
|
bdeb2c0753 | ||
|
|
97c44fb3bd | ||
|
|
6db18c1495 | ||
|
|
cd985ff5a3 | ||
|
|
2eed857503 | ||
|
|
2b91caece0 |
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
|
||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
# 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:
|
||||||
|
/.idea/
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/dictionaries
|
||||||
|
*.iml
|
||||||
|
convert_service
|
||||||
|
convert-service
|
||||||
|
|
||||||
|
# Sensitive or high-churn files:
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
|
||||||
|
# Gradle:
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-debug/
|
||||||
|
cmake-build-release/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin:
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
## File-based project format:
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
## Plugin-specific files:
|
||||||
|
|
||||||
|
# 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
|
||||||
|
### Go template
|
||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, build with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
/node_modules/
|
||||||
|
/vendor/
|
||||||
|
google/
|
||||||
|
package.json
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
|
conf/config_dev.yml
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
include:
|
||||||
|
- project: '$CI_PROJECT_PATH'
|
||||||
|
file: '/ci-isp-go-service.yml'
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
version: "2"
|
||||||
|
run:
|
||||||
|
allow-parallel-runners: true
|
||||||
|
linters:
|
||||||
|
default: all
|
||||||
|
disable:
|
||||||
|
- contextcheck # не имеет смысла
|
||||||
|
- depguard # не всегда имеет смысл
|
||||||
|
- dupword # не имеет смысла
|
||||||
|
- exhaustruct # не имеет смысла
|
||||||
|
- godot # не актуально для swagger
|
||||||
|
- godox # не позволяет оставлять todo
|
||||||
|
- musttag # у нас собственное правило: не используем теги, если работаем с пакетом isp-kit/json и с внутренними структурами(между нашими сервисами), при этом теги обязательный для всех внешних для нас структур
|
||||||
|
- nlreturn # не всегда имеет смысл
|
||||||
|
- nolintlint # Goland все равно форматирует с отступом
|
||||||
|
- perfsprint # мнимая производительность в угоду читаемости
|
||||||
|
- tagalign # не всегда имеет смысл
|
||||||
|
- testpackage
|
||||||
|
- 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:
|
||||||
|
- linters:
|
||||||
|
- wrapcheck
|
||||||
|
path: controller # достаточное кол-во контекста на уровне контроллеров
|
||||||
|
- linters:
|
||||||
|
- wrapcheck
|
||||||
|
path: transaction # транзакции прозрачны
|
||||||
|
- linters:
|
||||||
|
- wrapcheck
|
||||||
|
path: middleware #отсутствует необходимость оборачивать ошибки
|
||||||
|
- linters:
|
||||||
|
- gochecknoglobals
|
||||||
|
- mnd
|
||||||
|
path: proxy
|
||||||
|
- linters:
|
||||||
|
- wrapcheck
|
||||||
|
path: httperrors #отсутствует необходимость оборачивать ошибки
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
formatters:
|
||||||
|
enable:
|
||||||
|
- gofmt
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
+146
@@ -0,0 +1,146 @@
|
|||||||
|
### v5.5.1
|
||||||
|
* повышен приоритет `x-application-token` над basic-auth, при поиске в запросе токена приложения
|
||||||
|
### v5.5.0
|
||||||
|
* Добавлена поддержка basic-auth, где `username` - название приложения, `password` - токен приложения
|
||||||
|
### v5.4.1
|
||||||
|
* Оптимизация очистки тела запроса от экранирования unicode символов для корректного логирования
|
||||||
|
### v5.4.0
|
||||||
|
* Добавлена настройка `forwardReqIdClientSettings` для разрешения прокидывания `requestId` определённым приложениям по их идентификаторам (`requestId` клиента прокидывается если в `forwardReqIdClientSettings` для приложения включено прокидывание или включен глобальный флаг `enableClientRequestIdForwarding`)
|
||||||
|
* Обновлена версия go до 1.25
|
||||||
|
### v5.3.0
|
||||||
|
* обновлены зависимости
|
||||||
|
### v5.2.10
|
||||||
|
* добавлен контекст ошибки для grpc
|
||||||
|
### v5.2.9
|
||||||
|
* взаимодействие напрямую с `redis` заменено на взаимодействие с `isp-lock-service`
|
||||||
|
### v5.2.8
|
||||||
|
* добавлена обработка эндпоинта в двух форматах: с `/` в начале и без
|
||||||
|
* обновлены зависимости
|
||||||
|
### v5.2.7
|
||||||
|
* добавлен `Dockerfile` и скрипт для сборки и публикации образа в `GitHub Contaier Registry`
|
||||||
|
* обновлены зависимости
|
||||||
|
### v5.2.6
|
||||||
|
* исправлен баг с отсутствием проверки разрешенных действий
|
||||||
|
### v5.2.5
|
||||||
|
* добавлено новое поле `enableForceUnescapingUnicode` в конфигурации для очистки тела запроса от экранирования unicode символов при логирование
|
||||||
|
* реализована поддержка очистки тела запроса от экранирования unicode символов для корректного логирования
|
||||||
|
* обновлены зависимости
|
||||||
|
### v5.2.4
|
||||||
|
* обновлены зависимости
|
||||||
|
### v5.2.3
|
||||||
|
* добавлен заголовок `X-Request-Id` в ответ при проксировании grpc
|
||||||
|
* обновлены зависимости
|
||||||
|
* обновлена версия go до 1.24
|
||||||
|
### v5.2.1
|
||||||
|
* добавлен параметр для настройки проброса `requestId` из заголовка запроса
|
||||||
|
* добавлено логирование содержимого заголовка `requestId` из заголовка запроса (поле `clientRequestId`)
|
||||||
|
* обновлены зависимости
|
||||||
|
* обновлена версия go до 1.23
|
||||||
|
### v5.2.0
|
||||||
|
* изменён формат логов с `snake_case` на `camelCase`
|
||||||
|
### v5.1.1
|
||||||
|
* добавлен параметр `withPrefix` в локальном конфиге для `location`, чтобы не обрезать путь при проксировании запроса
|
||||||
|
### v5.1.0
|
||||||
|
* обновлены зависимости (увеличены лимиты по семплированию логов, добавлена возможность конфигурировать семплирование)
|
||||||
|
### v5.0.0
|
||||||
|
* добавлена авторизация ендпоинтов администратора
|
||||||
|
### v4.3.0
|
||||||
|
* обновлены зависимости
|
||||||
|
### v4.2.1
|
||||||
|
* исправлено поведение `skipBodyLoggingEndpointPrefixes`
|
||||||
|
### v4.2.0
|
||||||
|
* новый параметр в remote_config: `skipBodyLoggingEndpointPrefixes`. Массив re. Если они есть в пути, то запрос не будет логироваться
|
||||||
|
### v4.1.2
|
||||||
|
* исправлена опция логирования тела запроса (при настройке ws могла отключаться)
|
||||||
|
### v4.1.1
|
||||||
|
* исправлена маршрутизация запросов
|
||||||
|
### v4.1.0
|
||||||
|
* обновлены зависимости
|
||||||
|
* добавлена поддержка проксирования WebSocket `ws`
|
||||||
|
### v4.0.0
|
||||||
|
* реализована аутентификация токена администратора через msp-admin-service
|
||||||
|
### v3.0.3
|
||||||
|
* исправлено тело ответа grpc ошибок валидации
|
||||||
|
* обновлены зависимости
|
||||||
|
### v3.0.2
|
||||||
|
* добавлен charset=utf-8 в заголовок ответа для grpc
|
||||||
|
### v3.0.1
|
||||||
|
* исправлено проксирование http с GET параметрами
|
||||||
|
* исправлено логирование пути при проксировании HTTP
|
||||||
|
### v3.0.0
|
||||||
|
* реализация новой схемы аутентификации/авторизации
|
||||||
|
### v2.8.3
|
||||||
|
* use isp-kit logger instead local logger
|
||||||
|
* use log string instead log any (common log type)
|
||||||
|
* add replace grpc (isp-lib and isp-kit conflict)
|
||||||
|
### v2.8.2
|
||||||
|
* add file rotation
|
||||||
|
### v2.8.1
|
||||||
|
* add xml format support for new logger
|
||||||
|
### v2.8.0
|
||||||
|
* add new logger
|
||||||
|
* remove journal
|
||||||
|
* add identities to requests log
|
||||||
|
### v2.7.6
|
||||||
|
* updated dependencies
|
||||||
|
* migrated to common local config
|
||||||
|
### v2.7.5
|
||||||
|
* updated dependencies
|
||||||
|
### v2.7.4
|
||||||
|
* updated isp-lib
|
||||||
|
* updated isp-lib-test
|
||||||
|
### v2.7.3
|
||||||
|
* updated isp-lib
|
||||||
|
* updated isp-event-lib
|
||||||
|
## 2.7.2
|
||||||
|
* fix accounting
|
||||||
|
## 2.7.1
|
||||||
|
* fix default local config
|
||||||
|
## 2.7.0
|
||||||
|
* add support Redis Sentinel
|
||||||
|
* update grpc client
|
||||||
|
* code cleanup
|
||||||
|
## 2.6.3
|
||||||
|
* fix search from locations
|
||||||
|
* fix proxying URI in http and ws
|
||||||
|
## 2.6.2
|
||||||
|
* fix panic if journal enable and error logging
|
||||||
|
* add content-type, content-length header to response
|
||||||
|
* close journal
|
||||||
|
* journal module is not more required
|
||||||
|
* add missing journaling
|
||||||
|
## 2.6.0
|
||||||
|
* migrate to go mod
|
||||||
|
## 2.5.4
|
||||||
|
* fix auth cache
|
||||||
|
## 2.5.3
|
||||||
|
* fix grpc multipart error response
|
||||||
|
## 2.5.2
|
||||||
|
* fix init http
|
||||||
|
## 2.5.1
|
||||||
|
* fix code response when doesn't match user id
|
||||||
|
* fix config reload
|
||||||
|
## 2.5.0
|
||||||
|
* add skip for check exist method
|
||||||
|
* add handler for user methods
|
||||||
|
* fix user id replacing
|
||||||
|
## 2.4.0
|
||||||
|
* add access checkout by user id
|
||||||
|
## 2.3.0
|
||||||
|
* add support for tokens in get params
|
||||||
|
## 2.2.0
|
||||||
|
* add websocket proxy
|
||||||
|
## 2.1.0
|
||||||
|
* fix proxy path
|
||||||
|
* add skip authenticate
|
||||||
|
* add snapshot version
|
||||||
|
## 2.0.0
|
||||||
|
* add integration with isp-config-service 2.0
|
||||||
|
## 1.3.0
|
||||||
|
* add unload requests
|
||||||
|
## 1.2.0
|
||||||
|
* add snapshot account
|
||||||
|
## 1.1.0
|
||||||
|
* add token verification via JWT
|
||||||
|
* add accounting for applications
|
||||||
|
* add optional cache for application tokens
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
package assembly
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
"isp-gate-service/routes"
|
||||||
|
|
||||||
|
"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/client"
|
||||||
|
"github.com/txix-open/isp-kit/http"
|
||||||
|
"github.com/txix-open/isp-kit/lb"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Assembly struct {
|
||||||
|
boot *bootstrap.Bootstrap
|
||||||
|
server *http.Server
|
||||||
|
logger *log.Adapter
|
||||||
|
routes *routes.Routes
|
||||||
|
systemCli *client.Client
|
||||||
|
adminCli *client.Client
|
||||||
|
lockerCli *client.Client
|
||||||
|
|
||||||
|
locations []conf.Location
|
||||||
|
grpcClientByModuleName map[string]*client.Client
|
||||||
|
httpHostManagerByModuleName map[string]*lb.RoundRobin
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
|
||||||
|
server := http.NewServer(boot.App.Logger())
|
||||||
|
|
||||||
|
localConfig := conf.Local{}
|
||||||
|
err := boot.App.Config().Read(&localConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "read local config")
|
||||||
|
}
|
||||||
|
|
||||||
|
grpcClientByModuleName := make(map[string]*client.Client)
|
||||||
|
httpHostManagerByModuleName := make(map[string]*lb.RoundRobin)
|
||||||
|
for _, location := range localConfig.Locations {
|
||||||
|
switch location.Protocol {
|
||||||
|
case conf.GrpcProtocol:
|
||||||
|
cli, err := client.Default()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "new grpc client")
|
||||||
|
}
|
||||||
|
grpcClientByModuleName[location.TargetModule] = cli
|
||||||
|
case conf.HttpProtocol, conf.WsProtocol:
|
||||||
|
rb := lb.NewRoundRobin(nil)
|
||||||
|
httpHostManagerByModuleName[location.TargetModule] = rb
|
||||||
|
default:
|
||||||
|
return nil, errors.Errorf("unexpected location protocol: %s", location.Protocol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
systemCli, err := client.Default()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "create system cli")
|
||||||
|
}
|
||||||
|
adminCli, err := client.Default()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "create admin cli")
|
||||||
|
}
|
||||||
|
lockerCli, err := client.Default()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "create isp-lock-service client")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Assembly{
|
||||||
|
boot: boot,
|
||||||
|
server: server,
|
||||||
|
logger: boot.App.Logger(),
|
||||||
|
routes: routes.NewRoutes(),
|
||||||
|
locations: localConfig.Locations,
|
||||||
|
grpcClientByModuleName: grpcClientByModuleName,
|
||||||
|
httpHostManagerByModuleName: httpHostManagerByModuleName,
|
||||||
|
systemCli: systemCli,
|
||||||
|
adminCli: adminCli,
|
||||||
|
lockerCli: lockerCli,
|
||||||
|
}, 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.Logging.LogLevel)
|
||||||
|
|
||||||
|
locator := NewLocator(
|
||||||
|
a.logger,
|
||||||
|
a.grpcClientByModuleName,
|
||||||
|
a.httpHostManagerByModuleName,
|
||||||
|
a.routes,
|
||||||
|
a.systemCli,
|
||||||
|
a.adminCli,
|
||||||
|
a.lockerCli,
|
||||||
|
)
|
||||||
|
handler, err := locator.Handler(newCfg, a.locations)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "locator handler")
|
||||||
|
}
|
||||||
|
|
||||||
|
a.server.Upgrade(handler)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Assembly) Runners() []app.Runner {
|
||||||
|
eventHandler := cluster.NewEventHandler().
|
||||||
|
RoutesReceiver(a.routes).
|
||||||
|
RemoteConfigReceiver(a)
|
||||||
|
|
||||||
|
for moduleName, upgrader := range a.grpcClientByModuleName {
|
||||||
|
eventHandler.RequireModule(moduleName, upgrader)
|
||||||
|
}
|
||||||
|
for moduleName, upgrader := range a.httpHostManagerByModuleName {
|
||||||
|
eventHandler.RequireModule(moduleName, upgrader)
|
||||||
|
}
|
||||||
|
eventHandler.RequireModule("isp-system-service", a.systemCli)
|
||||||
|
eventHandler.RequireModule("msp-admin-service", a.adminCli)
|
||||||
|
eventHandler.RequireModule("isp-lock-service", a.lockerCli)
|
||||||
|
|
||||||
|
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 {
|
||||||
|
closers := []app.Closer{
|
||||||
|
a.boot.ClusterCli,
|
||||||
|
app.CloserFunc(func() error {
|
||||||
|
return a.server.Shutdown(context.Background())
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
for _, cliCloser := range a.grpcClientByModuleName {
|
||||||
|
closers = append(closers, cliCloser)
|
||||||
|
}
|
||||||
|
closers = append(closers, a.systemCli, a.adminCli, a.lockerCli)
|
||||||
|
|
||||||
|
return closers
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package assembly
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
"isp-gate-service/middleware"
|
||||||
|
"isp-gate-service/proxy"
|
||||||
|
"isp-gate-service/repository"
|
||||||
|
"isp-gate-service/routes"
|
||||||
|
"isp-gate-service/service"
|
||||||
|
|
||||||
|
mux2 "github.com/gorilla/mux"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"github.com/txix-open/isp-kit/lb"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Locator struct {
|
||||||
|
logger log.Logger
|
||||||
|
grpcClientByModuleName map[string]*client.Client
|
||||||
|
httpHostManagerByModuleName map[string]*lb.RoundRobin
|
||||||
|
routes *routes.Routes
|
||||||
|
systemCli *client.Client
|
||||||
|
adminCli *client.Client
|
||||||
|
lockerCli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLocator(
|
||||||
|
logger log.Logger,
|
||||||
|
grpcClientByModuleName map[string]*client.Client,
|
||||||
|
httpHostManagerByModuleName map[string]*lb.RoundRobin,
|
||||||
|
routes *routes.Routes,
|
||||||
|
systemCli *client.Client,
|
||||||
|
adminCli *client.Client,
|
||||||
|
lockerCli *client.Client,
|
||||||
|
) Locator {
|
||||||
|
return Locator{
|
||||||
|
logger: logger,
|
||||||
|
grpcClientByModuleName: grpcClientByModuleName,
|
||||||
|
httpHostManagerByModuleName: httpHostManagerByModuleName,
|
||||||
|
routes: routes,
|
||||||
|
systemCli: systemCli,
|
||||||
|
adminCli: adminCli,
|
||||||
|
lockerCli: lockerCli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l Locator) Handler(config conf.Remote, locations []conf.Location) (http.Handler, error) { // nolint:funlen
|
||||||
|
systemRepo := repository.NewSystem(l.systemCli)
|
||||||
|
adminRepo := repository.NewAdmin(l.adminCli)
|
||||||
|
|
||||||
|
authenticationCache := repository.NewAuthenticationCache(time.Duration(config.Caching.AuthenticationDataInSec) * time.Second)
|
||||||
|
authentication := service.NewAuthentication(authenticationCache, systemRepo)
|
||||||
|
|
||||||
|
adminService := service.NewAdmin(
|
||||||
|
repository.NewAuthorizationCache(time.Duration(config.Caching.AuthorizationDataInSec)*time.Second),
|
||||||
|
adminRepo,
|
||||||
|
)
|
||||||
|
|
||||||
|
authorization := service.NewAuthorization(
|
||||||
|
repository.NewAuthorizationCache(time.Duration(config.Caching.AuthorizationDataInSec)*time.Second),
|
||||||
|
systemRepo,
|
||||||
|
)
|
||||||
|
|
||||||
|
lockRepo := repository.NewLocker(l.lockerCli)
|
||||||
|
dailyLimitService := service.NewDailyLimit(lockRepo, config.DailyLimits)
|
||||||
|
throttlingService := service.NewThrottling(lockRepo, config.Throttling)
|
||||||
|
|
||||||
|
mux := mux2.NewRouter()
|
||||||
|
for _, location := range locations {
|
||||||
|
var proxyFunc middleware.Handler
|
||||||
|
enableBodyLog := config.Logging.BodyLogEnable
|
||||||
|
|
||||||
|
switch location.Protocol {
|
||||||
|
case conf.GrpcProtocol:
|
||||||
|
cli := l.grpcClientByModuleName[location.TargetModule]
|
||||||
|
proxyFunc = proxy.NewGrpc(cli, location.SkipAuth, time.Duration(config.Http.ProxyTimeoutInSec)*time.Second)
|
||||||
|
case conf.HttpProtocol:
|
||||||
|
hostManager := l.httpHostManagerByModuleName[location.TargetModule]
|
||||||
|
proxyFunc = proxy.NewHttp(hostManager, location.SkipAuth, time.Duration(config.Http.ProxyTimeoutInSec)*time.Second)
|
||||||
|
case conf.WsProtocol:
|
||||||
|
hostManager := l.httpHostManagerByModuleName[location.TargetModule]
|
||||||
|
proxyFunc = proxy.NewWs(hostManager, location.SkipAuth)
|
||||||
|
enableBodyLog = false
|
||||||
|
default:
|
||||||
|
return nil, errors.Errorf("not supported protocol %s", location.Protocol)
|
||||||
|
}
|
||||||
|
|
||||||
|
forwardReqIdByAppId := make(map[int]bool, len(config.ForwardReqIdClientSettings))
|
||||||
|
for _, setting := range config.ForwardReqIdClientSettings {
|
||||||
|
forwardReqIdByAppId[setting.ApplicationId] = setting.ForwardRequestId
|
||||||
|
}
|
||||||
|
|
||||||
|
handler := middleware.Chain(
|
||||||
|
proxyFunc,
|
||||||
|
middleware.Logger(
|
||||||
|
l.logger, config.Logging.RequestLogEnable,
|
||||||
|
enableBodyLog,
|
||||||
|
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
||||||
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
|
),
|
||||||
|
middleware.ErrorHandler(l.logger),
|
||||||
|
middleware.Authenticate(authentication),
|
||||||
|
middleware.AdminAuthenticate(adminService),
|
||||||
|
middleware.Authorize(authorization, l.logger),
|
||||||
|
middleware.AdminAuthorize(l.routes, adminService),
|
||||||
|
middleware.Throttling(throttlingService),
|
||||||
|
middleware.DailyLimit(dailyLimitService),
|
||||||
|
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
||||||
|
)
|
||||||
|
if location.SkipAuth {
|
||||||
|
handler = middleware.Chain(
|
||||||
|
proxyFunc,
|
||||||
|
middleware.Logger(l.logger, config.Logging.RequestLogEnable,
|
||||||
|
enableBodyLog,
|
||||||
|
config.Logging.SkipBodyLoggingEndpointPrefixes,
|
||||||
|
config.Logging.EnableForceUnescapingUnicode,
|
||||||
|
),
|
||||||
|
middleware.ErrorHandler(l.logger),
|
||||||
|
middleware.RequestId(config.EnableClientRequestIdForwarding, forwardReqIdByAppId),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
entrypoint := middleware.Entrypoint(
|
||||||
|
config.Http.MaxRequestBodySizeInMb*1024*1024, //nolint:mnd
|
||||||
|
handler,
|
||||||
|
middleware.EntryPointConfig{
|
||||||
|
WithPrefix: location.WithPrefix,
|
||||||
|
PathPrefix: location.PathPrefix,
|
||||||
|
},
|
||||||
|
l.routes,
|
||||||
|
l.logger,
|
||||||
|
)
|
||||||
|
mux.PathPrefix(location.PathPrefix).Handler(entrypoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
return mux, nil
|
||||||
|
}
|
||||||
Vendored
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Item struct {
|
||||||
|
data []byte
|
||||||
|
expiredAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type Cache struct {
|
||||||
|
store map[string]Item
|
||||||
|
lock *sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *Cache {
|
||||||
|
return &Cache{
|
||||||
|
store: map[string]Item{},
|
||||||
|
lock: &sync.RWMutex{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cache) Get(key string) ([]byte, bool) {
|
||||||
|
c.lock.RLock()
|
||||||
|
defer c.lock.RUnlock()
|
||||||
|
|
||||||
|
item, ok := c.store[key]
|
||||||
|
if !ok {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.now().After(item.expiredAt) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return item.data, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cache) Set(key string, data []byte, lifeTime time.Duration) {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
|
c.store[key] = Item{
|
||||||
|
data: data,
|
||||||
|
expiredAt: c.now().Add(lifeTime),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cache) now() time.Time {
|
||||||
|
return time.Now()
|
||||||
|
}
|
||||||
Vendored
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package cache_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"isp-gate-service/cache"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetBasic(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
cache := cache.New()
|
||||||
|
cache.Set("key", []byte("data"), 24*time.Hour)
|
||||||
|
|
||||||
|
data, ok := cache.Get("key")
|
||||||
|
require.True(ok)
|
||||||
|
require.EqualValues("data", data)
|
||||||
|
|
||||||
|
_, ok = cache.Get("key2")
|
||||||
|
require.False(ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetExpired(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
cache := cache.New()
|
||||||
|
cache.Set("key", []byte("data"), 500*time.Millisecond)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
data, ok := cache.Get("key")
|
||||||
|
require.False(ok)
|
||||||
|
require.Nil(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNilValue(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
cache := cache.New()
|
||||||
|
cache.Set("key", nil, 24*time.Hour)
|
||||||
|
|
||||||
|
data, ok := cache.Get("key")
|
||||||
|
require.True(ok)
|
||||||
|
require.Nil(data)
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
configServiceAddress:
|
||||||
|
ip: 127.0.0.1
|
||||||
|
port: 9001
|
||||||
|
grpcOuterAddress:
|
||||||
|
#ip: 127.0.0.1
|
||||||
|
port: 9003
|
||||||
|
grpcInnerAddress:
|
||||||
|
ip: 0.0.0.0
|
||||||
|
port: 9003
|
||||||
|
moduleName: isp-gate-service
|
||||||
|
|
||||||
|
infraServerPort: 9553
|
||||||
|
|
||||||
|
logfile:
|
||||||
|
path: /var/log/isp-gate-service/runtime.log
|
||||||
|
maxSizeMb: 512
|
||||||
|
maxBackups: 4
|
||||||
|
compress: true
|
||||||
|
|
||||||
|
|
||||||
|
locations:
|
||||||
|
- pathPrefix: /api
|
||||||
|
protocol: grpc
|
||||||
|
targetModule: router
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
configServiceAddress:
|
||||||
|
ip: 127.0.0.1
|
||||||
|
port: 9001
|
||||||
|
grpcOuterAddress:
|
||||||
|
#ip: 127.0.0.1
|
||||||
|
port: 9003
|
||||||
|
grpcInnerAddress:
|
||||||
|
ip: 0.0.0.0
|
||||||
|
port: 9003
|
||||||
|
moduleName: isp-gate-service
|
||||||
|
|
||||||
|
infraServerPort: 9553
|
||||||
|
|
||||||
|
logfile:
|
||||||
|
path: /var/log/isp-gate-service/runtime.log
|
||||||
|
maxSizeMb: 512
|
||||||
|
maxBackups: 4
|
||||||
|
compress: true
|
||||||
|
|
||||||
|
locations:
|
||||||
|
- pathPrefix: /ws/kkd-configuration-service
|
||||||
|
protocol: ws
|
||||||
|
targetModule: kkd-configuration-service
|
||||||
|
- pathPrefix: /api/kkd-configuration-service
|
||||||
|
protocol: http
|
||||||
|
targetModule: kkd-configuration-service
|
||||||
|
- withPrefix: false
|
||||||
|
pathPrefix: /api/kkd-storage-service/report/download
|
||||||
|
protocol: http
|
||||||
|
targetModule: kkd-storage-service
|
||||||
|
skipAuth: true
|
||||||
|
- pathPrefix: /api/kkd-storage-service
|
||||||
|
protocol: http
|
||||||
|
targetModule: kkd-storage-service
|
||||||
|
- pathPrefix: /api
|
||||||
|
protocol: grpc
|
||||||
|
skipAuth: false
|
||||||
|
targetModule: router
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"logging": {
|
||||||
|
"logLevel": "debug",
|
||||||
|
"requestLogEnable": true,
|
||||||
|
"bodyLogEnable": false,
|
||||||
|
"skipBodyLoggingEndpointPrefixes": [],
|
||||||
|
"enableForceUnescapingUnicode": false
|
||||||
|
},
|
||||||
|
"caching": {
|
||||||
|
"authenticationDataInSec": 60,
|
||||||
|
"authorizationDataInSec": 60
|
||||||
|
},
|
||||||
|
"http": {
|
||||||
|
"maxRequestBodySizeInMb": 64,
|
||||||
|
"proxyTimeoutInSec": 60
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package conf
|
||||||
|
|
||||||
|
const (
|
||||||
|
HttpProtocol = "http"
|
||||||
|
GrpcProtocol = "grpc"
|
||||||
|
WsProtocol = "ws"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Local struct {
|
||||||
|
Locations []Location
|
||||||
|
}
|
||||||
|
|
||||||
|
type Location struct {
|
||||||
|
WithPrefix bool
|
||||||
|
SkipAuth bool
|
||||||
|
PathPrefix string `validate:"required"`
|
||||||
|
Protocol string `validate:"required,oneof=http grpc ws"`
|
||||||
|
TargetModule string `validate:"required"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// nolint:gochecknoinits,lll
|
||||||
|
package conf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"github.com/txix-open/isp-kit/rc/schema"
|
||||||
|
"github.com/txix-open/jsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, t *jsonschema.Schema) {
|
||||||
|
t.Type = "string"
|
||||||
|
t.Enum = []interface{}{"debug", "info", "warn", "error", "fatal"}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type Remote struct {
|
||||||
|
Http Http `schema:"Настройки HTTP"`
|
||||||
|
Logging Logging `schema:"Настройки логирования"`
|
||||||
|
Caching Caching `schema:"Настройки кеширования"`
|
||||||
|
DailyLimits []DailyLimit `schema:"Настройки суточных ограничений,сбрасываются раз в сутки в 00:00"`
|
||||||
|
Throttling []Throttling `schema:"Настройки пропускной способности"`
|
||||||
|
EnableClientRequestIdForwarding bool `schema:"Включить проброс requestId из заголовка запроса"`
|
||||||
|
ForwardReqIdClientSettings []ForwardReqIdClientSettings `schema:"Настройки проброcа requestId для приложений"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ForwardReqIdClientSettings struct {
|
||||||
|
ApplicationId int `schema:"Идентификатор приложения"`
|
||||||
|
ForwardRequestId bool `schema:"Включить проброс requestId из заголовка запроса"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Http struct {
|
||||||
|
MaxRequestBodySizeInMb int64 `validate:"required" schema:"Максимальная длинна тела запроса,в мегабайтах"`
|
||||||
|
ProxyTimeoutInSec int `validate:"required" schema:"Таймаут на проксирование,в секундах"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Logging struct {
|
||||||
|
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования,логирование запросов осуществляется на уровне debug"`
|
||||||
|
RequestLogEnable bool `schema:"Включить логирование запросов"`
|
||||||
|
BodyLogEnable bool `schema:"Включить логирование тел запросов и ответов,должно быть включено логирование запросов"`
|
||||||
|
SkipBodyLoggingEndpointPrefixes []string `schema:"регулярные выражения для отключения логирования"`
|
||||||
|
EnableForceUnescapingUnicode bool `schema:"Включить перевод тел запроса из unicode в utf-8, должно быть включено логирование тел запросов и ответов"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Caching struct {
|
||||||
|
AuthenticationDataInSec int `validate:"required" schema:"Время кеширования данных аутентификации,в секундах"`
|
||||||
|
AuthorizationDataInSec int `validate:"required" schema:"Время кеширования данных авторизации,в секундах"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DailyLimit struct {
|
||||||
|
ApplicationId int `validate:"required" schema:"ID приложения"`
|
||||||
|
RequestsPerDay int64 `validate:"required" schema:"Запросов в сутки"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Throttling struct {
|
||||||
|
ApplicationId int `validate:"required" schema:"ID приложения"`
|
||||||
|
RequestsPerSeconds int `validate:"required,min=1,max=1000" schema:"Запросов в секунду,не конфликтует с суточными ограничениями, алгоритм не работает на значениях больше 1000"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package conf_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/test/rct"
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultRemoteConfig(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
rct.Test(t, "default_remote_config.json", conf.Remote{})
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
type AdminAuthenticateResponse struct {
|
||||||
|
Authenticated bool
|
||||||
|
ErrorReason string
|
||||||
|
AdminId int
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
type AuthData struct {
|
||||||
|
AppName string
|
||||||
|
SystemId int
|
||||||
|
DomainId int
|
||||||
|
ServiceId int
|
||||||
|
ApplicationId int
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrAuthenticationCacheMiss = errors.New("authentication not found in cache")
|
||||||
|
)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
type AuthenticateRequest struct {
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthenticateResponse struct {
|
||||||
|
Authenticated bool
|
||||||
|
ErrorReason string
|
||||||
|
AuthData *AuthData
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthorizeRequest struct {
|
||||||
|
ApplicationId int
|
||||||
|
Endpoint string
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthorizeResponse struct {
|
||||||
|
Authorized bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminAuthorizeRequest struct {
|
||||||
|
AdminId int
|
||||||
|
Permission string
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminAuthorizeResponse struct {
|
||||||
|
Authorized bool
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RateLimitResult struct {
|
||||||
|
Allow bool
|
||||||
|
Remaining int
|
||||||
|
RetryAfter time.Duration
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IncrementRequest struct {
|
||||||
|
Key string
|
||||||
|
Today time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type IncrementResponse struct {
|
||||||
|
Value uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type RateLimiterRequest struct {
|
||||||
|
Key string
|
||||||
|
MaxRps int
|
||||||
|
}
|
||||||
|
|
||||||
|
type RateLimiterResponse struct {
|
||||||
|
Allow bool
|
||||||
|
Remaining int
|
||||||
|
RetryAfter time.Duration
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
module isp-gate-service
|
||||||
|
|
||||||
|
go 1.25
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/gorilla/mux v1.8.1
|
||||||
|
github.com/gorilla/websocket v1.5.3
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
|
github.com/redis/go-redis/v9 v9.11.0
|
||||||
|
github.com/stretchr/testify v1.11.1
|
||||||
|
github.com/tomakado/websocketproxy v0.1.0
|
||||||
|
github.com/txix-open/isp-kit v1.63.3
|
||||||
|
github.com/txix-open/jsonschema v1.3.0
|
||||||
|
golang.org/x/net v0.44.0
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090
|
||||||
|
google.golang.org/grpc v1.75.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||||
|
github.com/txix-open/etp/v4 v4.0.1 // indirect
|
||||||
|
go.opentelemetry.io/auto/sdk v1.2.0 // indirect
|
||||||
|
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
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/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/coder/websocket v1.8.14 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
|
||||||
|
github.com/getsentry/sentry-go v0.35.2 // 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/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/julienschmidt/httprouter v1.3.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.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/txix-open/bellows v1.2.0 // indirect
|
||||||
|
github.com/txix-open/etp/v3 v3.2.0
|
||||||
|
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/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.63.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.42.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/protobuf v1.36.9 // indirect
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
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/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
|
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.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/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
|
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||||
|
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
|
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.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.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=
|
||||||
|
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-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
|
||||||
|
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
|
||||||
|
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/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||||
|
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||||
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
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/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.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/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs=
|
||||||
|
github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||||
|
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/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.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
|
github.com/tomakado/websocketproxy v0.1.0 h1:e037TLXDvEYYHlxHE5pqmj/DytFKm2NRn7i4wbVzIyE=
|
||||||
|
github.com/tomakado/websocketproxy v0.1.0/go.mod h1:EXg/3jcTJYZ04Hsf93RpY90FYA9lj1Sl+VM7lZI6xpM=
|
||||||
|
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/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.63.3 h1:UJLgR4z8sYXUX6r1sl6Ww1aijPx6b7ieMeB+elZoViM=
|
||||||
|
github.com/txix-open/isp-kit v1.63.3/go.mod h1:rwqKqB3PyZxaoep6iH1PKL89LS9nzRklA6+S4II72M4=
|
||||||
|
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=
|
||||||
|
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=
|
||||||
|
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/contrib/instrumentation/net/http/otelhttp v0.63.0 h1:RbKq8BG0FI8OiXhBfcRtqqHcZcka+gU3cskNuf05R18=
|
||||||
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0/go.mod h1:h06DGIukJOevXaj/xrNjhi/2098RZzcLTbc0jDAUbsg=
|
||||||
|
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=
|
||||||
|
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/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=
|
||||||
|
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/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=
|
||||||
@@ -0,0 +1,402 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1977-02-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"38924\",\"flat\":\"185\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Сергей\",\"middleName\":\"Петрович\",\"birthDay\":\"1977-02-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"38924\",\"flat\":\"185\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1950-08-18\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"63988\",\"flat\":\"78\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Иван\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1950-08-18\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"63988\",\"flat\":\"78\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1991-01-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"07460\",\"flat\":\"39\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Сергей\",\"middleName\":\"Козлович\",\"birthDay\":\"1991-01-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"07460\",\"flat\":\"39\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1982-05-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31319\",\"flat\":\"191\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Иван\",\"middleName\":\"Петрович\",\"birthDay\":\"1982-05-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31319\",\"flat\":\"191\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1993-01-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"70892\",\"flat\":\"51\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Алексей\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1993-01-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"70892\",\"flat\":\"51\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1963-10-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"64647\",\"flat\":\"176\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Петр\",\"middleName\":\"Михайлович\",\"birthDay\":\"1963-10-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"64647\",\"flat\":\"176\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1997-01-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"05466\",\"flat\":\"101\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1997-01-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"05466\",\"flat\":\"101\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1985-06-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"62526\",\"flat\":\"40\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Петр\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1985-06-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"62526\",\"flat\":\"40\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1964-02-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"67088\",\"flat\":\"111\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Иван\",\"middleName\":\"Петрович\",\"birthDay\":\"1964-02-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"67088\",\"flat\":\"111\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1985-11-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"59230\",\"flat\":\"143\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Михаил\",\"middleName\":\"Козлович\",\"birthDay\":\"1985-11-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"59230\",\"flat\":\"143\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1988-10-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"03392\",\"flat\":\"180\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Сергей\",\"middleName\":\"Козлович\",\"birthDay\":\"1988-10-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"03392\",\"flat\":\"180\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1977-06-16\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"20665\",\"flat\":\"166\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1977-06-16\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"20665\",\"flat\":\"166\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1987-12-12\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"66035\",\"flat\":\"90\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Сергей\",\"middleName\":\"Козлович\",\"birthDay\":\"1987-12-12\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"66035\",\"flat\":\"90\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1974-02-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"39439\",\"flat\":\"148\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Алексей\",\"middleName\":\"Петрович\",\"birthDay\":\"1974-02-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"39439\",\"flat\":\"148\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1989-02-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01481\",\"flat\":\"147\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Сергей\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1989-02-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01481\",\"flat\":\"147\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1952-11-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"54019\",\"flat\":\"67\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Петр\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1952-11-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"54019\",\"flat\":\"67\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1967-04-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80312\",\"flat\":\"79\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Сергей\",\"middleName\":\"Иванович\",\"birthDay\":\"1967-04-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80312\",\"flat\":\"79\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1951-12-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"60752\",\"flat\":\"136\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Иван\",\"middleName\":\"Козлович\",\"birthDay\":\"1951-12-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"60752\",\"flat\":\"136\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1989-07-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"52236\",\"flat\":\"49\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Михаил\",\"middleName\":\"Козлович\",\"birthDay\":\"1989-07-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"52236\",\"flat\":\"49\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1961-06-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"48602\",\"flat\":\"159\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Петр\",\"middleName\":\"Козлович\",\"birthDay\":\"1961-06-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"48602\",\"flat\":\"159\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1966-11-11\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"30072\",\"flat\":\"58\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Сергей\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1966-11-11\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"30072\",\"flat\":\"58\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1974-08-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"22508\",\"flat\":\"80\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Михаил\",\"middleName\":\"Петрович\",\"birthDay\":\"1974-08-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"22508\",\"flat\":\"80\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1993-04-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31222\",\"flat\":\"130\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Михаил\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1993-04-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31222\",\"flat\":\"130\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1969-11-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"43510\",\"flat\":\"98\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Петр\",\"middleName\":\"Петрович\",\"birthDay\":\"1969-11-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"43510\",\"flat\":\"98\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1965-04-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"93733\",\"flat\":\"39\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Алексей\",\"middleName\":\"Петрович\",\"birthDay\":\"1965-04-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"93733\",\"flat\":\"39\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1969-05-28\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"87093\",\"flat\":\"167\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Алексей\",\"middleName\":\"Михайлович\",\"birthDay\":\"1969-05-28\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"87093\",\"flat\":\"167\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1951-12-24\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"27732\",\"flat\":\"112\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Сергей\",\"middleName\":\"Михайлович\",\"birthDay\":\"1951-12-24\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"27732\",\"flat\":\"112\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1989-07-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31765\",\"flat\":\"51\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Михаил\",\"middleName\":\"Михайлович\",\"birthDay\":\"1989-07-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31765\",\"flat\":\"51\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1978-05-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"96998\",\"flat\":\"180\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Алексей\",\"middleName\":\"Иванович\",\"birthDay\":\"1978-05-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"96998\",\"flat\":\"180\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1993-10-12\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01064\",\"flat\":\"100\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Михаил\",\"middleName\":\"Михайлович\",\"birthDay\":\"1993-10-12\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01064\",\"flat\":\"100\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1993-04-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"45967\",\"flat\":\"82\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Петр\",\"middleName\":\"Иванович\",\"birthDay\":\"1993-04-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"45967\",\"flat\":\"82\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1981-08-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"74957\",\"flat\":\"64\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Петр\",\"middleName\":\"Михайлович\",\"birthDay\":\"1981-08-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"74957\",\"flat\":\"64\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1993-01-10\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"19023\",\"flat\":\"22\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Алексей\",\"middleName\":\"Михайлович\",\"birthDay\":\"1993-01-10\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"19023\",\"flat\":\"22\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1962-01-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"73929\",\"flat\":\"198\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Сергей\",\"middleName\":\"Козлович\",\"birthDay\":\"1962-01-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"73929\",\"flat\":\"198\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1956-08-03\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"46793\",\"flat\":\"83\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Петр\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1956-08-03\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"46793\",\"flat\":\"83\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1954-04-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"22410\",\"flat\":\"162\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Сергей\",\"middleName\":\"Петрович\",\"birthDay\":\"1954-04-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"22410\",\"flat\":\"162\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1991-12-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"92089\",\"flat\":\"62\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Иван\",\"middleName\":\"Петрович\",\"birthDay\":\"1991-12-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"92089\",\"flat\":\"62\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1970-10-10\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"91849\",\"flat\":\"22\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Иван\",\"middleName\":\"Иванович\",\"birthDay\":\"1970-10-10\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"91849\",\"flat\":\"22\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1952-07-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"49639\",\"flat\":\"87\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Сергей\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1952-07-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"49639\",\"flat\":\"87\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1967-03-09\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"43225\",\"flat\":\"165\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Иван\",\"middleName\":\"Петрович\",\"birthDay\":\"1967-03-09\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"43225\",\"flat\":\"165\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1969-05-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"90629\",\"flat\":\"102\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Алексей\",\"middleName\":\"Иванович\",\"birthDay\":\"1969-05-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"90629\",\"flat\":\"102\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1989-07-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"14363\",\"flat\":\"38\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Михаил\",\"middleName\":\"Козлович\",\"birthDay\":\"1989-07-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"14363\",\"flat\":\"38\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1992-12-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80159\",\"flat\":\"66\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1992-12-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80159\",\"flat\":\"66\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1982-05-14\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"76418\",\"flat\":\"69\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Сергей\",\"middleName\":\"Михайлович\",\"birthDay\":\"1982-05-14\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"76418\",\"flat\":\"69\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1966-08-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"63785\",\"flat\":\"185\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Михаил\",\"middleName\":\"Петрович\",\"birthDay\":\"1966-08-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"63785\",\"flat\":\"185\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1985-06-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"35007\",\"flat\":\"72\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Иван\",\"middleName\":\"Михайлович\",\"birthDay\":\"1985-06-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"35007\",\"flat\":\"72\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1966-07-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"78468\",\"flat\":\"85\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1966-07-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"78468\",\"flat\":\"85\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1959-10-28\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"40385\",\"flat\":\"40\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Михаил\",\"middleName\":\"Михайлович\",\"birthDay\":\"1959-10-28\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"40385\",\"flat\":\"40\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1982-07-15\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"20633\",\"flat\":\"74\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1982-07-15\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"20633\",\"flat\":\"74\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1983-11-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"61366\",\"flat\":\"140\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Иван\",\"middleName\":\"Петрович\",\"birthDay\":\"1983-11-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"61366\",\"flat\":\"140\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1991-10-02\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"05236\",\"flat\":\"4\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Сергей\",\"middleName\":\"Михайлович\",\"birthDay\":\"1991-10-02\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"05236\",\"flat\":\"4\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1960-08-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01631\",\"flat\":\"93\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Петр\",\"middleName\":\"Козлович\",\"birthDay\":\"1960-08-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01631\",\"flat\":\"93\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1999-09-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"76893\",\"flat\":\"170\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Сергей\",\"middleName\":\"Козлович\",\"birthDay\":\"1999-09-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"76893\",\"flat\":\"170\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1966-01-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"72424\",\"flat\":\"98\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1966-01-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"72424\",\"flat\":\"98\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1977-06-24\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"04063\",\"flat\":\"82\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Михаил\",\"middleName\":\"Петрович\",\"birthDay\":\"1977-06-24\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"04063\",\"flat\":\"82\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1969-04-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"43443\",\"flat\":\"80\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Сергей\",\"middleName\":\"Петрович\",\"birthDay\":\"1969-04-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"43443\",\"flat\":\"80\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1950-11-03\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"83732\",\"flat\":\"46\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Иван\",\"middleName\":\"Иванович\",\"birthDay\":\"1950-11-03\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"83732\",\"flat\":\"46\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1958-04-03\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"91863\",\"flat\":\"47\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Иван\",\"middleName\":\"Михайлович\",\"birthDay\":\"1958-04-03\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"91863\",\"flat\":\"47\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1953-10-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"67751\",\"flat\":\"61\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Алексей\",\"middleName\":\"Иванович\",\"birthDay\":\"1953-10-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"67751\",\"flat\":\"61\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1988-01-28\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"14661\",\"flat\":\"58\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Михаил\",\"middleName\":\"Козлович\",\"birthDay\":\"1988-01-28\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"14661\",\"flat\":\"58\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1981-12-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"10812\",\"flat\":\"57\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1981-12-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"10812\",\"flat\":\"57\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1970-01-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"87418\",\"flat\":\"150\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Михаил\",\"middleName\":\"Иванович\",\"birthDay\":\"1970-01-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"87418\",\"flat\":\"150\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1952-02-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"71225\",\"flat\":\"39\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Иван\",\"middleName\":\"Иванович\",\"birthDay\":\"1952-02-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"71225\",\"flat\":\"39\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1993-08-15\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80780\",\"flat\":\"188\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Иван\",\"middleName\":\"Михайлович\",\"birthDay\":\"1993-08-15\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80780\",\"flat\":\"188\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1981-07-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"17884\",\"flat\":\"138\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Петр\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1981-07-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"17884\",\"flat\":\"138\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1963-01-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"75966\",\"flat\":\"12\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Петр\",\"middleName\":\"Михайлович\",\"birthDay\":\"1963-01-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"75966\",\"flat\":\"12\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1962-11-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80065\",\"flat\":\"79\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Михаил\",\"middleName\":\"Иванович\",\"birthDay\":\"1962-11-13\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"80065\",\"flat\":\"79\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1963-07-18\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"42476\",\"flat\":\"4\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Алексей\",\"middleName\":\"Иванович\",\"birthDay\":\"1963-07-18\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"42476\",\"flat\":\"4\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1961-12-18\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"34741\",\"flat\":\"200\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Иван\",\"middleName\":\"Козлович\",\"birthDay\":\"1961-12-18\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"34741\",\"flat\":\"200\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1998-06-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"46796\",\"flat\":\"144\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Петр\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1998-06-17\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"46796\",\"flat\":\"144\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1965-07-24\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"98293\",\"flat\":\"188\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Михаил\",\"middleName\":\"Козлович\",\"birthDay\":\"1965-07-24\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"98293\",\"flat\":\"188\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1980-12-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"67475\",\"flat\":\"122\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Иван\",\"middleName\":\"Петрович\",\"birthDay\":\"1980-12-27\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"67475\",\"flat\":\"122\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1981-02-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"90604\",\"flat\":\"63\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Иван\",\"middleName\":\"Козлович\",\"birthDay\":\"1981-02-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"90604\",\"flat\":\"63\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1954-05-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"37669\",\"flat\":\"28\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1954-05-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"37669\",\"flat\":\"28\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1981-09-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"32425\",\"flat\":\"25\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Иван\",\"middleName\":\"Козлович\",\"birthDay\":\"1981-09-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"32425\",\"flat\":\"25\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1964-11-16\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"41589\",\"flat\":\"105\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Иван\",\"middleName\":\"Михайлович\",\"birthDay\":\"1964-11-16\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"41589\",\"flat\":\"105\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1969-12-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"06495\",\"flat\":\"32\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Петров\",\"firstName\":\"Петр\",\"middleName\":\"Петрович\",\"birthDay\":\"1969-12-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"06495\",\"flat\":\"32\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1969-01-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"58569\",\"flat\":\"79\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Петр\",\"middleName\":\"Иванович\",\"birthDay\":\"1969-01-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"58569\",\"flat\":\"79\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1983-01-11\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"39765\",\"flat\":\"162\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Алексей\",\"middleName\":\"Козлович\",\"birthDay\":\"1983-01-11\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"39765\",\"flat\":\"162\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1956-07-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"24412\",\"flat\":\"118\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Петр\",\"middleName\":\"Михайлович\",\"birthDay\":\"1956-07-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"24412\",\"flat\":\"118\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1981-08-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"45511\",\"flat\":\"88\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Михаил\",\"middleName\":\"Иванович\",\"birthDay\":\"1981-08-20\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"45511\",\"flat\":\"88\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1951-12-02\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"19511\",\"flat\":\"53\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Сергей\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1951-12-02\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"19511\",\"flat\":\"53\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1963-06-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"17982\",\"flat\":\"62\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Иван\",\"middleName\":\"Михайлович\",\"birthDay\":\"1963-06-22\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"17982\",\"flat\":\"62\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1960-11-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"52978\",\"flat\":\"30\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Алексей\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1960-11-06\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"52978\",\"flat\":\"30\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1966-01-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"75948\",\"flat\":\"49\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Михаил\",\"middleName\":\"Иванович\",\"birthDay\":\"1966-01-25\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"75948\",\"flat\":\"49\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1986-06-02\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"23634\",\"flat\":\"64\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Сергей\",\"middleName\":\"Иванович\",\"birthDay\":\"1986-06-02\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"23634\",\"flat\":\"64\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1969-11-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"26792\",\"flat\":\"87\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Михаил\",\"middleName\":\"Иванович\",\"birthDay\":\"1969-11-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"26792\",\"flat\":\"87\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1956-09-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"70768\",\"flat\":\"108\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Иван\",\"middleName\":\"Петрович\",\"birthDay\":\"1956-09-07\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"70768\",\"flat\":\"108\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0410\\u043B\\u0435\\u043A\\u0441\\u0435\\u0439\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1998-07-14\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"18771\",\"flat\":\"178\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Алексей\",\"middleName\":\"Михайлович\",\"birthDay\":\"1998-07-14\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"18771\",\"flat\":\"178\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1999-02-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01147\",\"flat\":\"162\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Михаил\",\"middleName\":\"Петрович\",\"birthDay\":\"1999-02-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"01147\",\"flat\":\"162\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1959-02-10\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"45931\",\"flat\":\"179\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Иван\",\"middleName\":\"Михайлович\",\"birthDay\":\"1959-02-10\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"45931\",\"flat\":\"179\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0421\\u0438\\u0434\\u043E\\u0440\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1967-07-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"42295\",\"flat\":\"130\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Сидоров\",\"firstName\":\"Михаил\",\"middleName\":\"Петрович\",\"birthDay\":\"1967-07-19\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"42295\",\"flat\":\"130\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1961-11-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"14998\",\"flat\":\"185\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Сергей\",\"middleName\":\"Иванович\",\"birthDay\":\"1961-11-21\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"14998\",\"flat\":\"185\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041C\\u0438\\u0445\\u0430\\u0438\\u043B\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1963-08-11\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31521\",\"flat\":\"198\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Михаил\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1963-08-11\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"31521\",\"flat\":\"198\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1965-09-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"50495\",\"flat\":\"67\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Сергей\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1965-09-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"50495\",\"flat\":\"67\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0418\\u0432\\u0430\\u043D\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1950-05-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"96951\",\"flat\":\"179\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Иван\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1950-05-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"96951\",\"flat\":\"179\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1998-01-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"59966\",\"flat\":\"108\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Петр\",\"middleName\":\"Козлович\",\"birthDay\":\"1998-01-23\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"59966\",\"flat\":\"108\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u0418\\u0432\\u0430\\u043D\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1981-02-14\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"49056\",\"flat\":\"113\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Иванов\",\"firstName\":\"Сергей\",\"middleName\":\"Петрович\",\"birthDay\":\"1981-02-14\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"49056\",\"flat\":\"113\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041A\\u043E\\u0437\\u043B\\u043E\\u0432\",\"firstName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0439\",\"middleName\":\"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432\\u0438\\u0447\",\"birthDay\":\"1995-08-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"27045\",\"flat\":\"107\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Козлов\",\"firstName\":\"Сергей\",\"middleName\":\"Петрович\",\"birthDay\":\"1995-08-26\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"27045\",\"flat\":\"107\"}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"raw": "{\"fiodr\":{\"lastName\":\"\\u041C\\u0438\\u0445\\u0430\\u0439\\u043B\\u043E\\u0432\",\"firstName\":\"\\u041F\\u0435\\u0442\\u0440\",\"middleName\":\"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447\",\"birthDay\":\"1958-07-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"35022\",\"flat\":\"180\"}}",
|
||||||
|
"expected": "{\"fiodr\":{\"lastName\":\"Михайлов\",\"firstName\":\"Петр\",\"middleName\":\"Сергеевич\",\"birthDay\":\"1958-07-05\"},\"objectType\":\"addresses.addr_registration\",\"params\":{\"unom\":\"35022\",\"flat\":\"180\"}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
// nolint:mnd
|
||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UnescapeUnicodeJson(data []byte) []byte {
|
||||||
|
var body any
|
||||||
|
err := json.Unmarshal(data, &body)
|
||||||
|
if err != nil {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
newData, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
return newData
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnescapeUnicode(data []byte) []byte {
|
||||||
|
n := len(data)
|
||||||
|
out := make([]byte, len(data)) // максимально возможный размер
|
||||||
|
j := 0 // индекс записи
|
||||||
|
|
||||||
|
for i := 0; i < n; {
|
||||||
|
if data[i] != '\\' {
|
||||||
|
// копируем весь блок до следующего '\'
|
||||||
|
start := i
|
||||||
|
for i < n && data[i] != '\\' {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
j += copy(out[j:], data[start:i])
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if isUnicodeEscape(data, i) {
|
||||||
|
r, consumed := decodeUnicodeEscape(data[i:])
|
||||||
|
if r >= 0 {
|
||||||
|
j = appendRuneAt(out, j, uint32(r))
|
||||||
|
i += consumed
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// обычный байт (одиночный '\')
|
||||||
|
out[j] = data[i]
|
||||||
|
j++
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
return out[:j]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяет, начинается ли здесь \uXXXX
|
||||||
|
func isUnicodeEscape(data []byte, i int) bool {
|
||||||
|
return i+5 < len(data) && data[i] == '\\' && data[i+1] == 'u'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Декодирует \uXXXX, учитывая суррогатную пару.
|
||||||
|
// Возвращает руну и сколько байт было прочитано.
|
||||||
|
func decodeUnicodeEscape(data []byte) (rune, int) {
|
||||||
|
v1, ok := parseHex4(data[2:6])
|
||||||
|
if !ok {
|
||||||
|
return -1, 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка суррогатной пары
|
||||||
|
if 0xD800 <= v1 && v1 <= 0xDBFF && isUnicodeEscape(data, 6) {
|
||||||
|
v2, ok2 := parseHex4(data[8:12])
|
||||||
|
if ok2 && 0xDC00 <= v2 && v2 <= 0xDFFF {
|
||||||
|
r := 0x10000 + ((uint32(v1)-0xD800)<<10 | (uint32(v2) - 0xDC00))
|
||||||
|
return rune(r), 12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rune(v1), 6
|
||||||
|
}
|
||||||
|
|
||||||
|
// Парсим 4 hex-символа через hexValue
|
||||||
|
func parseHex4(b []byte) (uint16, bool) {
|
||||||
|
v := uint16(0)
|
||||||
|
for _, c := range b {
|
||||||
|
h, ok := hexValue(c)
|
||||||
|
if !ok {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
v = v<<4 | h
|
||||||
|
}
|
||||||
|
return v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func hexValue(b byte) (uint16, bool) {
|
||||||
|
switch {
|
||||||
|
case '0' <= b && b <= '9':
|
||||||
|
return uint16(b - '0'), true
|
||||||
|
case 'a' <= b && b <= 'f':
|
||||||
|
return uint16(b - 'a' + 10), true
|
||||||
|
case 'A' <= b && b <= 'F':
|
||||||
|
return uint16(b - 'A' + 10), true
|
||||||
|
default:
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// appendRune добавляет руну в UTF-8
|
||||||
|
func appendRuneAt(buf []byte, j int, r uint32) int {
|
||||||
|
p := (*[4]byte)(unsafe.Pointer(&buf[j]))
|
||||||
|
switch {
|
||||||
|
case r < 0x80:
|
||||||
|
p[0] = byte(r)
|
||||||
|
return j + 1
|
||||||
|
case r < 0x800:
|
||||||
|
p[0] = 0xC0 | byte(r>>6)
|
||||||
|
p[1] = 0x80 | byte(r&0x3F)
|
||||||
|
return j + 2
|
||||||
|
case r < 0x10000:
|
||||||
|
p[0] = 0xE0 | byte(r>>12)
|
||||||
|
p[1] = 0x80 | byte((r>>6)&0x3F)
|
||||||
|
p[2] = 0x80 | byte(r&0x3F)
|
||||||
|
return j + 3
|
||||||
|
default:
|
||||||
|
p[0] = 0xF0 | byte(r>>18)
|
||||||
|
p[1] = 0x80 | byte((r>>12)&0x3F)
|
||||||
|
p[2] = 0x80 | byte((r>>6)&0x3F)
|
||||||
|
p[3] = 0x80 | byte(r&0x3F)
|
||||||
|
return j + 4
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package helpers_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"isp-gate-service/helpers"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// nolint:gochecknoglobals,lll
|
||||||
|
var (
|
||||||
|
rawUnicode = []byte(`{"fiodr":{"lastName":"\\u041F\\u0435\\u0442\\u0440\\u043E\\u0432","firstName":"\\u0418\\u0432\\u0430\\u043D","middleName":"\\u0421\\u0435\\u0440\\u0433\\u0435\\u0435\\u0432\\u0438\\u0447","birthDay":"1950-08-18"},"objectType":"addresses.addr_registration","params":{"unom":"63988","flat":"78"}}`)
|
||||||
|
rawAscii = []byte(`{"fiodr":{"lastName":"Петров","firstName":"Иван","middleName":"Сергеевич","birthDay":"1950-08-18"},"objectType":"addresses.addr_registration","params":{"unom":"63988","flat":"78"}}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
func Benchmark_UnescapeUnicodeJson_Unicode(b *testing.B) {
|
||||||
|
for b.Loop() {
|
||||||
|
_ = helpers.UnescapeUnicodeJson(rawUnicode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Benchmark_UnescapeUnicodeJson_Anscii(b *testing.B) {
|
||||||
|
for b.Loop() {
|
||||||
|
_ = helpers.UnescapeUnicodeJson(rawAscii)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Benchmark_UnescapeUnicode_Unicode(b *testing.B) {
|
||||||
|
for b.Loop() {
|
||||||
|
_ = helpers.UnescapeUnicode(rawUnicode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Benchmark_UnescapeUnicode_Anscii(b *testing.B) {
|
||||||
|
for b.Loop() {
|
||||||
|
_ = helpers.UnescapeUnicode(rawAscii)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package helpers_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"isp-gate-service/helpers"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/json"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestForceUnescapingUnicode(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
type testCase struct {
|
||||||
|
Raw string
|
||||||
|
Expected string
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile("./test_data/json_cases.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var testCases []testCase
|
||||||
|
require.NoError(t, json.Unmarshal(data, &testCases))
|
||||||
|
|
||||||
|
for i, tt := range testCases {
|
||||||
|
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
out := helpers.UnescapeUnicode([]byte(tt.Raw))
|
||||||
|
require.JSONEq(t, tt.Expected, string(out))
|
||||||
|
|
||||||
|
jsonOut := helpers.UnescapeUnicodeJson([]byte(tt.Raw))
|
||||||
|
require.JSONEq(t, tt.Expected, string(jsonOut))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package httperrors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HttpError struct {
|
||||||
|
statusCode int
|
||||||
|
userMessage string
|
||||||
|
details []any
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(statusCode int, userMessage string, internalError error) *HttpError {
|
||||||
|
return &HttpError{
|
||||||
|
statusCode: statusCode,
|
||||||
|
userMessage: userMessage,
|
||||||
|
err: internalError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *HttpError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *HttpError) WriteError(w http.ResponseWriter) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(e.statusCode)
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"errorCode": http.StatusText(e.statusCode),
|
||||||
|
"errorMessage": e.userMessage,
|
||||||
|
"details": e.details,
|
||||||
|
}
|
||||||
|
return json.NewEncoder(w).Encode(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *HttpError) WithDetails(details ...any) {
|
||||||
|
e.details = details
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/txix-open/isp-kit/bootstrap"
|
||||||
|
"github.com/txix-open/isp-kit/shutdown"
|
||||||
|
"isp-gate-service/assembly"
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
version = "1.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
boot := bootstrap.New(version, conf.Remote{}, nil)
|
||||||
|
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,48 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
adminAuthHeader = "x-auth-admin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminAuthenticator interface {
|
||||||
|
AdminAuthenticate(ctx context.Context, token string) (*domain.AdminAuthenticateResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AdminAuthenticate(auth AdminAuthenticator) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
adminToken := ctx.Param(adminAuthHeader)
|
||||||
|
if adminToken == "" {
|
||||||
|
return next.Handle(ctx)
|
||||||
|
}
|
||||||
|
resp, err := auth.AdminAuthenticate(ctx.Context(), adminToken)
|
||||||
|
if err != nil {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
"invalid admin token",
|
||||||
|
errors.WithMessage(err, "admin authenticate: authenticate"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if !resp.Authenticated {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
"invalid admin token",
|
||||||
|
errors.WithMessage(errors.New(resp.ErrorReason), "admin authenticate: authenticate"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ctx.AuthenticateAdmin(resp.AdminId, adminToken)
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminMethodStore interface {
|
||||||
|
IsInnerEndpoint(endpoint string) bool
|
||||||
|
RequiredAdminPermission(endpoint string) (string, bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminAuthorizer interface {
|
||||||
|
AdminAuthorize(ctx context.Context, adminId int, permission string) (bool, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AdminAuthorize(store AdminMethodStore, authorizer AdminAuthorizer) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
isInner := store.IsInnerEndpoint(ctx.Endpoint())
|
||||||
|
if !isInner {
|
||||||
|
return next.Handle(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ctx.IsAdminAuthenticated() {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusForbidden,
|
||||||
|
"admin authentication required",
|
||||||
|
errors.Errorf("admin authorization: admin authentication required for '%s'", ctx.Endpoint()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
requiredPerm, ok := store.RequiredAdminPermission(ctx.Endpoint())
|
||||||
|
if !ok {
|
||||||
|
return next.Handle(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := authorizer.AdminAuthorize(ctx.Context(), ctx.AdminId(), requiredPerm)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "admin authorization: authorize")
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusForbidden,
|
||||||
|
"endpoint is not allowed",
|
||||||
|
errors.Errorf(
|
||||||
|
"admin authorization: endpoint '%s' requires '%s' permission, but admin '%d' doesn't have it",
|
||||||
|
ctx.Endpoint(), requiredPerm, ctx.AdminId(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
applicationTokenHeader = "x-application-token"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Authenticator interface {
|
||||||
|
Authenticate(ctx context.Context, token string) (*domain.AuthenticateResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Authenticate(authenticator Authenticator) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
token, appName, err := extractToken(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if token == "" {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
"application token required",
|
||||||
|
errors.New("authenticate: application token required"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := authenticator.Authenticate(ctx.Context(), token)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "authenticate: authenticator error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !resp.Authenticated {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
"invalid application token",
|
||||||
|
errors.Errorf("authenticate: %s", resp.ErrorReason),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if appName != "" && resp.AuthData.AppName != appName {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
"invalid application token",
|
||||||
|
errors.New("authenticate: application name mismatch"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Authenticate(request.AuthData(*resp.AuthData))
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractToken(ctx *request.Context) (string, string, error) {
|
||||||
|
var (
|
||||||
|
appName string
|
||||||
|
token string
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
|
||||||
|
token = ctx.Param(applicationTokenHeader)
|
||||||
|
if token != "" {
|
||||||
|
return token, "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
appName, token, ok = ctx.Request().BasicAuth()
|
||||||
|
if ok && appName == "" {
|
||||||
|
return "", "", httperrors.New(
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
"application name required",
|
||||||
|
errors.New("authenticate: application name required on basic auth"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return token, appName, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Authorizer interface {
|
||||||
|
Authorize(ctx context.Context, applicationId int, endpoint string) (bool, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Authorize(authorizer Authorizer, logger log.Logger) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
authData, err := ctx.GetAuthData()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "authorize: get auth data")
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := authorizer.Authorize(ctx.Context(), authData.ApplicationId, ctx.Endpoint())
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "authorize: authorize")
|
||||||
|
}
|
||||||
|
if !ok && ctx.IsAdminAuthenticated() {
|
||||||
|
logger.Info(
|
||||||
|
ctx.Context(),
|
||||||
|
"bypassing unauthorized request because it has admin privilege",
|
||||||
|
log.Int("applicationId", authData.ApplicationId),
|
||||||
|
log.Int("adminId", ctx.AdminId()),
|
||||||
|
)
|
||||||
|
return next.Handle(ctx)
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusForbidden,
|
||||||
|
"endpoint is not allowed",
|
||||||
|
errors.Errorf("authorize: endpoint '%s' is not allowed for application '%d'", ctx.Endpoint(), authData.ApplicationId),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DailyLimitChecker interface {
|
||||||
|
IncrementAndCheck(ctx context.Context, applicationId int) (bool, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DailyLimit(checker DailyLimitChecker) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
authData, err := ctx.GetAuthData()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "daily limit: get auth data")
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := checker.IncrementAndCheck(ctx.Context(), authData.ApplicationId)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "daily limit: increment and check")
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusTooManyRequests,
|
||||||
|
"daily requests limit has been reached",
|
||||||
|
errors.Errorf("daily limit: daily requests limit has been reached for application '%d'", authData.ApplicationId),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EntryPointConfig struct {
|
||||||
|
PathPrefix string
|
||||||
|
WithPrefix bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type EndpointResolver interface {
|
||||||
|
ResolveEndpoint(path string, cfg EntryPointConfig) string
|
||||||
|
}
|
||||||
|
|
||||||
|
func Entrypoint(
|
||||||
|
maxReqBodySize int64,
|
||||||
|
next Handler,
|
||||||
|
cfg EntryPointConfig,
|
||||||
|
entryPointResolver EndpointResolver,
|
||||||
|
logger log.Logger,
|
||||||
|
) http.Handler {
|
||||||
|
return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
|
||||||
|
req.Body = http.MaxBytesReader(writer, req.Body, maxReqBodySize)
|
||||||
|
|
||||||
|
endpoint := entryPointResolver.ResolveEndpoint(req.URL.Path, cfg)
|
||||||
|
ctx := request.NewContext(req, writer, endpoint)
|
||||||
|
|
||||||
|
err := next.Handle(ctx)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(req.Context(), errors.WithMessage(err, "uncaught error"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HttpError interface {
|
||||||
|
WriteError(w http.ResponseWriter) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrorHandler(logger log.Logger) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
err := next.Handle(ctx)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Error(ctx.Context(), err)
|
||||||
|
|
||||||
|
httpErr, ok := err.(HttpError)
|
||||||
|
if ok {
|
||||||
|
return httpErr.WriteError(ctx.ResponseWriter())
|
||||||
|
}
|
||||||
|
|
||||||
|
return httperrors.
|
||||||
|
New(http.StatusInternalServerError, "internal service error", err).
|
||||||
|
WriteError(ctx.ResponseWriter())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"isp-gate-service/helpers"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/http/endpoint/buffer"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
unicodeEscapePrefix = []byte("\\u") // nolint:gochecknoglobals
|
||||||
|
)
|
||||||
|
|
||||||
|
type scSource interface {
|
||||||
|
StatusCode() int
|
||||||
|
}
|
||||||
|
|
||||||
|
type writerWrapper struct {
|
||||||
|
http.ResponseWriter
|
||||||
|
|
||||||
|
statusCode int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *writerWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
|
upstream, ok := w.ResponseWriter.(http.Hijacker)
|
||||||
|
if !ok {
|
||||||
|
return nil, nil, errors.New("writerWrapper: upstream writer doesn't implement Hijack")
|
||||||
|
}
|
||||||
|
return upstream.Hijack()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *writerWrapper) StatusCode() int {
|
||||||
|
if w.statusCode == 0 {
|
||||||
|
return http.StatusOK
|
||||||
|
}
|
||||||
|
return w.statusCode
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *writerWrapper) WriteHeader(statusCode int) {
|
||||||
|
w.statusCode = statusCode
|
||||||
|
w.ResponseWriter.WriteHeader(statusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Logger( // nolint:gocognit
|
||||||
|
logger log.Logger,
|
||||||
|
enableRequestLogging bool,
|
||||||
|
enableBodyLogging bool,
|
||||||
|
skipBodyLoggingEndpointPrefixes []string,
|
||||||
|
enableForceUnescapingUnicode bool,
|
||||||
|
) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
if !enableRequestLogging {
|
||||||
|
return next.Handle(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := ctx.Request()
|
||||||
|
|
||||||
|
logBodyFromCurrenRequest := enableBodyLogging
|
||||||
|
if logBodyFromCurrenRequest {
|
||||||
|
for _, prefix := range skipBodyLoggingEndpointPrefixes {
|
||||||
|
if strings.HasPrefix(ctx.Endpoint(), prefix) {
|
||||||
|
logBodyFromCurrenRequest = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var scSrc scSource
|
||||||
|
var buf *buffer.Buffer
|
||||||
|
if logBodyFromCurrenRequest {
|
||||||
|
buf = buffer.Acquire(ctx.ResponseWriter())
|
||||||
|
defer buffer.Release(buf)
|
||||||
|
|
||||||
|
err := buf.ReadRequestBody(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "logger: read request body for logging")
|
||||||
|
}
|
||||||
|
err = r.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "logger: close request reader")
|
||||||
|
}
|
||||||
|
r.Body = io.NopCloser(bytes.NewBuffer(buf.RequestBody()))
|
||||||
|
|
||||||
|
scSrc = buf
|
||||||
|
ctx.SetResponseWriter(buf)
|
||||||
|
} else {
|
||||||
|
writer := &writerWrapper{ResponseWriter: ctx.ResponseWriter()}
|
||||||
|
scSrc = writer
|
||||||
|
ctx.SetResponseWriter(writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
originalPath := r.URL.Path //
|
||||||
|
// can be changed in http proxy
|
||||||
|
err := next.Handle(ctx)
|
||||||
|
|
||||||
|
authData, _ := ctx.GetAuthData()
|
||||||
|
fields := []log.Field{
|
||||||
|
log.String("httpMethod", r.Method),
|
||||||
|
log.String("remoteAddr", r.RemoteAddr),
|
||||||
|
log.String("xForwardedFor", r.Header.Get("X-Forwarded-For")),
|
||||||
|
log.Int("statusCode", scSrc.StatusCode()),
|
||||||
|
log.String("path", originalPath),
|
||||||
|
log.String("endpoint", ctx.Endpoint()),
|
||||||
|
log.Int("applicationId", authData.ApplicationId),
|
||||||
|
log.Int("adminId", ctx.AdminId()),
|
||||||
|
}
|
||||||
|
|
||||||
|
if logBodyFromCurrenRequest {
|
||||||
|
if enableForceUnescapingUnicode && bytes.Contains(buf.RequestBody(), unicodeEscapePrefix) {
|
||||||
|
fields = append(fields, log.ByteString("request", helpers.UnescapeUnicode(buf.RequestBody())))
|
||||||
|
} else {
|
||||||
|
fields = append(fields, log.ByteString("request", buf.RequestBody()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fields = append(fields, log.ByteString("response", buf.ResponseBody()))
|
||||||
|
}
|
||||||
|
logger.Debug(ctx.Context(), "log request", fields...)
|
||||||
|
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"isp-gate-service/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Handler interface {
|
||||||
|
Handle(ctx *request.Context) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type HandlerFunc func(ctx *request.Context) error
|
||||||
|
|
||||||
|
func (f HandlerFunc) Handle(ctx *request.Context) error {
|
||||||
|
return f(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Middleware func(next Handler) Handler
|
||||||
|
|
||||||
|
// nolint:ireturn
|
||||||
|
func Chain(root Handler, middlewares ...Middleware) Handler {
|
||||||
|
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||||
|
root = middlewares[i](root)
|
||||||
|
}
|
||||||
|
return root
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"isp-gate-service/request"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"github.com/txix-open/isp-kit/requestid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
requestIdHeader = "x-request-id"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RequestId(forwardClientRequestId bool, forwardReqIdByApp map[int]bool) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
requestId := requestid.Next()
|
||||||
|
clientRequestId := strings.TrimSpace(ctx.Request().Header.Get(requestIdHeader))
|
||||||
|
|
||||||
|
logFields := make([]log.Field, 0)
|
||||||
|
if clientRequestId != "" {
|
||||||
|
logFields = append(logFields, log.String("clientRequestId", clientRequestId))
|
||||||
|
|
||||||
|
authData, _ := ctx.GetAuthData()
|
||||||
|
if forwardClientRequestId || forwardReqIdByApp[authData.ApplicationId] {
|
||||||
|
requestId = clientRequestId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logFields = append(logFields, log.String("requestId", requestId))
|
||||||
|
|
||||||
|
context := requestid.ToContext(ctx.Context(), requestId)
|
||||||
|
context = log.ToContext(context, logFields...)
|
||||||
|
|
||||||
|
ctx.SetContext(context)
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Throttler interface {
|
||||||
|
AllowRateLimit(ctx context.Context, applicationId int) (*domain.RateLimitResult, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Throttling(throttler Throttler) Middleware {
|
||||||
|
return func(next Handler) Handler {
|
||||||
|
return HandlerFunc(func(ctx *request.Context) error {
|
||||||
|
authData, err := ctx.GetAuthData()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "throttling: get auth data")
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := throttler.AllowRateLimit(ctx.Context(), authData.ApplicationId)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "throttling: allow rate limit")
|
||||||
|
}
|
||||||
|
if !result.Allow {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusTooManyRequests,
|
||||||
|
fmt.Sprintf("rate limit has been reached, try after %dms", result.RetryAfter.Milliseconds()),
|
||||||
|
errors.Errorf("throttling: rate limit has been reached for application '%d'", authData.ApplicationId),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return next.Handle(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
const (
|
||||||
|
xAdminIdHeader = "x-admin-id"
|
||||||
|
)
|
||||||
+166
@@ -0,0 +1,166 @@
|
|||||||
|
// nolint:gochecknoinits
|
||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
|
||||||
|
"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/isp"
|
||||||
|
"github.com/txix-open/isp-kit/json"
|
||||||
|
"github.com/txix-open/isp-kit/requestid"
|
||||||
|
_ "google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
for httpCode, grpcCode := range codeMap {
|
||||||
|
inverseCodeMap[grpcCode] = httpCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
codeMap = map[int]codes.Code{
|
||||||
|
http.StatusOK: codes.OK,
|
||||||
|
http.StatusRequestTimeout: codes.Canceled,
|
||||||
|
http.StatusBadRequest: codes.InvalidArgument,
|
||||||
|
http.StatusGatewayTimeout: codes.DeadlineExceeded,
|
||||||
|
http.StatusNotFound: codes.NotFound,
|
||||||
|
http.StatusConflict: codes.AlreadyExists,
|
||||||
|
http.StatusForbidden: codes.PermissionDenied,
|
||||||
|
http.StatusUnauthorized: codes.Unauthenticated,
|
||||||
|
http.StatusTooManyRequests: codes.ResourceExhausted,
|
||||||
|
http.StatusPreconditionFailed: codes.FailedPrecondition,
|
||||||
|
http.StatusNotImplemented: codes.Unimplemented,
|
||||||
|
http.StatusInternalServerError: codes.Internal,
|
||||||
|
http.StatusServiceUnavailable: codes.Unavailable,
|
||||||
|
}
|
||||||
|
inverseCodeMap = map[codes.Code]int{}
|
||||||
|
)
|
||||||
|
|
||||||
|
type Grpc struct {
|
||||||
|
cli *client.Client
|
||||||
|
skipAuth bool
|
||||||
|
timeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGrpc(cli *client.Client, skipAuth bool, timeout time.Duration) Grpc {
|
||||||
|
return Grpc{
|
||||||
|
cli: cli,
|
||||||
|
skipAuth: skipAuth,
|
||||||
|
timeout: timeout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Grpc) Handle(ctx *request.Context) error {
|
||||||
|
body, err := io.ReadAll(ctx.Request().Body)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "grpc: read body")
|
||||||
|
}
|
||||||
|
|
||||||
|
requestId := requestid.FromContext(ctx.Context())
|
||||||
|
md := metadata.MD{
|
||||||
|
grpc.ProxyMethodNameHeader: {ctx.Endpoint()},
|
||||||
|
requestid.Header: {requestId},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !p.skipAuth {
|
||||||
|
authData, err := ctx.GetAuthData()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "get auth data")
|
||||||
|
}
|
||||||
|
md[grpc.SystemIdHeader] = []string{strconv.Itoa(authData.SystemId)}
|
||||||
|
md[grpc.DomainIdHeader] = []string{strconv.Itoa(authData.DomainId)}
|
||||||
|
md[grpc.ServiceIdHeader] = []string{strconv.Itoa(authData.ServiceId)}
|
||||||
|
md[grpc.ApplicationIdHeader] = []string{strconv.Itoa(authData.ApplicationId)}
|
||||||
|
if ctx.IsAdminAuthenticated() {
|
||||||
|
md[xAdminIdHeader] = []string{strconv.Itoa(ctx.AdminId())}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requestContext := metadata.NewOutgoingContext(ctx.Context(), md)
|
||||||
|
|
||||||
|
requestContext, cancel := context.WithTimeout(requestContext, p.timeout)
|
||||||
|
defer cancel()
|
||||||
|
result, err := p.cli.BackendClient().Request(requestContext, &isp.Message{
|
||||||
|
Body: &isp.Message_BytesBody{BytesBody: body},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return p.handleError(err, ctx.ResponseWriter(), ctx.Endpoint())
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.writeResponse(http.StatusOK, result.GetBytesBody(), requestId, ctx.ResponseWriter())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Grpc) handleError(err error, w http.ResponseWriter, endpoint string) error {
|
||||||
|
status, ok := status.FromError(err)
|
||||||
|
if !ok {
|
||||||
|
return httperrors.New(
|
||||||
|
http.StatusServiceUnavailable,
|
||||||
|
"upstream is not available",
|
||||||
|
errors.WithMessage(err, "grpc proxy"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
statusCode := p.codeToHttpStatus(status.Code())
|
||||||
|
for _, detail := range status.Details() {
|
||||||
|
switch typeOfDetail := detail.(type) {
|
||||||
|
case *isp.Message:
|
||||||
|
switch {
|
||||||
|
case typeOfDetail.GetBytesBody() != nil:
|
||||||
|
return p.writeResponse(statusCode, typeOfDetail.GetBytesBody(), "", w)
|
||||||
|
case typeOfDetail.GetListBody() != nil:
|
||||||
|
return p.writeProto(statusCode, typeOfDetail.GetListBody(), w)
|
||||||
|
case typeOfDetail.GetStructBody() != nil:
|
||||||
|
return p.writeProto(statusCode, typeOfDetail.GetStructBody(), w)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return p.writeProto(statusCode, typeOfDetail, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return httperrors.New(
|
||||||
|
statusCode,
|
||||||
|
status.Message(),
|
||||||
|
errors.WithMessagef(err, "isp-routing-service: proxy '%s'", endpoint),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Grpc) writeProto(statusCode int, proto interface{}, w http.ResponseWriter) error {
|
||||||
|
data, err := json.Marshal(proto)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "marshal grpc details to json")
|
||||||
|
}
|
||||||
|
return p.writeResponse(statusCode, data, "", w)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Grpc) writeResponse(statusCode int, data []byte, requestId string, w http.ResponseWriter) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
if requestId != "" {
|
||||||
|
w.Header().Set(requestid.Header, requestId)
|
||||||
|
}
|
||||||
|
w.WriteHeader(statusCode)
|
||||||
|
_, err := w.Write(data)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "response write")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Grpc) codeToHttpStatus(code codes.Code) int {
|
||||||
|
s, ok := inverseCodeMap[code]
|
||||||
|
if !ok {
|
||||||
|
return http.StatusInternalServerError
|
||||||
|
}
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
+114
@@ -0,0 +1,114 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httputil"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
|
"github.com/txix-open/isp-kit/requestid"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
httpTransport = &http.Transport{
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
DialContext: defaultTransportDialContext(&net.Dialer{
|
||||||
|
Timeout: 3 * time.Second,
|
||||||
|
KeepAlive: 30 * time.Second,
|
||||||
|
}),
|
||||||
|
ForceAttemptHTTP2: true,
|
||||||
|
MaxIdleConns: 512,
|
||||||
|
MaxIdleConnsPerHost: 32,
|
||||||
|
IdleConnTimeout: 60 * time.Second,
|
||||||
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
|
ExpectContinueTimeout: 1 * time.Second,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type HttpHostManager interface {
|
||||||
|
Next() (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Http struct {
|
||||||
|
hostManager HttpHostManager
|
||||||
|
skipAuth bool
|
||||||
|
timeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHttp(hostManager HttpHostManager, skipAuth bool, timeout time.Duration) Http {
|
||||||
|
return Http{
|
||||||
|
hostManager: hostManager,
|
||||||
|
skipAuth: skipAuth,
|
||||||
|
timeout: timeout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Http) Handle(ctx *request.Context) error {
|
||||||
|
host, err := p.hostManager.Next()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "http: next host")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawUrl := fmt.Sprintf("http://%s", host) // secure HTTP links are reset connection
|
||||||
|
target, err := url.Parse(rawUrl)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "http: parse url")
|
||||||
|
}
|
||||||
|
|
||||||
|
request := ctx.Request()
|
||||||
|
request.URL.Path = ctx.Endpoint()
|
||||||
|
err = setHttpHeaders(ctx, request.Header, p.skipAuth)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
reverseProxy := httputil.NewSingleHostReverseProxy(target)
|
||||||
|
reverseProxy.Transport = httpTransport
|
||||||
|
var resultError error
|
||||||
|
reverseProxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, err error) {
|
||||||
|
resultError = httperrors.New(
|
||||||
|
http.StatusServiceUnavailable,
|
||||||
|
"upstream is not available",
|
||||||
|
errors.WithMessagef(err, "http proxy to %s", host),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
context, cancel := context.WithTimeout(request.Context(), p.timeout)
|
||||||
|
defer cancel()
|
||||||
|
request = request.WithContext(context)
|
||||||
|
reverseProxy.ServeHTTP(ctx.ResponseWriter(), request)
|
||||||
|
|
||||||
|
return resultError
|
||||||
|
}
|
||||||
|
|
||||||
|
func setHttpHeaders(ctx *request.Context, header http.Header, skipAuth bool) error {
|
||||||
|
header.Set(requestid.Header, requestid.FromContext(ctx.Context()))
|
||||||
|
if !skipAuth {
|
||||||
|
authData, err := ctx.GetAuthData()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "http: get auth data")
|
||||||
|
}
|
||||||
|
header.Set(grpc.SystemIdHeader, strconv.Itoa(authData.SystemId))
|
||||||
|
header.Set(grpc.DomainIdHeader, strconv.Itoa(authData.DomainId))
|
||||||
|
header.Set(grpc.ServiceIdHeader, strconv.Itoa(authData.ServiceId))
|
||||||
|
header.Set(grpc.ApplicationIdHeader, strconv.Itoa(authData.ApplicationId))
|
||||||
|
if ctx.IsAdminAuthenticated() {
|
||||||
|
header.Set(xAdminIdHeader, strconv.Itoa(ctx.AdminId())) //nolint:canonicalheader
|
||||||
|
} else {
|
||||||
|
header.Del(xAdminIdHeader) //nolint:canonicalheader
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultTransportDialContext(dialer *net.Dialer) func(context.Context, string, string) (net.Conn, error) {
|
||||||
|
return dialer.DialContext
|
||||||
|
}
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/tomakado/websocketproxy"
|
||||||
|
"isp-gate-service/httperrors"
|
||||||
|
"isp-gate-service/request"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Ws struct {
|
||||||
|
hostManager HttpHostManager
|
||||||
|
skipAuth bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWs(hostManager HttpHostManager, skipAuth bool) Ws {
|
||||||
|
return Ws{
|
||||||
|
hostManager: hostManager,
|
||||||
|
skipAuth: skipAuth,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ws Ws) Handle(ctx *request.Context) error {
|
||||||
|
host, err := ws.hostManager.Next()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "ws: next host")
|
||||||
|
}
|
||||||
|
|
||||||
|
rawUrl := fmt.Sprintf("ws://%s", host)
|
||||||
|
target, err := url.Parse(rawUrl)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "ws: parse url")
|
||||||
|
}
|
||||||
|
|
||||||
|
request := ctx.Request()
|
||||||
|
request.URL.Path = ctx.Endpoint()
|
||||||
|
|
||||||
|
var resultError error
|
||||||
|
proxy := websocketproxy.NewProxy(target)
|
||||||
|
proxy.Director = func(incoming *http.Request, out http.Header) {
|
||||||
|
_ = setHttpHeaders(ctx, out, ws.skipAuth)
|
||||||
|
}
|
||||||
|
proxy.Upgrader = &websocket.Upgrader{
|
||||||
|
HandshakeTimeout: 5 * time.Second,
|
||||||
|
ReadBufferSize: 1024,
|
||||||
|
WriteBufferSize: 1024,
|
||||||
|
WriteBufferPool: nil,
|
||||||
|
Subprotocols: nil,
|
||||||
|
Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {
|
||||||
|
resultError = httperrors.New(
|
||||||
|
http.StatusServiceUnavailable,
|
||||||
|
"upstream is not available",
|
||||||
|
errors.WithMessagef(reason, "ws proxy to %s", host),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
EnableCompression: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy.ServeHTTP(ctx.ResponseWriter(), ctx.Request())
|
||||||
|
|
||||||
|
return resultError
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// nolint:dupl
|
||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
adminAuthenticate = "admin/secure/authenticate"
|
||||||
|
adminAuthorize = "admin/secure/authorize"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Admin struct {
|
||||||
|
cli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdmin(cli *client.Client) Admin {
|
||||||
|
return Admin{cli: cli}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Admin) Authenticate(ctx context.Context, token string) (*domain.AdminAuthenticateResponse, error) {
|
||||||
|
resp := domain.AdminAuthenticateResponse{}
|
||||||
|
err := r.cli.Invoke(adminAuthenticate).
|
||||||
|
JsonRequestBody(domain.AuthenticateRequest{Token: token}).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessagef(err, "grpc client invoke %s", adminAuthenticate)
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Admin) Authorize(ctx context.Context, adminId int, permission string) (bool, error) {
|
||||||
|
resp := domain.AdminAuthorizeResponse{}
|
||||||
|
err := r.cli.Invoke(adminAuthorize).
|
||||||
|
JsonRequestBody(domain.AdminAuthorizeRequest{AdminId: adminId, Permission: permission}).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessagef(err, "grpc client invoke: %s", adminAuthorize)
|
||||||
|
}
|
||||||
|
return resp.Authorized, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/json"
|
||||||
|
"isp-gate-service/cache"
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthenticationCache struct {
|
||||||
|
cache *cache.Cache
|
||||||
|
duration time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthenticationCache(duration time.Duration) AuthenticationCache {
|
||||||
|
return AuthenticationCache{
|
||||||
|
duration: duration,
|
||||||
|
cache: cache.New(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r AuthenticationCache) Get(ctx context.Context, token string) (*domain.AuthData, error) {
|
||||||
|
data, ok := r.cache.Get(token)
|
||||||
|
if !ok {
|
||||||
|
return nil, domain.ErrAuthenticationCacheMiss
|
||||||
|
}
|
||||||
|
|
||||||
|
result := domain.AuthData{}
|
||||||
|
err := json.Unmarshal(data, &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "json unmarshal auth data")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r AuthenticationCache) Set(ctx context.Context, token string, data domain.AuthData) error {
|
||||||
|
value, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "json marshal auth data")
|
||||||
|
}
|
||||||
|
|
||||||
|
r.cache.Set(token, value, r.duration)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"isp-gate-service/cache"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthorizationCache struct {
|
||||||
|
duration time.Duration
|
||||||
|
cache *cache.Cache
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthorizationCache(duration time.Duration) *AuthorizationCache {
|
||||||
|
return &AuthorizationCache{
|
||||||
|
duration: duration,
|
||||||
|
cache: cache.New(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r AuthorizationCache) Get(ctx context.Context, id int, endpoint string) (bool, error) {
|
||||||
|
key := r.key(id, endpoint)
|
||||||
|
_, ok := r.cache.Get(key)
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r AuthorizationCache) SetAuthorized(ctx context.Context, id int, endpoint string) error {
|
||||||
|
key := r.key(id, endpoint)
|
||||||
|
r.cache.Set(key, nil, r.duration)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r AuthorizationCache) key(id int, endpoint string) string {
|
||||||
|
return fmt.Sprintf("%d:%s", id, endpoint)
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"isp-gate-service/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
incrementEndpoint = "isp-lock-service/daily_limit/increment"
|
||||||
|
rateLimitEndpoint = "isp-lock-service/rate_limit"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Locker struct {
|
||||||
|
cli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLocker(cli *client.Client) Locker {
|
||||||
|
return Locker{
|
||||||
|
cli: cli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Locker) Increment(ctx context.Context, key string, today time.Time) (int64, error) {
|
||||||
|
resp := new(entity.IncrementResponse)
|
||||||
|
err := r.cli.Invoke(incrementEndpoint).
|
||||||
|
JsonRequestBody(entity.IncrementRequest{
|
||||||
|
Key: key,
|
||||||
|
Today: today,
|
||||||
|
}).
|
||||||
|
JsonResponseBody(resp).
|
||||||
|
Do(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return 0, errors.WithMessagef(err, "invoke isp-lock-service: '%s'", incrementEndpoint)
|
||||||
|
default:
|
||||||
|
return int64(resp.Value), nil //nolint:gosec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Locker) IsAllowRequestPerSecond(ctx context.Context, key string, rate int) (*entity.RateLimiterResponse, error) {
|
||||||
|
resp := new(entity.RateLimiterResponse)
|
||||||
|
err := r.cli.Invoke(rateLimitEndpoint).
|
||||||
|
JsonRequestBody(entity.RateLimiterRequest{
|
||||||
|
Key: key,
|
||||||
|
MaxRps: rate,
|
||||||
|
}).
|
||||||
|
JsonResponseBody(resp).
|
||||||
|
Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessagef(err, "invoke isp-lock-service: '%s'", rateLimitEndpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// nolint:dupl
|
||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
authenticate = "system/secure/authenticate"
|
||||||
|
authorize = "system/secure/authorize"
|
||||||
|
)
|
||||||
|
|
||||||
|
type System struct {
|
||||||
|
cli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSystem(cli *client.Client) System {
|
||||||
|
return System{
|
||||||
|
cli: cli,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r System) Authenticate(ctx context.Context, token string) (*domain.AuthenticateResponse, error) {
|
||||||
|
resp := domain.AuthenticateResponse{}
|
||||||
|
err := r.cli.Invoke(authenticate).
|
||||||
|
JsonRequestBody(domain.AuthenticateRequest{Token: token}).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessagef(err, "grpc client invoke: %s", authenticate)
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r System) Authorize(ctx context.Context, applicationId int, endpoint string) (bool, error) {
|
||||||
|
resp := domain.AuthorizeResponse{}
|
||||||
|
err := r.cli.Invoke(authorize).
|
||||||
|
JsonRequestBody(domain.AuthorizeRequest{ApplicationId: applicationId, Endpoint: endpoint}).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessagef(err, "grpc client invoke: %s", authorize)
|
||||||
|
}
|
||||||
|
return resp.Authorized, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package unused
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
"github.com/txix-open/isp-kit/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RedisAuthCache struct {
|
||||||
|
cli redis.UniversalClient
|
||||||
|
duration time.Duration
|
||||||
|
db int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRedisAuthCache(cli redis.UniversalClient, duration time.Duration, db int) RedisAuthCache {
|
||||||
|
return RedisAuthCache{
|
||||||
|
cli: cli,
|
||||||
|
duration: duration,
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r RedisAuthCache) Get(ctx context.Context, token string) (*domain.AuthData, error) {
|
||||||
|
results, err := r.cli.Pipelined(ctx, func(p redis.Pipeliner) error {
|
||||||
|
p.Select(ctx, r.db)
|
||||||
|
p.Get(ctx, token)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil && !errors.Is(err, redis.Nil) {
|
||||||
|
return nil, errors.WithMessage(err, "pipelined")
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := results[1].(*redis.StringCmd).Result() // nolint: forcetypeassert
|
||||||
|
if errors.Is(err, redis.Nil) {
|
||||||
|
return nil, domain.ErrAuthenticationCacheMiss
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get")
|
||||||
|
}
|
||||||
|
|
||||||
|
result := domain.AuthData{}
|
||||||
|
err = json.Unmarshal([]byte(data), &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "json unmarshal auth data")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r RedisAuthCache) Set(ctx context.Context, token string, data domain.AuthData) error {
|
||||||
|
value, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "json marshal auth data")
|
||||||
|
}
|
||||||
|
|
||||||
|
results, err := r.cli.Pipelined(ctx, func(p redis.Pipeliner) error {
|
||||||
|
p.Select(ctx, r.db)
|
||||||
|
p.SetEx(ctx, token, string(value), r.duration)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "pipelined")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = results[1].Err()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "set ex")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package unused
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RedisAuthzCache struct {
|
||||||
|
cli redis.UniversalClient
|
||||||
|
duration time.Duration
|
||||||
|
db int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRedisAuthzCache(cli redis.UniversalClient, duration time.Duration, db int) *RedisAuthzCache {
|
||||||
|
return &RedisAuthzCache{
|
||||||
|
cli: cli,
|
||||||
|
duration: duration,
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r RedisAuthzCache) Get(ctx context.Context, applicationId int, endpoint string) (bool, error) {
|
||||||
|
result, err := r.cli.Pipelined(ctx, func(p redis.Pipeliner) error {
|
||||||
|
p.Select(ctx, r.db)
|
||||||
|
p.Get(ctx, r.key(applicationId, endpoint))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil && !errors.Is(err, redis.Nil) {
|
||||||
|
return false, errors.WithMessage(err, "pipelined")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = result[1].(*redis.StringCmd).Result() // nolint: forcetypeassert
|
||||||
|
if errors.Is(err, redis.Nil) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessage(err, "get")
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r RedisAuthzCache) SetAuthorized(ctx context.Context, applicationId int, endpoint string) error {
|
||||||
|
result, err := r.cli.Pipelined(ctx, func(p redis.Pipeliner) error {
|
||||||
|
p.Select(ctx, r.db)
|
||||||
|
p.SetEx(ctx, r.key(applicationId, endpoint), "authorized", r.duration)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "pipelined")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = result[1].Err()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "set ex")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r RedisAuthzCache) key(applicationId int, endpoint string) string {
|
||||||
|
return fmt.Sprintf("%d:%s", applicationId, endpoint)
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package request
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotAuthenticated = errors.New("not authenticated")
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthData struct {
|
||||||
|
AppName string
|
||||||
|
SystemId int
|
||||||
|
DomainId int
|
||||||
|
ServiceId int
|
||||||
|
ApplicationId int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Context struct {
|
||||||
|
request *http.Request
|
||||||
|
responseWriter http.ResponseWriter
|
||||||
|
|
||||||
|
endpoint string
|
||||||
|
|
||||||
|
authenticated bool
|
||||||
|
authData *AuthData
|
||||||
|
|
||||||
|
adminAuthenticated bool
|
||||||
|
adminId int
|
||||||
|
adminToken string
|
||||||
|
|
||||||
|
queryParams map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewContext(request *http.Request, response http.ResponseWriter, endpoint string) *Context {
|
||||||
|
return &Context{
|
||||||
|
request: request,
|
||||||
|
responseWriter: response,
|
||||||
|
endpoint: endpoint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) Request() *http.Request {
|
||||||
|
return c.request
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) ResponseWriter() http.ResponseWriter {
|
||||||
|
return c.responseWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) SetResponseWriter(writer http.ResponseWriter) {
|
||||||
|
c.responseWriter = writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) Endpoint() string {
|
||||||
|
return c.endpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) Authenticate(authData AuthData) {
|
||||||
|
c.authenticated = true
|
||||||
|
c.authData = &authData
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) GetAuthData() (AuthData, error) {
|
||||||
|
if !c.authenticated {
|
||||||
|
return AuthData{}, ErrNotAuthenticated
|
||||||
|
}
|
||||||
|
return *c.authData, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) IsAdminAuthenticated() bool {
|
||||||
|
return c.adminAuthenticated
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) AdminId() int {
|
||||||
|
return c.adminId
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) AdminToken() string {
|
||||||
|
return c.adminToken
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) AuthenticateAdmin(adminId int, adminToken string) {
|
||||||
|
c.adminAuthenticated = true
|
||||||
|
c.adminId = adminId
|
||||||
|
c.adminToken = adminToken
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) Context() context.Context {
|
||||||
|
return c.request.Context()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) SetContext(ctx context.Context) {
|
||||||
|
c.request = c.request.WithContext(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) Param(name string) string {
|
||||||
|
value := c.request.Header.Get(name)
|
||||||
|
if value != "" {
|
||||||
|
return strings.TrimSpace(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.queryParams == nil {
|
||||||
|
query := c.request.URL.Query()
|
||||||
|
c.queryParams = map[string]string{}
|
||||||
|
for key, values := range query {
|
||||||
|
if len(values) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.queryParams[strings.ToLower(key)] = values[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
value = c.queryParams[strings.ToLower(name)]
|
||||||
|
|
||||||
|
return strings.TrimSpace(value)
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"isp-gate-service/middleware"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Routes struct {
|
||||||
|
allEndpoints map[string]bool
|
||||||
|
innerEndpoints map[string]bool
|
||||||
|
requiredPermissions map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRoutes() *Routes {
|
||||||
|
return &Routes{
|
||||||
|
allEndpoints: make(map[string]bool),
|
||||||
|
innerEndpoints: make(map[string]bool),
|
||||||
|
requiredPermissions: make(map[string]string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Routes) ReceiveRoutes(ctx context.Context, routes cluster.RoutingConfig) error {
|
||||||
|
newAllEndpoints := make(map[string]bool)
|
||||||
|
newInnerMethods := make(map[string]bool)
|
||||||
|
newRequiredPermissions := make(map[string]string)
|
||||||
|
for _, backend := range routes {
|
||||||
|
for _, v := range backend.Endpoints {
|
||||||
|
newAllEndpoints[v.Path] = true
|
||||||
|
if v.Inner {
|
||||||
|
newInnerMethods[v.Path] = true
|
||||||
|
}
|
||||||
|
perm, ok := cluster.GetRequiredAdminPermission(v)
|
||||||
|
if ok {
|
||||||
|
newRequiredPermissions[v.Path] = perm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s.allEndpoints = newAllEndpoints
|
||||||
|
s.innerEndpoints = newInnerMethods
|
||||||
|
s.requiredPermissions = newRequiredPermissions
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Routes) ResolveEndpoint(path string, cfg middleware.EntryPointConfig) string {
|
||||||
|
if cfg.WithPrefix {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix := fmt.Sprintf("%s/", cfg.PathPrefix)
|
||||||
|
noPrefixPath := strings.TrimPrefix(path, prefix)
|
||||||
|
ok := s.allEndpoints[noPrefixPath]
|
||||||
|
if ok {
|
||||||
|
return noPrefixPath
|
||||||
|
}
|
||||||
|
|
||||||
|
invertedLeadingSlash := invertLeadingSlash(noPrefixPath)
|
||||||
|
ok = s.allEndpoints[invertedLeadingSlash]
|
||||||
|
if ok {
|
||||||
|
return invertedLeadingSlash
|
||||||
|
}
|
||||||
|
|
||||||
|
return noPrefixPath // pdp-webapi-service(анонсирует вот такой ендпоинт GET /api/:token/profile/me/:blocks) hack =(
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Routes) IsInnerEndpoint(endpoint string) bool {
|
||||||
|
return s.innerEndpoints[endpoint]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Routes) RequiredAdminPermission(endpoint string) (string, bool) {
|
||||||
|
perm, ok := s.requiredPermissions[endpoint]
|
||||||
|
return perm, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func invertLeadingSlash(path string) string {
|
||||||
|
path, withoutSlash := strings.CutPrefix(path, "/")
|
||||||
|
if withoutSlash {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
return "/" + path
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminAuth interface {
|
||||||
|
Authenticate(ctx context.Context, token string) (*domain.AdminAuthenticateResponse, error)
|
||||||
|
Authorize(ctx context.Context, adminId int, permission string) (bool, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Admin struct {
|
||||||
|
cache AuthorizationCache
|
||||||
|
repo AdminAuth
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdmin(cache AuthorizationCache, adminAuth AdminAuth) Admin {
|
||||||
|
return Admin{
|
||||||
|
cache: cache,
|
||||||
|
repo: adminAuth,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Admin) AdminAuthenticate(ctx context.Context, token string) (*domain.AdminAuthenticateResponse, error) {
|
||||||
|
resp, err := s.repo.Authenticate(ctx, token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get admin token data from admin service")
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Admin) AdminAuthorize(ctx context.Context, adminId int, permission string) (bool, error) {
|
||||||
|
ok, err := s.cache.Get(ctx, adminId, permission)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessage(err, "authz cache get")
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err = s.repo.Authorize(ctx, adminId, permission)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessagef(err, "authz repo authorize")
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
err = s.cache.SetAuthorized(ctx, adminId, permission)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessagef(err, "authz cache set")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthenticationCache interface {
|
||||||
|
Get(ctx context.Context, token string) (*domain.AuthData, error)
|
||||||
|
Set(ctx context.Context, token string, data domain.AuthData) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthenticationRepo interface {
|
||||||
|
Authenticate(ctx context.Context, token string) (*domain.AuthenticateResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Auth struct {
|
||||||
|
cache AuthenticationCache
|
||||||
|
repo AuthenticationRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthentication(cache AuthenticationCache, repo AuthenticationRepo) Auth {
|
||||||
|
return Auth{
|
||||||
|
cache: cache,
|
||||||
|
repo: repo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Auth) Authenticate(ctx context.Context, token string) (*domain.AuthenticateResponse, error) {
|
||||||
|
authData, err := s.cache.Get(ctx, token)
|
||||||
|
if errors.Is(err, domain.ErrAuthenticationCacheMiss) {
|
||||||
|
resp, err := s.repo.Authenticate(ctx, token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "auth repo authenticate")
|
||||||
|
}
|
||||||
|
if !resp.Authenticated {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
err = s.cache.Set(ctx, token, *resp.AuthData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "auth cache set")
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "auth cache get")
|
||||||
|
}
|
||||||
|
return &domain.AuthenticateResponse{
|
||||||
|
Authenticated: true,
|
||||||
|
ErrorReason: "",
|
||||||
|
AuthData: authData,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthorizationCache interface {
|
||||||
|
Get(ctx context.Context, applicationId int, endpoint string) (bool, error)
|
||||||
|
SetAuthorized(ctx context.Context, applicationId int, endpoint string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuthorizationRepo interface {
|
||||||
|
Authorize(ctx context.Context, applicationId int, endpoint string) (bool, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Authorization struct {
|
||||||
|
cache AuthorizationCache
|
||||||
|
repo AuthorizationRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthorization(cache AuthorizationCache, repo AuthorizationRepo) Authorization {
|
||||||
|
return Authorization{
|
||||||
|
cache: cache,
|
||||||
|
repo: repo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Authorization) Authorize(ctx context.Context, applicationId int, endpoint string) (bool, error) {
|
||||||
|
ok, err := s.cache.Get(ctx, applicationId, endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessage(err, "authz cache get")
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err = s.repo.Authorize(ctx, applicationId, endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessagef(err, "authz repo authorize")
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
err = s.cache.SetAuthorized(ctx, applicationId, endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessagef(err, "authz cache set")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DailyLimitRepo interface {
|
||||||
|
Increment(ctx context.Context, key string, today time.Time) (int64, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DailyLimit struct {
|
||||||
|
repo DailyLimitRepo
|
||||||
|
limits map[int]int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDailyLimit(repo DailyLimitRepo, configs []conf.DailyLimit) DailyLimit {
|
||||||
|
limits := make(map[int]int64)
|
||||||
|
for _, config := range configs {
|
||||||
|
limits[config.ApplicationId] = config.RequestsPerDay
|
||||||
|
}
|
||||||
|
return DailyLimit{
|
||||||
|
repo: repo,
|
||||||
|
limits: limits,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DailyLimit) IncrementAndCheck(ctx context.Context, applicationId int) (bool, error) {
|
||||||
|
limit, ok := s.limits[applicationId]
|
||||||
|
if !ok {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
key := s.key(applicationId, time.Now())
|
||||||
|
newValue, err := s.repo.Increment(ctx, key, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.WithMessage(err, "increment")
|
||||||
|
}
|
||||||
|
|
||||||
|
return newValue <= limit, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DailyLimit) key(applicationId int, today time.Time) string {
|
||||||
|
y, m, d := today.Date()
|
||||||
|
return fmt.Sprintf("isp-gate-service::daily-limit::%d:%d-%d-%d", applicationId, y, m, d)
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
"isp-gate-service/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LockRepo interface {
|
||||||
|
IsAllowRequestPerSecond(ctx context.Context, key string, rate int) (*entity.RateLimiterResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Throttling struct {
|
||||||
|
repo LockRepo
|
||||||
|
limits map[int]int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewThrottling(repo LockRepo, configs []conf.Throttling) Throttling {
|
||||||
|
limits := make(map[int]int)
|
||||||
|
for _, config := range configs {
|
||||||
|
limits[config.ApplicationId] = config.RequestsPerSeconds
|
||||||
|
}
|
||||||
|
return Throttling{
|
||||||
|
repo: repo,
|
||||||
|
limits: limits,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Throttling) AllowRateLimit(ctx context.Context, applicationId int) (*domain.RateLimitResult, error) {
|
||||||
|
rate, ok := s.limits[applicationId]
|
||||||
|
if !ok {
|
||||||
|
return &domain.RateLimitResult{
|
||||||
|
Allow: true,
|
||||||
|
Remaining: -1,
|
||||||
|
RetryAfter: -1,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
key := s.key(applicationId)
|
||||||
|
result, err := s.repo.IsAllowRequestPerSecond(ctx, key, rate)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "is allow request per second")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &domain.RateLimitResult{
|
||||||
|
Allow: result.Allow,
|
||||||
|
Remaining: result.Remaining,
|
||||||
|
RetryAfter: result.RetryAfter,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Throttling) key(applicationId int) string {
|
||||||
|
return fmt.Sprintf("isp-gate-service::rate-limit::%d", applicationId)
|
||||||
|
}
|
||||||
@@ -0,0 +1,373 @@
|
|||||||
|
// nolint:canonicalheader
|
||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"isp-gate-service/assembly"
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
"isp-gate-service/routes"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/txix-open/etp/v3"
|
||||||
|
"github.com/txix-open/etp/v3/msg"
|
||||||
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
|
"github.com/txix-open/isp-kit/http/httpcli"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"github.com/txix-open/isp-kit/lb"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"github.com/txix-open/isp-kit/requestid"
|
||||||
|
"github.com/txix-open/isp-kit/test"
|
||||||
|
"github.com/txix-open/isp-kit/test/grpct"
|
||||||
|
"github.com/txix-open/isp-kit/test/httpt"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
)
|
||||||
|
|
||||||
|
type request struct {
|
||||||
|
Id string
|
||||||
|
}
|
||||||
|
|
||||||
|
type response struct {
|
||||||
|
Id string
|
||||||
|
}
|
||||||
|
|
||||||
|
type HappyPathTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HappyPathTestSuite) TestGrpcProxy() {
|
||||||
|
test, require := test.New(s.T())
|
||||||
|
config, systemCli, adminCli := s.commonDependencies(test)
|
||||||
|
|
||||||
|
requestId := requestid.Next()
|
||||||
|
targetService, targetCli := grpct.NewMock(test)
|
||||||
|
targetService.Mock("endpoint", func(ctx context.Context, authData grpc.AuthData, req request) response {
|
||||||
|
systemId, err := authData.SystemId()
|
||||||
|
require.NoError(err)
|
||||||
|
domainId, err := authData.DomainId()
|
||||||
|
require.NoError(err)
|
||||||
|
serviceId, err := authData.ServiceId()
|
||||||
|
require.NoError(err)
|
||||||
|
applicationId, err := authData.ApplicationId()
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues(requestId, requestid.FromContext(ctx))
|
||||||
|
require.EqualValues(1, systemId)
|
||||||
|
require.EqualValues(2, domainId)
|
||||||
|
require.EqualValues(3, serviceId)
|
||||||
|
require.EqualValues(4, applicationId)
|
||||||
|
|
||||||
|
adminId, err := grpc.StringFromMd("x-admin-id", metadata.MD(authData))
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues("1", adminId)
|
||||||
|
|
||||||
|
return response{Id: req.Id}
|
||||||
|
})
|
||||||
|
targetClients := map[string]*client.Client{"target": targetCli}
|
||||||
|
logger, err := log.New(log.WithLevel(log.DebugLevel))
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
routes := routes.NewRoutes()
|
||||||
|
err = routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
||||||
|
Endpoints: []cluster.EndpointDescriptor{{
|
||||||
|
Path: "endpoint",
|
||||||
|
}},
|
||||||
|
}})
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
locator := assembly.NewLocator(logger, targetClients, nil, routes, systemCli, adminCli, nil)
|
||||||
|
|
||||||
|
locations := []conf.Location{{
|
||||||
|
SkipAuth: false,
|
||||||
|
PathPrefix: "/api",
|
||||||
|
Protocol: "grpc",
|
||||||
|
TargetModule: "target",
|
||||||
|
}}
|
||||||
|
handler, err := locator.Handler(config, locations)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
srv := httptest.NewServer(handler)
|
||||||
|
cli := httpcli.New()
|
||||||
|
req := request{Id: uuid.New().String()}
|
||||||
|
resp := response{}
|
||||||
|
_, err = cli.Post(srv.URL+"/api/endpoint").
|
||||||
|
Header("x-application-token", "token").
|
||||||
|
Header("x-request-id", requestId).
|
||||||
|
Header("x-auth-admin", "mock-token").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
StatusCodeToError().
|
||||||
|
Do(context.Background())
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues(req.Id, resp.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HappyPathTestSuite) TestHttpProxy() {
|
||||||
|
test, require := test.New(s.T())
|
||||||
|
config, systemCli, adminCli := s.commonDependencies(test)
|
||||||
|
|
||||||
|
requestId := requestid.Next()
|
||||||
|
targetService := httpt.NewMock(test)
|
||||||
|
targetService.POST("/endpoint", func(ctx context.Context, httpReq *http.Request, req request) response {
|
||||||
|
assertHeaders(require, requestId, ctx, httpReq.Header)
|
||||||
|
return response{Id: req.Id}
|
||||||
|
})
|
||||||
|
targetUrl, err := url.Parse(targetService.BaseURL())
|
||||||
|
require.NoError(err)
|
||||||
|
rr := lb.NewRoundRobin([]string{targetUrl.Host})
|
||||||
|
targetClients := map[string]*lb.RoundRobin{"target": rr}
|
||||||
|
|
||||||
|
routes := routes.NewRoutes()
|
||||||
|
err = routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
||||||
|
Endpoints: []cluster.EndpointDescriptor{{
|
||||||
|
Path: "/endpoint",
|
||||||
|
}},
|
||||||
|
}})
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
locator := assembly.NewLocator(test.Logger(), nil, targetClients, routes, systemCli, adminCli, nil)
|
||||||
|
locations := []conf.Location{{
|
||||||
|
SkipAuth: false,
|
||||||
|
PathPrefix: "/api",
|
||||||
|
Protocol: "http",
|
||||||
|
TargetModule: "target",
|
||||||
|
}}
|
||||||
|
handler, err := locator.Handler(config, locations)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
srv := httptest.NewServer(handler)
|
||||||
|
cli := httpcli.New()
|
||||||
|
req := request{Id: uuid.New().String()}
|
||||||
|
resp := response{}
|
||||||
|
_, err = cli.Post(srv.URL+"/api/endpoint").
|
||||||
|
Header("x-application-token", "token").
|
||||||
|
Header("x-request-id", requestId).
|
||||||
|
Header("x-auth-admin", "mock-token").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
StatusCodeToError().
|
||||||
|
Do(context.Background())
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues(req.Id, resp.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HappyPathTestSuite) TestWsProxy() { // nolint: funlen
|
||||||
|
test, require := test.New(s.T())
|
||||||
|
config, systemCli, adminCli := s.commonDependencies(test)
|
||||||
|
|
||||||
|
requestId := requestid.Next()
|
||||||
|
wsServer := etp.NewServer(etp.WithServerReadLimit(2048))
|
||||||
|
wsServer.On("hello", wsEventHandlerMock{
|
||||||
|
requestId: requestId,
|
||||||
|
require: require,
|
||||||
|
t: test.T(),
|
||||||
|
})
|
||||||
|
|
||||||
|
wsMux := http.NewServeMux()
|
||||||
|
wsMux.Handle("/service", http.HandlerFunc(func(writer http.ResponseWriter, r *http.Request) {
|
||||||
|
wsServer.ServeHTTP(writer, r)
|
||||||
|
}))
|
||||||
|
targetService := httptest.NewServer(wsMux)
|
||||||
|
targetUrl, err := url.Parse(targetService.URL)
|
||||||
|
require.NoError(err)
|
||||||
|
rr := lb.NewRoundRobin([]string{targetUrl.Host})
|
||||||
|
targetClients := map[string]*lb.RoundRobin{"target": rr}
|
||||||
|
|
||||||
|
routes := routes.NewRoutes()
|
||||||
|
err = routes.ReceiveRoutes(s.T().Context(), cluster.RoutingConfig{{
|
||||||
|
Endpoints: []cluster.EndpointDescriptor{{
|
||||||
|
Path: "/service",
|
||||||
|
}},
|
||||||
|
}})
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
locator := assembly.NewLocator(test.Logger(), nil, targetClients, routes, systemCli, adminCli, nil)
|
||||||
|
locations := []conf.Location{{
|
||||||
|
SkipAuth: false,
|
||||||
|
PathPrefix: "/ws",
|
||||||
|
Protocol: "ws",
|
||||||
|
TargetModule: "target",
|
||||||
|
}}
|
||||||
|
handler, err := locator.Handler(config, locations)
|
||||||
|
require.NoError(err)
|
||||||
|
srv := httptest.NewServer(handler)
|
||||||
|
|
||||||
|
cli := etp.NewClient(etp.WithClientDialOptions(&etp.DialOptions{
|
||||||
|
HTTPHeader: map[string][]string{
|
||||||
|
"x-request-id": {requestId},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
requestUrl, err := url.Parse(srv.URL)
|
||||||
|
require.NoError(err)
|
||||||
|
requestUrl.Path = "ws/service"
|
||||||
|
requestUrl.RawQuery = url.Values{
|
||||||
|
"x-application-token": []string{"token"},
|
||||||
|
"x-auth-admin": []string{"mock-token"},
|
||||||
|
}.Encode()
|
||||||
|
err = cli.Dial(context.Background(), requestUrl.String())
|
||||||
|
require.NoError(err)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
|
||||||
|
defer cancel()
|
||||||
|
resp, err := cli.EmitWithAck(ctx, "hello", []byte("data"))
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues("world", string(resp))
|
||||||
|
err = cli.Close()
|
||||||
|
require.NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type wsEventHandlerMock struct {
|
||||||
|
requestId string
|
||||||
|
require *require.Assertions
|
||||||
|
t require.TestingT
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s wsEventHandlerMock) Handle(_ context.Context, conn *etp.Conn, event msg.Event) []byte {
|
||||||
|
headers := conn.HttpRequest().Header
|
||||||
|
ctx := requestid.ToContext(context.Background(), headers.Get("x-request-id"))
|
||||||
|
assertHeaders(s.require, s.requestId, ctx, headers)
|
||||||
|
require.EqualValues(s.t, "data", event.Data)
|
||||||
|
return []byte("world")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *HappyPathTestSuite) TestAdminAuthorization() {
|
||||||
|
test, require := test.New(s.T())
|
||||||
|
config, systemCli, adminCli := s.commonDependencies(test)
|
||||||
|
|
||||||
|
targetService, targetCli := grpct.NewMock(test)
|
||||||
|
targetService.Mock("endpoint", func(ctx context.Context, authData grpc.AuthData, req request) response {
|
||||||
|
return response{Id: req.Id}
|
||||||
|
})
|
||||||
|
targetClients := map[string]*client.Client{"target": targetCli}
|
||||||
|
logger, err := log.New(log.WithLevel(log.DebugLevel))
|
||||||
|
require.NoError(err)
|
||||||
|
routes := routes.NewRoutes()
|
||||||
|
locator := assembly.NewLocator(logger, targetClients, nil, routes, systemCli, adminCli, nil)
|
||||||
|
|
||||||
|
locations := []conf.Location{{
|
||||||
|
SkipAuth: false,
|
||||||
|
PathPrefix: "/api",
|
||||||
|
Protocol: "grpc",
|
||||||
|
TargetModule: "target",
|
||||||
|
}}
|
||||||
|
handler, err := locator.Handler(config, locations)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
err = routes.ReceiveRoutes(context.Background(), cluster.RoutingConfig{{
|
||||||
|
ModuleName: "target",
|
||||||
|
Endpoints: []cluster.EndpointDescriptor{{
|
||||||
|
Path: "endpoint",
|
||||||
|
Inner: true,
|
||||||
|
Extra: cluster.RequireAdminPermission("ok_permission"),
|
||||||
|
}, {
|
||||||
|
Path: "failed_endpoint",
|
||||||
|
Inner: true,
|
||||||
|
Extra: cluster.RequireAdminPermission("failed_permission"),
|
||||||
|
}},
|
||||||
|
}})
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
srv := httptest.NewServer(handler)
|
||||||
|
cli := httpcli.New()
|
||||||
|
req := request{Id: uuid.New().String()}
|
||||||
|
resp := response{}
|
||||||
|
_, err = cli.Post(srv.URL+"/api/endpoint").
|
||||||
|
Header("x-application-token", "token").
|
||||||
|
Header("x-auth-admin", "mock-token").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
StatusCodeToError().
|
||||||
|
Do(context.Background())
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues(req.Id, resp.Id)
|
||||||
|
|
||||||
|
_, err = cli.Post(srv.URL+"/api/failed_endpoint").
|
||||||
|
Header("x-application-token", "token").
|
||||||
|
Header("x-auth-admin", "mock-token").
|
||||||
|
JsonRequestBody(req).
|
||||||
|
JsonResponseBody(&resp).
|
||||||
|
StatusCodeToError().
|
||||||
|
Do(context.Background())
|
||||||
|
errResp := httpcli.ErrorResponse{}
|
||||||
|
require.ErrorAs(err, &errResp)
|
||||||
|
require.EqualValues(http.StatusForbidden, errResp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// nolint:ireturn
|
||||||
|
func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, *client.Client, *client.Client) {
|
||||||
|
config := conf.Remote{
|
||||||
|
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
|
||||||
|
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true,
|
||||||
|
SkipBodyLoggingEndpointPrefixes: []string{"endpoint"}},
|
||||||
|
Caching: conf.Caching{AuthorizationDataInSec: 1, AuthenticationDataInSec: 1},
|
||||||
|
DailyLimits: []conf.DailyLimit{{ApplicationId: 1, RequestsPerDay: 100}},
|
||||||
|
Throttling: []conf.Throttling{{ApplicationId: 1, RequestsPerSeconds: 100}},
|
||||||
|
EnableClientRequestIdForwarding: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
systemService, systemCli := grpct.NewMock(test)
|
||||||
|
systemService.Mock("system/secure/authenticate", func() domain.AuthenticateResponse {
|
||||||
|
return domain.AuthenticateResponse{
|
||||||
|
Authenticated: true,
|
||||||
|
ErrorReason: "",
|
||||||
|
AuthData: &domain.AuthData{
|
||||||
|
SystemId: 1,
|
||||||
|
DomainId: 2,
|
||||||
|
ServiceId: 3,
|
||||||
|
ApplicationId: 4,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}).Mock("system/secure/authorize", func() domain.AuthorizeResponse {
|
||||||
|
return domain.AuthorizeResponse{Authorized: true}
|
||||||
|
})
|
||||||
|
|
||||||
|
adminService, adminCli := grpct.NewMock(test)
|
||||||
|
adminService.Mock("admin/secure/authenticate", func(req domain.AdminAuthorizeRequest) domain.AdminAuthenticateResponse {
|
||||||
|
return domain.AdminAuthenticateResponse{
|
||||||
|
Authenticated: true,
|
||||||
|
ErrorReason: "",
|
||||||
|
AdminId: 1,
|
||||||
|
}
|
||||||
|
}).Mock("admin/secure/authorize", func(req domain.AdminAuthorizeRequest) domain.AdminAuthorizeResponse {
|
||||||
|
if req.Permission == "ok_permission" {
|
||||||
|
return domain.AdminAuthorizeResponse{Authorized: true}
|
||||||
|
}
|
||||||
|
return domain.AdminAuthorizeResponse{Authorized: false}
|
||||||
|
})
|
||||||
|
|
||||||
|
return config, systemCli, adminCli
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHappyPathTestSuite(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
suite.Run(t, new(HappyPathTestSuite))
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertHeaders(require *require.Assertions, requestId string, ctx context.Context, headers http.Header) {
|
||||||
|
systemId, err := strconv.Atoi(headers.Get("x-system-identity"))
|
||||||
|
require.NoError(err)
|
||||||
|
domainId, err := strconv.Atoi(headers.Get("x-domain-identity"))
|
||||||
|
require.NoError(err)
|
||||||
|
serviceId, err := strconv.Atoi(headers.Get("x-service-identity"))
|
||||||
|
require.NoError(err)
|
||||||
|
applicationId, err := strconv.Atoi(headers.Get("x-application-identity"))
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues(requestId, requestid.FromContext(ctx))
|
||||||
|
require.EqualValues(1, systemId)
|
||||||
|
require.EqualValues(2, domainId)
|
||||||
|
require.EqualValues(3, serviceId)
|
||||||
|
require.EqualValues(4, applicationId)
|
||||||
|
|
||||||
|
adminId, err := strconv.Atoi(headers.Get("x-admin-id"))
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues(1, adminId)
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
|
"isp-gate-service/assembly"
|
||||||
|
"isp-gate-service/conf"
|
||||||
|
"isp-gate-service/domain"
|
||||||
|
"isp-gate-service/routes"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
endpoint2 "github.com/txix-open/isp-kit/grpc/endpoint"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/isp"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type request struct {
|
||||||
|
Id string
|
||||||
|
}
|
||||||
|
|
||||||
|
type response struct {
|
||||||
|
Id string
|
||||||
|
}
|
||||||
|
|
||||||
|
// nolint
|
||||||
|
func main() {
|
||||||
|
redisCli := redis.NewClient(&redis.Options{})
|
||||||
|
ctx := context.Background()
|
||||||
|
logger, err := log.New()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_, _ = redisCli.Pipelined(ctx, func(p redis.Pipeliner) error {
|
||||||
|
p.Select(ctx, 0)
|
||||||
|
p.FlushDB(ctx)
|
||||||
|
p.Select(ctx, 1)
|
||||||
|
p.FlushDB(ctx)
|
||||||
|
p.Select(ctx, 2)
|
||||||
|
p.FlushDB(ctx)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
config := conf.Remote{
|
||||||
|
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
|
||||||
|
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true},
|
||||||
|
Caching: conf.Caching{AuthorizationDataInSec: 15, AuthenticationDataInSec: 15},
|
||||||
|
DailyLimits: []conf.DailyLimit{{ApplicationId: 1, RequestsPerDay: 100000000}},
|
||||||
|
Throttling: []conf.Throttling{{ApplicationId: 1, RequestsPerSeconds: 5000}},
|
||||||
|
}
|
||||||
|
|
||||||
|
systemService, systemCli, _ := NewMock(logger)
|
||||||
|
systemService.Mock("system/secure/authenticate", func() domain.AuthenticateResponse {
|
||||||
|
return domain.AuthenticateResponse{
|
||||||
|
Authenticated: true,
|
||||||
|
ErrorReason: "",
|
||||||
|
AuthData: &domain.AuthData{
|
||||||
|
SystemId: 1,
|
||||||
|
DomainId: 1,
|
||||||
|
ServiceId: 1,
|
||||||
|
ApplicationId: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}).Mock("system/secure/authorize", func() domain.AuthorizeResponse {
|
||||||
|
return domain.AuthorizeResponse{Authorized: true}
|
||||||
|
})
|
||||||
|
|
||||||
|
adminService, _, adminCli := NewMock(logger)
|
||||||
|
adminService.Mock("admin/secure/authenticate", func() domain.AdminAuthenticateResponse {
|
||||||
|
return domain.AdminAuthenticateResponse{
|
||||||
|
Authenticated: true,
|
||||||
|
ErrorReason: "",
|
||||||
|
AdminId: 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
targetService, targetCli, _ := NewMock(logger)
|
||||||
|
targetService.Mock("endpoint", func(req request) response {
|
||||||
|
return response{Id: req.Id}
|
||||||
|
})
|
||||||
|
targetClients := map[string]*client.Client{"target": targetCli}
|
||||||
|
logger, _ = log.New(log.WithLevel(log.DebugLevel))
|
||||||
|
locator := assembly.NewLocator(logger, targetClients, nil, routes.NewRoutes(), systemCli, adminCli, nil)
|
||||||
|
locations := []conf.Location{{
|
||||||
|
SkipAuth: false,
|
||||||
|
PathPrefix: "/api",
|
||||||
|
Protocol: "grpc",
|
||||||
|
TargetModule: "target",
|
||||||
|
}}
|
||||||
|
handler, _ := locator.Handler(config, locations)
|
||||||
|
|
||||||
|
srv := &http.Server{
|
||||||
|
Addr: "localhost:8000",
|
||||||
|
Handler: handler,
|
||||||
|
}
|
||||||
|
srv.ListenAndServe()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServer(service isp.BackendServiceServer) (*grpc.Server, *client.Client, *client.Client) {
|
||||||
|
listener, _ := net.Listen("tcp", "127.0.0.1:") // nolint:noctx
|
||||||
|
srv := grpc.NewServer()
|
||||||
|
sysCli, _ := client.Default()
|
||||||
|
adminCli, _ := client.Default()
|
||||||
|
srv.Upgrade(service)
|
||||||
|
go func() {
|
||||||
|
_ = srv.Serve(listener)
|
||||||
|
}()
|
||||||
|
|
||||||
|
sysCli.Upgrade([]string{listener.Addr().String()})
|
||||||
|
adminCli.Upgrade([]string{listener.Addr().String()})
|
||||||
|
return srv, sysCli, adminCli
|
||||||
|
}
|
||||||
|
|
||||||
|
type MockServer struct {
|
||||||
|
srv *grpc.Server
|
||||||
|
logger log.Logger
|
||||||
|
mockEndpoints map[string]any
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMock(logger log.Logger) (*MockServer, *client.Client, *client.Client) {
|
||||||
|
srv, syscli, admincli := TestServer(grpc.NewMux())
|
||||||
|
return &MockServer{
|
||||||
|
srv: srv,
|
||||||
|
logger: logger,
|
||||||
|
mockEndpoints: make(map[string]interface{}),
|
||||||
|
}, syscli, admincli
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockServer) Mock(endpoint string, handler interface{}) *MockServer {
|
||||||
|
m.mockEndpoints[endpoint] = handler
|
||||||
|
wrapper := endpoint2.DefaultWrapper(m.logger)
|
||||||
|
muxer := grpc.NewMux()
|
||||||
|
for e, handler := range m.mockEndpoints {
|
||||||
|
muxer.Handle(e, wrapper.Endpoint(handler))
|
||||||
|
}
|
||||||
|
m.srv.Upgrade(muxer)
|
||||||
|
return m
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"id": "GO4IIZW5uav4cSo2zyR6i41LdalKytNH628yDhC92jXQF07gu4LS75JuzQgc6d3Dly48fwla9iHK6LPTJcvFbOcklXp7Zr9g3b180s0H3dVgaYGcO8BrAFxMVb2KcHyu"
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
bombardier -c 128 -t 1s -d 60s --fasthttp -H "x-application-token: token" -m POST -f body.json http://localhost:8000/api/endpoint
|
||||||
|
|
||||||
Reference in new issue
Block a user