Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12b71a1777 | ||
|
|
1badb6b931 | ||
|
|
14221f778c | ||
|
|
a5ca7b230a | ||
|
|
3427a92d08 | ||
|
|
ef7c017e4c |
No files matched your search
+6
-2
@@ -9,8 +9,8 @@
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
*.iml
|
||||
config_service
|
||||
config-service
|
||||
convert_service
|
||||
convert-service
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
@@ -69,3 +69,7 @@ fabric.properties
|
||||
|
||||
/node_modules/
|
||||
/vendor/
|
||||
package.json
|
||||
yarn.lock
|
||||
|
||||
conf/config_dev.yml
|
||||
@@ -0,0 +1,57 @@
|
||||
run:
|
||||
allow-parallel-runners: true
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: controller #достаточное кол-во контекса на уровне контроллеров
|
||||
linters:
|
||||
- wrapcheck
|
||||
- path: transaction #транзакции прозрачны
|
||||
linters:
|
||||
- wrapcheck
|
||||
linters:
|
||||
enable-all: true
|
||||
disable:
|
||||
- goimports #у нас собственные правила форматирования импортов
|
||||
- wsl #расставление пробелов очень индивидуально
|
||||
- exhaustivestruct #не имеет смысла
|
||||
- varnamelen #очень индивидуально (db)
|
||||
- exhaustruct #не имеет смысла
|
||||
- golint #устарел
|
||||
- contextcheck #не имеет смысла
|
||||
- gci #у нас собственные правила форматирования импортов
|
||||
- gofumpt #у нас собственные правила форматирования импортов
|
||||
- nolintlint #Goland все равно форматирует с отступом
|
||||
- nlreturn #не всегда имеет смысл
|
||||
- godot #не актуально для свагера
|
||||
- ifshort #приняли решение, что мы так не пишем if err := ...; err != nil {}
|
||||
- godox #не позволяет оставлять todo
|
||||
- maligned #аллокацией памяти для структур конфликтует с удобством их чтения
|
||||
- nosnakecase #не позволяет заводить пакеты используя snake_case
|
||||
- depguard #не всегда имеет смысл
|
||||
- dupword #не имеет смысла
|
||||
- tagalign #не всегда имеет смысл
|
||||
- musttag #у нас собственные правило: не используем теги, если работаем с пакетом isp-kit/json и с внутренними структурами(между нашими сервисами), при этом теги обязательный для всех внених для нас структур
|
||||
- perfsprint #мнимая производительность в угоду читаемости
|
||||
- gomoddirectives #требует rqlite
|
||||
- tagliatelle
|
||||
linters-settings:
|
||||
funlen:
|
||||
lines: 80
|
||||
lll:
|
||||
line-length: 150
|
||||
cyclop:
|
||||
max-complexity: 15 #по умолчанию 10 мало
|
||||
revive:
|
||||
rules:
|
||||
- name: var-naming #отключаем Id -> ID
|
||||
disabled: true
|
||||
stylecheck:
|
||||
checks: #отключаем Id -> ID
|
||||
- "-ST1000"
|
||||
- "-ST1016"
|
||||
- "-ST1020"
|
||||
- "-ST1021"
|
||||
- "-ST1022"
|
||||
testifylint:
|
||||
disable:
|
||||
- compares
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
FROM golang:1.23-alpine3.20 as builder
|
||||
WORKDIR /build
|
||||
ARG version
|
||||
ENV version_env=$version
|
||||
ARG app_name
|
||||
ENV app_name_env=$app_name
|
||||
COPY . .
|
||||
RUN apk update && apk upgrade && apk add --no-cache gcc musl-dev
|
||||
RUN go build -ldflags="-X 'main.version=$version_env'" -o /main .
|
||||
|
||||
FROM alpine:3.20
|
||||
|
||||
RUN apk add --no-cache tzdata
|
||||
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
||||
RUN echo "Europe/Moscow" > /etc/timezone
|
||||
|
||||
ARG UID=10001
|
||||
RUN adduser \
|
||||
--disabled-password \
|
||||
--gecos "" \
|
||||
--home "/nonexistent" \
|
||||
--shell "/sbin/nologin" \
|
||||
--no-create-home \
|
||||
--uid "${UID}" \
|
||||
appuser
|
||||
USER appuser
|
||||
|
||||
WORKDIR /app
|
||||
ARG app_name
|
||||
ENV app_name_env=$app_name
|
||||
COPY --from=builder main /app/$app_name_env
|
||||
COPY /conf/config.yml /app/config.yml
|
||||
COPY /conf/default_remote_config.json* /app/default_remote_config.json
|
||||
COPY /migrations /app/migrations
|
||||
ENTRYPOINT /app/$app_name_env
|
||||
Generated
-618
@@ -1,618 +0,0 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
digest = "1:e92f5581902c345eb4ceffdcd4a854fb8f73cf436d47d837d1ec98ef1fe0a214"
|
||||
name = "github.com/StackExchange/wmi"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "5d049714c4a64225c3c79a7cf7d02f7fb5b96338"
|
||||
version = "1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:320e7ead93de9fd2b0e59b50fd92a4d50c1f8ab455d96bc2eb083267453a9709"
|
||||
name = "github.com/asaskevich/govalidator"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f"
|
||||
version = "v9"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:652880afc6b57ce0a67173f552cb35ccda816493a1da6ca20e5074a66bcd083f"
|
||||
name = "github.com/buaazp/fasthttprouter"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "ade4e2031af3aed7fffd241084aad80a58faf421"
|
||||
version = "v0.1.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:553f73a4171c265045ae4f5d3122429ecf2c9c0c232c91f336127fe45480104a"
|
||||
name = "github.com/cenkalti/backoff"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "62661b46c4093e2c1f38d943e663db1a29873e80"
|
||||
version = "v2.1.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:abeb38ade3f32a92943e5be54f55ed6d6e3b6602761d74b4aab4c9dd45c18abd"
|
||||
name = "github.com/fsnotify/fsnotify"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
|
||||
version = "v1.4.7"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:64a5a67c69b70c2420e607a8545d674a23778ed9c3e80607bfd17b77c6c87f6a"
|
||||
name = "github.com/go-ole/go-ole"
|
||||
packages = [
|
||||
".",
|
||||
"oleutil",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "a41e3c4b706f6ae8dfbff342b06e40fa4d2d0506"
|
||||
version = "v1.2.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:e7f1117ec9d37b59ba6d70bbd8feaa9cd2d1c6f676dc88ee152f5a57908fea4b"
|
||||
name = "github.com/go-pg/pg"
|
||||
packages = [
|
||||
".",
|
||||
"internal",
|
||||
"internal/parser",
|
||||
"internal/pool",
|
||||
"orm",
|
||||
"types",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "514bed76d8f579d6ff8d40294fa77e476a5c1b3f"
|
||||
version = "v6.15.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:fa5e9e1af8a8645086811ec5ab003806026babc57c8bb3a6f7e1ab34b80e2ff1"
|
||||
name = "github.com/golang/protobuf"
|
||||
packages = [
|
||||
"jsonpb",
|
||||
"proto",
|
||||
"protoc-gen-go/descriptor",
|
||||
"ptypes",
|
||||
"ptypes/any",
|
||||
"ptypes/duration",
|
||||
"ptypes/struct",
|
||||
"ptypes/timestamp",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5"
|
||||
version = "v1.2.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:324591cd9122f94cc39a87bd44ec71153672c239e2cff5743bfad96b60be3749"
|
||||
name = "github.com/googollee/go-engine.io"
|
||||
packages = [
|
||||
".",
|
||||
"message",
|
||||
"parser",
|
||||
"polling",
|
||||
"transport",
|
||||
"websocket",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "e2f255711dcb2ea41e42c6d9d98c172d7edf6509"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:3eb026ba34d6dd12b45bb6abd63b4e917ebca8d8f3022a139c0881d900ad1bee"
|
||||
name = "github.com/googollee/go-socket.io"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "c8aeb1ed9b49d7de8fef8662efb18f1d289c5f2e"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:7b5c6e2eeaa9ae5907c391a91c132abfd5c9e8a784a341b5625e750c67e6825d"
|
||||
name = "github.com/gorilla/websocket"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "66b9c49e59c6c48f0ffce28c2d8b8a5678502c6d"
|
||||
version = "v1.4.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:d544928ef5b57ff39325b4fea31f262db66c9241324aee38ba55dfe3e836e2c8"
|
||||
name = "github.com/grpc-ecosystem/grpc-gateway"
|
||||
packages = [
|
||||
"runtime",
|
||||
"runtime/internal",
|
||||
"utilities",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "e8bd377da7395186f2f042ee6b366fa5a11d2b39"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10"
|
||||
name = "github.com/hashicorp/hcl"
|
||||
packages = [
|
||||
".",
|
||||
"hcl/ast",
|
||||
"hcl/parser",
|
||||
"hcl/printer",
|
||||
"hcl/scanner",
|
||||
"hcl/strconv",
|
||||
"hcl/token",
|
||||
"json/parser",
|
||||
"json/scanner",
|
||||
"json/token",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:1b1d9534e35d61e861a7356f7f2d766e57e2777dbf79be60e1ac56bbd60adf51"
|
||||
name = "github.com/integration-system/go-cmp"
|
||||
packages = [
|
||||
"cmp",
|
||||
"cmp/internal/diff",
|
||||
"cmp/internal/function",
|
||||
"cmp/internal/value",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "ed1c8d9bf7906aec13cf28080fdf069d7687471a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:9e2fd899fdb17e28e9d036fe7a604a1e04918aa4865d5a2150008fc12c6134be"
|
||||
name = "github.com/integration-system/golang-socketio"
|
||||
packages = [
|
||||
".",
|
||||
"protocol",
|
||||
"transport",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "5959fcea049facd9441fff9de976191accd3cf9f"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:900583da99fb5a30a9c3b829bab8acca29a9474d5b40a5c3cb28e7bc7cd27788"
|
||||
name = "github.com/integration-system/isp-lib"
|
||||
packages = [
|
||||
"backend",
|
||||
"bootstrap",
|
||||
"config",
|
||||
"config/schema",
|
||||
"controller",
|
||||
"database",
|
||||
"http",
|
||||
"logger",
|
||||
"metric",
|
||||
"proto/stubs",
|
||||
"socket",
|
||||
"streaming",
|
||||
"structure",
|
||||
"utils",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "0f71aaf83133a59c9fc143faecbd38b86ed068e2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:a992b3ab79433b828258f9fe99af29da5aeb2e48bf8076a41ba556ac90ac04d3"
|
||||
name = "github.com/integration-system/jsonschema"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "170a88febd847f36821e99ec54a095e6cec48528"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:fd97437fbb6b7dce04132cf06775bd258cce305c44add58eb55ca86c6c325160"
|
||||
name = "github.com/jinzhu/inflection"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "04140366298a54a039076d798123ffa108fff46c"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:5d713dbcad44f3358fec51fd5573d4f733c02cac5a40dcb177787ad5ffe9272f"
|
||||
name = "github.com/json-iterator/go"
|
||||
packages = [
|
||||
".",
|
||||
"extra",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "1624edc4454b8682399def8740d46db5e4362ba4"
|
||||
version = "v1.1.5"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:aaa8e0e7e35d92e21daed3f241832cee73d15ca1cd3302ba3843159a959a7eac"
|
||||
name = "github.com/klauspost/compress"
|
||||
packages = [
|
||||
"flate",
|
||||
"gzip",
|
||||
"zlib",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "30be6041bed523c18e269a700ebd9c2ea9328574"
|
||||
version = "v1.4.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:2d643962fac133904694fffa959bc3c5dcfdcee38c6f5ffdd99a3c93eb9c835c"
|
||||
name = "github.com/klauspost/cpuid"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "e7e905edc00ea8827e58662220139109efea09db"
|
||||
version = "v1.2.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:0a69a1c0db3591fcefb47f115b224592c8dfa4368b7ba9fae509d5e16cdc95c8"
|
||||
name = "github.com/konsorten/go-windows-terminal-sequences"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "5c8c8bd35d3832f5d134ae1e1e375b69a4d25242"
|
||||
version = "v1.0.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8ef506fc2bb9ced9b151dafa592d4046063d744c646c1bbe801982ce87e4bc24"
|
||||
name = "github.com/lib/pq"
|
||||
packages = [
|
||||
".",
|
||||
"oid",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "4ded0e9383f75c197b3a2aaa6d590ac52df6fd79"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c568d7727aa262c32bdf8a3f7db83614f7af0ed661474b24588de635c20024c7"
|
||||
name = "github.com/magiconair/properties"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "c2353362d570a7bfa228149c62842019201cfb71"
|
||||
version = "v1.8.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c658e84ad3916da105a761660dcaeb01e63416c8ec7bc62256a9b411a05fcd67"
|
||||
name = "github.com/mattn/go-colorable"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
|
||||
version = "v0.0.9"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:0981502f9816113c9c8c4ac301583841855c8cf4da8c72f696b3ebedf6d0e4e5"
|
||||
name = "github.com/mattn/go-isatty"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c"
|
||||
version = "v0.0.4"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:2b32af4d2a529083275afc192d1067d8126b578c7a9613b26600e4df9c735155"
|
||||
name = "github.com/mgutz/ansi"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "9520e82c474b0a04dd04f8a40959027271bab992"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:53bc4cd4914cd7cd52139990d5170d6dc99067ae31c56530621b18b35fc30318"
|
||||
name = "github.com/mitchellh/mapstructure"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe"
|
||||
version = "v1.1.2"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:33422d238f147d247752996a26574ac48dcf472976eda7f5134015f06bf16563"
|
||||
name = "github.com/modern-go/concurrent"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94"
|
||||
version = "1.0.3"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:e32bdbdb7c377a07a9a46378290059822efdce5c8d96fe71940d87cb4f918855"
|
||||
name = "github.com/modern-go/reflect2"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd"
|
||||
version = "1.0.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:84bd7f8a2e0bcd53ddc33c3b47c34c1fe340c8632cbe928f7f8ae10ec6ecdd62"
|
||||
name = "github.com/mohae/deepcopy"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "c48cc78d482608239f6c4c92a4abd87eb8761c90"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:95741de3af260a92cc5c7f3f3061e85273f5a81b5db20d4bd68da74bd521675e"
|
||||
name = "github.com/pelletier/go-toml"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "c01d1270ff3e442a8a57cddc1c92dc1138598194"
|
||||
version = "v1.2.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:d4c5d57ac0163eb71e09f1a94ca998961668700232f948d47a6269c8d7651d38"
|
||||
name = "github.com/pressly/goose"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "7a98874933001af28951c83e958b1db750f39f8d"
|
||||
version = "v2.4.5"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:d38f81081a389f1466ec98192cf9115a82158854d6f01e1c23e2e7554b97db71"
|
||||
name = "github.com/rcrowley/go-metrics"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "3113b8401b8a98917cde58f8bbd42a1b1c03b1fd"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:564e4136357b9d481ad8eb9d87f7fc144a28bb41cb0e29e739db3535e2d87575"
|
||||
name = "github.com/shirou/gopsutil"
|
||||
packages = [
|
||||
"cpu",
|
||||
"internal/common",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "0f70a4a06f7a1039305ec9b3ba9c2800f8929fba"
|
||||
version = "v2.18.11"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:69b1cc331fca23d702bd72f860c6a647afd0aa9fcbc1d0659b1365e26546dd70"
|
||||
name = "github.com/sirupsen/logrus"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "bcd833dfe83d3cebad139e4a29ed79cb2318bf95"
|
||||
version = "v1.2.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:6a4a11ba764a56d2758899ec6f3848d24698d48442ebce85ee7a3f63284526cd"
|
||||
name = "github.com/spf13/afero"
|
||||
packages = [
|
||||
".",
|
||||
"mem",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "d40851caa0d747393da1ffb28f7f9d8b4eeffebd"
|
||||
version = "v1.1.2"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:08d65904057412fc0270fc4812a1c90c594186819243160dc779a402d4b6d0bc"
|
||||
name = "github.com/spf13/cast"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "8c9545af88b134710ab1cd196795e7f2388358d7"
|
||||
version = "v1.3.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:68ea4e23713989dc20b1bded5d9da2c5f9be14ff9885beef481848edd18c26cb"
|
||||
name = "github.com/spf13/jwalterweatherman"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "4a4406e478ca629068e7768fc33f3f044173c0a6"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c1b1102241e7f645bc8e0c22ae352e8f0dc6484b6cb4d132fa9f24174e0119e2"
|
||||
name = "github.com/spf13/pflag"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "298182f68c66c05229eb03ac171abe6e309ee79a"
|
||||
version = "v1.0.3"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:214775c11fd26da94a100111a62daa25339198a4f9c57cb4aab352da889f5b93"
|
||||
name = "github.com/spf13/viper"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "2c12c60302a5a0e62ee102ca9bc996277c2f64f5"
|
||||
version = "v1.2.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:d32b64a7a82dd36b674fb73ff767e949eb7155b6b574ff276f49d4edc8af105f"
|
||||
name = "github.com/thecodeteam/goodbye"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "a83968bda2d37294a3541b7d2207fb6f5a3559a3"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c468422f334a6b46a19448ad59aaffdfc0a36b08fdcc1c749a0b29b6453d7e59"
|
||||
name = "github.com/valyala/bytebufferpool"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:c911cc6a838b0d6be5de154aaea7b36530d5c97e019c3bb56b67fa8531aa17df"
|
||||
name = "github.com/valyala/fasthttp"
|
||||
packages = [
|
||||
".",
|
||||
"fasthttputil",
|
||||
"stackless",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "1d2d99cba311e04b8d58f5d113ee07086c3e64f6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:c83590426ecf1362e77a9054afed570b201de1a353398a6157ecce06583ea024"
|
||||
name = "github.com/vmihailenco/sasl"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "2f13c189728a02f8cc31b3b9cc06047b383c21cc"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:39a425f98fb19427061a693fe6bf0683c9bddec4b25b17067e34fdb465e39cb9"
|
||||
name = "github.com/x-cray/logrus-prefixed-formatter"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "bb2702d423886830dee131692131d35648c382e2"
|
||||
version = "v0.5.2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:9ff2b9f8d4e47013a213b9ea0d850ed787c51f5eab2038842d82397ad85a19c1"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = [
|
||||
"pbkdf2",
|
||||
"ssh/terminal",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "505ab145d0a99da450461ae2c1a9f6cd10d1f447"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:7a2e3d6819e7a97a877f8604e737901c6941e76d56ae98a51a1ca2f13de351fb"
|
||||
name = "golang.org/x/net"
|
||||
packages = [
|
||||
"context",
|
||||
"http/httpguts",
|
||||
"http2",
|
||||
"http2/hpack",
|
||||
"idna",
|
||||
"internal/timeseries",
|
||||
"trace",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "351d144fa1fc0bd934e2408202be0c29f25e35a0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:b9dceb1408ba5105803d5859193bc7d89ac3199b611cf8681dbaa0aa09c10d9c"
|
||||
name = "golang.org/x/sys"
|
||||
packages = [
|
||||
"unix",
|
||||
"windows",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "a5c9d58dba9a56f97aaa86f55e638b718c5a6c42"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
|
||||
name = "golang.org/x/text"
|
||||
packages = [
|
||||
"collate",
|
||||
"collate/build",
|
||||
"internal/colltab",
|
||||
"internal/gen",
|
||||
"internal/tag",
|
||||
"internal/triegen",
|
||||
"internal/ucd",
|
||||
"language",
|
||||
"secure/bidirule",
|
||||
"transform",
|
||||
"unicode/bidi",
|
||||
"unicode/cldr",
|
||||
"unicode/norm",
|
||||
"unicode/rangetable",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
|
||||
version = "v0.3.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:6aec038013fe4a5de91d89b51283cd0ddc0b8ed60ac58e0a173a9d8cf39438c5"
|
||||
name = "google.golang.org/genproto"
|
||||
packages = [
|
||||
"googleapis/api/annotations",
|
||||
"googleapis/rpc/errdetails",
|
||||
"googleapis/rpc/status",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "bd91e49a0898e27abb88c339b432fa53d7497ac0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:9edd250a3c46675d0679d87540b30c9ed253b19bd1fd1af08f4f5fb3c79fc487"
|
||||
name = "google.golang.org/grpc"
|
||||
packages = [
|
||||
".",
|
||||
"balancer",
|
||||
"balancer/base",
|
||||
"balancer/roundrobin",
|
||||
"binarylog/grpc_binarylog_v1",
|
||||
"codes",
|
||||
"connectivity",
|
||||
"credentials",
|
||||
"credentials/internal",
|
||||
"encoding",
|
||||
"encoding/proto",
|
||||
"grpclog",
|
||||
"internal",
|
||||
"internal/backoff",
|
||||
"internal/binarylog",
|
||||
"internal/channelz",
|
||||
"internal/envconfig",
|
||||
"internal/grpcrand",
|
||||
"internal/grpcsync",
|
||||
"internal/syscall",
|
||||
"internal/transport",
|
||||
"keepalive",
|
||||
"metadata",
|
||||
"naming",
|
||||
"peer",
|
||||
"resolver",
|
||||
"resolver/dns",
|
||||
"resolver/passthrough",
|
||||
"stats",
|
||||
"status",
|
||||
"tap",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "df014850f6dee74ba2fc94874043a9f3f75fbfd8"
|
||||
version = "v1.17.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c805e517269b0ba4c21ded5836019ed7d16953d4026cb7d00041d039c7906be9"
|
||||
name = "gopkg.in/natefinch/lumberjack.v2"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
|
||||
version = "v2.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "51d6538a90f86fe93ac480b35f37b2be17fef232"
|
||||
version = "v2.2.2"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = [
|
||||
"github.com/asaskevich/govalidator",
|
||||
"github.com/cenkalti/backoff",
|
||||
"github.com/go-pg/pg",
|
||||
"github.com/go-pg/pg/orm",
|
||||
"github.com/golang/protobuf/proto",
|
||||
"github.com/golang/protobuf/ptypes/struct",
|
||||
"github.com/googollee/go-socket.io",
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime",
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities",
|
||||
"github.com/integration-system/isp-lib/backend",
|
||||
"github.com/integration-system/isp-lib/bootstrap",
|
||||
"github.com/integration-system/isp-lib/config",
|
||||
"github.com/integration-system/isp-lib/config/schema",
|
||||
"github.com/integration-system/isp-lib/controller",
|
||||
"github.com/integration-system/isp-lib/database",
|
||||
"github.com/integration-system/isp-lib/logger",
|
||||
"github.com/integration-system/isp-lib/metric",
|
||||
"github.com/integration-system/isp-lib/socket",
|
||||
"github.com/integration-system/isp-lib/structure",
|
||||
"github.com/integration-system/isp-lib/utils",
|
||||
"github.com/valyala/fasthttp",
|
||||
"golang.org/x/net/context",
|
||||
"google.golang.org/genproto/googleapis/api/annotations",
|
||||
"google.golang.org/grpc",
|
||||
"google.golang.org/grpc/codes",
|
||||
"google.golang.org/grpc/grpclog",
|
||||
"google.golang.org/grpc/status",
|
||||
]
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/grpc-ecosystem/grpc-gateway"
|
||||
revision = "e8bd377da7395186f2f042ee6b366fa5a11d2b39"
|
||||
@@ -1,92 +1,2 @@
|
||||
## Contents
|
||||
## [1. Installing](#installing)
|
||||
## [2. Using](#using)
|
||||
## [3. Environment variables](#environment-variables)
|
||||
|
||||
# isp-config-service
|
||||
|
||||
|
||||
|
||||
## Installing
|
||||
### 1. Download dependencies
|
||||
```
|
||||
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
|
||||
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
|
||||
go get -u github.com/golang/protobuf/protoc-gen-go
|
||||
```
|
||||
### 2. Generate GRPC, GRPC-gateway, GRPC-gateway-swagger
|
||||
###### WINDOWS
|
||||
```cmd
|
||||
protoc ^
|
||||
-I. -I%GOPATH%\src ^
|
||||
-I%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis ^
|
||||
--go_out=plugins=grpc:. --grpc-gateway_out=logtostderr=true:. --swagger_out=logtostderr=true:. ^
|
||||
proto\config_service.proto
|
||||
```
|
||||
###### LINUX
|
||||
```bash
|
||||
protoc -I. \
|
||||
-I$GOPATH \
|
||||
-I$GOPATH/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
||||
--go_out=plugins=grpc:. --grpc-gateway_out=logtostderr=true:. --swagger_out=logtostderr=true:. \
|
||||
proto/config_service.proto
|
||||
```
|
||||
|
||||
## Using
|
||||
### 1. GRPC
|
||||
Default GRPC port is: `5001`, might be changed in config file
|
||||
Proto file is: `proto/config_service.proto`
|
||||
### 2. REST proxy to GRPC
|
||||
Default port is: `5000`, might be changed in config file
|
||||
Swagger work on http://0.0.0.0:5000/swagger
|
||||
### 3. SocketIO
|
||||
For connect to this server two variables must be sent in query path:
|
||||
1. `module_name` - Module name, for example `auth`.
|
||||
2. `instance_uuid` - UUID - instance identity.
|
||||
|
||||
#### Events
|
||||
##### Event to a client
|
||||
`CONFIG:SEND_CONFIG_WHEN_CONNECTED` - When a connection is established to a client will send an event.
|
||||
|
||||
`CONFIG:SEND_CONFIG_CHANGED` - When config for particular module had been changed this event with new config will send to a client.
|
||||
|
||||
`CONFIG:SEND_CONFIG_ON_REQUEST` - the server will send to a client actual config with this event after `CONFIG:REQUEST_CONFIG`
|
||||
|
||||
###### The next events work on both sides. First, when new backend publishes new methods at config service there is incoming one of this events:
|
||||
|
||||
`ROUTES:SEND_ROUTES_WHEN_CONNECTED` - A backend sends this event when a connection is established with a config server.
|
||||
|
||||
`ROUTES:SEND_ROUTES_CHANGED` - Any module can say that something had changed in its methods.
|
||||
|
||||
`ROUTES:SEND_ROUTES_ON_REQUEST` - A config service is able to make a request to renew list methods.
|
||||
|
||||
###### A config service, in turn, send the same events types in each its connection.
|
||||
|
||||
For all of this events we wait for next data structure:
|
||||
```json
|
||||
{
|
||||
"address": {
|
||||
"ip": "10.10.10.10",
|
||||
"port": "5001"
|
||||
},
|
||||
"endpoints": [
|
||||
{"path": "/api/user/get"},
|
||||
{"path": "/api/user/save"},
|
||||
{"path": "/api/user/delete"}
|
||||
]
|
||||
}
|
||||
```
|
||||
##### Event to the server
|
||||
`CONFIG:REQUEST_CONFIG` - A client can request current config with this event.
|
||||
|
||||
## Environment variables
|
||||
`APP_PROFILE` - Name for config file, default is `config`. Will seek file with name: `config.yml`.
|
||||
|
||||
`APP_CONFIG_PATH` - Absolute path where a config file is. If a variable hadn't been specified config will seek into the same directory, when binary file placed.
|
||||
|
||||
`LOG_LEVEL` - Log level, the default is `INFO`.
|
||||
|
||||
`APP_MODE` - If set to `dev` logger for SQL will be on and if `LOG_LEVEL` hadn't been specified it will set to `DEBUG`.
|
||||
|
||||
## Changes
|
||||
#### 0.2.2 - 2018-10-05
|
||||
- Add default config for mdm module
|
||||
@@ -0,0 +1,179 @@
|
||||
package assembly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"isp-config-service/conf"
|
||||
"isp-config-service/service/module/backend"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/txix-open/etp/v4"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"github.com/txix-open/isp-kit/worker"
|
||||
"isp-config-service/controller"
|
||||
"isp-config-service/controller/api"
|
||||
"isp-config-service/repository"
|
||||
"isp-config-service/routes"
|
||||
apisvs "isp-config-service/service/api"
|
||||
"isp-config-service/service/event"
|
||||
"isp-config-service/service/module"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
"isp-config-service/service/subscription"
|
||||
)
|
||||
|
||||
const (
|
||||
wsReadLimit = 4 * 1024 * 1024
|
||||
handleEventsInterval = 500 * time.Millisecond
|
||||
cleanEventInterval = 60 * time.Second
|
||||
cleanPhantomBackendsInterval = 5 * time.Minute
|
||||
eventTtl = 60 * time.Second
|
||||
)
|
||||
|
||||
type LocalConfig struct {
|
||||
Local conf.Local
|
||||
RqliteAddress string
|
||||
}
|
||||
|
||||
type Locator struct {
|
||||
db db.DB
|
||||
cfg LocalConfig
|
||||
leaderChecker LeaderChecker
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
type LeaderChecker interface {
|
||||
IsLeader() bool
|
||||
}
|
||||
|
||||
type OwnBackendsCleaner interface {
|
||||
DeleteOwnBackends(ctx context.Context)
|
||||
}
|
||||
|
||||
func NewLocator(
|
||||
db db.DB,
|
||||
leaderChecker LeaderChecker,
|
||||
cfg LocalConfig,
|
||||
logger log.Logger,
|
||||
) Locator {
|
||||
return Locator{
|
||||
db: db,
|
||||
leaderChecker: leaderChecker,
|
||||
cfg: cfg,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
GrpcMux *grpc.Mux
|
||||
HttpMux http.Handler
|
||||
EtpSrv *etp.Server
|
||||
HandleEventWorker *worker.Worker
|
||||
CleanEventWorker *worker.Worker
|
||||
CleanPhantomBackendWorker *worker.Worker
|
||||
OwnBackendsCleaner OwnBackendsCleaner
|
||||
}
|
||||
|
||||
//nolint:funlen
|
||||
func (l Locator) Config() *Config {
|
||||
moduleRepo := repository.NewModule(l.db)
|
||||
backendRepo := repository.NewBackend(l.db)
|
||||
eventRepo := repository.NewEvent(l.db)
|
||||
configRepo := repository.NewConfig(l.db)
|
||||
configSchemaRepo := repository.NewConfigSchema(l.db)
|
||||
configHistoryRepo := repository.NewConfigHistory(l.db)
|
||||
|
||||
etpSrv := etp.NewServer(
|
||||
etp.WithServerReadLimit(wsReadLimit),
|
||||
etp.WithServerAcceptOptions(&etp.AcceptOptions{
|
||||
InsecureSkipVerify: true,
|
||||
}),
|
||||
)
|
||||
emitter := module.NewEmitter(l.logger)
|
||||
subscriptionService := subscription.NewService(
|
||||
moduleRepo,
|
||||
backendRepo,
|
||||
configRepo,
|
||||
etpSrv.Rooms(),
|
||||
emitter,
|
||||
l.logger,
|
||||
)
|
||||
|
||||
backendService := backend.NewBackend(
|
||||
backendRepo,
|
||||
eventRepo,
|
||||
l.cfg.Local.Rqlite.NodeId,
|
||||
etpSrv.Rooms(),
|
||||
l.logger,
|
||||
)
|
||||
cleanPhantomBackendJob := backend.NewCleaner(backendService, l.logger)
|
||||
cleanPhantomBackendWorker := worker.New(cleanPhantomBackendJob, worker.WithInterval(cleanPhantomBackendsInterval))
|
||||
|
||||
moduleService := module.NewService(
|
||||
moduleRepo,
|
||||
backendService,
|
||||
configRepo,
|
||||
configSchemaRepo,
|
||||
subscriptionService,
|
||||
emitter,
|
||||
l.logger,
|
||||
)
|
||||
moduleController := controller.NewModule(moduleService, l.logger)
|
||||
|
||||
configHistoryApiService := apisvs.NewConfigHistory(configHistoryRepo, l.cfg.Local.KeepConfigVersions, l.logger)
|
||||
configHistoryController := api.NewConfigHistory(configHistoryApiService)
|
||||
|
||||
moduleApiService := apisvs.NewModule(moduleRepo, backendRepo, configSchemaRepo)
|
||||
moduleApiController := api.NewModule(moduleApiService)
|
||||
|
||||
configApiService := apisvs.NewConfig(
|
||||
configRepo,
|
||||
moduleRepo,
|
||||
configSchemaRepo,
|
||||
eventRepo,
|
||||
configHistoryApiService,
|
||||
)
|
||||
configApiController := api.NewConfig(configApiService)
|
||||
|
||||
configSchemaApiService := apisvs.NewConfigSchema(configSchemaRepo)
|
||||
configSchemaController := api.NewConfigSchema(configSchemaApiService)
|
||||
|
||||
controllers := routes.Controllers{
|
||||
Module: moduleController,
|
||||
ModuleApi: moduleApiController,
|
||||
ConfigApi: configApiController,
|
||||
ConfigHistoryApi: configHistoryController,
|
||||
ConfigSchemaApi: configSchemaController,
|
||||
}
|
||||
mapper := endpoint.DefaultWrapper(l.logger)
|
||||
grpcMux := routes.GrpcHandler(mapper, controllers)
|
||||
|
||||
routes.BindEtp(etpSrv, controllers, l.logger)
|
||||
|
||||
rqliteUrl, err := url.Parse(l.cfg.RqliteAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
rqliteProxy := httputil.NewSingleHostReverseProxy(rqliteUrl)
|
||||
httpMux := routes.HttpHandler(etpSrv, l.cfg.Local, rqliteProxy)
|
||||
|
||||
eventHandler := event.NewHandler(subscriptionService, l.logger)
|
||||
handleEventJob := event.NewWorker(eventRepo, eventHandler, l.logger)
|
||||
handleEventWorker := worker.New(handleEventJob, worker.WithInterval(handleEventsInterval))
|
||||
|
||||
cleanerJob := event.NewCleaner(eventRepo, l.leaderChecker, eventTtl, l.logger)
|
||||
cleanEventWorker := worker.New(cleanerJob, worker.WithInterval(cleanEventInterval))
|
||||
|
||||
return &Config{
|
||||
GrpcMux: grpcMux,
|
||||
EtpSrv: etpSrv,
|
||||
HttpMux: httpMux,
|
||||
HandleEventWorker: handleEventWorker,
|
||||
CleanEventWorker: cleanEventWorker,
|
||||
CleanPhantomBackendWorker: cleanPhantomBackendWorker,
|
||||
OwnBackendsCleaner: backendService,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
## v3.1.0
|
||||
* добавлено возможность анонсировать несколько бекендов с одинаковыми адресами
|
||||
* реализован механизм поиска и очистки фантомных бекендов (те который отключились, но остались висеть в таблице маршрутизации)
|
||||
* добавлена очистка таблицы маршрутизации в момент отключения самого модуля
|
||||
## v3.0.2
|
||||
* Новая реализация модуля на базе rqlite
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
go install github.com/mitchellh/gox@latest
|
||||
gox -os="linux windows darwin" -arch="amd64" -output="build/{{.OS}}_{{.Arch}}/{{.Dir}}"
|
||||
@@ -0,0 +1,12 @@
|
||||
db:
|
||||
host: 127.0.0.1
|
||||
port: 5432
|
||||
database: test
|
||||
username: test
|
||||
password: test
|
||||
schema: config_service
|
||||
|
||||
newConfigService:
|
||||
address: http://127.0.0.1:9002/
|
||||
username: default
|
||||
password: test
|
||||
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
)
|
||||
|
||||
type Module struct {
|
||||
Id string
|
||||
Name string
|
||||
LastConnectedAt *time.Time
|
||||
LastDisconnectedAt *time.Time
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Id string
|
||||
ModuleId string
|
||||
Name string
|
||||
Version int
|
||||
Active bool
|
||||
Data json.RawMessage
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type ConfigHistory struct {
|
||||
Id string
|
||||
ConfigId string
|
||||
ConfigVersion int
|
||||
Data json.RawMessage
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type ConfigSchema struct {
|
||||
Id string
|
||||
ModuleId string
|
||||
Version string
|
||||
Schema json.RawMessage
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
module isp-config-service/migrate
|
||||
|
||||
go 1.23
|
||||
|
||||
replace isp-config-service => ../..
|
||||
|
||||
require (
|
||||
github.com/jmoiron/sqlx v1.4.0
|
||||
github.com/mattn/go-sqlite3 v1.14.22
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pressly/goose/v3 v3.22.1
|
||||
github.com/txix-open/isp-kit v1.39.1
|
||||
isp-config-service v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.5.4 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/coder/websocket v1.8.12 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
|
||||
github.com/iancoleman/strcase v0.3.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx/v5 v5.7.1 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mfridman/interpolate v0.0.2 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/prometheus/client_golang v1.20.5 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.60.1 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/sethvargo/go-retry v0.3.0 // indirect
|
||||
github.com/tidwall/gjson v1.18.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/txix-open/bellows v1.2.0 // indirect
|
||||
github.com/txix-open/etp/v4 v4.0.1 // indirect
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 // indirect
|
||||
go.opentelemetry.io/otel v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.31.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
|
||||
google.golang.org/grpc v1.67.1 // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
@@ -0,0 +1,210 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
|
||||
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
|
||||
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/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
|
||||
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/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.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
|
||||
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
|
||||
github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA=
|
||||
github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-resty/resty/v2 v2.15.3 h1:bqff+hcqAflpiF591hhJzNdkRsFhlB96CYfBwSFvql8=
|
||||
github.com/go-resty/resty/v2 v2.15.3/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
|
||||
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
||||
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
|
||||
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
|
||||
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
|
||||
github.com/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.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
|
||||
github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg=
|
||||
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/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pressly/goose/v3 v3.22.1 h1:2zICEfr1O3yTP9BRZMGPj7qFxQ+ik6yeo+z1LMuioLc=
|
||||
github.com/pressly/goose/v3 v3.22.1/go.mod h1:xtMpbstWyCpyH+0cxLTMCENWBG+0CSxvTsXhW95d5eo=
|
||||
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
||||
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||
github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc=
|
||||
github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
|
||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
|
||||
github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
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.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
|
||||
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
|
||||
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
|
||||
github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA=
|
||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
||||
github.com/txix-open/isp-kit v1.39.1 h1:10zEILNQSPY7naiuaQkIKNS2/fnWxuE9bz+dTiAptXw=
|
||||
github.com/txix-open/isp-kit v1.39.1/go.mod h1:xB6mkoOewZBI1ND8kjU5TR6kvLu3VQI3Rdkh6g6FE4I=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 h1:Z0Sqf+U+Sc6hfIXtRCIZlbJprkCjwMFbS4ZbEPQ44To=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99/go.mod h1:pA0NYmhL0uEkkxj55S+S7MZU4e2QIt46x9XSrzrWc3c=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 h1:4BZHA+B1wXEQoGNHxW8mURaLhcdGwvRnmhGbm+odRbc=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0/go.mod h1:3qi2EEwMgB4xnKgPLqsDP3j9qxnHDZeHsnAxfjQqTko=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM=
|
||||
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
|
||||
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 h1:K0XaT3DwHAcV4nKLzcQvwAgSyisUghWoY20I7huthMk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0/go.mod h1:B5Ki776z/MBnVha1Nzwp5arlzBbE3+1jk+pGmaP5HME=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 h1:lUsI2TYsQw2r1IASwoROaCnjdj2cvC2+Jbxvk6nHnWU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0/go.mod h1:2HpZxxQurfGxJlJDblybejHB6RX6pmExPNe517hREw4=
|
||||
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
|
||||
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
|
||||
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
|
||||
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
|
||||
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
|
||||
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 h1:2oV8dfuIkM1Ti7DwXc0BJfnwr9csz4TDXI9EmiI+Rbw=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38/go.mod h1:vuAjtvlwkDKF6L1GQ0SokiRLCGFfeBUXWr/aFFkHACc=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:zciRKQ4kBpFgpfC5QQCVtnnNAcLIqweL7plyZRQHVpI=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
|
||||
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
||||
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
||||
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
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=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
|
||||
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU=
|
||||
modernc.org/sqlite v1.33.0 h1:WWkA/T2G17okiLGgKAj4/RMIvgyMT19yQ038160IeYk=
|
||||
modernc.org/sqlite v1.33.0/go.mod h1:9uQ9hF/pCZoYZK73D/ud5Z7cIRIILSZI8NdIemVMTX8=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
@@ -0,0 +1,193 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pressly/goose/v3"
|
||||
"github.com/txix-open/isp-kit/config"
|
||||
"github.com/txix-open/isp-kit/dbx"
|
||||
"github.com/txix-open/isp-kit/http/httpcli"
|
||||
"github.com/txix-open/isp-kit/http/httpclix"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"github.com/txix-open/isp-kit/validator"
|
||||
"isp-config-service/service/rqlite/goose_store"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/app"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/entity/xtypes"
|
||||
"isp-config-service/migrate/migration"
|
||||
"isp-config-service/migrations"
|
||||
"isp-config-service/repository"
|
||||
)
|
||||
|
||||
type Cfg struct {
|
||||
Db dbx.Config
|
||||
NewConfigService struct {
|
||||
Address string
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app, err := app.New(app.WithConfigOptions(
|
||||
config.WithValidator(validator.Default),
|
||||
config.WithExtraSource(config.NewYamlConfig("config.yml")),
|
||||
))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logger := app.Logger()
|
||||
logger.SetLevel(log.DebugLevel)
|
||||
ctx := app.Context()
|
||||
cfg := Cfg{}
|
||||
err = app.Config().Read(&cfg)
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "read config"))
|
||||
}
|
||||
|
||||
pgDb, err := dbx.Open(ctx, cfg.Db, dbx.WithQueryTracer(dbx.NewLogTracer(logger)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer pgDb.Close()
|
||||
|
||||
fileName := fmt.Sprintf("db_%d.sqlite", time.Now().Unix())
|
||||
dbClient := &db.Client{}
|
||||
dbClient.DB, err = sqlx.Open("sqlite3", fileName)
|
||||
dbClient.DB.MapperFunc(db.ToSnakeCase)
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "err opening db"))
|
||||
}
|
||||
defer dbClient.Close()
|
||||
|
||||
migrationStore := goose_store.NewStore(dbClient.DB.DB)
|
||||
mr := migration.NewRunner("", migrations.Migrations, logger)
|
||||
err = mr.Run(ctx, dbClient.DB.DB, goose.WithStore(migrationStore))
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "err connecting to db"))
|
||||
}
|
||||
|
||||
moduleRepo := repository.NewModule(dbClient)
|
||||
configRepo := repository.NewConfig(dbClient)
|
||||
configSchemaRepo := repository.NewConfigSchema(dbClient)
|
||||
configHistoryRepo := repository.NewConfigHistory(dbClient)
|
||||
|
||||
logger.Info(ctx, "start modules migration")
|
||||
modules := make([]Module, 0)
|
||||
err = pgDb.Select(ctx, &modules, "select * from modules")
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "err selecting modules"))
|
||||
}
|
||||
for _, module := range modules {
|
||||
result := entity.Module{
|
||||
Id: module.Id,
|
||||
Name: module.Name,
|
||||
CreatedAt: xtypes.Time(module.CreatedAt),
|
||||
}
|
||||
_, _ = moduleRepo.Upsert(ctx, result)
|
||||
}
|
||||
logger.Info(ctx, "modules migrated")
|
||||
|
||||
logger.Info(ctx, "start configs migration")
|
||||
configs := make([]Config, 0)
|
||||
err = pgDb.Select(ctx, &configs, "select id, module_id, version, active, created_at, updated_at, data, name from configs")
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "err selecting configs"))
|
||||
}
|
||||
for _, config := range configs {
|
||||
result := entity.Config{
|
||||
Id: config.Id,
|
||||
Name: config.Name,
|
||||
ModuleId: config.ModuleId,
|
||||
Data: config.Data,
|
||||
Version: config.Version,
|
||||
Active: xtypes.Bool(config.Active),
|
||||
AdminId: 0,
|
||||
CreatedAt: xtypes.Time(config.CreatedAt),
|
||||
UpdatedAt: xtypes.Time(config.UpdatedAt),
|
||||
}
|
||||
err := configRepo.Insert(ctx, result)
|
||||
if err != nil {
|
||||
panic(errors.WithMessagef(err, "err inserting config: %s", config.Id))
|
||||
}
|
||||
}
|
||||
logger.Info(ctx, "configs migrated")
|
||||
|
||||
logger.Info(ctx, "start config schemas migration")
|
||||
schemas := make([]ConfigSchema, 0)
|
||||
err = pgDb.Select(ctx, &schemas, "select * from config_schemas")
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "err selecting schemas"))
|
||||
}
|
||||
for _, schema := range schemas {
|
||||
result := entity.ConfigSchema{
|
||||
Id: schema.Id,
|
||||
ModuleId: schema.ModuleId,
|
||||
Data: schema.Schema,
|
||||
ModuleVersion: schema.Version,
|
||||
CreatedAt: xtypes.Time(schema.CreatedAt),
|
||||
UpdatedAt: xtypes.Time(schema.UpdatedAt),
|
||||
}
|
||||
err := configSchemaRepo.Upsert(ctx, result)
|
||||
if err != nil {
|
||||
panic(errors.WithMessagef(err, "err upserting config_schema: %s", schema.Id))
|
||||
}
|
||||
}
|
||||
logger.Info(ctx, "config schemas migrated")
|
||||
|
||||
logger.Info(ctx, "start config history migration")
|
||||
configHistories := make([]ConfigHistory, 0)
|
||||
err = pgDb.Select(ctx, &configHistories, "select * from version_config")
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "err selecting configs"))
|
||||
}
|
||||
for _, history := range configHistories {
|
||||
result := entity.ConfigHistory{
|
||||
Id: history.Id,
|
||||
ConfigId: history.ConfigId,
|
||||
Data: history.Data,
|
||||
Version: history.ConfigVersion,
|
||||
AdminId: 0,
|
||||
CreatedAt: xtypes.Time(history.CreatedAt),
|
||||
}
|
||||
err := configHistoryRepo.Insert(ctx, result)
|
||||
if err != nil {
|
||||
panic(errors.WithMessagef(err, "err inserting config_history: %s", history.Id))
|
||||
}
|
||||
}
|
||||
logger.Info(ctx, "config history migrated")
|
||||
|
||||
logger.Info(ctx, "close sqlite db")
|
||||
_ = dbClient.Close()
|
||||
|
||||
logger.Info(ctx, "loading db to isp-config-service")
|
||||
sqliteFile, err := os.ReadFile(fileName)
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "err opening sqlite file"))
|
||||
}
|
||||
|
||||
cli := httpcli.New(httpcli.WithMiddlewares(httpclix.Log(logger)))
|
||||
cli.GlobalRequestConfig().BaseUrl = cfg.NewConfigService.Address
|
||||
cli.GlobalRequestConfig().BasicAuth = &httpcli.BasicAuth{
|
||||
Username: cfg.NewConfigService.Username,
|
||||
Password: cfg.NewConfigService.Password,
|
||||
}
|
||||
ctx = httpclix.LogConfigToContext(ctx, false, true)
|
||||
err = cli.Post("/db/load").
|
||||
Header("Content-Type", "application/octet-stream").
|
||||
RequestBody(sqliteFile).
|
||||
StatusCodeToError().
|
||||
Timeout(60 * time.Second).
|
||||
DoWithoutResponse(ctx)
|
||||
if err != nil {
|
||||
panic(errors.WithMessage(err, "load sqlite file"))
|
||||
}
|
||||
|
||||
logger.Info(ctx, "done!")
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pressly/goose/v3"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
)
|
||||
|
||||
const (
|
||||
DialectPostgreSQL = goose.DialectPostgres
|
||||
DialectSqlite3 = goose.DialectSQLite3
|
||||
DialectClickhouse = goose.DialectClickHouse
|
||||
)
|
||||
|
||||
type Runner struct {
|
||||
dialect goose.Dialect
|
||||
fs fs.FS
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewRunner(
|
||||
dialect goose.Dialect,
|
||||
fs fs.FS,
|
||||
logger log.Logger,
|
||||
) Runner {
|
||||
return Runner{
|
||||
dialect: dialect,
|
||||
fs: fs,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Runner) Run(ctx context.Context, db *sql.DB, gooseOpts ...goose.ProviderOption) error {
|
||||
ctx = log.ToContext(ctx, log.String("worker", "goose_db_migration"))
|
||||
|
||||
provider, err := goose.NewProvider(r.dialect, db, r.fs, gooseOpts...)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get goose provider")
|
||||
}
|
||||
|
||||
dbVersion, err := provider.GetDBVersion(ctx)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get db version")
|
||||
}
|
||||
r.logger.Info(ctx, fmt.Sprintf("current db version: %d", dbVersion))
|
||||
|
||||
migrations, err := provider.Status(ctx)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get status migrations")
|
||||
}
|
||||
r.logger.Info(ctx, "print migration list")
|
||||
if len(migrations) == 0 {
|
||||
r.logger.Info(ctx, "no migrations")
|
||||
}
|
||||
for _, migration := range migrations {
|
||||
appliedAt := "Pending"
|
||||
if !migration.AppliedAt.IsZero() {
|
||||
appliedAt = migration.AppliedAt.Format(time.RFC3339)
|
||||
}
|
||||
msg := fmt.Sprintf(
|
||||
"migration: %s %s %s",
|
||||
filepath.Base(migration.Source.Path),
|
||||
strings.ToUpper(string(migration.State)),
|
||||
appliedAt,
|
||||
)
|
||||
r.logger.Info(ctx, msg)
|
||||
}
|
||||
|
||||
result, err := provider.Up(ctx)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "apply pending migrations")
|
||||
}
|
||||
for _, migrationResult := range result {
|
||||
r.logger.Info(ctx, fmt.Sprintf("applied migration: %s", migrationResult.String()))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+30
-26
@@ -1,30 +1,34 @@
|
||||
database:
|
||||
address: "127.0.0.1"
|
||||
schema: "config_service"
|
||||
database: "isp"
|
||||
port: "5432"
|
||||
username: "isp"
|
||||
password: "isp_password"
|
||||
createSchema: true
|
||||
|
||||
moduleName: "config"
|
||||
grpcOuterAddress:
|
||||
configServiceAddress:
|
||||
ip: 127.0.0.1
|
||||
port: 9001
|
||||
grpcOuterAddress:
|
||||
ip: isp-config-service
|
||||
port: 9002
|
||||
grpcInnerAddress:
|
||||
ip: 0.0.0.0
|
||||
port: 9002
|
||||
moduleName: isp-config-service
|
||||
|
||||
ws:
|
||||
rest:
|
||||
port: "9001"
|
||||
ip: "0.0.0.0"
|
||||
grpc:
|
||||
port: "9002"
|
||||
ip: "0.0.0.0"
|
||||
infraServerPort: 9006
|
||||
|
||||
metrics:
|
||||
gc: true
|
||||
memory: true
|
||||
address:
|
||||
addressConfiguration:
|
||||
ip: "0.0.0.0"
|
||||
port: "9551"
|
||||
path: "/metrics"
|
||||
logLevel: debug
|
||||
|
||||
maintenanceMode: false
|
||||
|
||||
keepConfigVersions: 64
|
||||
|
||||
credentials:
|
||||
- username: default
|
||||
password: 38kPk0upqI5j
|
||||
perms: ["all"]
|
||||
internalClientCredential: default
|
||||
|
||||
rqlite:
|
||||
DataPath: "data"
|
||||
NodeID: 1
|
||||
BootstrapExpect: 1
|
||||
RaftAddr: "127.0.0.1:9008"
|
||||
JoinAddrs: "127.0.0.1:9008"
|
||||
FKConstraints: true
|
||||
AutoVacInterval: 12h
|
||||
JoinAs: default
|
||||
@@ -1,17 +0,0 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-lib/database"
|
||||
"github.com/integration-system/isp-lib/structure"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
Database database.DBConfiguration `valid:"required~Required"`
|
||||
GrpcOuterAddress structure.AddressConfiguration `valid:"required~Required" json:"grpcOuterAddress"`
|
||||
ModuleName string `valid:"required~Required"`
|
||||
WS struct {
|
||||
Rest structure.AddressConfiguration `valid:"required~Required"`
|
||||
Grpc structure.AddressConfiguration `valid:"required~Required"`
|
||||
}
|
||||
Metrics structure.MetricConfiguration
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,19 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"github.com/rqlite/rqlite/v8/auth"
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
)
|
||||
|
||||
type Local struct {
|
||||
ConfigServiceAddress bootstrap.ConfigServiceAddr
|
||||
MaintenanceMode bool
|
||||
Credentials []auth.Credential
|
||||
KeepConfigVersions int `validate:"required"`
|
||||
InternalClientCredential string `validate:"required"`
|
||||
Rqlite Rqlite
|
||||
}
|
||||
|
||||
type Rqlite struct {
|
||||
NodeId string `validate:"required"`
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package conf
|
||||
|
||||
type Remote struct {
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
//nolint:lll
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type ConfigService interface {
|
||||
GetActiveConfigByModuleName(ctx context.Context, moduleName string) (*domain.Config, error)
|
||||
GetConfigsByModuleId(ctx context.Context, moduleId string) ([]domain.Config, error)
|
||||
CreateUpdateConfig(ctx context.Context, adminId int, req domain.CreateUpdateConfigRequest) (*domain.Config, error)
|
||||
GetConfigById(ctx context.Context, configId string) (*domain.Config, error)
|
||||
MarkConfigAsActive(ctx context.Context, configId string) error
|
||||
DeleteConfig(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
service ConfigService
|
||||
}
|
||||
|
||||
func NewConfig(service ConfigService) Config {
|
||||
return Config{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// GetActiveConfigByModuleName
|
||||
// @Summary Метод получения объекта конфигурации по названию модуля
|
||||
// @Description Возвращает активную конфиграцию по названию модуля
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.GetByModuleNameRequest true "название модуля"
|
||||
// @Success 200 {object} domain.Config
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2001` - модуль не найден<br/>`errorCode: 2002` - конфиг не найден"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/get_active_config_by_module_name [POST]
|
||||
func (c Config) GetActiveConfigByModuleName(ctx context.Context, req domain.GetByModuleNameRequest) (*domain.Config, error) {
|
||||
config, err := c.service.GetActiveConfigByModuleName(ctx, req.ModuleName)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrModuleNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeModuleNotFound,
|
||||
"module not found",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, entity.ErrConfigNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeConfigNotFound,
|
||||
"active config not found",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return config, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetConfigsByModuleId
|
||||
// @Summary Метод получения списка конфигураций по ID модуля
|
||||
// @Description Возвращает список конфиграции по ID модуля
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.GetByModuleIdRequest true "ID модуля"
|
||||
// @Success 200 {array} domain.Config
|
||||
// @Failure 400 {object} apierrors.Error "если идентификатор не указан"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/get_configs_by_module_id [POST]
|
||||
func (c Config) GetConfigsByModuleId(ctx context.Context, req domain.GetByModuleIdRequest) ([]domain.Config, error) {
|
||||
configs, err := c.service.GetConfigsByModuleId(ctx, req.ModuleId)
|
||||
switch {
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return configs, nil
|
||||
}
|
||||
}
|
||||
|
||||
// CreateUpdateConfig
|
||||
// @Summary Метод обновления конфигурации
|
||||
// @Description Если конфиг с таким id существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Description В случае обновления рассылает всем подключенным модулям актуальную конфигурацию
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.CreateUpdateConfigRequest true "объект для сохранения"
|
||||
// @Success 200 {object} domain.Config
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2003` - конфиг не соотвествует текущей схеме<br/>`errorCode: 2002` - указанного id не сущесвует<br/>`errorCode: 2004` - кто-то уже обновил конфигурацию<br/>`errorCode: 2005` - схема конфигурации не найдена<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/create_update_config [POST]
|
||||
func (c Config) CreateUpdateConfig(
|
||||
ctx context.Context,
|
||||
authData grpc.AuthData,
|
||||
req domain.CreateUpdateConfigRequest,
|
||||
) (*domain.Config, error) {
|
||||
adminIdValue, _ := grpc.StringFromMd("x-admin-id", metadata.MD(authData))
|
||||
var adminId int
|
||||
if adminIdValue != "" {
|
||||
adminId, _ = strconv.Atoi(adminIdValue)
|
||||
}
|
||||
|
||||
config, err := c.service.CreateUpdateConfig(ctx, adminId, req)
|
||||
|
||||
var validationError domain.ConfigValidationError
|
||||
switch {
|
||||
case errors.As(err, &validationError):
|
||||
details := map[string]any{}
|
||||
for key, value := range validationError.Details {
|
||||
details[key] = value
|
||||
}
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeInvalidConfig,
|
||||
"invalid config",
|
||||
err,
|
||||
).WithDetails(details)
|
||||
case errors.Is(err, entity.ErrConfigNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeConfigNotFound,
|
||||
"config not found",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, entity.ErrConfigConflictUpdate):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeConfigVersionConflict,
|
||||
"someone has updated the config",
|
||||
err,
|
||||
)
|
||||
case errors.Is(err, entity.ErrSchemaNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeSchemaNotFound,
|
||||
"config schema not found",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return config, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetConfigById
|
||||
// @Summary Метод получение конфигурации по id
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id конфигурации"
|
||||
// @Success 200 {object} domain.Config
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2002` - конфиг не найден<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/get_config_by_id [POST]
|
||||
func (c Config) GetConfigById(ctx context.Context, req domain.ConfigIdRequest) (*domain.Config, error) {
|
||||
config, err := c.service.GetConfigById(ctx, req.Id)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrConfigNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeConfigNotFound,
|
||||
"config not found",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return config, nil
|
||||
}
|
||||
}
|
||||
|
||||
// MarkConfigAsActive
|
||||
// @Summary Метод активации конфигурации для модуля
|
||||
// @Description Активирует указанную конфигурацию и деактивирует остальные, возвращает активированную конфигурацию
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id конфигурации для изменения"
|
||||
// @Success 200
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2002` - конфиг не найден<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/mark_config_as_active [POST]
|
||||
func (c Config) MarkConfigAsActive(ctx context.Context, identity domain.ConfigIdRequest) error {
|
||||
err := c.service.MarkConfigAsActive(ctx, identity.Id)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrConfigNotFound):
|
||||
return apierrors.NewBusinessError(
|
||||
domain.ErrorCodeConfigNotFound,
|
||||
"config not found",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteConfigs
|
||||
// @Summary Метод удаления объектов конфигурации по идентификаторам
|
||||
// @Description Возвращает количество удаленных модулей
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []string true "массив идентификаторов конфигураций"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} apierrors.Error "если не указан массив идентификаторов"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/delete_config [POST]
|
||||
func (c Config) DeleteConfigs(ctx context.Context, identities []string) (*domain.DeleteResponse, error) {
|
||||
configId, err := getSingleId(identities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = c.service.DeleteConfig(ctx, configId)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrConfigNotFoundOrActive):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeConfigNotFound,
|
||||
"config not found or is active",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return &domain.DeleteResponse{
|
||||
Deleted: 1,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"isp-config-service/domain"
|
||||
)
|
||||
|
||||
type ConfigHistoryService interface {
|
||||
GetAllVersions(ctx context.Context, configId string) ([]domain.ConfigVersion, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
type ConfigHistory struct {
|
||||
service ConfigHistoryService
|
||||
}
|
||||
|
||||
func NewConfigHistory(service ConfigHistoryService) ConfigHistory {
|
||||
return ConfigHistory{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAllVersion
|
||||
// @Summary Метод получение старых версий конфигурации
|
||||
// @Description Возвращает предыдущие версии конфигураций
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id конфигурации"
|
||||
// @Success 200 {array} domain.ConfigVersion
|
||||
// @Failure 400 {object} apierrors.Error "если не указан массив идентификаторов"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/get_all_version [POST]
|
||||
func (c ConfigHistory) GetAllVersion(ctx context.Context, req domain.ConfigIdRequest) ([]domain.ConfigVersion, error) {
|
||||
versions, err := c.service.GetAllVersions(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
// DeleteConfigVersion
|
||||
// @Summary Метод удаления версии конфигурации
|
||||
// @Description Возвращает количество удаленных версий
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id версии конфигурации"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} apierrors.Error "не указан массив идентификаторов"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/delete_version [POST]
|
||||
func (c ConfigHistory) DeleteConfigVersion(ctx context.Context, req domain.ConfigIdRequest) (*domain.DeleteResponse, error) {
|
||||
err := c.service.Delete(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return &domain.DeleteResponse{
|
||||
Deleted: 1,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type ConfigSchemaService interface {
|
||||
SchemaByModuleId(ctx context.Context, moduleId string) (*domain.ConfigSchema, error)
|
||||
}
|
||||
|
||||
type ConfigSchema struct {
|
||||
service ConfigSchemaService
|
||||
}
|
||||
|
||||
func NewConfigSchema(service ConfigSchemaService) ConfigSchema {
|
||||
return ConfigSchema{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// SchemaByModuleId
|
||||
// @Summary Метод получения схемы конфигурации модуля
|
||||
// @Description Возвращает текущую json схему конфигурации модуля
|
||||
// @Tags Схема
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.GetByModuleIdRequest true "идентификатор модуля"
|
||||
// @Success 200 {object} domain.ConfigSchema
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2005` - схема для модуля не найдена"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /schema/get_by_module_id [POST]
|
||||
func (c ConfigSchema) SchemaByModuleId(ctx context.Context, request domain.GetByModuleIdRequest) (*domain.ConfigSchema, error) {
|
||||
schema, err := c.service.SchemaByModuleId(ctx, request.ModuleId)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrSchemaNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeSchemaNotFound,
|
||||
"config schema not found",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return schema, nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"isp-config-service/domain"
|
||||
)
|
||||
|
||||
type ModuleService interface {
|
||||
Status(ctx context.Context) ([]domain.ModuleInfo, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
Connections(ctx context.Context) ([]domain.Connection, error)
|
||||
}
|
||||
|
||||
type Module struct {
|
||||
service ModuleService
|
||||
}
|
||||
|
||||
func NewModule(service ModuleService) Module {
|
||||
return Module{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// Status
|
||||
// @Summary Метод полчения полной информации о состоянии модулей
|
||||
// @Description Возвращает полное состояние всех модулей в кластере (схема конфигурации, подключенные экземпляры)
|
||||
// @Tags Модули
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.ModuleInfo
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /module/get_modules_info [POST]
|
||||
func (c Module) Status(ctx context.Context) ([]domain.ModuleInfo, error) {
|
||||
modulesInfo, err := c.service.Status(ctx)
|
||||
if err != nil {
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return modulesInfo, nil
|
||||
}
|
||||
|
||||
// DeleteModule
|
||||
// @Summary Метод удаления объектов модулей по идентификаторам
|
||||
// @Description Возвращает количество удаленных модулей
|
||||
// @Tags Модули
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []string true "массив идентификаторов модулей"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /module/delete_module [POST]
|
||||
func (c Module) DeleteModule(ctx context.Context, identities []string) (*domain.DeleteResponse, error) {
|
||||
id, err := getSingleId(identities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = c.service.Delete(ctx, id)
|
||||
if err != nil {
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
|
||||
return &domain.DeleteResponse{
|
||||
Deleted: len(identities),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Connections
|
||||
// @Summary Метод получения маршрутов
|
||||
// @Description Возвращает все доступные роуты
|
||||
// @Tags Модули
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.Connection
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /routing/get_routes [POST]
|
||||
func (c Module) Connections(ctx context.Context) ([]domain.Connection, error) {
|
||||
connections, err := c.service.Connections(ctx)
|
||||
if err != nil {
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return connections, nil
|
||||
}
|
||||
|
||||
func getSingleId(identities []string) (string, error) {
|
||||
if len(identities) == 0 {
|
||||
return "", apierrors.NewBusinessError(domain.ErrorCodeBadRequest, "at least one id is required", nil)
|
||||
}
|
||||
if len(identities) > 1 {
|
||||
return "", apierrors.NewBusinessError(domain.ErrorCodeBadRequest, "accept only single identity", nil)
|
||||
}
|
||||
return identities[0], nil
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/txix-open/etp/v4"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/etp/v4/msg"
|
||||
"github.com/txix-open/isp-kit/cluster"
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-config-service/helpers"
|
||||
)
|
||||
|
||||
var (
|
||||
ok = []byte("ok") //nolint:gochecknoglobals
|
||||
)
|
||||
|
||||
type ModuleService interface {
|
||||
OnConnect(ctx context.Context, conn *etp.Conn, moduleName string) error
|
||||
OnDisconnect(ctx context.Context, conn *etp.Conn, moduleName string, isNormalClose bool, err error) error
|
||||
OnError(ctx context.Context, conn *etp.Conn, err error)
|
||||
OnModuleReady(
|
||||
ctx context.Context,
|
||||
conn *etp.Conn,
|
||||
backend cluster.BackendDeclaration,
|
||||
) error
|
||||
OnModuleRequirements(
|
||||
ctx context.Context,
|
||||
conn *etp.Conn,
|
||||
requirements cluster.ModuleRequirements,
|
||||
) error
|
||||
OnModuleConfigSchema(
|
||||
ctx context.Context,
|
||||
conn *etp.Conn,
|
||||
data cluster.ConfigData,
|
||||
) error
|
||||
}
|
||||
|
||||
type Module struct {
|
||||
service ModuleService
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewModule(service ModuleService, logger log.Logger) Module {
|
||||
return Module{
|
||||
service: service,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (m Module) OnConnect(conn *etp.Conn) {
|
||||
ctx := conn.HttpRequest().Context()
|
||||
err := conn.HttpRequest().ParseForm()
|
||||
if err != nil {
|
||||
m.handleError(ctx, errors.WithMessage(err, "parse form"))
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
moduleName := helpers.ModuleName(conn)
|
||||
if moduleName == "" {
|
||||
m.handleError(ctx, errors.New("module_name is required query param"))
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
err = m.service.OnConnect(ctx, conn, moduleName)
|
||||
if err != nil {
|
||||
m.handleError(ctx, errors.WithMessage(err, "handle onConnect"))
|
||||
}
|
||||
}
|
||||
|
||||
func (m Module) OnDisconnect(conn *etp.Conn, err error) {
|
||||
ctx := conn.HttpRequest().Context()
|
||||
handleDisconnectErr := m.service.OnDisconnect(
|
||||
ctx,
|
||||
conn,
|
||||
helpers.ModuleName(conn),
|
||||
etp.IsNormalClose(err),
|
||||
err,
|
||||
)
|
||||
if handleDisconnectErr != nil {
|
||||
m.handleError(ctx, errors.WithMessage(handleDisconnectErr, "handle onDisconnect"))
|
||||
}
|
||||
}
|
||||
|
||||
func (m Module) OnError(conn *etp.Conn, err error) {
|
||||
m.service.OnError(conn.HttpRequest().Context(), conn, err)
|
||||
}
|
||||
|
||||
func (m Module) OnModuleReady(ctx context.Context, conn *etp.Conn, event msg.Event) []byte {
|
||||
backend := cluster.BackendDeclaration{}
|
||||
err := json.Unmarshal(event.Data, &backend)
|
||||
if err != nil {
|
||||
return m.handleError(ctx, errors.WithMessage(err, "unmarshal event data"))
|
||||
}
|
||||
|
||||
err = m.service.OnModuleReady(ctx, conn, backend)
|
||||
if err != nil {
|
||||
return m.handleError(ctx, errors.WithMessage(err, "handle onModuleReady"))
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
func (m Module) OnModuleRequirements(ctx context.Context, conn *etp.Conn, event msg.Event) []byte {
|
||||
requirements := cluster.ModuleRequirements{}
|
||||
err := json.Unmarshal(event.Data, &requirements)
|
||||
if err != nil {
|
||||
return m.handleError(ctx, errors.WithMessage(err, "unmarshal event data"))
|
||||
}
|
||||
|
||||
err = m.service.OnModuleRequirements(ctx, conn, requirements)
|
||||
if err != nil {
|
||||
return m.handleError(ctx, errors.WithMessage(err, "handle onModuleRequirements"))
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
func (m Module) OnModuleConfigSchema(ctx context.Context, conn *etp.Conn, event msg.Event) []byte {
|
||||
configData := cluster.ConfigData{}
|
||||
err := json.Unmarshal(event.Data, &configData)
|
||||
if err != nil {
|
||||
return m.handleError(ctx, errors.WithMessage(err, "unmarshal event data"))
|
||||
}
|
||||
|
||||
err = m.service.OnModuleConfigSchema(ctx, conn, configData)
|
||||
if err != nil {
|
||||
return m.handleError(ctx, errors.WithMessage(err, "handle onModuleConfigSchema"))
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
func (m Module) handleError(
|
||||
ctx context.Context,
|
||||
err error,
|
||||
) []byte {
|
||||
m.logger.Error(ctx, err)
|
||||
return []byte(err.Error())
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
st "isp-config-service/entity"
|
||||
"isp-config-service/model"
|
||||
"isp-config-service/socket"
|
||||
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-config-service/domain"
|
||||
)
|
||||
|
||||
func GetConfigs(identities []int64) ([]st.Config, error) {
|
||||
configs, err := model.ConfigRep.GetConfigs(identities)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
return configs, nil
|
||||
}
|
||||
|
||||
func GetConfigByInstanceUUIDAndModuleName(request st.ModuleInstanceIdentity) (*st.Config, error) {
|
||||
config, err := model.ConfigRep.GetConfigByInstanceUUIDAndModuleName(request.Uuid, request.Name)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
if config == nil {
|
||||
return nil, status.Error(codes.NotFound, utils.ValidationError)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func CreateUpdateConfig(config st.Config) (*st.Config, error) {
|
||||
var err error
|
||||
var cfg *st.Config
|
||||
if config.Id == 0 {
|
||||
cfg, err = model.ConfigRep.CreateConfig(&config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
configExists, err := model.ConfigRep.GetConfigById(config.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if configExists == nil {
|
||||
validationErrors := map[string]string{
|
||||
"id": fmt.Sprintf("Entity with id: %d not found", config.Id),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.NotFound, utils.ValidationError, validationErrors)
|
||||
}
|
||||
cfg, err = model.ConfigRep.UpdateConfig(&config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Active {
|
||||
moduleInstanceIdentity, err := model.ConfigRep.GetModuleNameAndInstanceUUIDByConfigId(cfg.Id)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
socket.SendNewConfig(moduleInstanceIdentity.Uuid, moduleInstanceIdentity.Name, cfg)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func UpdateActiveConfigByInstanceUUIDAndModuleName(configReq domain.ConfigInstanceModuleName) (*st.Config, error) {
|
||||
config, err := model.ConfigRep.GetConfigByInstanceUUIDAndModuleName(configReq.InstanceUuid, configReq.ModuleName)
|
||||
if err != nil || config == nil {
|
||||
validationErrors := map[string]string{
|
||||
"id": fmt.Sprintf("Active config for module: %s and instance uuid: %s not found",
|
||||
configReq.ModuleName, configReq.InstanceUuid),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.NotFound, utils.ValidationError, validationErrors)
|
||||
}
|
||||
config.Data = configReq.ConfigData
|
||||
return CreateUpdateConfig(*config)
|
||||
}
|
||||
|
||||
func MarkConfigAsActive(identity domain.LongIdentitiesRequest) (*st.Config, error) {
|
||||
configExists, err := model.ConfigRep.GetConfigById(identity.Id)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
if configExists == nil {
|
||||
validationErrors := map[string]string{
|
||||
"id": fmt.Sprintf("Entity with id: %d not found", identity.Id),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.NotFound, utils.ValidationError, validationErrors)
|
||||
}
|
||||
configExists.Active = true
|
||||
configExists, err = model.ConfigRep.UpdateConfig(configExists)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if configExists.Active {
|
||||
moduleInstanceIdentity, err := model.ConfigRep.GetModuleNameAndInstanceUUIDByConfigId(configExists.Id)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
socket.SendNewConfig(moduleInstanceIdentity.Uuid, moduleInstanceIdentity.Name, configExists)
|
||||
}
|
||||
|
||||
return configExists, nil
|
||||
}
|
||||
|
||||
func DeleteConfig(identities []int64) (*domain.DeleteResponse, error) {
|
||||
if len(identities) == 0 {
|
||||
validationErrors := map[string]string{
|
||||
"ids": "Required",
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.InvalidArgument, utils.ValidationError, validationErrors)
|
||||
}
|
||||
count, err := model.ConfigRep.DeleteConfig(identities)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
return &domain.DeleteResponse{Deleted: count}, err
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
st "isp-config-service/entity"
|
||||
"isp-config-service/model"
|
||||
|
||||
"isp-config-service/domain"
|
||||
|
||||
"github.com/integration-system/isp-lib/logger"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func GetInstances(identities []int32) ([]st.Instance, error) {
|
||||
instances, err := model.InstanceRep.GetInstances(identities)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
return instances, err
|
||||
}
|
||||
|
||||
func CreateUpdateInstance(instance st.Instance) (*st.Instance, error) {
|
||||
if instance.Id == 0 {
|
||||
moduleExists, err := model.InstanceRep.GetInstanceByUuid(instance.Uuid)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
if moduleExists.Id != 0 {
|
||||
validationErrors := map[string]string{
|
||||
"name": fmt.Sprintf("Entity with uuid: %s already exists", instance.Name),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.AlreadyExists, utils.ValidationError, validationErrors)
|
||||
}
|
||||
instance, err = model.InstanceRep.CreateInstance(instance)
|
||||
} else {
|
||||
instanceExists, err := model.InstanceRep.GetInstanceById(instance.Id)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
if instanceExists.Id == 0 {
|
||||
validationErrors := map[string]string{
|
||||
"id": fmt.Sprintf("Entity with id: %d not found", instance.Id),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.NotFound, utils.ValidationError, validationErrors)
|
||||
}
|
||||
instance, err = model.InstanceRep.UpdateInstance(instance)
|
||||
instance.CreatedAt = instanceExists.CreatedAt
|
||||
}
|
||||
|
||||
return &instance, nil
|
||||
}
|
||||
|
||||
func DeleteInstance(identities []int32) (*domain.DeleteResponse, error) {
|
||||
if len(identities) == 0 {
|
||||
validationErrors := map[string]string{
|
||||
"ids": "Required",
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.InvalidArgument, utils.ValidationError, validationErrors)
|
||||
}
|
||||
count, err := model.InstanceRep.DeleteInstance(identities)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
return &domain.DeleteResponse{Deleted: count}, err
|
||||
}
|
||||
|
||||
func createUnknownError(err error) error {
|
||||
logger.Error(err)
|
||||
return status.Error(codes.Unknown, utils.ServiceError)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package controllers
|
||||
|
||||
/*var HandlerSwagger = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
values, err := url.ParseQuery(r.URL.RawQuery)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte("Method not received"))
|
||||
}
|
||||
method := values.Get("method")
|
||||
if method == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte("Method not received"))
|
||||
}
|
||||
proxyRequestHandle(w, r, method)
|
||||
})
|
||||
*/
|
||||
@@ -1,113 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
st "isp-config-service/entity"
|
||||
"isp-config-service/model"
|
||||
"isp-config-service/module"
|
||||
"isp-config-service/socket"
|
||||
|
||||
"isp-config-service/domain"
|
||||
|
||||
"github.com/integration-system/isp-lib/structure"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
func GetModules(identities []int32) ([]st.Module, error) {
|
||||
modules, err := model.ModulesRep.GetModules(identities)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
|
||||
return modules, nil
|
||||
}
|
||||
|
||||
func GetModulesAggregatedInfo(i structure.Isolation) ([]*domain.ModuleInfo, error) {
|
||||
instanceId, err := i.GetInstanceId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return module.GetAggregatedModuleInfo(instanceId)
|
||||
}
|
||||
|
||||
func GetActiveModules() ([]st.Module, error) {
|
||||
modules, err := model.ModulesRep.GetActiveModules()
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
|
||||
return modules, nil
|
||||
}
|
||||
|
||||
func GetConnectedModules() (map[string]interface{}, error) {
|
||||
modules := socket.GetRoomsCount()
|
||||
bytes, err := json.Marshal(modules)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
var response map[string]interface{}
|
||||
err = json.Unmarshal(bytes, &response)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func CreateUpdateModule(module st.Module) (*st.Module, error) {
|
||||
if module.Id == 0 {
|
||||
instanceExists, err := model.InstanceRep.GetInstanceById(module.InstanceId)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
if instanceExists.Id == 0 {
|
||||
validationErrors := map[string]string{
|
||||
"instanceId": fmt.Sprintf("Entity with instanceId: %d not found", module.InstanceId),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.NotFound, utils.ValidationError, validationErrors)
|
||||
}
|
||||
moduleExists, err := model.ModulesRep.GetModuleByInstanceIdAndName(module.InstanceId, module.Name)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
if moduleExists.Id != 0 {
|
||||
validationErrors := map[string]string{
|
||||
"name": fmt.Sprintf("Entity with name: %s already exists", module.Name),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.AlreadyExists, utils.ValidationError, validationErrors)
|
||||
}
|
||||
module, err = model.ModulesRep.CreateModule(module)
|
||||
} else {
|
||||
moduleExists, err := model.ModulesRep.GetModuleById(module.Id)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
if moduleExists.Id == 0 {
|
||||
validationErrors := map[string]string{
|
||||
"id": fmt.Sprintf("Entity with id: %d not found", module.Id),
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.NotFound, utils.ValidationError, validationErrors)
|
||||
}
|
||||
module, err = model.ModulesRep.UpdateModule(module)
|
||||
module.CreatedAt = moduleExists.CreatedAt
|
||||
module.Active = moduleExists.Active
|
||||
}
|
||||
|
||||
return &module, nil
|
||||
}
|
||||
|
||||
func DeleteModule(identities []int32) (*domain.DeleteResponse, error) {
|
||||
if len(identities) == 0 {
|
||||
validationErrors := map[string]string{
|
||||
"ids": "Required",
|
||||
}
|
||||
return nil, utils.CreateValidationErrorDetails(codes.InvalidArgument, utils.ValidationError, validationErrors)
|
||||
}
|
||||
count, err := model.ModulesRep.DeleteModule(identities)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
return &domain.DeleteResponse{Deleted: count}, err
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"isp-config-service/socket"
|
||||
)
|
||||
|
||||
func GetRoutes() (map[string]interface{}, error) {
|
||||
bytes, err := json.Marshal(socket.GetRoutes().Routes)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
var response map[string]interface{}
|
||||
err = json.Unmarshal(bytes, &response)
|
||||
if err != nil {
|
||||
return nil, createUnknownError(err)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
basePath: /api/config
|
||||
definitions:
|
||||
domain.Address:
|
||||
properties:
|
||||
ip:
|
||||
type: string
|
||||
port:
|
||||
type: string
|
||||
type: object
|
||||
domain.Config:
|
||||
properties:
|
||||
active:
|
||||
type: boolean
|
||||
createdAt:
|
||||
type: string
|
||||
data:
|
||||
type: object
|
||||
id:
|
||||
type: string
|
||||
moduleId:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
updatedAt:
|
||||
type: string
|
||||
valid:
|
||||
type: boolean
|
||||
version:
|
||||
type: integer
|
||||
type: object
|
||||
domain.ConfigIdRequest:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
type: object
|
||||
domain.ConfigSchema:
|
||||
properties:
|
||||
createdAt:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
moduleId:
|
||||
type: string
|
||||
schema:
|
||||
type: object
|
||||
updatedAt:
|
||||
type: string
|
||||
version:
|
||||
type: string
|
||||
type: object
|
||||
domain.ConfigVersion:
|
||||
properties:
|
||||
configId:
|
||||
type: string
|
||||
configVersion:
|
||||
type: integer
|
||||
createdAt:
|
||||
type: string
|
||||
data:
|
||||
type: object
|
||||
id:
|
||||
type: string
|
||||
type: object
|
||||
domain.Connection:
|
||||
properties:
|
||||
address:
|
||||
$ref: '#/definitions/domain.Address'
|
||||
endpoints:
|
||||
items:
|
||||
$ref: '#/definitions/domain.EndpointDescriptor'
|
||||
type: array
|
||||
establishedAt:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
libVersion:
|
||||
type: string
|
||||
moduleName:
|
||||
type: string
|
||||
version:
|
||||
type: string
|
||||
type: object
|
||||
domain.CreateUpdateConfigRequest:
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
id:
|
||||
type: string
|
||||
moduleId:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
unsafe:
|
||||
type: boolean
|
||||
version:
|
||||
type: integer
|
||||
required:
|
||||
- moduleId
|
||||
- name
|
||||
type: object
|
||||
domain.DeleteResponse:
|
||||
properties:
|
||||
deleted:
|
||||
type: integer
|
||||
type: object
|
||||
domain.EndpointDescriptor:
|
||||
properties:
|
||||
inner:
|
||||
type: boolean
|
||||
path:
|
||||
type: string
|
||||
type: object
|
||||
domain.GetByModuleIdRequest:
|
||||
properties:
|
||||
moduleId:
|
||||
type: string
|
||||
required:
|
||||
- moduleId
|
||||
type: object
|
||||
domain.GetByModuleNameRequest:
|
||||
properties:
|
||||
moduleName:
|
||||
type: string
|
||||
required:
|
||||
- moduleName
|
||||
type: object
|
||||
domain.ModuleInfo:
|
||||
properties:
|
||||
active:
|
||||
type: boolean
|
||||
configSchema:
|
||||
type: object
|
||||
createdAt:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
lastConnectedAt:
|
||||
type: string
|
||||
lastDisconnectedAt:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
status:
|
||||
items:
|
||||
$ref: '#/definitions/domain.Connection'
|
||||
type: array
|
||||
type: object
|
||||
github_com_txix-open_isp-kit_grpc_apierrors.Error:
|
||||
properties:
|
||||
details:
|
||||
additionalProperties: true
|
||||
type: object
|
||||
errorCode:
|
||||
type: integer
|
||||
errorMessage:
|
||||
type: string
|
||||
type: object
|
||||
host: localhost:9000
|
||||
info:
|
||||
contact: {}
|
||||
description: Модуль управления конфигурациями
|
||||
license:
|
||||
name: GNU GPL v3.0
|
||||
title: isp-config-service
|
||||
version: 3.0.0
|
||||
paths:
|
||||
/config/create_update_config:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: |-
|
||||
Если конфиг с таким id существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
В случае обновления рассылает всем подключенным модулям актуальную конфигурацию
|
||||
parameters:
|
||||
- description: объект для сохранения
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.CreateUpdateConfigRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Config'
|
||||
"400":
|
||||
description: '`errorCode: 2003` - конфиг не соотвествует текущей схеме<br/>`errorCode:
|
||||
2002` - указанного id не сущесвует<br/>`errorCode: 2004` - кто-то уже
|
||||
обновил конфигурацию<br/>`errorCode: 2005` - схема конфигурации не найдена<br/>'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод обновления конфигурации
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/delete_config:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает количество удаленных модулей
|
||||
parameters:
|
||||
- description: массив идентификаторов конфигураций
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"400":
|
||||
description: если не указан массив идентификаторов
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод удаления объектов конфигурации по идентификаторам
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/delete_version:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает количество удаленных версий
|
||||
parameters:
|
||||
- description: id версии конфигурации
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"400":
|
||||
description: не указан массив идентификаторов
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод удаления версии конфигурации
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/get_active_config_by_module_name:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает активную конфиграцию по названию модуля
|
||||
parameters:
|
||||
- description: название модуля
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GetByModuleNameRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Config'
|
||||
"400":
|
||||
description: '`errorCode: 2001` - модуль не найден<br/>`errorCode: 2002`
|
||||
- конфиг не найден'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получения объекта конфигурации по названию модуля
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/get_all_version:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает предыдущие версии конфигураций
|
||||
parameters:
|
||||
- description: id конфигурации
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.ConfigVersion'
|
||||
type: array
|
||||
"400":
|
||||
description: если не указан массив идентификаторов
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получение старых версий конфигурации
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/get_config_by_id:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: id конфигурации
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Config'
|
||||
"400":
|
||||
description: '`errorCode: 2002` - конфиг не найден<br/>'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получение конфигурации по id
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/get_configs_by_module_id:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает список конфиграции по ID модуля
|
||||
parameters:
|
||||
- description: ID модуля
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GetByModuleIdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.Config'
|
||||
type: array
|
||||
"400":
|
||||
description: если идентификатор не указан
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получения списка конфигураций по ID модуля
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/mark_config_as_active:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Активирует указанную конфигурацию и деактивирует остальные, возвращает
|
||||
активированную конфигурацию
|
||||
parameters:
|
||||
- description: id конфигурации для изменения
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
"400":
|
||||
description: '`errorCode: 2002` - конфиг не найден<br/>'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод активации конфигурации для модуля
|
||||
tags:
|
||||
- Конфигурация
|
||||
/module/delete_module:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает количество удаленных модулей
|
||||
parameters:
|
||||
- description: массив идентификаторов модулей
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод удаления объектов модулей по идентификаторам
|
||||
tags:
|
||||
- Модули
|
||||
/module/get_modules_info:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает полное состояние всех модулей в кластере (схема конфигурации,
|
||||
подключенные экземпляры)
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.ModuleInfo'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод полчения полной информации о состоянии модулей
|
||||
tags:
|
||||
- Модули
|
||||
/routing/get_routes:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает все доступные роуты
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.Connection'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получения маршрутов
|
||||
tags:
|
||||
- Модули
|
||||
/schema/get_by_module_id:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Возвращает текущую json схему конфигурации модуля
|
||||
parameters:
|
||||
- description: идентификатор модуля
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GetByModuleIdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigSchema'
|
||||
"400":
|
||||
description: '`errorCode: 2005` - схема для модуля не найдена'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получения схемы конфигурации модуля
|
||||
tags:
|
||||
- Схема
|
||||
swagger: "2.0"
|
||||
@@ -0,0 +1,33 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorCodeBadRequest = 400
|
||||
ErrorCodeModuleNotFound = 2001
|
||||
ErrorCodeConfigNotFound = 2002
|
||||
ErrorCodeInvalidConfig = 2003
|
||||
ErrorCodeConfigVersionConflict = 2004
|
||||
ErrorCodeSchemaNotFound = 2005
|
||||
)
|
||||
|
||||
type ConfigValidationError struct {
|
||||
Details map[string]string
|
||||
}
|
||||
|
||||
func NewConfigValidationError(details map[string]string) ConfigValidationError {
|
||||
return ConfigValidationError{
|
||||
Details: details,
|
||||
}
|
||||
}
|
||||
|
||||
func (e ConfigValidationError) Error() string {
|
||||
descriptions := make([]string, 0, len(e.Details))
|
||||
for field, err := range e.Details {
|
||||
descriptions = append(descriptions, fmt.Sprintf("%s -> %s", field, err))
|
||||
}
|
||||
return strings.Join(descriptions, "; ")
|
||||
}
|
||||
+19
-8
@@ -1,15 +1,26 @@
|
||||
package domain
|
||||
|
||||
type IdentitiesRequest struct {
|
||||
Ids []int32 `json:"ids" valid:"required~Required"`
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
)
|
||||
|
||||
type ConfigIdRequest struct {
|
||||
Id string `validate:"required"`
|
||||
}
|
||||
|
||||
type LongIdentitiesRequest struct {
|
||||
Id int64 `json:"id" valid:"required~Required"`
|
||||
type GetByModuleIdRequest struct {
|
||||
ModuleId string `validate:"required"`
|
||||
}
|
||||
|
||||
type ConfigInstanceModuleName struct {
|
||||
ModuleName string `valid:"required~Required"`
|
||||
InstanceUuid string `valid:"required~Required"`
|
||||
ConfigData map[string]interface{} `valid:"required~Required"`
|
||||
type GetByModuleNameRequest struct {
|
||||
ModuleName string `validate:"required"`
|
||||
}
|
||||
|
||||
type CreateUpdateConfigRequest struct {
|
||||
Id string
|
||||
Name string `validate:"required"`
|
||||
ModuleId string `validate:"required"`
|
||||
Version int
|
||||
Data json.RawMessage `swaggertype:"object"`
|
||||
Unsafe bool
|
||||
}
|
||||
+53
-16
@@ -3,32 +3,69 @@ package domain
|
||||
import (
|
||||
"time"
|
||||
|
||||
"isp-config-service/entity"
|
||||
|
||||
"github.com/integration-system/isp-lib/config/schema"
|
||||
"github.com/integration-system/isp-lib/structure"
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
)
|
||||
|
||||
type DeleteResponse struct {
|
||||
Deleted int
|
||||
}
|
||||
|
||||
type ModuleInfo struct {
|
||||
Id string
|
||||
Name string
|
||||
Active bool
|
||||
LastConnectedAt *time.Time
|
||||
LastDisconnectedAt *time.Time
|
||||
ConfigSchema json.RawMessage `swaggertype:"object"`
|
||||
Status []Connection
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
Id string
|
||||
ModuleName string
|
||||
LibVersion string
|
||||
Version string
|
||||
Address structure.AddressConfiguration
|
||||
Endpoints []structure.EndpointConfig `json:",omitempty"`
|
||||
Address Address
|
||||
Endpoints []EndpointDescriptor
|
||||
EstablishedAt time.Time
|
||||
}
|
||||
|
||||
type ModuleInfo struct {
|
||||
Id int32
|
||||
Name string
|
||||
Active bool
|
||||
CreatedAt time.Time
|
||||
LastConnectedAt time.Time
|
||||
LastDisconnectedAt time.Time
|
||||
Configs []entity.Config `json:",omitempty"`
|
||||
ConfigSchema *schema.Schema `json:",omitempty"`
|
||||
Status []Connection `json:",omitempty"`
|
||||
type Address struct {
|
||||
Ip string
|
||||
Port string
|
||||
}
|
||||
|
||||
type EndpointDescriptor struct {
|
||||
Path string
|
||||
Inner bool
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Id string
|
||||
Name string
|
||||
ModuleId string
|
||||
Valid bool
|
||||
Data json.RawMessage `swaggertype:"object"`
|
||||
Version int
|
||||
Active bool
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type ConfigVersion struct {
|
||||
Id string
|
||||
ConfigId string
|
||||
ConfigVersion int
|
||||
Data json.RawMessage `swaggertype:"object"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type ConfigSchema struct {
|
||||
Id string
|
||||
Version string
|
||||
ModuleId string
|
||||
Schema json.RawMessage `swaggertype:"object"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/cluster"
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
type Backend struct {
|
||||
WsConnectionId string `json:"ws_connection_id"`
|
||||
ModuleId string `json:"module_id"`
|
||||
Address string `json:"address"`
|
||||
Version string `json:"version"`
|
||||
LibVersion string `json:"lib_version"`
|
||||
ModuleName string `json:"module_name"`
|
||||
ConfigServiceNodeId string `json:"config_service_node_id"`
|
||||
Endpoints xtypes.Json[[]cluster.EndpointDescriptor] `json:"endpoints"`
|
||||
RequiredModules xtypes.Json[[]cluster.ModuleDependency] `json:"required_modules"`
|
||||
CreatedAt xtypes.Time `json:"created_at"`
|
||||
}
|
||||
+24
-29
@@ -1,40 +1,35 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/integration-system/isp-lib/config/schema"
|
||||
"github.com/integration-system/isp-lib/logger"
|
||||
"time"
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
type ConfigData map[string]interface{}
|
||||
|
||||
func (cd ConfigData) ToJSON() string {
|
||||
if bytes, err := json.Marshal(cd); err == nil {
|
||||
return string(bytes)
|
||||
} else {
|
||||
logger.Warn("Could not serialize config data to JSON", err)
|
||||
return "{}"
|
||||
}
|
||||
type Config struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ModuleId string `json:"module_id"`
|
||||
Data []byte `json:"data"`
|
||||
Version int `json:"version"`
|
||||
Active xtypes.Bool `json:"active"`
|
||||
AdminId int `json:"admin_id"`
|
||||
CreatedAt xtypes.Time `json:"created_at"`
|
||||
UpdatedAt xtypes.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name" valid:"required~Required"`
|
||||
Description string `json:"description"`
|
||||
ModuleId int32 `json:"moduleId" valid:"required~Required"`
|
||||
Version int32 `json:"version" sql:",null"`
|
||||
Active bool `json:"active" sql:",null"`
|
||||
CreatedAt time.Time `json:"createdAt" sql:",null"`
|
||||
UpdatedAt time.Time `json:"updatedAt" sql:",null"`
|
||||
Data ConfigData `json:"data" sql:",notnull"`
|
||||
type ConfigHistory struct {
|
||||
Id string `json:"id"`
|
||||
ConfigId string `json:"config_id"`
|
||||
Data []byte `json:"data"`
|
||||
Version int `json:"version"`
|
||||
AdminId int `json:"admin_id"`
|
||||
CreatedAt xtypes.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type ConfigSchema struct {
|
||||
Id int32
|
||||
Version string
|
||||
ModuleId int32
|
||||
Schema schema.Schema
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Id string `json:"id"`
|
||||
ModuleId string `json:"module_id"`
|
||||
Data []byte `json:"data"`
|
||||
ModuleVersion string `json:"module_version"`
|
||||
CreatedAt xtypes.Time `json:"created_at"`
|
||||
UpdatedAt xtypes.Time `json:"updated_at"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrConfigNotFound = errors.New("no active config")
|
||||
ErrModuleNotFound = errors.New("module not found")
|
||||
ErrSchemaNotFound = errors.New("config schema not found")
|
||||
ErrConfigNotFoundOrActive = errors.New("config not found or markers as active")
|
||||
ErrConfigConflictUpdate = errors.New("config conflict update")
|
||||
)
|
||||
@@ -0,0 +1,51 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Id int `json:"id"`
|
||||
Payload xtypes.Json[EventPayload] `json:"payload"`
|
||||
}
|
||||
|
||||
func NewEvent(payload EventPayload) Event {
|
||||
return Event{
|
||||
Payload: xtypes.Json[EventPayload]{
|
||||
Value: payload,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (e Event) Key() string {
|
||||
switch {
|
||||
case e.Payload.Value.ConfigUpdated != nil:
|
||||
return fmt.Sprintf("config_updated_%s", e.Payload.Value.ConfigUpdated.ModuleId)
|
||||
case e.Payload.Value.ModuleReady != nil:
|
||||
return fmt.Sprintf("module_lifecycle_%s", e.Payload.Value.ModuleReady.ModuleId)
|
||||
case e.Payload.Value.ModuleDisconnected != nil:
|
||||
return fmt.Sprintf("module_lifecycle_%s", e.Payload.Value.ModuleDisconnected.ModuleId)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
type EventPayload struct {
|
||||
ConfigUpdated *PayloadConfigUpdated `json:",omitempty"`
|
||||
ModuleReady *PayloadModuleReady `json:",omitempty"`
|
||||
ModuleDisconnected *PayloadModuleDisconnected `json:",omitempty"`
|
||||
}
|
||||
|
||||
type PayloadConfigUpdated struct {
|
||||
ModuleId string
|
||||
}
|
||||
|
||||
type PayloadModuleReady struct {
|
||||
ModuleId string
|
||||
}
|
||||
|
||||
type PayloadModuleDisconnected struct {
|
||||
ModuleId string
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
Id int32 `json:"id"`
|
||||
Uuid string `json:"uuid" valid:"required~Required,uuid~must be a valid uuid"`
|
||||
Name string `json:"name" valid:"required~Required"`
|
||||
// CreatedAtJson utils.JSONTime `json:"createdAt" sql:"-"`
|
||||
CreatedAt time.Time `json:"createdAt" sql:",null"`
|
||||
}
|
||||
+6
-13
@@ -1,20 +1,13 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
type Module struct {
|
||||
Id int32 `json:"id"`
|
||||
InstanceId int32 `json:"instanceId" valid:"required~Required"`
|
||||
Name string `json:"name" valid:"required~Required"`
|
||||
Active bool `json:"active" sql:",null"`
|
||||
CreatedAt time.Time `json:"createdAt" sql:",null"`
|
||||
LastConnectedAt time.Time `json:"lastConnectedAt"`
|
||||
LastDisconnectedAt time.Time `json:"lastDisconnectedAt"`
|
||||
}
|
||||
|
||||
type ModuleInstanceIdentity struct {
|
||||
Name string `valid:"required~Required"`
|
||||
Uuid string `valid:"required~Required,uuid~must be a valid uuid"`
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
LastConnectedAt *xtypes.Time `json:"last_connected_at"`
|
||||
LastDisconnectedAt *xtypes.Time `json:"last_disconnected_at"`
|
||||
CreatedAt xtypes.Time `json:"created_at"`
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package xtypes
|
||||
|
||||
type Bool bool
|
||||
|
||||
func (l Bool) MarshalJSON() ([]byte, error) {
|
||||
return l.MarshalText()
|
||||
}
|
||||
|
||||
func (l *Bool) UnmarshalJSON(data []byte) error {
|
||||
return l.UnmarshalText(data)
|
||||
}
|
||||
|
||||
func (l Bool) MarshalText() ([]byte, error) {
|
||||
if l {
|
||||
return []byte("1"), nil
|
||||
}
|
||||
return []byte("0"), nil
|
||||
}
|
||||
|
||||
func (l *Bool) UnmarshalText(data []byte) error {
|
||||
*l = string(data) == "1"
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package xtypes
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
)
|
||||
|
||||
type Json[T any] struct {
|
||||
Value T
|
||||
}
|
||||
|
||||
func (l Json[T]) MarshalJSON() ([]byte, error) {
|
||||
data, err := l.MarshalText()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte(strconv.Quote(string(data))), nil
|
||||
}
|
||||
|
||||
func (l *Json[T]) UnmarshalJSON(data []byte) error {
|
||||
s, err := strconv.Unquote(string(data))
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "unquote text")
|
||||
}
|
||||
return l.UnmarshalText([]byte(s))
|
||||
}
|
||||
|
||||
func (l Json[T]) MarshalText() ([]byte, error) {
|
||||
data, err := json.Marshal(l.Value)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "marshal json")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (l *Json[T]) UnmarshalText(data []byte) error {
|
||||
err := json.Unmarshal(data, &l.Value)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "unmarshal json")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package xtypes
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Time time.Time
|
||||
|
||||
func (l Time) MarshalJSON() ([]byte, error) {
|
||||
return l.MarshalText()
|
||||
}
|
||||
|
||||
func (l *Time) UnmarshalJSON(data []byte) error {
|
||||
return l.UnmarshalText(data)
|
||||
}
|
||||
|
||||
func (l Time) MarshalText() ([]byte, error) {
|
||||
t := time.Time(l)
|
||||
value := strconv.Itoa(int(t.Unix()))
|
||||
return []byte(value), nil
|
||||
}
|
||||
|
||||
func (l *Time) UnmarshalText(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
value, err := strconv.Atoi(string(data))
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "parse int: %s", string(data))
|
||||
}
|
||||
*l = Time(time.Unix(int64(value), 0))
|
||||
return nil
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: proto/backend_service.proto
|
||||
|
||||
/*
|
||||
Package isp is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
proto/backend_service.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Message
|
||||
*/
|
||||
package isp
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import _ "google.golang.org/genproto/googleapis/api/annotations"
|
||||
import google_protobuf1 "github.com/golang/protobuf/ptypes/struct"
|
||||
|
||||
import (
|
||||
context "golang.org/x/net/context"
|
||||
grpc "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Message struct {
|
||||
// Types that are valid to be assigned to Body:
|
||||
// *Message_StructBody
|
||||
// *Message_ListBody
|
||||
Body isMessage_Body `protobuf_oneof:"body"`
|
||||
}
|
||||
|
||||
func (m *Message) Reset() { *m = Message{} }
|
||||
func (m *Message) String() string { return proto.CompactTextString(m) }
|
||||
func (*Message) ProtoMessage() {}
|
||||
func (*Message) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
|
||||
type isMessage_Body interface {
|
||||
isMessage_Body()
|
||||
}
|
||||
|
||||
type Message_StructBody struct {
|
||||
StructBody *google_protobuf1.Struct `protobuf:"bytes,1,opt,name=structBody,oneof"`
|
||||
}
|
||||
type Message_ListBody struct {
|
||||
ListBody *google_protobuf1.ListValue `protobuf:"bytes,2,opt,name=listBody,oneof"`
|
||||
}
|
||||
|
||||
func (*Message_StructBody) isMessage_Body() {}
|
||||
func (*Message_ListBody) isMessage_Body() {}
|
||||
|
||||
func (m *Message) GetBody() isMessage_Body {
|
||||
if m != nil {
|
||||
return m.Body
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Message) GetStructBody() *google_protobuf1.Struct {
|
||||
if x, ok := m.GetBody().(*Message_StructBody); ok {
|
||||
return x.StructBody
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Message) GetListBody() *google_protobuf1.ListValue {
|
||||
if x, ok := m.GetBody().(*Message_ListBody); ok {
|
||||
return x.ListBody
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||
func (*Message) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
|
||||
return _Message_OneofMarshaler, _Message_OneofUnmarshaler, _Message_OneofSizer, []interface{}{
|
||||
(*Message_StructBody)(nil),
|
||||
(*Message_ListBody)(nil),
|
||||
}
|
||||
}
|
||||
|
||||
func _Message_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||
m := msg.(*Message)
|
||||
// body
|
||||
switch x := m.Body.(type) {
|
||||
case *Message_StructBody:
|
||||
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||
if err := b.EncodeMessage(x.StructBody); err != nil {
|
||||
return err
|
||||
}
|
||||
case *Message_ListBody:
|
||||
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||
if err := b.EncodeMessage(x.ListBody); err != nil {
|
||||
return err
|
||||
}
|
||||
case nil:
|
||||
default:
|
||||
return fmt.Errorf("Message.Body has unexpected type %T", x)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _Message_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||
m := msg.(*Message)
|
||||
switch tag {
|
||||
case 1: // body.structBody
|
||||
if wire != proto.WireBytes {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
msg := new(google_protobuf1.Struct)
|
||||
err := b.DecodeMessage(msg)
|
||||
m.Body = &Message_StructBody{msg}
|
||||
return true, err
|
||||
case 2: // body.listBody
|
||||
if wire != proto.WireBytes {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
msg := new(google_protobuf1.ListValue)
|
||||
err := b.DecodeMessage(msg)
|
||||
m.Body = &Message_ListBody{msg}
|
||||
return true, err
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func _Message_OneofSizer(msg proto.Message) (n int) {
|
||||
m := msg.(*Message)
|
||||
// body
|
||||
switch x := m.Body.(type) {
|
||||
case *Message_StructBody:
|
||||
s := proto.Size(x.StructBody)
|
||||
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||
n += proto.SizeVarint(uint64(s))
|
||||
n += s
|
||||
case *Message_ListBody:
|
||||
s := proto.Size(x.ListBody)
|
||||
n += proto.SizeVarint(2<<3 | proto.WireBytes)
|
||||
n += proto.SizeVarint(uint64(s))
|
||||
n += s
|
||||
case nil:
|
||||
default:
|
||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Message)(nil), "isp.Message")
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion4
|
||||
|
||||
// Client API for BackendService service
|
||||
|
||||
type BackendServiceClient interface {
|
||||
// ===== SYSTEM =====
|
||||
Request(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error)
|
||||
}
|
||||
|
||||
type backendServiceClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewBackendServiceClient(cc *grpc.ClientConn) BackendServiceClient {
|
||||
return &backendServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *backendServiceClient) Request(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) {
|
||||
out := new(Message)
|
||||
err := grpc.Invoke(ctx, "/isp.BackendService/Request", in, out, c.cc, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for BackendService service
|
||||
|
||||
type BackendServiceServer interface {
|
||||
// ===== SYSTEM =====
|
||||
Request(context.Context, *Message) (*Message, error)
|
||||
}
|
||||
|
||||
func RegisterBackendServiceServer(s *grpc.Server, srv BackendServiceServer) {
|
||||
s.RegisterService(&_BackendService_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _BackendService_Request_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Message)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BackendServiceServer).Request(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/isp.BackendService/Request",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BackendServiceServer).Request(ctx, req.(*Message))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _BackendService_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "isp.BackendService",
|
||||
HandlerType: (*BackendServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Request",
|
||||
Handler: _BackendService_Request_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "proto/backend_service.proto",
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("proto/backend_service.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 264 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2e, 0x28, 0xca, 0x2f,
|
||||
0xc9, 0xd7, 0x4f, 0x4a, 0x4c, 0xce, 0x4e, 0xcd, 0x4b, 0x89, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c,
|
||||
0x4e, 0xd5, 0x03, 0x8b, 0x0a, 0x31, 0xe7, 0x16, 0x17, 0x48, 0xc9, 0xa4, 0xe7, 0xe7, 0xa7, 0xe7,
|
||||
0xa4, 0xea, 0x27, 0x16, 0x64, 0xea, 0x27, 0xe6, 0xe5, 0xe5, 0x97, 0x24, 0x96, 0x64, 0xe6, 0xe7,
|
||||
0x15, 0x43, 0x94, 0xc0, 0x65, 0xc1, 0xbc, 0xa4, 0xd2, 0x34, 0xfd, 0xe2, 0x92, 0xa2, 0xd2, 0xe4,
|
||||
0x12, 0x88, 0xac, 0x52, 0x1b, 0x23, 0x17, 0xbb, 0x6f, 0x6a, 0x71, 0x71, 0x62, 0x7a, 0xaa, 0x90,
|
||||
0x25, 0x17, 0x17, 0x44, 0xce, 0x29, 0x3f, 0xa5, 0x52, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48,
|
||||
0x5c, 0x0f, 0xa2, 0x5d, 0x0f, 0xa6, 0x5d, 0x2f, 0x18, 0xac, 0xc4, 0x83, 0x21, 0x08, 0x49, 0xb1,
|
||||
0x90, 0x05, 0x17, 0x47, 0x4e, 0x66, 0x31, 0x44, 0x23, 0x13, 0x58, 0xa3, 0x14, 0x86, 0x46, 0x9f,
|
||||
0xcc, 0xe2, 0x92, 0xb0, 0xc4, 0x9c, 0xd2, 0x54, 0x0f, 0x86, 0x20, 0xb8, 0x6a, 0x27, 0x36, 0x2e,
|
||||
0x96, 0xa4, 0xfc, 0x94, 0x4a, 0x23, 0x0f, 0x2e, 0x3e, 0x27, 0x88, 0x17, 0x83, 0x21, 0x3e, 0x14,
|
||||
0x32, 0xe3, 0x62, 0x0f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x11, 0xe2, 0xd1, 0xcb, 0x2d, 0x2e,
|
||||
0xd0, 0x83, 0xba, 0x53, 0x0a, 0x85, 0xa7, 0xc4, 0xdf, 0x74, 0xf9, 0xc9, 0x64, 0x26, 0x4e, 0x25,
|
||||
0x16, 0x90, 0xff, 0xad, 0x18, 0xb5, 0x9c, 0xf4, 0xb9, 0xc4, 0x32, 0xf3, 0xf5, 0xd2, 0x8b, 0x0a,
|
||||
0x92, 0xf5, 0x92, 0xf3, 0xf3, 0xca, 0x52, 0x8b, 0x4a, 0xa0, 0x26, 0x3a, 0x09, 0x3b, 0xa3, 0xf0,
|
||||
0x03, 0x40, 0x2e, 0x0b, 0x60, 0x4c, 0x62, 0x03, 0x3b, 0xd1, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff,
|
||||
0x64, 0xa9, 0x7f, 0x65, 0x6a, 0x01, 0x00, 0x00,
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: proto/backend_service.proto
|
||||
|
||||
/*
|
||||
Package isp is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package isp
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
|
||||
func request_BackendService_Request_0(ctx context.Context, marshaler runtime.Marshaler, client BackendServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq Message
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if req.ContentLength > 0 {
|
||||
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
msg, err := client.Request(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterBackendServiceHandlerFromEndpoint is same as RegisterBackendServiceHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterBackendServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.Dial(endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterBackendServiceHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterBackendServiceHandler registers the http handlers for service BackendService to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterBackendServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterBackendServiceHandlerClient(ctx, mux, NewBackendServiceClient(conn))
|
||||
}
|
||||
|
||||
// RegisterBackendServiceHandler registers the http handlers for service BackendService to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over the given implementation of "BackendServiceClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "BackendServiceClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "BackendServiceClient" to call the correct interceptors.
|
||||
func RegisterBackendServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client BackendServiceClient) error {
|
||||
|
||||
mux.Handle("POST", pattern_BackendService_Request_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
if cn, ok := w.(http.CloseNotifier); ok {
|
||||
go func(done <-chan struct{}, closed <-chan bool) {
|
||||
select {
|
||||
case <-done:
|
||||
case <-closed:
|
||||
cancel()
|
||||
}
|
||||
}(ctx.Done(), cn.CloseNotify())
|
||||
}
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_BackendService_Request_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_BackendService_Request_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_BackendService_Request_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"api"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_BackendService_Request_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
@@ -0,0 +1,100 @@
|
||||
module isp-config-service
|
||||
|
||||
go 1.23
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.5.4
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pressly/goose/v3 v3.22.1
|
||||
github.com/prometheus/client_golang v1.20.5
|
||||
github.com/rqlite/gorqlite v0.0.0-20241013203532-4385768ae85d
|
||||
github.com/rqlite/rqlite/v8 v8.32.5
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/tidwall/gjson v1.18.0
|
||||
github.com/txix-open/etp/v4 v4.0.1
|
||||
github.com/txix-open/isp-kit v1.39.1
|
||||
github.com/xeipuuv/gojsonschema v1.2.0
|
||||
golang.org/x/sync v0.8.0
|
||||
google.golang.org/grpc v1.67.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/armon/go-metrics v0.5.3 // indirect
|
||||
github.com/bahlo/generic-list-go v0.2.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/coder/websocket v1.8.12 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/fatih/color v1.18.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
|
||||
github.com/getsentry/sentry-go v0.29.1 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
|
||||
github.com/hashicorp/go-hclog v1.6.3 // indirect
|
||||
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||
github.com/hashicorp/go-msgpack v1.1.5 // indirect
|
||||
github.com/hashicorp/go-msgpack/v2 v2.1.2 // indirect
|
||||
github.com/hashicorp/go-uuid v1.0.3 // indirect
|
||||
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
||||
github.com/hashicorp/raft v1.7.1 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mfridman/interpolate v0.0.2 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.60.1 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/rqlite/go-sqlite3 v1.36.0 // indirect
|
||||
github.com/rqlite/raft-boltdb/v2 v2.0.0-20230523104317-c08e70f4de48 // indirect
|
||||
github.com/rqlite/sql v0.0.0-20241029220113-152a320b02f7 // indirect
|
||||
github.com/sethvargo/go-retry v0.3.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/txix-open/bellows v1.2.0 // indirect
|
||||
github.com/txix-open/jsonschema v1.2.0 // indirect
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 // indirect
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
go.etcd.io/bbolt v1.3.11 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 // indirect
|
||||
go.opentelemetry.io/otel v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.31.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.31.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/armon/go-metrics => github.com/hashicorp/go-metrics v0.5.1
|
||||
golang.org/x/text => golang.org/x/text v0.3.8
|
||||
)
|
||||
@@ -0,0 +1,365 @@
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
|
||||
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
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 v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
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/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
|
||||
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
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/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
|
||||
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
|
||||
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
|
||||
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
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.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
|
||||
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
|
||||
github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA=
|
||||
github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0=
|
||||
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-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-resty/resty/v2 v2.15.3 h1:bqff+hcqAflpiF591hhJzNdkRsFhlB96CYfBwSFvql8=
|
||||
github.com/go-resty/resty/v2 v2.15.3/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
|
||||
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
|
||||
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
|
||||
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-metrics v0.5.1 h1:rfPwUqFU6uZXNvGl4hzjY8LEBsqFVU4si1H9/Hqck/U=
|
||||
github.com/hashicorp/go-metrics v0.5.1/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE=
|
||||
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-msgpack v1.1.5 h1:9byZdVjKTe5mce63pRVNP1L7UAmdHOTEMGehn6KvJWs=
|
||||
github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YNK9NfGLXJ69/4=
|
||||
github.com/hashicorp/go-msgpack/v2 v2.1.2 h1:4Ee8FTp834e+ewB71RDrQ0VKpyFdrKOjvYtnQ/ltVj0=
|
||||
github.com/hashicorp/go-msgpack/v2 v2.1.2/go.mod h1:upybraOAblm4S7rx0+jeNy+CWWhzywQsSRV5033mMu4=
|
||||
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
|
||||
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
|
||||
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM=
|
||||
github.com/hashicorp/raft v1.7.1 h1:ytxsNx4baHsRZrhUcbt3+79zc4ly8qm7pi0393pSchY=
|
||||
github.com/hashicorp/raft v1.7.1/go.mod h1:hUeiEwQQR/Nk2iKDD0dkEhklSsu3jcAcqvPzPoZSAEM=
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea/go.mod h1:qRd6nFJYYS6Iqnc/8HcUmko2/2Gw8qTFEmxDLii6W5I=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
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.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
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.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
|
||||
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.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
|
||||
github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg=
|
||||
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 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
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/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
|
||||
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
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.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pressly/goose/v3 v3.22.1 h1:2zICEfr1O3yTP9BRZMGPj7qFxQ+ik6yeo+z1LMuioLc=
|
||||
github.com/pressly/goose/v3 v3.22.1/go.mod h1:xtMpbstWyCpyH+0cxLTMCENWBG+0CSxvTsXhW95d5eo=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
|
||||
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
||||
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
|
||||
github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc=
|
||||
github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
|
||||
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/rqlite/go-sqlite3 v1.36.0 h1:dNW9Hn4v3HVVlO+q6QmQC5glZYIWFOzOWUjrKOxK3cE=
|
||||
github.com/rqlite/go-sqlite3 v1.36.0/go.mod h1:R9H7CatgYBt3c+fSV/5yo2vLh4ZjCB0aMHdkv69fP4A=
|
||||
github.com/rqlite/gorqlite v0.0.0-20241013203532-4385768ae85d h1:c88ius/WcN19inn14R+X2EQCFjjAu92txgdxNNnGxDI=
|
||||
github.com/rqlite/gorqlite v0.0.0-20241013203532-4385768ae85d/go.mod h1:xF/KoXmrRyahPfo5L7Szb5cAAUl53dMWBh9cMruGEZg=
|
||||
github.com/rqlite/raft-boltdb/v2 v2.0.0-20230523104317-c08e70f4de48 h1:NZ62M+kT0JqhyFUMc8I4SMmfmD4NGJxhb2ePJQXjryc=
|
||||
github.com/rqlite/raft-boltdb/v2 v2.0.0-20230523104317-c08e70f4de48/go.mod h1:CRnsxgy5G8fAf5J+AM0yrsSdxXHKkIYOaq2sm+Q4DYc=
|
||||
github.com/rqlite/rqlite/v8 v8.32.5 h1:wEzDX2HrGWMvFkg2fcCmi+rb1wQ1m5yEefUQfOMvMSY=
|
||||
github.com/rqlite/rqlite/v8 v8.32.5/go.mod h1:a1irqNWEZ+pWuWpgekbScCXp85QtNTJLarN3bVPjn9M=
|
||||
github.com/rqlite/sql v0.0.0-20241029220113-152a320b02f7 h1:Mnz6yd4FWtiD6bbH9WHFFHfrOM2OYTUTmwrsckRc4W8=
|
||||
github.com/rqlite/sql v0.0.0-20241029220113-152a320b02f7/go.mod h1:ib9zVtNgRKiGuoMyUqqL5aNpk+r+++YlyiVIkclVqPg=
|
||||
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
|
||||
github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/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.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
|
||||
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||
github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
|
||||
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
|
||||
github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA=
|
||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
||||
github.com/txix-open/grmq v1.6.0 h1:V4QRb0sI2CMfdMaMsFGvGvUIDGad5vr3khNU7A3LlP8=
|
||||
github.com/txix-open/grmq v1.6.0/go.mod h1:s+NNNv42+32yLpjvl2tpqtyBbMB9e7kKFee3lfa/dyo=
|
||||
github.com/txix-open/isp-kit v1.39.1 h1:10zEILNQSPY7naiuaQkIKNS2/fnWxuE9bz+dTiAptXw=
|
||||
github.com/txix-open/isp-kit v1.39.1/go.mod h1:xB6mkoOewZBI1ND8kjU5TR6kvLu3VQI3Rdkh6g6FE4I=
|
||||
github.com/txix-open/jsonschema v1.2.0 h1:B8TrdSsPhDvYv67oi/LVqf7/+PuqFlMsNwUzGeHfl1s=
|
||||
github.com/txix-open/jsonschema v1.2.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 h1:Z0Sqf+U+Sc6hfIXtRCIZlbJprkCjwMFbS4ZbEPQ44To=
|
||||
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99/go.mod h1:pA0NYmhL0uEkkxj55S+S7MZU4e2QIt46x9XSrzrWc3c=
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
|
||||
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0 h1:4BZHA+B1wXEQoGNHxW8mURaLhcdGwvRnmhGbm+odRbc=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.56.0/go.mod h1:3qi2EEwMgB4xnKgPLqsDP3j9qxnHDZeHsnAxfjQqTko=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM=
|
||||
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
|
||||
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 h1:K0XaT3DwHAcV4nKLzcQvwAgSyisUghWoY20I7huthMk=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0/go.mod h1:B5Ki776z/MBnVha1Nzwp5arlzBbE3+1jk+pGmaP5HME=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 h1:lUsI2TYsQw2r1IASwoROaCnjdj2cvC2+Jbxvk6nHnWU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0/go.mod h1:2HpZxxQurfGxJlJDblybejHB6RX6pmExPNe517hREw4=
|
||||
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
|
||||
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
|
||||
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
|
||||
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
|
||||
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
|
||||
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/tools v0.0.0-20190424220101-1e8e1cfdf96b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 h1:2oV8dfuIkM1Ti7DwXc0BJfnwr9csz4TDXI9EmiI+Rbw=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38/go.mod h1:vuAjtvlwkDKF6L1GQ0SokiRLCGFfeBUXWr/aFFkHACc=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:zciRKQ4kBpFgpfC5QQCVtnnNAcLIqweL7plyZRQHVpI=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
|
||||
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
||||
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
||||
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/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.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
|
||||
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU=
|
||||
modernc.org/sqlite v1.33.0 h1:WWkA/T2G17okiLGgKAj4/RMIvgyMT19yQ038160IeYk=
|
||||
modernc.org/sqlite v1.33.0/go.mod h1:9uQ9hF/pCZoYZK73D/ud5Z7cIRIILSZI8NdIemVMTX8=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
@@ -1,58 +0,0 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-lib/structure"
|
||||
"isp-config-service/controllers"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type Handlers struct {
|
||||
// ===== INSTANCE =====
|
||||
GetInstances func(identities []int32) ([]entity.Instance, error) `method:"get_instances" group:"instance" inner:"true"`
|
||||
CreateUpdateInstance func(instance entity.Instance) (*entity.Instance, error) `method:"create_update_instance" group:"instance" inner:"true"`
|
||||
DeleteInstance func(identities []int32) (*domain.DeleteResponse, error) `method:"delete_instance" group:"instance" inner:"true"`
|
||||
|
||||
// ===== MODULE =====
|
||||
GetModules func(identities []int32) ([]entity.Module, error) `method:"get_modules" group:"module" inner:"true"`
|
||||
GetActiveModules func() ([]entity.Module, error) `method:"get_active_modules" group:"module" inner:"true"`
|
||||
GetConnectedModules func() (map[string]interface{}, error) `method:"get_connected_modules" group:"module" inner:"true"`
|
||||
CreateUpdateModule func(module entity.Module) (*entity.Module, error) `method:"create_update_module" group:"module" inner:"true"`
|
||||
DeleteModule func(identities []int32) (*domain.DeleteResponse, error) `method:"delete_module" group:"module" inner:"true"`
|
||||
GetModulesInfo func(i structure.Isolation) ([]*domain.ModuleInfo, error) `method:"get_modules_info" group:"module" inner:"true"`
|
||||
|
||||
// ===== CONFIG =====
|
||||
GetConfigs func(identities []int64) ([]entity.Config, error) `method:"get_configs" group:"config" inner:"true"`
|
||||
GetConfigByInstanceUUIDAndModuleName func(request entity.ModuleInstanceIdentity) (*entity.Config, error) `method:"get_config_by_instance_uuid_and_module_name" group:"config" inner:"true"`
|
||||
CreateUpdateConfig func(config entity.Config) (*entity.Config, error) `method:"create_update_config" group:"config" inner:"true"`
|
||||
UpdateActiveConfigByInstanceUUIDAndModuleName func(config domain.ConfigInstanceModuleName) (*entity.Config, error) `method:"update_active_config_by_instance_uuid_and_module_name" group:"config" inner:"true"`
|
||||
MarkConfigAsActive func(identity domain.LongIdentitiesRequest) (*entity.Config, error) `method:"mark_config_as_active" group:"config" inner:"true"`
|
||||
DeleteConfig func(identities []int64) (*domain.DeleteResponse, error) `method:"delete_config" group:"config" inner:"true"`
|
||||
|
||||
// ===== ROUTING =====
|
||||
GetRoutes func() (map[string]interface{}, error) `method:"get_routes" group:"routing" inner:"true"`
|
||||
}
|
||||
|
||||
func GetHandlers() *Handlers {
|
||||
return &Handlers{
|
||||
GetInstances: controllers.GetInstances,
|
||||
CreateUpdateInstance: controllers.CreateUpdateInstance,
|
||||
DeleteInstance: controllers.DeleteInstance,
|
||||
|
||||
GetModules: controllers.GetModules,
|
||||
GetActiveModules: controllers.GetActiveModules,
|
||||
GetConnectedModules: controllers.GetConnectedModules,
|
||||
CreateUpdateModule: controllers.CreateUpdateModule,
|
||||
DeleteModule: controllers.DeleteModule,
|
||||
GetModulesInfo: controllers.GetModulesAggregatedInfo,
|
||||
|
||||
GetConfigs: controllers.GetConfigs,
|
||||
GetConfigByInstanceUUIDAndModuleName: controllers.GetConfigByInstanceUUIDAndModuleName,
|
||||
CreateUpdateConfig: controllers.CreateUpdateConfig,
|
||||
UpdateActiveConfigByInstanceUUIDAndModuleName: controllers.UpdateActiveConfigByInstanceUUIDAndModuleName,
|
||||
MarkConfigAsActive: controllers.MarkConfigAsActive,
|
||||
DeleteConfig: controllers.DeleteConfig,
|
||||
|
||||
GetRoutes: controllers.GetRoutes,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/etp/v4"
|
||||
"github.com/txix-open/isp-kit/cluster"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-config-service/entity"
|
||||
"net"
|
||||
)
|
||||
|
||||
func ModuleName(conn *etp.Conn) string {
|
||||
return conn.HttpRequest().Form.Get("module_name")
|
||||
}
|
||||
|
||||
func SplitAddress(backend entity.Backend) (cluster.AddressConfiguration, error) {
|
||||
host, port, err := net.SplitHostPort(backend.Address)
|
||||
if err != nil {
|
||||
return cluster.AddressConfiguration{}, errors.WithMessagef(err, "split backend %s address: %s", backend.ModuleId, backend.Address)
|
||||
}
|
||||
return cluster.AddressConfiguration{
|
||||
IP: host,
|
||||
Port: port,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func LogFields(conn *etp.Conn) []log.Field {
|
||||
return []log.Field{
|
||||
log.String("moduleName", ModuleName(conn)),
|
||||
log.String("connId", conn.Id()),
|
||||
}
|
||||
}
|
||||
@@ -1,247 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/integration-system/isp-lib/bootstrap"
|
||||
"github.com/valyala/fasthttp"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/module"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
rn "runtime"
|
||||
"time"
|
||||
|
||||
"github.com/txix-open/isp-kit/bootstrap"
|
||||
"github.com/txix-open/isp-kit/shutdown"
|
||||
"isp-config-service/conf"
|
||||
"isp-config-service/generated"
|
||||
"isp-config-service/helper"
|
||||
"isp-config-service/model"
|
||||
"isp-config-service/socket"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/integration-system/isp-lib/backend"
|
||||
"github.com/integration-system/isp-lib/config"
|
||||
"github.com/integration-system/isp-lib/controller"
|
||||
"github.com/integration-system/isp-lib/database"
|
||||
"github.com/integration-system/isp-lib/logger"
|
||||
"github.com/integration-system/isp-lib/metric"
|
||||
"github.com/integration-system/isp-lib/structure"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
const (
|
||||
routerModule = "router"
|
||||
converterModule = "converter"
|
||||
"isp-config-service/routes"
|
||||
"isp-config-service/service/startup"
|
||||
)
|
||||
|
||||
var (
|
||||
configData *conf.Configuration
|
||||
echoEndpoint *string
|
||||
executableFileDir string
|
||||
version = "0.1.0"
|
||||
date = "undefined"
|
||||
version = "1.0.0"
|
||||
)
|
||||
|
||||
func init() {
|
||||
configData = config.InitConfig(&conf.Configuration{}).(*conf.Configuration)
|
||||
database.InitDbWithSchema(configData.Database, configData.Database.Schema)
|
||||
db := database.GetDBManager()
|
||||
model.InitDbManager(db.Db)
|
||||
model.SetSchema(configData.Database.Schema)
|
||||
echoEndpoint = flag.String("echo_endpoint", configData.WS.Grpc.GetAddress(), "endpoint of YourService")
|
||||
module.Version = version
|
||||
}
|
||||
// @title isp-config-service
|
||||
// @version 3.0.0
|
||||
// @description Модуль управления конфигурациями
|
||||
|
||||
// @license.name GNU GPL v3.0
|
||||
|
||||
// @host localhost:9000
|
||||
// @BasePath /api/config
|
||||
|
||||
//go:generate swag init --parseDependency
|
||||
//go:generate rm -f docs/swagger.json docs/docs.go
|
||||
func main() {
|
||||
ex, err := os.Executable()
|
||||
executableFileDir = path.Dir(ex)
|
||||
boot := bootstrap.New(version, conf.Remote{}, routes.EndpointDescriptors())
|
||||
app := boot.App
|
||||
logger := app.Logger()
|
||||
|
||||
startup, err := startup.New(boot)
|
||||
if err != nil {
|
||||
logger.Fatal(err)
|
||||
boot.Fatal(err)
|
||||
}
|
||||
if utils.DEV {
|
||||
_, filename, _, _ := rn.Caller(0)
|
||||
executableFileDir = path.Dir(filename)
|
||||
}
|
||||
metric.InitCollectors(configData.Metrics, structure.MetricConfiguration{})
|
||||
metric.InitStatusChecker("routers", checkRouters)
|
||||
metric.InitStatusChecker("converters", checkConverters)
|
||||
metric.InitHttpServer(configData.Metrics)
|
||||
metric.GerHttpRouter().GET("/modules", handleModulesRequest)
|
||||
app.AddRunners(startup)
|
||||
app.AddClosers(startup.Closers()...)
|
||||
|
||||
createGrpcServer()
|
||||
createRestServer(runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{OrigName: true, EmitDefaults: true}))
|
||||
}
|
||||
|
||||
func checkRouters() interface{} {
|
||||
result := make([]string, 0)
|
||||
|
||||
instances, err := model.InstanceRep.GetInstances(nil)
|
||||
if err != nil {
|
||||
logger.Warn(err)
|
||||
}
|
||||
for _, v := range instances {
|
||||
list := socket.GetModuleAddressList(v.Uuid, routerModule)
|
||||
for _, v := range list {
|
||||
result = append(result, v.GetAddress())
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func checkConverters() interface{} {
|
||||
result := make([]string, 0)
|
||||
instances, err := model.InstanceRep.GetInstances(nil)
|
||||
if err != nil {
|
||||
logger.Warn(err)
|
||||
}
|
||||
for _, v := range instances {
|
||||
list := socket.GetModuleAddressList(v.Uuid, converterModule)
|
||||
for _, v := range list {
|
||||
result = append(result, v.GetAddress())
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// newGateway returns a new gateway server which translates HTTP into gRPC.
|
||||
func newGateway(ctx context.Context, opts ...runtime.ServeMuxOption) (http.Handler, error) {
|
||||
mux := runtime.NewServeMux(opts...)
|
||||
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
err := isp.RegisterBackendServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint, dialOpts)
|
||||
if err != nil {
|
||||
logger.Fatalf("failed to serve rest proxy: %v", err)
|
||||
}
|
||||
return mux, nil
|
||||
}
|
||||
|
||||
// Start a GRPC server.
|
||||
func createGrpcServer() {
|
||||
// Run our server in a goroutine so that it doesn't block.
|
||||
handlers := helper.GetHandlers()
|
||||
addr := structure.AddressConfiguration{IP: configData.WS.Grpc.IP, Port: configData.WS.Grpc.Port}
|
||||
addrOuter := structure.AddressConfiguration{IP: configData.GrpcOuterAddress.IP, Port: configData.GrpcOuterAddress.Port}
|
||||
backend.StartBackendGrpcServer(addr, backend.GetDefaultService(configData.ModuleName, handlers))
|
||||
enndpoints := backend.GetEndpoints(configData.ModuleName, handlers)
|
||||
|
||||
socket.SetBackendMethods(&structure.BackendDeclaration{
|
||||
ModuleName: configData.ModuleName,
|
||||
Version: version,
|
||||
LibVersion: bootstrap.LibraryVersion,
|
||||
Endpoints: enndpoints,
|
||||
Address: addrOuter,
|
||||
shutdown.On(func() {
|
||||
logger.Info(app.Context(), "starting shutdown")
|
||||
app.Shutdown()
|
||||
logger.Info(app.Context(), "shutdown completed")
|
||||
})
|
||||
logger.Infof("EXPORTED MODULE METHODS: %v, module_name: %s, version: %s",
|
||||
enndpoints, configData.ModuleName, version)
|
||||
}
|
||||
|
||||
// Start a HTTP server.
|
||||
func createRestServer(opts ...runtime.ServeMuxOption) {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// === Socket.IO ===
|
||||
mux.Handle("/socket.io/", socket.Get())
|
||||
|
||||
// === REST ===
|
||||
mux.Handle("/swagger/", controller.StaticHandler(
|
||||
http.StripPrefix(
|
||||
"/swagger/", http.FileServer(
|
||||
http.Dir(path.Join(executableFileDir, "static", "swagger-ui"))))))
|
||||
|
||||
gw, err := newGateway(ctx, opts...)
|
||||
err = app.Run()
|
||||
if err != nil {
|
||||
logger.Fatalf("failed to serve: %v", err)
|
||||
}
|
||||
mux.Handle("/", gw)
|
||||
|
||||
/*r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
})*/
|
||||
|
||||
var wait time.Duration
|
||||
flag.DurationVar(&wait, "graceful-timeout", time.Second*15,
|
||||
"the duration for which the server gracefully wait for existing connections to finish - e.g. 15s or 1m")
|
||||
flag.Parse()
|
||||
|
||||
restAddress := configData.WS.Rest.GetAddress()
|
||||
logger.Infof("Serving at %s ...", restAddress)
|
||||
srv := &http.Server{
|
||||
Addr: restAddress,
|
||||
// Good practice to set timeouts to avoid Slowloris attacks.
|
||||
WriteTimeout: time.Second * 15,
|
||||
ReadTimeout: time.Second * 15,
|
||||
IdleTimeout: time.Second * 60,
|
||||
Handler: mux, // Pass our instance of gorilla/mux in.
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(); err != nil {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
// We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C)
|
||||
// SIGKILL, SIGQUIT or SIGTERM (Ctrl+/) will not be caught.
|
||||
signal.Notify(c, os.Interrupt)
|
||||
|
||||
// Block until we receive our signal.
|
||||
<-c
|
||||
|
||||
// Create a deadline to wait for.
|
||||
ctx, cancel = context.WithTimeout(context.Background(), wait)
|
||||
defer cancel()
|
||||
// Doesn't block if no connections, but will otherwise wait
|
||||
// until the timeout deadline.
|
||||
_ = srv.Shutdown(ctx)
|
||||
// Optionally, you could run srv.Shutdown in a goroutine and block on
|
||||
// <-ctx.Done() if your application should wait for other services
|
||||
// to finalize based on context cancellation.
|
||||
logger.Info("shutting down")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func handleModulesRequest(ctx *fasthttp.RequestCtx) {
|
||||
instances, err := model.InstanceRep.GetInstances(nil)
|
||||
if err != nil {
|
||||
logger.Warn(err)
|
||||
ctx.Error("internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string][]*domain.ModuleInfo, len(instances))
|
||||
for _, i := range instances {
|
||||
info, err := module.GetAggregatedModuleInfo(i.Uuid)
|
||||
if err != nil {
|
||||
logger.Warn(err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, inf := range info {
|
||||
inf.ConfigSchema = nil
|
||||
inf.Configs = nil
|
||||
for i := range inf.Status {
|
||||
s := &inf.Status[i]
|
||||
s.Endpoints = nil
|
||||
}
|
||||
}
|
||||
|
||||
result[i.Uuid] = info
|
||||
}
|
||||
|
||||
if bytes, err := utils.ConvertInterfaceToBytes(result, nil); err != nil {
|
||||
logger.Warn(err)
|
||||
ctx.Error("internal server error", http.StatusInternalServerError)
|
||||
} else {
|
||||
ctx.SetStatusCode(http.StatusOK)
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetBody(bytes)
|
||||
boot.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/txix-open/isp-kit/http/httpcli"
|
||||
"github.com/txix-open/isp-kit/metrics"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
)
|
||||
|
||||
func SqlOperationMiddleware() httpcli.Middleware {
|
||||
//nolint:promlinter
|
||||
sqlQueryDuration := metrics.GetOrRegister(metrics.DefaultRegistry, prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||
Subsystem: "sql",
|
||||
Name: "query_duration_ms",
|
||||
Help: "The latencies of sql query",
|
||||
Objectives: metrics.DefaultObjectives,
|
||||
}, []string{"operation"}))
|
||||
return func(next httpcli.RoundTripper) httpcli.RoundTripper {
|
||||
return httpcli.RoundTripperFunc(func(ctx context.Context, request *httpcli.Request) (*httpcli.Response, error) {
|
||||
label := sql_metrics.OperationLabelFromContext(ctx)
|
||||
now := time.Now()
|
||||
resp, err := next.RoundTrip(ctx, request)
|
||||
if label != "" {
|
||||
duration := time.Since(now)
|
||||
sqlQueryDuration.WithLabelValues(label).Observe(metrics.Milliseconds(duration))
|
||||
}
|
||||
return resp, err //nolint:wrapcheck
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package sql_metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type tracerContextKey int
|
||||
|
||||
const (
|
||||
labelContextKey = tracerContextKey(2)
|
||||
)
|
||||
|
||||
func OperationLabelToContext(ctx context.Context, label string) context.Context {
|
||||
return context.WithValue(ctx, labelContextKey, label)
|
||||
}
|
||||
|
||||
func OperationLabelFromContext(ctx context.Context) string {
|
||||
value, _ := ctx.Value(labelContextKey).(string)
|
||||
return value
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/txix-open/etp/v4"
|
||||
|
||||
"github.com/txix-open/etp/v4/msg"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-config-service/helpers"
|
||||
)
|
||||
|
||||
type EtpMiddleware func(next etp.Handler) etp.Handler
|
||||
|
||||
func EtpLogger(logger log.Logger) EtpMiddleware {
|
||||
return func(next etp.Handler) etp.Handler {
|
||||
return etp.HandlerFunc(func(ctx context.Context, conn *etp.Conn, event msg.Event) []byte {
|
||||
fields := append(
|
||||
helpers.LogFields(conn),
|
||||
log.String("event", event.Name),
|
||||
)
|
||||
logger.Debug(ctx, "event received", fields...)
|
||||
return next.Handle(ctx, conn, event)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:ireturn
|
||||
func EtpChain(root etp.Handler, middlewares ...EtpMiddleware) etp.Handler {
|
||||
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||
root = middlewares[i](root)
|
||||
}
|
||||
return root
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
-- +goose Up
|
||||
CREATE schema if NOT EXISTS "config_service";
|
||||
|
||||
-- +goose Down
|
||||
DROP schema if EXISTS config_service CASCADE;
|
||||
@@ -0,0 +1,81 @@
|
||||
-- +goose Up
|
||||
-- +goose NO TRANSACTION
|
||||
create table isp_config_service__module
|
||||
(
|
||||
id text not null primary key,
|
||||
name text not null unique,
|
||||
last_connected_at integer,
|
||||
last_disconnected_at integer,
|
||||
created_at integer not null default (unixepoch())
|
||||
);
|
||||
|
||||
create table isp_config_service__config
|
||||
(
|
||||
id text not null primary key,
|
||||
name text not null,
|
||||
module_id text not null,
|
||||
data blob not null,
|
||||
version int not null default 1,
|
||||
active int not null default 0,
|
||||
admin_id int not null default 0,
|
||||
created_at integer not null default (unixepoch()),
|
||||
updated_at integer not null default (unixepoch()),
|
||||
foreign key (module_id) references isp_config_service__module (id) on delete cascade on update cascade
|
||||
);
|
||||
|
||||
create index IX_isp_config_service__config__module_id on isp_config_service__config (module_id);
|
||||
|
||||
create table isp_config_service__config_history
|
||||
(
|
||||
id text not null primary key,
|
||||
config_id text not null,
|
||||
data blob not null,
|
||||
version int not null default 1,
|
||||
admin_id int not null default 0,
|
||||
created_at integer not null default (unixepoch()),
|
||||
foreign key (config_id) references isp_config_service__config (id) on delete cascade on update cascade
|
||||
);
|
||||
|
||||
create index IX_isp_config_service__config_history__config_id on isp_config_service__config_history (config_id);
|
||||
|
||||
create table isp_config_service__config_schema
|
||||
(
|
||||
id text not null primary key,
|
||||
module_id text not null unique,
|
||||
data blob not null,
|
||||
module_version text not null default 1,
|
||||
created_at integer not null default (unixepoch()),
|
||||
updated_at integer not null default (unixepoch()),
|
||||
foreign key (module_id) references isp_config_service__module (id) on delete cascade on update cascade
|
||||
);
|
||||
|
||||
create table isp_config_service__backend
|
||||
(
|
||||
module_id text not null,
|
||||
address text not null,
|
||||
version text not null,
|
||||
lib_version text not null,
|
||||
module_name text not null,
|
||||
endpoints blob not null,
|
||||
required_modules blob not null,
|
||||
created_at integer not null default (unixepoch()),
|
||||
updated_at integer not null default (unixepoch()),
|
||||
primary key (module_id, address),
|
||||
foreign key (module_id) references isp_config_service__module (id) on delete cascade on update cascade
|
||||
);
|
||||
|
||||
create table isp_config_service__event
|
||||
(
|
||||
id integer,
|
||||
payload blob not null,
|
||||
created_at integer not null default (unixepoch()),
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
drop table isp_config_service__module;
|
||||
drop table isp_config_service__config;
|
||||
drop table isp_config_service__config_history;
|
||||
drop table isp_config_service__config_schema;
|
||||
drop table isp_config_service__backend;
|
||||
drop table isp_config_service__event;
|
||||
@@ -0,0 +1,31 @@
|
||||
-- +goose Up
|
||||
-- +goose NO TRANSACTION
|
||||
CREATE TABLE isp_config_service__event_autoincrement (
|
||||
id integer primary key autoincrement,
|
||||
payload blob not null,
|
||||
created_at integer not null default (unixepoch())
|
||||
);
|
||||
|
||||
INSERT INTO
|
||||
isp_config_service__event_autoincrement (id, payload, created_at)
|
||||
SELECT id, payload, created_at
|
||||
FROM isp_config_service__event;
|
||||
DROP TABLE isp_config_service__event;
|
||||
|
||||
ALTER TABLE isp_config_service__event_autoincrement RENAME TO isp_config_service__event;
|
||||
-- +goose Down
|
||||
CREATE TABLE isp_config_service__event_without_autoincrement (
|
||||
id integer primary key,
|
||||
payload blob not null,
|
||||
created_at integer not null default (unixepoch())
|
||||
);
|
||||
|
||||
INSERT INTO
|
||||
isp_config_service__event_without_autoincrement (id, payload, created_at)
|
||||
SELECT id, payload, created_at
|
||||
FROM isp_config_service__event;
|
||||
|
||||
DROP TABLE isp_config_service__event;
|
||||
|
||||
ALTER TABLE isp_config_service__event_without_autoincrement
|
||||
RENAME TO isp_config_service__event;
|
||||
@@ -0,0 +1,23 @@
|
||||
-- +goose Up
|
||||
drop table isp_config_service__backend;
|
||||
|
||||
create table isp_config_service__backend
|
||||
(
|
||||
ws_connection_id text not null,
|
||||
module_id text not null,
|
||||
address text not null,
|
||||
version text not null,
|
||||
lib_version text not null,
|
||||
module_name text not null,
|
||||
config_service_node_id text not null,
|
||||
endpoints blob not null,
|
||||
required_modules blob not null,
|
||||
created_at integer not null default (unixepoch()),
|
||||
primary key (ws_connection_id),
|
||||
foreign key (module_id) references isp_config_service__module (id) on delete cascade on update cascade
|
||||
);
|
||||
|
||||
create index IX_isp_config_service__backend__module_id on isp_config_service__backend (module_id);
|
||||
create index IX_isp_config_service__backend__node_id on isp_config_service__backend(config_service_node_id);
|
||||
|
||||
-- +goose Down
|
||||
@@ -0,0 +1,10 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"embed"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed *
|
||||
Migrations embed.FS
|
||||
)
|
||||
@@ -1,5 +0,0 @@
|
||||
-- +goose Up
|
||||
CREATE schema if NOT EXISTS "config_service";
|
||||
|
||||
-- +goose Down
|
||||
DROP schema if EXISTS config_service CASCADE;
|
||||
@@ -1,47 +0,0 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE instances (
|
||||
id serial4 NOT NULL PRIMARY KEY,
|
||||
uuid UUID NOT NULL,
|
||||
"name" varchar(255) NOT NULL,
|
||||
created_at timestamp DEFAULT (now() at time zone 'utc') NOT NULL
|
||||
);
|
||||
|
||||
-- +goose StatementBegin
|
||||
CREATE OR REPLACE FUNCTION update_created_modified_column_date()
|
||||
RETURNS TRIGGER AS
|
||||
$body$
|
||||
BEGIN
|
||||
IF TG_OP = 'UPDATE' THEN
|
||||
NEW.created_at = OLD.created_at;
|
||||
NEW.updated_at = (now() at time zone 'utc');
|
||||
ELSIF TG_OP = 'INSERT' THEN
|
||||
NEW.updated_at = (now() at time zone 'utc');
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$body$ LANGUAGE plpgsql;
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose StatementBegin
|
||||
CREATE OR REPLACE FUNCTION update_created_column_date()
|
||||
RETURNS TRIGGER AS
|
||||
$body$
|
||||
BEGIN
|
||||
IF TG_OP = 'UPDATE' THEN
|
||||
NEW.created_at = OLD.created_at;
|
||||
ELSIF TG_OP = 'INSERT' THEN
|
||||
NEW.created_at = (now() at time zone 'utc');
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$body$ LANGUAGE plpgsql;
|
||||
-- +goose StatementEnd
|
||||
|
||||
CREATE TRIGGER update_customer_modtime BEFORE INSERT OR UPDATE ON instances
|
||||
FOR EACH ROW EXECUTE PROCEDURE update_created_column_date();
|
||||
|
||||
ALTER TABLE instances ADD CONSTRAINT "UQ_instances_uuid" UNIQUE ("uuid");
|
||||
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE instances;
|
||||
@@ -1,24 +0,0 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE modules (
|
||||
id serial4 NOT NULL PRIMARY KEY,
|
||||
instance_id int4 NOT NULL,
|
||||
"name" varchar(255) NOT NULL,
|
||||
"active" bool DEFAULT true,
|
||||
created_at timestamp DEFAULT (now() at time zone 'utc') NOT NULL,
|
||||
last_connected_at timestamp,
|
||||
last_disconnected_at timestamp
|
||||
);
|
||||
|
||||
ALTER TABLE modules
|
||||
ADD CONSTRAINT "FK_modules_instanceId_instances_id"
|
||||
FOREIGN KEY ("instance_id") REFERENCES instances ("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
CREATE INDEX IX_modules_instanceId ON modules USING hash (instance_id);
|
||||
|
||||
CREATE TRIGGER update_customer_modtime BEFORE INSERT OR UPDATE ON modules
|
||||
FOR EACH ROW EXECUTE PROCEDURE update_created_column_date();
|
||||
|
||||
ALTER TABLE modules ADD CONSTRAINT "UQ_modules_instanceId_name" UNIQUE ("instance_id", "name");
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE modules;
|
||||
@@ -1,70 +0,0 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE configs (
|
||||
id serial8 NOT NULL PRIMARY KEY,
|
||||
module_id int4 NOT NULL,
|
||||
"version" int4 NOT NULL,
|
||||
"active" bool DEFAULT false,
|
||||
created_at timestamp DEFAULT (now() at time zone 'utc') NOT NULL,
|
||||
updated_at timestamp DEFAULT (now() at time zone 'utc') NOT NULL,
|
||||
"data" jsonb NOT NULL DEFAULT '{}'
|
||||
);
|
||||
|
||||
ALTER TABLE configs
|
||||
ADD CONSTRAINT "FK_configs_moduleId_modules_id"
|
||||
FOREIGN KEY ("module_id") REFERENCES modules ("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
CREATE INDEX IX_configs_moduleId ON configs USING hash (module_id);
|
||||
|
||||
-- +goose StatementBegin
|
||||
CREATE OR REPLACE FUNCTION deactivate_config()
|
||||
RETURNS TRIGGER AS
|
||||
$body$
|
||||
DECLARE
|
||||
last_version integer;
|
||||
BEGIN
|
||||
NEW.updated_at = (now() at time zone 'utc');
|
||||
IF TG_OP = 'INSERT'
|
||||
THEN
|
||||
EXECUTE format('
|
||||
SELECT version
|
||||
FROM %I.configs
|
||||
WHERE module_id = ' || NEW.module_id || '
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1;
|
||||
', TG_TABLE_SCHEMA) INTO last_version;
|
||||
IF last_version IS NOT NULL
|
||||
THEN
|
||||
NEW.version = last_version + 1;
|
||||
ELSE
|
||||
NEW.version = 1;
|
||||
END IF;
|
||||
ELSE
|
||||
NEW.version = OLD.version;
|
||||
NEW.created_at = OLD.created_at;
|
||||
END IF;
|
||||
|
||||
IF NEW.active = TRUE
|
||||
THEN
|
||||
EXECUTE format('
|
||||
UPDATE %I.configs
|
||||
SET active = FALSE,
|
||||
updated_at = (now() at time zone ''utc'')
|
||||
WHERE active = TRUE AND ' || NEW.id || ' != id AND module_id = ' || NEW.module_id || ';
|
||||
', TG_TABLE_SCHEMA);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$body$ LANGUAGE plpgsql;
|
||||
-- +goose StatementEnd
|
||||
|
||||
CREATE TRIGGER "deactivate_config"
|
||||
BEFORE INSERT OR UPDATE ON configs
|
||||
FOR EACH ROW EXECUTE PROCEDURE deactivate_config();
|
||||
|
||||
CREATE TRIGGER update_config_create_time BEFORE INSERT OR UPDATE ON configs
|
||||
FOR EACH ROW EXECUTE PROCEDURE update_created_column_date();
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE configs;
|
||||
DROP FUNCTION deactivate_config;
|
||||
@@ -1,6 +0,0 @@
|
||||
-- +goose Up
|
||||
INSERT INTO instances VALUES (1, 'bf482806-0c3d-4e0d-b9d4-12c037b12d70', 'main', NULL);
|
||||
SELECT setval(pg_get_serial_sequence('instances', 'id'), 2, FALSE);
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM instances WHERE id=1
|
||||
@@ -1,10 +0,0 @@
|
||||
-- +goose Up
|
||||
INSERT INTO modules VALUES (1, 1, 'auth', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (2, 1, 'converter', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (3, 1, 'router', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (4, 1, 'system', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (5, 1, 'admin', 't', NULL, NULL, NULL);
|
||||
SELECT setval(pg_get_serial_sequence('modules', 'id'), 6, FALSE);
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM modules WHERE id IN (1,2,3,4,5);
|
||||
@@ -1,11 +0,0 @@
|
||||
-- +goose Up
|
||||
INSERT INTO modules VALUES (6, 1, 'user', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (7, 1, 'mobile', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (8, 1, 'awip', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (9, 1, 'mongo-backend', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (10, 1, 'sql-backend', 't', NULL, NULL, NULL);
|
||||
INSERT INTO modules VALUES (11, 1, 'events', 't', NULL, NULL, NULL);
|
||||
SELECT setval(pg_get_serial_sequence('modules', 'id'), 12, FALSE);
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM modules WHERE id IN (6,7,8,9,10,11);
|
||||
@@ -1,58 +0,0 @@
|
||||
-- +goose Up
|
||||
set migration.db_host = 'msk-pgsql.isp.mobi';
|
||||
set migration.db_port = '5432';
|
||||
set migration.db_dbname = 'isp-alpha';
|
||||
set migration.db_user = 'isp-alpha';
|
||||
set migration.db_pass = 'JxY96xLF8zfh3g8EWvSDtLUBw';
|
||||
|
||||
set migration.redis_host = '10.250.9.117';
|
||||
set migration.redis_port = '6379';
|
||||
|
||||
-- auth
|
||||
INSERT INTO configs VALUES (1, 1, NULL, 't', NULL, NULL, ('{"redis": {' ||
|
||||
'"ip": "' || current_setting('migration.redis_host') || '", ' ||
|
||||
'"port": ' || current_setting('migration.redis_port') ||
|
||||
'}, "header": {"token": {"user": "X-USER-TOKEN", "device": "X-DEVICE-TOKEN", "application": "X-APPLICATION-TOKEN"}, "identity": {"user": "X-USER-IDENTITY", "device": "X-DEVICE-IDENTITY", "domain": "X-DOMAIN-IDENTITY", "system": "X-SYSTEM-IDENTITY", "service": "X-SERVICE-IDENTITY", "application": "X-APPLICATION-IDENTITY"}}, "unauthorized.html": "<HTML><BODY><H1>401 Unauthorized BAD CREDENTIALS</H1></BODY></HTML>"}')::jsonb);
|
||||
-- converter
|
||||
INSERT INTO configs VALUES (2, 2, NULL, 't', NULL, NULL, ('{"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9553"}}}')::jsonb);
|
||||
-- router
|
||||
INSERT INTO configs VALUES (3, 3, NULL, 't', NULL, NULL, ('{"database": {' ||
|
||||
'"port": "' || current_setting('migration.db_port') || '", ' ||
|
||||
'"schema": "admin_service", ' ||
|
||||
'"address": "' || current_setting('migration.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migration.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migration.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migration.db_user') || '", ' ||
|
||||
'"createSchema": true}, ' ||
|
||||
'"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9554"}}' ||
|
||||
'}')::jsonb);
|
||||
-- system
|
||||
INSERT INTO configs VALUES (4, 4, NULL, 't', NULL, NULL, ('{"db": {' ||
|
||||
'"port": "' || current_setting('migration.db_port') || '", ' ||
|
||||
'"schema": "system_service", ' ||
|
||||
'"address": "' || current_setting('migration.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migration.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migration.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migration.db_user') || '", ' ||
|
||||
'"createSchema": true}, "RedisAddress": {' ||
|
||||
'"ip": "' || current_setting('migration.redis_host') || '", ' ||
|
||||
'"port": "' || current_setting('migration.redis_port') || '"' ||
|
||||
'}, ' ||
|
||||
'"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9555"}}' ||
|
||||
'}')::jsonb);
|
||||
-- admin
|
||||
INSERT INTO configs VALUES (5, 5, NULL, 't', NULL, NULL, ('{"database": {' ||
|
||||
'"port": "' || current_setting('migration.db_port') || '", ' ||
|
||||
'"schema": "admin_service", ' ||
|
||||
'"address": "' || current_setting('migration.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migration.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migration.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migration.db_user') || '", ' ||
|
||||
'"createSchema": true}, ' ||
|
||||
'"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9557"}}' ||
|
||||
'}')::jsonb);
|
||||
|
||||
SELECT setval(pg_get_serial_sequence('configs', 'id'), 6, FALSE);
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM configs WHERE id IN (1,2,3,4,5)
|
||||
@@ -1,127 +0,0 @@
|
||||
-- +goose Up
|
||||
set migration.db_host = 'msk-pgsql.isp.mobi';
|
||||
set migration.db_port = '5432';
|
||||
set migration.db_dbname = 'isp-alpha';
|
||||
set migration.db_user = 'isp-alpha';
|
||||
set migration.db_pass = 'JxY96xLF8zfh3g8EWvSDtLUBw';
|
||||
|
||||
set migration.redis_host = '10.250.9.117';
|
||||
set migration.redis_port = '6379';
|
||||
|
||||
-- user
|
||||
INSERT INTO configs VALUES (6, 6, NULL, 't', NULL, NULL, (format('{
|
||||
"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9556"}},
|
||||
"database": {
|
||||
"username": "%s",
|
||||
"createSchema": true,
|
||||
"port": "%s",
|
||||
"schema": "user_service",
|
||||
"address": "%s",
|
||||
"database": "%s",
|
||||
"password": "%s"
|
||||
},
|
||||
"redisAddress": {
|
||||
"ip": "%s",
|
||||
"port": "%s"
|
||||
},
|
||||
"userTokenExpireMs": -1,
|
||||
"authSmsSystemSender": "",
|
||||
"authSmsTextTemplate": "Your code {{code}}",
|
||||
"deviceTokenExpireMs": -1,
|
||||
"authSmsShortCodeLength": 4,
|
||||
"authSmsShortCodeExpireMs": 300000
|
||||
}', current_setting('migration.db_user'),
|
||||
current_setting('migration.db_port'),
|
||||
current_setting('migration.db_host'),
|
||||
current_setting('migration.db_dbname'),
|
||||
current_setting('migration.db_pass'),
|
||||
current_setting('migration.redis_host'),
|
||||
current_setting('migration.redis_port')
|
||||
)) :: jsonb);
|
||||
-- mobile
|
||||
INSERT INTO configs VALUES (7, 7, NULL, 't', NULL, NULL, ('{"database": {' ||
|
||||
'"port": "' || current_setting('migration.db_port') || '", ' ||
|
||||
'"schema": "mobile_service", ' ||
|
||||
'"address": "' || current_setting('migration.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migration.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migration.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migration.db_user') || '", ' ||
|
||||
'"createSchema": true}, ' ||
|
||||
'"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9562"}}' ||
|
||||
'}')::jsonb);
|
||||
-- awip
|
||||
INSERT INTO configs VALUES (8, 8, NULL, 't', NULL, NULL, '{
|
||||
"backends": [
|
||||
{
|
||||
"id": "450e754f-aafb-4a9c-8d87-23c6a2da9833",
|
||||
"url": "http://{{ cname }}-nginx.isp.mobi:18888/ru.isp.starter.awip.backend.ws/backend?wsdl",
|
||||
"name": "citymatica_user_new",
|
||||
"wrapList": true,
|
||||
"createDate": "2018-09-07T09:41:03.853Z",
|
||||
"clientPoolSize": 0,
|
||||
"requestTimeout": 30000,
|
||||
"systemIdentity": "1"
|
||||
},
|
||||
{
|
||||
"id": "74d76314-b28b-11e8-96f8-529269fb1459",
|
||||
"url": "http://{{ cname }}-nginx.isp.mobi:18880/ru.mp.storage.backend.ws/backend?wsdl",
|
||||
"name": "citymatica_user_old",
|
||||
"wrapList": true,
|
||||
"createDate": "2018-09-07T09:41:03.853Z",
|
||||
"clientPoolSize": 0,
|
||||
"requestTimeout": 30000,
|
||||
"systemIdentity": "1"
|
||||
},
|
||||
{
|
||||
"id": "74d7659e-b28b-11e8-96f8-529269fb1459",
|
||||
"url": "http://{{ cname }}-nginx.isp.mobi:18890/ru.isp.starter.awip.backend.ws/backend?wsdl",
|
||||
"name": "citymatica_user_object_storage",
|
||||
"wrapList": true,
|
||||
"createDate": "2018-09-07T09:41:03.853Z",
|
||||
"clientPoolSize": 0,
|
||||
"requestTimeout": 30000,
|
||||
"systemIdentity": "1"
|
||||
},
|
||||
{
|
||||
"id": "74d75cc0-b28b-11e8-96f8-529269fb1459",
|
||||
"url": "http://{{ cname }}-nginx.isp.mobi:18891/ru.isp.starter.awip.backend.ws/backend?wsdl",
|
||||
"name": "citymatica_user_events",
|
||||
"wrapList": true,
|
||||
"createDate": "2018-09-07T09:41:03.853Z",
|
||||
"clientPoolSize": 0,
|
||||
"requestTimeout": 30000,
|
||||
"systemIdentity": "1"
|
||||
},
|
||||
{
|
||||
"id": "d5575047-6588-46d9-be58-b487d42d217c",
|
||||
"url": "http://{{ cname }}-nginx.isp.mobi:18889/ru.isp.starter.awip.backend.ws/backend?wsdl",
|
||||
"name": "citymatica_operator",
|
||||
"wrapList": true,
|
||||
"createDate": "2018-09-07T09:41:03.853Z",
|
||||
"clientPoolSize": 0,
|
||||
"requestTimeout": 30000,
|
||||
"systemIdentity": "1"
|
||||
},
|
||||
{
|
||||
"id": "74d76094-b28b-11e8-96f8-529269fb1459",
|
||||
"url": "http://{{ cname }}-nginx.isp.mobi:18895/ru.isp.starter.awip.backend.ws/backend?wsdl",
|
||||
"name": "citymatica_operator_metrics",
|
||||
"wrapList": true,
|
||||
"createDate": "2018-09-07T09:41:03.853Z",
|
||||
"clientPoolSize": 0,
|
||||
"requestTimeout": 30000,
|
||||
"systemIdentity": "1"
|
||||
}
|
||||
]
|
||||
}');
|
||||
-- mongo-backend
|
||||
INSERT INTO configs VALUES (9, 9, NULL, 't', NULL, NULL, '{"connections": [],"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9563"}}}');
|
||||
-- sql-backend
|
||||
INSERT INTO configs VALUES (10, 10, NULL, 't', NULL, NULL, '{"connections": [], "metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9566"}}}');
|
||||
-- events
|
||||
INSERT INTO configs VALUES (11, 11, NULL, 't', NULL, NULL, '{"eventRoutes": [{"handlers": {}, "applicationGroupId": 1}, {"handlers": {}, "applicationGroupId": 5}], "queueEndpoints": []}');
|
||||
|
||||
SELECT setval(pg_get_serial_sequence('configs', 'id'), 12, FALSE);
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM configs WHERE id IN (6,7,8,9,10,11)
|
||||
@@ -1,9 +0,0 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE configs
|
||||
ADD COLUMN name VARCHAR(255) NOT NULL DEFAULT 'unnamed',
|
||||
ADD COLUMN description TEXT;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE configs
|
||||
DROP COLUMN name,
|
||||
DROP COLUMN description;
|
||||
@@ -1,23 +0,0 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE config_schemas (
|
||||
id SERIAL4 PRIMARY KEY,
|
||||
module_id INTEGER NOT NULL,
|
||||
version VARCHAR(255) NOT NULL,
|
||||
schema JSONB NOT NULL DEFAULT '{}',
|
||||
created_at TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc'),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc'),
|
||||
CONSTRAINT FK_module_id__module_id FOREIGN KEY (module_id)
|
||||
REFERENCES modules (id) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TRIGGER update_schema_create_time
|
||||
BEFORE INSERT OR UPDATE
|
||||
ON config_schemas
|
||||
FOR EACH ROW EXECUTE PROCEDURE update_created_column_date();
|
||||
|
||||
CREATE INDEX IX_schemes_moduleId
|
||||
ON config_schemas
|
||||
USING hash (module_id);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE config_schemas;
|
||||
@@ -1,43 +0,0 @@
|
||||
-- +goose Up
|
||||
set migration.db_host = 'msk-pgsql.isp.mobi';
|
||||
set migration.db_port = '5432';
|
||||
set migration.db_dbname = 'isp-alpha';
|
||||
set migration.db_user = 'isp-alpha';
|
||||
set migration.db_pass = 'JxY96xLF8zfh3g8EWvSDtLUBw';
|
||||
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'template', 't') RETURNING id
|
||||
)
|
||||
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
('{"database": {' ||
|
||||
'"port": "' || current_setting('migration.db_port') || '", ' ||
|
||||
'"schema": "template_service", ' ||
|
||||
'"address": "' || current_setting('migration.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migration.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migration.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migration.db_user') || '", ' ||
|
||||
'"createSchema": true}, "defaultLanguage": "en", ' ||
|
||||
'"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9567"}}' ||
|
||||
'}')::jsonb);
|
||||
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'message-bundle', 't') RETURNING id
|
||||
)
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
('{"database": {' ||
|
||||
'"port": "' || current_setting('migration.db_port') || '", ' ||
|
||||
'"schema": "message_bundle_service", ' ||
|
||||
'"address": "' || current_setting('migration.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migration.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migration.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migration.db_user') || '", ' ||
|
||||
'"createSchema": true}, "defaultLanguage": "en", ' ||
|
||||
'"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9560"}}' ||
|
||||
'}')::jsonb);
|
||||
|
||||
-- +goose Down
|
||||
@@ -1,88 +0,0 @@
|
||||
-- +goose Up
|
||||
set migration.nats_host = '10.250.9.117';
|
||||
set migration.nats_port = '4223';
|
||||
set migration.nats_cluster_id = 'test-cluster';
|
||||
|
||||
WITH moduleVar AS (INSERT INTO modules (instance_id, name, active) VALUES (1, 'mobile-push', 't') RETURNING id)
|
||||
INSERT INTO configs (module_id, active, data)
|
||||
VALUES ((SELECT id FROM moduleVar), 't', (
|
||||
format('{
|
||||
"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9561"}},
|
||||
"firebaseConfig": {
|
||||
"token_uri": "https://accounts.google.com/o/oauth2/token",
|
||||
"client_id": "115553569331708875508",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"client_email": "firebase-adminsdk-f70qo@test-ccdab.iam.gserviceaccount.com",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCM7Rl7AmGQSOxx\nUdQs+yY7cwaUmqi2khmsre0/kfJU2zCJxotbYNeyfWJZk3D8hngxnmI6hrYqWEq3\nyy/J8rhI7AmcY3eXC1yyL/sKTClFjyZVEoDcBWTn0HOuM8YAQAqRAx2vznKDquoj\nLgUHl09qTxsVRmPdfc7fKE45OZBdetA/kdIEd4S5J+CKeYB7tpuT+0eL4QUNOzE1\n6SGqYnhA97QD7K3ylhWxKC8U0Ozyqub/OTg7WRLEYV36Z+6Ok0BZkYiCXbUNukST\nXaKc8DGAFrzcu7jW8rJIRZ/uc/Im5judjuMRznzu1SMPVT6pL8HfduGFc23FIAL/\nGjmcDwWbAgMBAAECggEAETe6oDvHPcCbGrE7sg8xOZwxFqDasguhlWZekSC8sb9h\n68NVLWHkmIsXJAiOilvHfZBzQeFJilzlLBVoDk1YVJh6CCBi8RJTTfXsvvJVLIlz\nznsHQVprXKMsLwFmVIt+fv8ZdmxLs2iDWK77sFS9QCjQD0ZdVydSyhL7k6RDzhfP\nw6It0H3JyyqD8W7DOvYSUfi/oZKZvufBAkEauhuiVVyite97cJtV8YNmiVCznOtK\nOw0OpuzemKez0rh673VtEEvUgrvOy5WNtjunoRkNKZkW1JiAWYpf6FpOOFub/lG3\nQPFwjLZeEUa8xc/E2JJP6HQMON0qF5zvtKr4QH/9uQKBgQDByXfLh+56Cu+6E0CL\nigH0GmagwZQnw7/+zhi1AhC2DjxAmXq9Y0kFrmpwr6FXqtRJm5AANOipASsRknaq\n5kAlDCGdqHnw1LDlNbrxywDvTYADo13ebx2cXfxESDfx0gofXehGhfFfOyXJ0lwp\ngXbgxIQFNjv2QWjSdb637ZaOrQKBgQC6KzmZcMAWo7j+eGo0WoAVTCVu/SDcV/sG\nF4+NxhLjMYSuMbBF7BdMy1rJ6g3SrdULGzw0KDeEqo1XzneOyzHOnEiZFKTkgIPQ\n347fWOYTBKMNEJd37jAIHKrrFiyD/pvL2ZLu1mSnCHsi/v5u02gqpf8Vkvwo/5ME\n4BuhB/PWZwKBgQC7V0adl+rfR0VcURJcE+4xi3hdvua4zpAFCD9wde+r4PU0ymuT\nPbGxcV1rVQ8YTojuJBrBaGToRb3aPgrEytWGO0UgQmiofyYIYLo62LMtpXG1krDD\nwg4RRfcEGAEloZWxnzpXO1QOaYLtqpT4dzVys+ihlT3AoplwpO3cqC6d/QKBgEGu\nkmnSX9Mc/F27eizyaRIahXJ9GCTlXYkustUgNvW1OMyEd16UBzxu2p82Vp4n+mwq\ntbjpH31M9wUtsPzOL8pnVS29HNgJh3ggB7ZBFRtMnYI0glwrywJxqtO6RQZkw+7N\n2ostVOGhmmAkevv61luFqVOhQhns4Z/suZK8zYitAoGAHwLWUQViCy0HFkhED5GV\nWrZZFRH2ucpK+ljOp7dbbUPA+dTD2qu/hho3QCaT5odJWap42TbSL6YhZg/7jN7h\nOSQW8DiDPzjUtL1gfqOxJdQavrgR2a2AW054loM0R508699Vx6Hir/ayD4nZ9IUo\nm2meeJVZcknz/L9LXOOIUBk=\n-----END PRIVATE KEY-----\n",
|
||||
"private_key_id": "88d1af761304de758388747d72931c3457df54ef",
|
||||
"project_id": "test-ccdab",
|
||||
"type": "service_account",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-f70qo%%40test-ccdab.iam.gserviceaccount.com"
|
||||
},
|
||||
"concurrentSendersCount": 6,
|
||||
"natsConfig": {
|
||||
"address": {
|
||||
"port": "%s",
|
||||
"ip": "%s"
|
||||
},
|
||||
"clusterId": "%s"
|
||||
}
|
||||
}', current_setting('migration.nats_port'),
|
||||
current_setting('migration.nats_host'),
|
||||
current_setting('migration.nats_cluster_id')
|
||||
)) :: jsonb);
|
||||
|
||||
WITH moduleVar AS (INSERT INTO modules (instance_id, name, active) VALUES (1, 'sms', 't') RETURNING id)
|
||||
INSERT INTO configs (module_id, active, data)
|
||||
VALUES ((SELECT id FROM moduleVar), 't', (format('{
|
||||
"natsConfig": {
|
||||
"clusterId": "%s",
|
||||
"address": {
|
||||
"ip": "%s",
|
||||
"port": "%s"
|
||||
}
|
||||
},
|
||||
"smppClients": [
|
||||
{
|
||||
"default": true,
|
||||
"poolSize": 1,
|
||||
"connection": {
|
||||
"password": "1q2w3e!",
|
||||
"user": "isp",
|
||||
"address": {
|
||||
"ip": "5.187.0.65",
|
||||
"port": "9931"
|
||||
}
|
||||
},
|
||||
"ResponseTimeoutMs": 5000,
|
||||
"concurrentSendersCount": 2,
|
||||
"name": "smsc"
|
||||
}
|
||||
],
|
||||
"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9565"}}
|
||||
}', current_setting('migration.nats_cluster_id'),
|
||||
current_setting('migration.nats_host'),
|
||||
current_setting('migration.nats_port')
|
||||
)) :: jsonb);
|
||||
|
||||
WITH moduleVar AS (INSERT INTO modules (instance_id, name, active) VALUES (1, 'email', 't') RETURNING id)
|
||||
INSERT INTO configs (module_id, active, data)
|
||||
VALUES ((SELECT id FROM moduleVar), 't', (format('{
|
||||
"natsConfig": {
|
||||
"clusterId": "%s",
|
||||
"address": {
|
||||
"ip": "%s",
|
||||
"port": "%s"
|
||||
}
|
||||
},
|
||||
"smtpClients": [
|
||||
|
||||
],
|
||||
"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9558"}}
|
||||
}', current_setting('migration.nats_cluster_id'),
|
||||
current_setting('migration.nats_host'),
|
||||
current_setting('migration.nats_port')
|
||||
)) :: jsonb);
|
||||
|
||||
-- +goose Down
|
||||
@@ -1,27 +0,0 @@
|
||||
-- +goose Up
|
||||
WITH moduleVar AS (INSERT INTO modules (instance_id, name, active) VALUES (1, 'file-storage', 't')
|
||||
RETURNING id)
|
||||
INSERT INTO configs (module_id, active, data)
|
||||
VALUES ((SELECT id FROM moduleVar), 't', '{
|
||||
"imageSizeList": [
|
||||
75,
|
||||
130,
|
||||
200,
|
||||
320,
|
||||
510,
|
||||
604,
|
||||
807
|
||||
],
|
||||
"rootDirectory": "./files/",
|
||||
"maxRequestBodySizeInBytes": 1073741824,
|
||||
"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9559"}}
|
||||
}' :: jsonb);
|
||||
|
||||
WITH moduleVar AS (INSERT INTO modules (instance_id, name, active) VALUES (1, 'rest-backend', 't')
|
||||
RETURNING id)
|
||||
INSERT INTO configs (module_id, active, data)
|
||||
VALUES ((SELECT id FROM moduleVar), 't', '{
|
||||
"backends": [], "metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9564"}}
|
||||
}' :: jsonb);
|
||||
|
||||
-- +goose Down
|
||||
@@ -1,54 +0,0 @@
|
||||
-- +goose Up
|
||||
set migrationRead.db_host = 'msk-pgsql.isp.mobi';
|
||||
set migrationRead.db_port = '5432';
|
||||
set migrationRead.db_dbname = 'isp-alpha';
|
||||
set migrationRead.db_user = 'isp-alpha';
|
||||
set migrationRead.db_pass = 'JxY96xLF8zfh3g8EWvSDtLUBw';
|
||||
|
||||
set migrationWrite.db_host = 'msk-pgsql.isp.mobi';
|
||||
set migrationWrite.db_port = '5432';
|
||||
set migrationWrite.db_dbname = 'isp-alpha';
|
||||
set migrationWrite.db_user = 'isp-alpha';
|
||||
set migrationWrite.db_pass = 'JxY96xLF8zfh3g8EWvSDtLUBw';
|
||||
|
||||
set migrationNotification.db_host = 'msk-pgsql.isp.mobi';
|
||||
set migrationNotification.db_port = '5432';
|
||||
set migrationNotification.db_dbname = 'isp-alpha';
|
||||
set migrationNotification.db_user = 'isp-alpha';
|
||||
set migrationNotification.db_pass = 'JxY96xLF8zfh3g8EWvSDtLUBw';
|
||||
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'mdm', 't') RETURNING id
|
||||
)
|
||||
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
('{"databaseRead": {' ||
|
||||
'"port": "' || current_setting('migrationRead.db_port') || '", ' ||
|
||||
'"schema": "mdm_service", ' ||
|
||||
'"address": "' || current_setting('migrationRead.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migrationRead.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migrationRead.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migrationRead.db_user') || '", ' ||
|
||||
'"createSchema": true},' ||
|
||||
'"metrics": {"gc": true, "memory": true, "address": {"ip": "0.0.0.0", "path": "/metrics", "port": "9568"}},' ||
|
||||
'"databaseWrite": {' ||
|
||||
'"port": "' || current_setting('migrationWrite.db_port') || '", ' ||
|
||||
'"schema": "mdm_service", ' ||
|
||||
'"address": "' || current_setting('migrationWrite.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migrationWrite.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migrationWrite.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migrationWrite.db_user') || '", ' ||
|
||||
'"createSchema": true},' ||
|
||||
'"databaseNotifications": {' ||
|
||||
'"port": "' || current_setting('migrationNotification.db_port') || '", ' ||
|
||||
'"schema": "mdm_service", ' ||
|
||||
'"address": "' || current_setting('migrationNotification.db_host') || '", ' ||
|
||||
'"database": "' || current_setting('migrationNotification.db_dbname') || '", ' ||
|
||||
'"password": "' || current_setting('migrationNotification.db_pass') || '", ' ||
|
||||
'"username": "' || current_setting('migrationNotification.db_user') || '", ' ||
|
||||
'"createSchema": true}}')::jsonb);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
-- +goose Up
|
||||
set migration.nats_host = '10.250.9.117';
|
||||
set migration.nats_port = '4223';
|
||||
set migration.nats_cluster_id = 'test-cluster';
|
||||
|
||||
set migration.rabbit_host = '10.250.9.117';
|
||||
set migration.rabbit_port = '5672';
|
||||
set migration.rabbit_user = 'guest';
|
||||
set migration.rabbit_password = 'guest';
|
||||
set migration.rabbit_system_queue_prefix = 'test';
|
||||
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'mdm-notify', 't') RETURNING id
|
||||
)
|
||||
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
('{
|
||||
"notifyConfigurations":[],
|
||||
"logger": {
|
||||
"sendAddRequestSudirV1IsOn": true,
|
||||
"sendFindRequestSudirV1IsOn": true,
|
||||
"sendUpdateRequestSudirV1IsOn": true,
|
||||
"sendUpdateRequestSudirV2IsOn": true,
|
||||
"creatingSystemNotificationsIsOn": true,
|
||||
"sendErlRequestQueueIsOn": true,
|
||||
"sendJsonRequestQueueIsOn": true,
|
||||
"syncLogger": {
|
||||
"enable": false,
|
||||
"filename": "/opt/isp/isp-mdm-notify-service/events_logs/events.log.gz"
|
||||
},
|
||||
"asyncLogger": {
|
||||
"enable": false,
|
||||
"nats": {
|
||||
"address": {
|
||||
"ip": "mdm-taxcom-test-nats.isp.mobi",
|
||||
"port": "4222"
|
||||
},
|
||||
"clusterId": "work-cluster"
|
||||
}
|
||||
},
|
||||
"sendAddRequestSudirV1IsOn": true
|
||||
},
|
||||
"metrics":{
|
||||
"gc": true,
|
||||
"memory": true,
|
||||
"address": {
|
||||
"port": "9572",
|
||||
"ip": "0.0.0.0",
|
||||
"path": "/metrics"
|
||||
}
|
||||
},
|
||||
"rabbit": {
|
||||
"routingKey": "notification",
|
||||
"exchangeName": "notifications",
|
||||
"systemQueuesPrefix": "' || current_setting('migration.rabbit_system_queue_prefix') || '",
|
||||
"declareQueueAndExchange": true,
|
||||
"password": "' || current_setting('migration.rabbit_password') || '",
|
||||
"user": "' || current_setting('migration.rabbit_user') || '",
|
||||
"address": {
|
||||
"ip": "' || current_setting('migration.rabbit_host') || '",
|
||||
"port": "' || current_setting('migration.rabbit_port') || '"
|
||||
}
|
||||
"queue": {
|
||||
"name": "notifier.queue",
|
||||
"prefetchCount": 1000
|
||||
},
|
||||
},
|
||||
"logRabbitEnabled": true,
|
||||
"logRabbit": {
|
||||
"address": {
|
||||
"ip": "10.250.9.50",
|
||||
"port": "5672"
|
||||
},
|
||||
"password": "ohk7athXehev3aiGfic2ZeiD",
|
||||
"routingKey": "mdm-taxcom-test.notify.log",
|
||||
"exchangeName": "mdm-taxcom-test.notify.log",
|
||||
"systemQueuesPrefix": "mdm-taxcom-test",
|
||||
"declareQueueAndExchange": true,
|
||||
"user": "isp",
|
||||
"queue": {
|
||||
"name": "mdm-taxcom-test.notify.log.queue",
|
||||
"prefetchCount": 300
|
||||
}
|
||||
}
|
||||
}')::jsonb);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
-- +goose Up
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'mdm-notify', 't') RETURNING id
|
||||
)
|
||||
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
('{
|
||||
"rules": {
|
||||
"1": [
|
||||
"etalon_id",
|
||||
"last_name",
|
||||
"$$documents.#passport",
|
||||
"vehicles",
|
||||
"addresses"
|
||||
]
|
||||
},
|
||||
"mappingSchema": {
|
||||
"$$documents.1000019.ref_num": "DRIVER_LICENSE.DriverLicense",
|
||||
"gkupays.mesmeter": "[]HOUSE.MesMeterNumber",
|
||||
"$$documents.1000016.start_dt": "PASSPORT_RF.PassportIssueDate",
|
||||
"$$addresses.1000009.moscow_district_id": "[]REG_ADDRESS.RegAddressDistrictId",
|
||||
"$$addresses.7.unom": "[]ADDRESS.RealAddressUnom",
|
||||
"$$addresses.1000009.unom": "[]REG_ADDRESS.RegAddressUnom",
|
||||
"$$addresses.1000009.moscow_area_ext_id": "[]REG_ADDRESS.RegAddressAreaId",
|
||||
"$$addresses.7.moscow_area_ext_id": "[]ADDRESS.RealAddressAreaId",
|
||||
"$$escredentials.1000004.etalon_id": "[]OLYMPIAD.OlympiadId",
|
||||
"last_name": "FIO.LastName",
|
||||
"vehicles.reg_number": "[]VEHICLE.VehicleRegistrationNumber",
|
||||
"$$contacts.1.ref_num": "REG_DATA.Phone",
|
||||
"$$addresses.7.corpus_no": "[]ADDRESS.RealAddressCorpus",
|
||||
"$$users.NOT_SSO.id_value": "USER.LoginName",
|
||||
"$$addresses.7.residence_num": "[]ADDRESS.RealAddressFlat",
|
||||
"$$users.SSO.id_value": "USER.LoginName",
|
||||
"birth_place_line_one": "PASSPORT_RF.PassportBirthPlace",
|
||||
"$$addresses.7.house_no": "[]ADDRESS.RealAddressHouse",
|
||||
"$$addresses.1000009.street_name_ex": "[]REG_ADDRESS.RegAddressStreet",
|
||||
"gkupays.mesaccount": "[]HOUSE.MesAccountNumber",
|
||||
"vehicles.etalon_id": "[]VEHICLE.VehicleId",
|
||||
"$$addresses.7.street_id": "[]ADDRESS.RealAddressStreetId",
|
||||
"$$documents.1000014.ref_num": "COMPLEX_OMS.oms",
|
||||
"$$addresses.1000009.stroenie_no": "[]REG_ADDRESS.RegAddressBuilding",
|
||||
"$$addresses.7.moscow_district_id": "[]ADDRESS.RealAddressDistrictId",
|
||||
"$$addresses.7.unad": "[]ADDRESS.RealAddressUnad",
|
||||
"vehicles.pts_number": "[]VEHICLE.VehiclePTSNumber",
|
||||
"$$documents.1000016.identification_issuer": "PASSPORT_RF.PassportIssuer",
|
||||
"etalon_id": "USER.LoginName",
|
||||
"$$addresses.1000009.street_id": "[]REG_ADDRESS.RegAddressStreetId",
|
||||
"$$escredentials.1000003.etalon_id": "[]GIA.GIAId",
|
||||
"$$addresses.1000009.moscow_district_name": "[]REG_ADDRESS.RegAddressDistrict",
|
||||
"given_name_one": "FIO.FirstName",
|
||||
"vehicles.vin_number": "[]VEHICLE.VehicleVin",
|
||||
"$$escredentials.1000004.login": "[]OLYMPIAD.OlympiadLogin",
|
||||
"$$escredentials.1000003.doc_number": "[]GIA.GIADocNumber",
|
||||
"$$addresses.1000009.moscow_area_name": "[]REG_ADDRESS.RegAddressArea",
|
||||
"gkupays.gkupay_address_rel": "[]HOUSE.EpdAddressId",
|
||||
"$$addresses.7.building_name": "[]ADDRESS.RealAddressHouseId",
|
||||
"$$addresses.7.moscow_area_name": "[]ADDRESS.RealAddressArea",
|
||||
"$$addresses.7.moscow_district_name": "[]ADDRESS.RealAddressDistrict",
|
||||
"gender_tp_code": "PERSON.Gender",
|
||||
"$$addresses.7.stroenie_no": "[]ADDRESS.RealAddressBuilding",
|
||||
"$$documents.1000013.ref_num": "TAX_INFO.INN",
|
||||
"$$addresses.1000009.building_name": "[]REG_ADDRESS.RegAddressHouseId",
|
||||
"$$escredentials.1000004.description": "[]OLYMPIAD.OlympiadComment",
|
||||
"birth_dt": "PERSON.Birthday",
|
||||
"gkupays.epd": "[]HOUSE.EpdAddressNumber",
|
||||
"$$addresses.1000009.house_no": "[]REG_ADDRESS.RegAddressHouse",
|
||||
"$$addresses.1000009.street_omk": "[]REG_ADDRESS.RegAddressStreetOMK",
|
||||
"$$citizen_relatives.OTHERS.etalon_id": "[]RELATIVES.RltvId",
|
||||
"vehicles.stsnumber": "[]VEHICLE.VehicleSTSNumber",
|
||||
"vehicles.description": "[]VEHICLE.VehicleDescription",
|
||||
"$$addresses.1000009.unad": "[]REG_ADDRESS.RegAddressUnad",
|
||||
"$$escredentials.1000004.password": "[]OLYMPIAD.OlympiadPassword",
|
||||
"gkupays.phone": "[]HOUSE.EpdAddressCityPhone",
|
||||
"$$addresses.7.street_omk": "[]ADDRESS.RealAddressStreetOMK",
|
||||
"$$documents.1000019.start_dt": "DRIVER_LICENSE.DriverLicenseIssueDate",
|
||||
"$$addresses.1000009.corpus_no": "[]REG_ADDRESS.RegAddressCorpus",
|
||||
"$$citizen_relatives.1000004.etalon_id": "[]CHILDREN.ChildId",
|
||||
"$$documents.1000016.identification_issuer_code": "PASSPORT_RF.PassportIssuerCode",
|
||||
"$$escredentials.1000003.login": "[]GIA.GIARegCode",
|
||||
"$$addresses.1000009.residence_num": "[]REG_ADDRESS.RegAddressFlat",
|
||||
"given_name_two": "FIO.MiddleName",
|
||||
"$$contacts.2.ref_num": "REG_DATA.Email",
|
||||
"$$documents.1000015.ref_num": "SNILS.snils",
|
||||
"$$documents.1000016.ref_num": "PASSPORT_RF.PassportNumber",
|
||||
"$$addresses.7.street_name_ex": "[]ADDRESS.RealAddressStreet",
|
||||
"$$documents.1000014.etalon_id": "COMPLEX_OMS.OmsId",
|
||||
"$$escredentials.1000003.description": "[]GIA.GIAComment",
|
||||
"$$citizen_relatives.1000003.etalon_id": "[]CHILDREN.ChildId",
|
||||
"$$documents.1000016.identification_passport_birth_place": "PASSPORT_RF.PassportBirthPlace"
|
||||
},
|
||||
"metrics": {
|
||||
"memory": true,
|
||||
"address": {
|
||||
"path": "/metrics",
|
||||
"port": "9571",
|
||||
"ip": "0.0.0.0"
|
||||
},
|
||||
"gc": true
|
||||
}
|
||||
}')::jsonb);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
-- +goose Up
|
||||
set migration.nats_host = '10.250.9.117';
|
||||
set migration.nats_port = '4223';
|
||||
set migration.nats_cluster_id = 'test-cluster';
|
||||
|
||||
set migration.rabbit_host = '10.250.9.117';
|
||||
set migration.rabbit_port = '5672';
|
||||
set migration.rabbit_user = 'guest';
|
||||
set migration.rabbit_password = 'guest';
|
||||
|
||||
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'mdm-notify', 't') RETURNING id
|
||||
)
|
||||
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
('{
|
||||
"isNatsLoggerEnabled": false,
|
||||
"nats": {
|
||||
"address": {
|
||||
"port": "' || current_setting('migration.nats_port') || '",
|
||||
"ip": "' || current_setting('migration.nats_host') || '"
|
||||
},
|
||||
"clusterId": "' || current_setting('migration.nats_cluster_id') || '"
|
||||
},
|
||||
"queue": {
|
||||
"init": {
|
||||
"concurrentConsumers": 8,
|
||||
"name": "init",
|
||||
"prefetchCount": 10
|
||||
},
|
||||
"tempQueue": {
|
||||
"name": "tempt",
|
||||
"prefetchCount": 10,
|
||||
"concurrentConsumers": 128
|
||||
},
|
||||
"defaultQueue": {
|
||||
"concurrentConsumers": 128,
|
||||
"name": "events",
|
||||
"prefetchCount": 10
|
||||
}
|
||||
},
|
||||
"rabbit": {
|
||||
"password": "' || current_setting('migration.rabbit_password') || '",
|
||||
"reconnectionTimeoutMs": 0,
|
||||
"user": "' || current_setting('migration.rabbit_user') || '",
|
||||
"address": {
|
||||
"ip": "' || current_setting('migration.rabbit_host') || '",
|
||||
"port": "' || current_setting('migration.rabbit_port') || '"
|
||||
}
|
||||
},
|
||||
"metrics": {
|
||||
"memory": true,
|
||||
"address": {
|
||||
"path": "/metrics",
|
||||
"port": "9569",
|
||||
"ip": "0.0.0.0"
|
||||
},
|
||||
"gc": true
|
||||
}
|
||||
}')::jsonb);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
-- +goose Up
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'mdm-api', 't') RETURNING id
|
||||
)
|
||||
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
('{' ||
|
||||
'"pKAttributeName": "id"' ||
|
||||
'}')::jsonb);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
-- +goose Up
|
||||
set rabbit.host = '10.250.9.117';
|
||||
set rabbit.port = '5672';
|
||||
set rabbit.user = 'guest';
|
||||
set rabbit.password = 'guest';
|
||||
|
||||
set elastic.url = 'http://10.250.9.48:9200';
|
||||
|
||||
WITH moduleVar AS (
|
||||
INSERT INTO modules (instance_id, name, active) VALUES (1, 'mdm-search', 't') RETURNING id
|
||||
)
|
||||
|
||||
INSERT INTO configs (module_id, active, data) VALUES (
|
||||
(SELECT id FROM moduleVar),
|
||||
't',
|
||||
((format('{
|
||||
"queue": {
|
||||
"prefetchSize": 1000,
|
||||
"searcherQueue": "searcher.queue",
|
||||
"concurrentConsumers": 4
|
||||
},
|
||||
"rabbit": {
|
||||
"user": "%s",
|
||||
"address": {
|
||||
"ip": "%s",
|
||||
"port": "%s"
|
||||
},
|
||||
"password": "%s"
|
||||
},
|
||||
"elastic": {
|
||||
"uRL": "%s",
|
||||
"shards": 1
|
||||
},
|
||||
"metrics": {
|
||||
"address": {
|
||||
"ip": "0.0.0.0",
|
||||
"path": "/metrics",
|
||||
"port": "9573"
|
||||
},
|
||||
"gc": true,
|
||||
"memory": true
|
||||
},
|
||||
"isFieldsListWhite": false,
|
||||
"fieldsList": [
|
||||
"documents",
|
||||
"citizen_relatives",
|
||||
"contacts",
|
||||
"addresses",
|
||||
"escredentials",
|
||||
"users"
|
||||
]
|
||||
}', current_setting('rabbit.user'),
|
||||
current_setting('rabbit.host'),
|
||||
current_setting('rabbit.port'),
|
||||
current_setting('rabbit.password'),
|
||||
|
||||
current_setting('elastic.url')
|
||||
)) :: jsonb));
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"isp-config-service/entity"
|
||||
|
||||
"github.com/go-pg/pg"
|
||||
"github.com/go-pg/pg/orm"
|
||||
)
|
||||
|
||||
type ConfigRepository struct {
|
||||
DB orm.DB
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) GetConfigs(identities []int64) ([]entity.Config, error) {
|
||||
var configs []entity.Config
|
||||
var err error
|
||||
if len(identities) > 0 {
|
||||
err = r.DB.Model(&configs).
|
||||
Where("id IN (?)", pg.In(identities)).
|
||||
Order("created_at DESC").
|
||||
Limit(500).
|
||||
Select()
|
||||
} else {
|
||||
err = r.DB.Model(&configs).
|
||||
Order("created_at DESC").
|
||||
Limit(500).
|
||||
Select()
|
||||
}
|
||||
return configs, err
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) GetConfigsByModulesId(modulesId []int32) ([]entity.Config, error) {
|
||||
var res []entity.Config
|
||||
err := r.DB.Model(&res).Where("module_id IN (?)", pg.In(modulesId)).Order("created_at DESC").Select()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) CreateConfig(config *entity.Config) (*entity.Config, error) {
|
||||
_, err := r.DB.Model(config).
|
||||
Returning("*").
|
||||
Insert()
|
||||
return config, err
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) UpdateConfig(config *entity.Config) (*entity.Config, error) {
|
||||
_, err := r.DB.Model(config).WherePK().
|
||||
Returning("*").
|
||||
Update()
|
||||
return config, err
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) DeleteConfig(identities []int64) (int, error) {
|
||||
result, err := r.DB.Exec("DELETE FROM "+schema+".configs WHERE id IN (?)", pg.In(identities))
|
||||
return result.RowsAffected(), err
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) GetConfigById(identity int64) (*entity.Config, error) {
|
||||
cfg := new(entity.Config)
|
||||
err := r.DB.Model(cfg).
|
||||
Where("id = ?", identity).
|
||||
First()
|
||||
if err == pg.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) GetConfigByInstanceUUIDAndModuleName(instanceUUID string, moduleName string) (*entity.Config, error) {
|
||||
cfg := new(entity.Config)
|
||||
err := r.DB.Model(cfg).
|
||||
Where(`module_id = (SELECT id FROM `+schema+`.modules WHERE name = ?
|
||||
AND instance_id = (SELECT id FROM `+schema+`.instances WHERE uuid = ?))`, moduleName, instanceUUID).
|
||||
Where("active = true").
|
||||
Order("updated_at DESC").
|
||||
First()
|
||||
if err == pg.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
func (r *ConfigRepository) GetModuleNameAndInstanceUUIDByConfigId(configId int64) (entity.ModuleInstanceIdentity, error) {
|
||||
var cfg entity.ModuleInstanceIdentity
|
||||
_, err := r.DB.Query(&cfg, `SELECT temp.name, uuid
|
||||
FROM (SELECT name, instance_id FROM `+schema+`.modules WHERE id =
|
||||
(SELECT module_id FROM `+schema+`.configs WHERE id = ? AND active = true)) temp
|
||||
LEFT JOIN `+schema+`.instances s ON s.id = temp.instance_id`, configId)
|
||||
|
||||
if err != nil && err == pg.ErrNoRows {
|
||||
return cfg, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"isp-config-service/entity"
|
||||
|
||||
"github.com/go-pg/pg"
|
||||
"github.com/go-pg/pg/orm"
|
||||
)
|
||||
|
||||
type InstanceRepository struct {
|
||||
DB orm.DB
|
||||
}
|
||||
|
||||
func (r *InstanceRepository) GetInstances(identities []int32) ([]entity.Instance, error) {
|
||||
var instances []entity.Instance
|
||||
var err error
|
||||
if len(identities) > 0 {
|
||||
err = r.DB.Model(&instances).
|
||||
Where("id IN (?)", pg.In(identities)).
|
||||
Order("created_at DESC").
|
||||
Limit(500).
|
||||
Select()
|
||||
} else {
|
||||
err = r.DB.Model(&instances).
|
||||
Order("created_at DESC").
|
||||
Limit(500).
|
||||
Select()
|
||||
}
|
||||
return instances, err
|
||||
}
|
||||
|
||||
func (r *InstanceRepository) CreateInstance(instance entity.Instance) (entity.Instance, error) {
|
||||
_, err := r.DB.Model(&instance).
|
||||
Returning("id").
|
||||
Returning("created_at").
|
||||
Insert()
|
||||
return instance, err
|
||||
}
|
||||
|
||||
func (r *InstanceRepository) UpdateInstance(instance entity.Instance) (entity.Instance, error) {
|
||||
_, err := r.DB.Model(&instance).WherePK().
|
||||
Returning("id").
|
||||
Returning("created_at").
|
||||
Update()
|
||||
return instance, err
|
||||
}
|
||||
|
||||
func (r *InstanceRepository) DeleteInstance(identities []int32) (int, error) {
|
||||
result, err := r.DB.Exec("DELETE FROM "+schema+".instances WHERE id IN (?)", pg.In(identities))
|
||||
return result.RowsAffected(), err
|
||||
}
|
||||
|
||||
func (r *InstanceRepository) GetInstanceById(identity int32) (entity.Instance, error) {
|
||||
var module entity.Instance
|
||||
err := r.DB.Model(&module).
|
||||
Where("id = ?", identity).
|
||||
First()
|
||||
if err != nil && err == pg.ErrNoRows {
|
||||
return module, nil
|
||||
}
|
||||
return module, err
|
||||
}
|
||||
|
||||
func (r *InstanceRepository) GetInstanceByUuid(instanceUuid string) (entity.Instance, error) {
|
||||
var instance entity.Instance
|
||||
err := r.DB.Model(&instance).
|
||||
Where("uuid = ?", instanceUuid).
|
||||
First()
|
||||
if err != nil && err == pg.ErrNoRows {
|
||||
return instance, nil
|
||||
}
|
||||
return instance, err
|
||||
}
|
||||
-135
@@ -1,135 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"isp-config-service/entity"
|
||||
|
||||
"github.com/go-pg/pg"
|
||||
|
||||
"github.com/go-pg/pg/orm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ModulesRepository struct {
|
||||
DB orm.DB
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) GetModules(identities []int32) ([]entity.Module, error) {
|
||||
var modules []entity.Module
|
||||
var err error
|
||||
if len(identities) > 0 {
|
||||
err = r.DB.Model(&modules).
|
||||
Where("id IN (?)", pg.In(identities)).
|
||||
Order("created_at DESC").
|
||||
Limit(500).
|
||||
Select()
|
||||
} else {
|
||||
err = r.DB.Model(&modules).
|
||||
Order("created_at DESC").
|
||||
Limit(500).
|
||||
Select()
|
||||
}
|
||||
return modules, err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) GetActiveModules() ([]entity.Module, error) {
|
||||
var modules []entity.Module
|
||||
err := r.DB.Model(&modules).
|
||||
Order("created_at DESC").
|
||||
Where("active = true").
|
||||
Limit(500).
|
||||
Select()
|
||||
return modules, err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) CreateModule(module entity.Module) (entity.Module, error) {
|
||||
_, err := r.DB.Model(&module).
|
||||
Returning("id").
|
||||
Returning("active").
|
||||
Returning("created_at").
|
||||
Insert()
|
||||
return module, err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) UpdateModule(module entity.Module) (entity.Module, error) {
|
||||
_, err := r.DB.Model(&module).WherePK().
|
||||
Returning("id").
|
||||
Returning("active").
|
||||
Returning("created_at").
|
||||
Update()
|
||||
return module, err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) DeleteModule(identities []int32) (int, error) {
|
||||
result, err := r.DB.Exec("DELETE FROM "+schema+".modules WHERE id IN (?)", pg.In(identities))
|
||||
return result.RowsAffected(), err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) GetModuleById(identity int32) (entity.Module, error) {
|
||||
var module entity.Module
|
||||
err := r.DB.Model(&module).
|
||||
Where("id = ?", identity).
|
||||
First()
|
||||
if err != nil && err == pg.ErrNoRows {
|
||||
return module, nil
|
||||
}
|
||||
return module, err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) GetModuleByInstanceIdAndName(instanceId int32, moduleName string) (entity.Module, error) {
|
||||
var module entity.Module
|
||||
err := r.DB.Model(&module).
|
||||
Where("name = ?", moduleName).
|
||||
Where("instance_id = ?", instanceId).
|
||||
First()
|
||||
if err == pg.ErrNoRows {
|
||||
return module, nil
|
||||
}
|
||||
return module, err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) UpdateModuleDisconnect(instanceUuid string, moduleName string) error {
|
||||
var module entity.Module
|
||||
|
||||
err := r.DB.Model(&module).
|
||||
Where("name = ?", moduleName).
|
||||
Where("instance_id = (SELECT id FROM "+schema+".instances WHERE uuid = ?)", instanceUuid).
|
||||
First()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if module.Id != 0 {
|
||||
module.LastDisconnectedAt = time.Now()
|
||||
_, err := r.DB.Model(&module).WherePK().Update()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) GetModulesByInstanceUuid(instanceUuid string) ([]entity.Module, error) {
|
||||
var res []entity.Module
|
||||
err := r.DB.Model(&res).
|
||||
Where("instance_id = (SELECT id FROM "+schema+".instances WHERE uuid = ?)", instanceUuid).
|
||||
Select()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (r *ModulesRepository) GetModulesByInstanceUuidAndName(instanceUuid string, name string) (*entity.Module, error) {
|
||||
res := new(entity.Module)
|
||||
err := r.DB.Model(res).
|
||||
Where("instance_id = (SELECT id FROM "+schema+".instances WHERE uuid = ?)", instanceUuid).
|
||||
Where("name = ?", name).
|
||||
First()
|
||||
if err == pg.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg"
|
||||
)
|
||||
|
||||
var (
|
||||
schema = ""
|
||||
ConfigRep ConfigRepository
|
||||
ModulesRep ModulesRepository
|
||||
InstanceRep InstanceRepository
|
||||
SchemaRep SchemaRepository
|
||||
)
|
||||
|
||||
func SetSchema(s string) {
|
||||
schema = s
|
||||
}
|
||||
|
||||
func InitDbManager(db *pg.DB) {
|
||||
ConfigRep = ConfigRepository{db}
|
||||
ModulesRep = ModulesRepository{db}
|
||||
InstanceRep = InstanceRepository{db}
|
||||
SchemaRep = SchemaRepository{db}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg"
|
||||
"github.com/go-pg/pg/orm"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type SchemaRepository struct {
|
||||
DB orm.DB
|
||||
}
|
||||
|
||||
func (r *SchemaRepository) InsertConfigSchema(s *entity.ConfigSchema) (*entity.ConfigSchema, error) {
|
||||
_, err := r.DB.Model(s).Returning("*").Insert()
|
||||
return s, err
|
||||
}
|
||||
|
||||
func (r *SchemaRepository) UpdateConfigSchema(s *entity.ConfigSchema) (*entity.ConfigSchema, error) {
|
||||
_, err := r.DB.Model(s).Returning("*").WherePK().Update()
|
||||
return s, err
|
||||
}
|
||||
|
||||
func (r *SchemaRepository) GetSchemasByModulesId(modulesId []int32) ([]entity.ConfigSchema, error) {
|
||||
var res []entity.ConfigSchema
|
||||
err := r.DB.Model(&res).Where("module_id IN (?)", pg.In(modulesId)).Select()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-lib/config"
|
||||
"isp-config-service/conf"
|
||||
"isp-config-service/domain"
|
||||
st "isp-config-service/entity"
|
||||
"isp-config-service/model"
|
||||
"isp-config-service/socket"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
startAt = time.Now()
|
||||
Version = "0.1.0"
|
||||
)
|
||||
|
||||
func GetAggregatedModuleInfo(instanceUuid string) ([]*domain.ModuleInfo, error) {
|
||||
modules, err := model.ModulesRep.GetModulesByInstanceUuid(instanceUuid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config := config.Get().(*conf.Configuration)
|
||||
modules = append(modules, st.Module{
|
||||
Id: -1,
|
||||
Name: config.ModuleName,
|
||||
Active: true,
|
||||
CreatedAt: startAt,
|
||||
InstanceId: -1,
|
||||
})
|
||||
l := len(modules)
|
||||
res := make([]*domain.ModuleInfo, l)
|
||||
m := make(map[int32]*domain.ModuleInfo, l)
|
||||
idList := make([]int32, l)
|
||||
for i, module := range modules {
|
||||
idList[i] = module.Id
|
||||
info := &domain.ModuleInfo{
|
||||
Id: module.Id,
|
||||
Name: module.Name,
|
||||
Active: module.Active,
|
||||
CreatedAt: module.CreatedAt,
|
||||
LastConnectedAt: module.LastConnectedAt,
|
||||
LastDisconnectedAt: module.LastDisconnectedAt,
|
||||
}
|
||||
m[module.Id] = info
|
||||
res[i] = info
|
||||
}
|
||||
|
||||
configs, err := model.ConfigRep.GetConfigsByModulesId(idList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, cfg := range configs {
|
||||
info := m[cfg.ModuleId]
|
||||
info.Configs = append(info.Configs, cfg)
|
||||
}
|
||||
|
||||
schemas, err := model.SchemaRep.GetSchemasByModulesId(idList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, s := range schemas {
|
||||
info := m[s.ModuleId]
|
||||
schema := s.Schema
|
||||
info.ConfigSchema = &schema
|
||||
}
|
||||
|
||||
connMap := socket.GetModuleConnectionIdMapByInstanceId(instanceUuid)
|
||||
routes := socket.GetRoutes().Routes
|
||||
//converters := socket.GetConverters()
|
||||
//routers := socket.GetRouters()
|
||||
roomsStat := socket.GetRoomsCount()
|
||||
for _, info := range res {
|
||||
if info.Id == -1 {
|
||||
info.Status = append(info.Status, domain.Connection{
|
||||
Address: config.GrpcOuterAddress,
|
||||
Version: Version,
|
||||
Endpoints: socket.ConfigServiceBackendDeclaration.Endpoints,
|
||||
LibVersion: socket.ConfigServiceBackendDeclaration.LibVersion,
|
||||
EstablishedAt: startAt,
|
||||
})
|
||||
} else if conns, connected := connMap[info.Name]; connected {
|
||||
for _, conId := range conns {
|
||||
hasRoutes := false
|
||||
var data *domain.Connection
|
||||
if backend, ok := routes[conId]; ok {
|
||||
data = &domain.Connection{
|
||||
Version: backend.Version,
|
||||
LibVersion: backend.LibVersion,
|
||||
Address: backend.Address,
|
||||
Endpoints: backend.Endpoints,
|
||||
}
|
||||
|
||||
hasRoutes = true
|
||||
} else if roomsStat[instanceUuid][info.Name] <= 0 {
|
||||
continue
|
||||
}
|
||||
if c, ok := socket.GetConnectionById(instanceUuid, conId); ok {
|
||||
if !hasRoutes {
|
||||
data = &domain.Connection{
|
||||
Version: "unknown",
|
||||
}
|
||||
/*if router, ok := routers[conId]; ok {
|
||||
data.Address = router
|
||||
} else if converter, ok := converters[conId]; ok {
|
||||
data.Address = converter
|
||||
}*/
|
||||
}
|
||||
|
||||
data.EstablishedAt = c.EstablishedAt
|
||||
}
|
||||
|
||||
info.Status = append(info.Status, *data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range res {
|
||||
sort.Slice(s.Status, func(i, j int) bool {
|
||||
return s.Status[i].EstablishedAt.Before(s.Status[j].EstablishedAt)
|
||||
})
|
||||
for _, con := range s.Status {
|
||||
sort.Slice(con.Endpoints, func(i, j int) bool {
|
||||
return con.Endpoints[i].Path < con.Endpoints[j].Path
|
||||
})
|
||||
}
|
||||
}
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i].Name < res[j].Name
|
||||
})
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
syntax = "proto3";
|
||||
// /home/andrey/Applications/protoc/bin/protoc -I ./ proto/system.proto --go_out=plugins=grpc:./
|
||||
option java_multiple_files = true;
|
||||
option java_package = "io.grpc.convertService";
|
||||
option java_outer_classname = "ConvertServiceProto";
|
||||
|
||||
package isp;
|
||||
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/struct.proto";
|
||||
|
||||
message Message {
|
||||
oneof body {
|
||||
google.protobuf.Struct structBody = 1;
|
||||
google.protobuf.ListValue listBody = 2;
|
||||
google.protobuf.NullValue NullBody = 3;
|
||||
}
|
||||
}
|
||||
|
||||
service BackendService {
|
||||
// ===== SYSTEM =====
|
||||
rpc Request (Message) returns (Message) {
|
||||
option (google.api.http) = {
|
||||
post: "/api"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "proto/backend_service.proto",
|
||||
"version": "version not set"
|
||||
},
|
||||
"schemes": [
|
||||
"http",
|
||||
"https"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/api": {
|
||||
"post": {
|
||||
"summary": "===== SYSTEM =====",
|
||||
"operationId": "Request",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ispMessage"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "Grpc-Metadata-proxy_method_name",
|
||||
"in": "header",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ispMessage"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"BackendService"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"ispMessage": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"structBody": {
|
||||
"$ref": "#/definitions/protobufStruct"
|
||||
},
|
||||
"listBody": {
|
||||
"$ref": "#/definitions/protobufListValue"
|
||||
},
|
||||
"NullBody": {
|
||||
"$ref": "#/definitions/protobufNullValue"
|
||||
}
|
||||
}
|
||||
},
|
||||
"protobufListValue": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"values": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/protobufValue"
|
||||
},
|
||||
"description": "Repeated field of dynamically typed values."
|
||||
}
|
||||
},
|
||||
"description": "`ListValue` is a wrapper around a repeated field of values.\n\nThe JSON representation for `ListValue` is JSON array."
|
||||
},
|
||||
"protobufNullValue": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"NULL_VALUE"
|
||||
],
|
||||
"default": "NULL_VALUE",
|
||||
"description": "`NullValue` is a singleton enumeration to represent the null value for the\n`Value` type union.\n\n The JSON representation for `NullValue` is JSON `null`.\n\n - NULL_VALUE: Null value."
|
||||
},
|
||||
"protobufStruct": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/protobufValue"
|
||||
},
|
||||
"description": "Unordered map of dynamically typed values."
|
||||
}
|
||||
},
|
||||
"description": "`Struct` represents a structured data value, consisting of fields\nwhich map to dynamically typed values. In some languages, `Struct`\nmight be supported by a native representation. For example, in\nscripting languages like JS a struct is represented as an\nobject. The details of that representation are described together\nwith the proto support for the language.\n\nThe JSON representation for `Struct` is JSON object."
|
||||
},
|
||||
"protobufValue": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"null_value": {
|
||||
"$ref": "#/definitions/protobufNullValue",
|
||||
"description": "Represents a null value."
|
||||
},
|
||||
"number_value": {
|
||||
"type": "number",
|
||||
"format": "double",
|
||||
"description": "Represents a double value."
|
||||
},
|
||||
"string_value": {
|
||||
"type": "string",
|
||||
"description": "Represents a string value."
|
||||
},
|
||||
"bool_value": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"description": "Represents a boolean value."
|
||||
},
|
||||
"struct_value": {
|
||||
"$ref": "#/definitions/protobufStruct",
|
||||
"description": "Represents a structured value."
|
||||
},
|
||||
"list_value": {
|
||||
"$ref": "#/definitions/protobufListValue",
|
||||
"description": "Represents a repeated `Value`."
|
||||
}
|
||||
},
|
||||
"description": "`Value` represents a dynamically typed value which can be either\nnull, a number, a string, a boolean, a recursive struct value, or a\nlist of values. A producer of value is expected to set one of that\nvariants, absence of any variant indicates an error.\n\nThe JSON representation for `Value` is JSON value."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
syntax = "proto3";
|
||||
// /home/andrey/Applications/protoc/bin/protoc -I ./ proto/system.proto --go_out=plugins=grpc:./
|
||||
option java_multiple_files = true;
|
||||
option java_package = "io.grpc.configService";
|
||||
option java_outer_classname = "ConfigServiceProto";
|
||||
|
||||
package config.service;
|
||||
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/struct.proto";
|
||||
|
||||
service ConfigService {
|
||||
// ===== INSTANCE =====
|
||||
rpc GetInstances (RequestByIdentities) returns (InstancesResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/instances"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc CreateUpdateInstance (Instance) returns (Instance) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/instances/save"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc DeleteInstance (RequestByIdentities) returns (DeleteResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/instances/delete"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// ===== INSTANCE END =====
|
||||
|
||||
// ===== MODULE =====
|
||||
rpc GetModules (RequestByIdentities) returns (ModulesResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/modules"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc GetActiveModules (Empty) returns (ModulesResponse) {
|
||||
option (google.api.http).get = "/api/modules/actives";
|
||||
}
|
||||
|
||||
rpc CreateUpdateModule (Module) returns (Module) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/modules/save"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc DeleteModule (RequestByIdentities) returns (DeleteResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/modules/delete"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc GetConnectedModules (Empty) returns (ConnectedModules) {
|
||||
option (google.api.http).get = "/api/modules/connected";
|
||||
}
|
||||
// ===== MODULE END =====
|
||||
|
||||
// ===== CONFIG =====
|
||||
rpc GetConfigs (RequestByIdentities) returns (ConfigsResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/configs"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc GetConfigByInstanceUUIDAndModuleName (RequestConfig) returns (Config) {
|
||||
option (google.api.http).get = "/api/configs_by_module_names/{name}";
|
||||
}
|
||||
|
||||
rpc CreateUpdateConfig (Config) returns (Config) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/configs/save"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc DeleteConfig (RequestByIdentities) returns (DeleteResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/configs/delete"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
|
||||
rpc MarkConfigAsActive (RequestByLongIdentity) returns (Config) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/configs/active"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// ===== CONFIG END =====
|
||||
}
|
||||
|
||||
message RequestByLongIdentity {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
message RequestByIdentities {
|
||||
repeated int32 ids = 1;
|
||||
}
|
||||
|
||||
message RequestConfig {
|
||||
string instanceUuid = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message ConnectedModules {
|
||||
google.protobuf.Struct items = 1;
|
||||
}
|
||||
|
||||
message Instance {
|
||||
int32 id = 1;
|
||||
string uuid = 2;
|
||||
string name = 3;
|
||||
string createdAt = 4;
|
||||
}
|
||||
|
||||
message Module {
|
||||
int32 id = 1;
|
||||
int32 instanceId = 2;
|
||||
string name = 3;
|
||||
bool active = 4;
|
||||
string createdAt = 5;
|
||||
string lastConnectedAt = 6;
|
||||
string lastDisconnectedAt = 7;
|
||||
}
|
||||
|
||||
message Config {
|
||||
int64 id = 1;
|
||||
int32 moduleId = 2;
|
||||
int32 version = 3;
|
||||
bool active = 4;
|
||||
string createdAt = 5;
|
||||
string updatedAt = 6;
|
||||
google.protobuf.Struct data = 7;
|
||||
}
|
||||
|
||||
message InstancesResponse {
|
||||
repeated Instance items = 1;
|
||||
}
|
||||
|
||||
message ModulesResponse {
|
||||
repeated Module items = 1;
|
||||
}
|
||||
|
||||
message ConfigsResponse {
|
||||
repeated Config items = 1;
|
||||
}
|
||||
|
||||
message DeleteResponse {
|
||||
int32 deleted = 1;
|
||||
}
|
||||
|
||||
message Empty {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
)
|
||||
|
||||
type Backend struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewBackend(db db.DB) Backend {
|
||||
return Backend{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Backend) Insert(ctx context.Context, backend entity.Backend) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.Insert")
|
||||
|
||||
query, args, err := squirrel.Insert(Table("backend")).
|
||||
Columns("ws_connection_id", "module_id", "address",
|
||||
"version", "lib_version", "module_name", "config_service_node_id",
|
||||
"endpoints", "required_modules").
|
||||
Values(backend.WsConnectionId, backend.ModuleId, backend.Address,
|
||||
backend.Version, backend.LibVersion, backend.ModuleName, backend.ConfigServiceNodeId,
|
||||
backend.Endpoints, backend.RequiredModules,
|
||||
).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Backend) DeleteByWsConnectionIds(ctx context.Context, wsConnectionIds []string) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.DeleteByWsConnectionIds")
|
||||
|
||||
query, args, err := squirrel.Delete(Table("backend")).
|
||||
Where(squirrel.Eq{
|
||||
"ws_connection_id": wsConnectionIds,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Backend) DeleteByConfigServiceNodeId(ctx context.Context, configServiceNodeId string) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.DeleteByConfigServiceNodeId")
|
||||
|
||||
query, args, err := squirrel.Delete(Table("backend")).
|
||||
Where(squirrel.Eq{
|
||||
"config_service_node_id": configServiceNodeId,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result, err := r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
deleted, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "rows affected")
|
||||
}
|
||||
|
||||
return int(deleted), nil
|
||||
}
|
||||
|
||||
func (r Backend) GetByConfigServiceNodeId(ctx context.Context, configServiceNodeId string) ([]entity.Backend, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.GetByConfigServiceNodeId")
|
||||
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("backend")).
|
||||
Where(squirrel.Eq{
|
||||
"config_service_node_id": configServiceNodeId,
|
||||
}).OrderBy("created_at desc").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Backend, 0)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Backend) All(ctx context.Context) ([]entity.Backend, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.All")
|
||||
|
||||
result := make([]entity.Backend, 0)
|
||||
query := fmt.Sprintf("SELECT * FROM %s order by created_at desc", Table("backend"))
|
||||
err := r.db.Select(ctx, &result, query)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Backend) GetByModuleId(ctx context.Context, moduleId string) ([]entity.Backend, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.GetByModuleId")
|
||||
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("backend")).
|
||||
Where(squirrel.Eq{
|
||||
"module_id": moduleId,
|
||||
}).OrderBy("created_at desc").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Backend, 0)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/entity/xtypes"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewConfig(db db.DB) Config {
|
||||
return Config{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Config) Insert(ctx context.Context, cfg entity.Config) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.Insert")
|
||||
|
||||
query, args, err := squirrel.Insert(Table("config")).
|
||||
Columns("id", "name", "module_id", "data", "version", "active", "admin_id").
|
||||
Values(cfg.Id, cfg.Name, cfg.ModuleId, cfg.Data, cfg.Version, cfg.Active, cfg.AdminId).
|
||||
Suffix("on conflict (id) do nothing").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Config) GetActive(ctx context.Context, moduleId string) (*entity.Config, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.GetActive")
|
||||
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config")).
|
||||
Where(squirrel.Eq{
|
||||
"module_id": moduleId,
|
||||
"active": xtypes.Bool(true),
|
||||
}).OrderBy("version DESC").
|
||||
Limit(1).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
return selectRow[entity.Config](ctx, r.db, query, args...)
|
||||
}
|
||||
|
||||
func (r Config) GetByModuleId(ctx context.Context, moduleId string) ([]entity.Config, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.GetByModuleId")
|
||||
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config")).
|
||||
Where(squirrel.Eq{
|
||||
"module_id": moduleId,
|
||||
}).OrderBy("created_at desc").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Config, 0)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Config) GetById(ctx context.Context, id string) (*entity.Config, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.GetById")
|
||||
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config")).
|
||||
Where(squirrel.Eq{
|
||||
"id": id,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
return selectRow[entity.Config](ctx, r.db, query, args...)
|
||||
}
|
||||
|
||||
func (r Config) DeleteNonActiveById(ctx context.Context, id string) (bool, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.DeleteNonActiveById")
|
||||
|
||||
query, args, err := squirrel.Delete(Table("config")).
|
||||
Where(squirrel.Eq{
|
||||
"id": id,
|
||||
"active": xtypes.Bool(false),
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result, err := r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return false, errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "get rows affected")
|
||||
}
|
||||
return affected > 0, nil
|
||||
}
|
||||
|
||||
func (r Config) UpdateByVersion(ctx context.Context, cfg entity.Config) (bool, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.UpdateByVersion")
|
||||
|
||||
query, args, err := squirrel.Update(Table("config")).
|
||||
SetMap(map[string]any{
|
||||
"name": cfg.Name,
|
||||
"data": cfg.Data,
|
||||
"version": squirrel.Expr("version + 1"),
|
||||
"updated_at": squirrel.Expr("unixepoch()"),
|
||||
"admin_id": cfg.AdminId,
|
||||
}).Where(squirrel.Eq{
|
||||
"id": cfg.Id,
|
||||
"version": cfg.Version,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result, err := r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return false, errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "get rows affected")
|
||||
}
|
||||
return affected > 0, nil
|
||||
}
|
||||
|
||||
func (r Config) SetActive(ctx context.Context, configId string, active xtypes.Bool) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.SetActive")
|
||||
|
||||
query, args, err := squirrel.Update(Table("config")).
|
||||
Set("active", active).
|
||||
Set("updated_at", squirrel.Expr("unixepoch()")).
|
||||
Where(squirrel.Eq{
|
||||
"id": configId,
|
||||
}).ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
)
|
||||
|
||||
type ConfigHistory struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewConfigHistory(db db.DB) ConfigHistory {
|
||||
return ConfigHistory{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r ConfigHistory) GetByConfigId(ctx context.Context, configId string) ([]entity.ConfigHistory, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigHistory.GetByConfigId")
|
||||
|
||||
query := fmt.Sprintf(`select * from %s where config_id = ? order by version desc`, Table("config_history"))
|
||||
result := make([]entity.ConfigHistory, 0)
|
||||
err := r.db.Select(ctx, &result, query, configId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r ConfigHistory) Delete(ctx context.Context, id string) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigHistory.Delete")
|
||||
|
||||
query := fmt.Sprintf(`delete from %s where id = ?`, Table("config_history"))
|
||||
_, err := r.db.Exec(ctx, query, id)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r ConfigHistory) Insert(ctx context.Context, history entity.ConfigHistory) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigHistory.Insert")
|
||||
|
||||
query, args, err := squirrel.Insert(Table("config_history")).
|
||||
Columns("id", "config_id", "data", "version", "admin_id").
|
||||
Values(history.Id, history.ConfigId, history.Data, history.Version, history.AdminId).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r ConfigHistory) DeleteOld(ctx context.Context, configId string, keepVersions int) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigHistory.DeleteOld")
|
||||
|
||||
query := fmt.Sprintf(`delete from %s where config_id = ? and id not in (
|
||||
select id from %s where config_id = ? order by version desc limit ?
|
||||
)`, Table("config_history"), Table("config_history"))
|
||||
result, err := r.db.Exec(ctx, query, configId, configId, keepVersions)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "get rows affected")
|
||||
}
|
||||
|
||||
return int(rowsAffected), nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
)
|
||||
|
||||
type ConfigSchema struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewConfigSchema(db db.DB) ConfigSchema {
|
||||
return ConfigSchema{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r ConfigSchema) Upsert(ctx context.Context, schema entity.ConfigSchema) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigSchema.Upsert")
|
||||
|
||||
query, args, err := squirrel.Insert(Table("config_schema")).
|
||||
Columns("id", "module_id", "data", "module_version").
|
||||
Values(schema.Id, schema.ModuleId, schema.Data, schema.ModuleVersion).
|
||||
Suffix(`on conflict (module_id) do update
|
||||
set data = excluded.data, module_version = excluded.module_version, updated_at = unixepoch()`).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r ConfigSchema) All(ctx context.Context) ([]entity.ConfigSchema, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigSchema.All")
|
||||
|
||||
result := make([]entity.ConfigSchema, 0)
|
||||
query := fmt.Sprintf("select * from %s order by created_at", Table("config_schema"))
|
||||
err := r.db.Select(ctx, &result, query)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r ConfigSchema) GetByModuleId(ctx context.Context, moduleId string) (*entity.ConfigSchema, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigSchema.GetByModuleId")
|
||||
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config_schema")).
|
||||
Where(squirrel.Eq{"module_id": moduleId}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
return selectRow[entity.ConfigSchema](ctx, r.db, query, args...)
|
||||
}
|
||||
|
||||
//nolint:nilnil
|
||||
func selectRow[T any](ctx context.Context, db db.DB, query string, args ...interface{}) (*T, error) {
|
||||
var result T
|
||||
err := db.SelectRow(ctx, &result, query, args...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select row: %s", query)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/entity/xtypes"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewEvent(db db.DB) Event {
|
||||
return Event{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Event) Insert(ctx context.Context, event entity.Event) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Event.Insert")
|
||||
|
||||
query := fmt.Sprintf("insert into %s (payload) values (?)", Table("event"))
|
||||
_, err := r.db.Exec(ctx, query, event.Payload)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Event) Get(ctx context.Context, lastEventId int, limit int) ([]entity.Event, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Event.Get")
|
||||
|
||||
query := fmt.Sprintf("select * from %s where id > ? order by id limit ?", Table("event"))
|
||||
result := make([]entity.Event, 0)
|
||||
err := r.db.Select(ctx, &result, query, lastEventId, limit)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Event) DeleteByCreatedAt(ctx context.Context, before xtypes.Time) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Event.DeleteByCreatedAt")
|
||||
|
||||
query := fmt.Sprintf("delete from %s where created_at < ?", Table("event"))
|
||||
result, err := r.db.Exec(ctx, query, before)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "get affected rows")
|
||||
}
|
||||
|
||||
return int(affected), nil
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
)
|
||||
|
||||
type Module struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewModule(db db.DB) Module {
|
||||
return Module{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r Module) Upsert(ctx context.Context, module entity.Module) (string, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.Upsert")
|
||||
|
||||
query, args, err := squirrel.Insert(Table("module")).
|
||||
Columns("id", "name", "last_connected_at").
|
||||
Values(module.Id, module.Name, squirrel.Expr("unixepoch()")).
|
||||
Suffix(`on conflict (name) do update set last_connected_at = unixepoch() returning id`).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return "", errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make(map[string]string)
|
||||
err = r.db.SelectRow(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return "", errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
return result["id"], nil
|
||||
}
|
||||
|
||||
func (r Module) SetDisconnectedAtNow(
|
||||
ctx context.Context,
|
||||
moduleId string,
|
||||
) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.SetDisconnectedAtNow")
|
||||
|
||||
query, args, err := squirrel.Update(Table("module")).
|
||||
Set("last_disconnected_at", squirrel.Expr("unixepoch()")).
|
||||
Where(squirrel.Eq{"id": moduleId}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r Module) GetByNames(ctx context.Context, names []string) ([]entity.Module, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.GetByNames")
|
||||
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("module")).
|
||||
Where(squirrel.Eq{
|
||||
"name": names,
|
||||
}).OrderBy("created_at desc").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Module, 0)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Module) GetById(ctx context.Context, id string) (*entity.Module, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.GetById")
|
||||
|
||||
query := fmt.Sprintf("select * from %s where id = ?", Table("module"))
|
||||
return selectRow[entity.Module](ctx, r.db, query, id)
|
||||
}
|
||||
|
||||
func (r Module) All(ctx context.Context) ([]entity.Module, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.All")
|
||||
|
||||
result := make([]entity.Module, 0)
|
||||
query := fmt.Sprintf("select * from %s order by name", Table("module"))
|
||||
err := r.db.Select(ctx, &result, query)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Module) Delete(ctx context.Context, id string) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.Delete")
|
||||
|
||||
query, args, err := squirrel.Delete(Table("module")).
|
||||
Where(squirrel.Eq{"id": id}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
_, err = r.db.Exec(ctx, query, args...)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "exec: %s", query)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Table(table string) string {
|
||||
return fmt.Sprintf("isp_config_service__%s", table)
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/txix-open/etp/v4"
|
||||
"isp-config-service/conf"
|
||||
"net/http"
|
||||
|
||||
"github.com/txix-open/isp-kit/cluster"
|
||||
"github.com/txix-open/isp-kit/grpc"
|
||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-config-service/controller"
|
||||
"isp-config-service/controller/api"
|
||||
mws "isp-config-service/middlewares"
|
||||
)
|
||||
|
||||
type Controllers struct {
|
||||
Module controller.Module
|
||||
ModuleApi api.Module
|
||||
ConfigApi api.Config
|
||||
ConfigHistoryApi api.ConfigHistory
|
||||
ConfigSchemaApi api.ConfigSchema
|
||||
}
|
||||
|
||||
func EndpointDescriptors() []cluster.EndpointDescriptor {
|
||||
return endpointDescriptors(Controllers{})
|
||||
}
|
||||
|
||||
func GrpcHandler(wrapper endpoint.Wrapper, c Controllers) *grpc.Mux {
|
||||
muxer := grpc.NewMux()
|
||||
for _, descriptor := range endpointDescriptors(c) {
|
||||
muxer.Handle(descriptor.Path, wrapper.Endpoint(descriptor.Handler))
|
||||
}
|
||||
return muxer
|
||||
}
|
||||
|
||||
func BindEtp(etpSrv *etp.Server, c Controllers, logger log.Logger) {
|
||||
middlewares := []mws.EtpMiddleware{
|
||||
mws.EtpLogger(logger),
|
||||
}
|
||||
etpSrv.OnConnect(c.Module.OnConnect)
|
||||
etpSrv.OnDisconnect(c.Module.OnDisconnect)
|
||||
etpSrv.OnError(c.Module.OnError)
|
||||
|
||||
onConfigSchema := mws.EtpChain(etp.HandlerFunc(c.Module.OnModuleConfigSchema), middlewares...)
|
||||
etpSrv.On(cluster.ModuleSendConfigSchema, onConfigSchema)
|
||||
|
||||
onRequirements := mws.EtpChain(etp.HandlerFunc(c.Module.OnModuleRequirements), middlewares...)
|
||||
etpSrv.On(cluster.ModuleSendRequirements, onRequirements)
|
||||
|
||||
onModuleReady := mws.EtpChain(etp.HandlerFunc(c.Module.OnModuleReady), middlewares...)
|
||||
etpSrv.On(cluster.ModuleReady, onModuleReady)
|
||||
}
|
||||
|
||||
func HttpHandler(etpSrv *etp.Server, conf conf.Local, rqliteProxy http.Handler) http.Handler {
|
||||
httpMux := http.NewServeMux()
|
||||
if conf.MaintenanceMode {
|
||||
httpMux.Handle("/", rqliteProxy)
|
||||
} else {
|
||||
httpMux.Handle("/isp-etp/", etpSrv)
|
||||
}
|
||||
return httpMux
|
||||
}
|
||||
|
||||
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||
return []cluster.EndpointDescriptor{{
|
||||
Path: "config/module/get_modules_info",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.Status,
|
||||
}, {
|
||||
Path: "config/module/delete_module",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.DeleteModule,
|
||||
}, {
|
||||
Path: "config/routing/get_routes",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.Connections,
|
||||
}, {
|
||||
Path: "config/config/get_active_config_by_module_name",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetActiveConfigByModuleName,
|
||||
}, {
|
||||
Path: "config/config/get_configs_by_module_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetConfigsByModuleId,
|
||||
}, {
|
||||
Path: "config/config/create_update_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.CreateUpdateConfig,
|
||||
}, {
|
||||
Path: "config/config/get_config_by_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetConfigById,
|
||||
}, {
|
||||
Path: "config/config/mark_config_as_active",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.MarkConfigAsActive,
|
||||
}, {
|
||||
Path: "config/config/delete_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.DeleteConfigs,
|
||||
}, {
|
||||
Path: "config/config/get_all_version",
|
||||
Inner: true,
|
||||
Handler: c.ConfigHistoryApi.GetAllVersion,
|
||||
}, {
|
||||
Path: "config/config/delete_version",
|
||||
Inner: true,
|
||||
Handler: c.ConfigHistoryApi.DeleteConfigVersion,
|
||||
}, {
|
||||
Path: "config/schema/get_by_module_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigSchemaApi.SchemaByModuleId,
|
||||
}}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/xeipuuv/gojsonschema"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
type ConfigRepo interface {
|
||||
GetActive(ctx context.Context, moduleId string) (*entity.Config, error)
|
||||
GetByModuleId(ctx context.Context, moduleId string) ([]entity.Config, error)
|
||||
GetById(ctx context.Context, id string) (*entity.Config, error)
|
||||
DeleteNonActiveById(ctx context.Context, id string) (bool, error)
|
||||
Insert(ctx context.Context, cfg entity.Config) error
|
||||
UpdateByVersion(ctx context.Context, cfg entity.Config) (bool, error)
|
||||
SetActive(ctx context.Context, configId string, active xtypes.Bool) error
|
||||
}
|
||||
|
||||
type EventRepo interface {
|
||||
Insert(ctx context.Context, event entity.Event) error
|
||||
}
|
||||
|
||||
type ConfigHistoryService interface {
|
||||
OnUpdateConfig(ctx context.Context, oldConfig entity.Config) error
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
configRepo ConfigRepo
|
||||
moduleRepo ModuleRepo
|
||||
schemaRepo SchemaRepo
|
||||
eventRepo EventRepo
|
||||
configHistoryService ConfigHistoryService
|
||||
}
|
||||
|
||||
func NewConfig(
|
||||
configRepo ConfigRepo,
|
||||
moduleRepo ModuleRepo,
|
||||
schemaRepo SchemaRepo,
|
||||
eventRepo EventRepo,
|
||||
configHistoryService ConfigHistoryService,
|
||||
) Config {
|
||||
return Config{
|
||||
configRepo: configRepo,
|
||||
moduleRepo: moduleRepo,
|
||||
schemaRepo: schemaRepo,
|
||||
eventRepo: eventRepo,
|
||||
configHistoryService: configHistoryService,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Config) GetActiveConfigByModuleName(ctx context.Context, moduleName string) (*domain.Config, error) {
|
||||
modules, err := c.moduleRepo.GetByNames(ctx, []string{moduleName})
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get config by module name")
|
||||
}
|
||||
if len(modules) == 0 {
|
||||
return nil, entity.ErrModuleNotFound
|
||||
}
|
||||
|
||||
moduleId := modules[0].Id
|
||||
config, err := c.configRepo.GetActive(ctx, moduleId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get active config")
|
||||
}
|
||||
if config == nil {
|
||||
return nil, entity.ErrConfigNotFound
|
||||
}
|
||||
|
||||
result := configToDto(*config, nil)
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c Config) GetConfigsByModuleId(ctx context.Context, moduleId string) ([]domain.Config, error) {
|
||||
configs, err := c.configRepo.GetByModuleId(ctx, moduleId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get configs by module id")
|
||||
}
|
||||
if len(configs) == 0 {
|
||||
return make([]domain.Config, 0), nil
|
||||
}
|
||||
|
||||
schema, err := c.schemaRepo.GetByModuleId(ctx, moduleId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get config schema by module id")
|
||||
}
|
||||
var jsonSchema []byte
|
||||
if schema != nil {
|
||||
jsonSchema = schema.Data
|
||||
}
|
||||
|
||||
result := make([]domain.Config, 0)
|
||||
for _, config := range configs {
|
||||
result = append(result, configToDto(config, jsonSchema))
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c Config) CreateUpdateConfig(
|
||||
ctx context.Context,
|
||||
adminId int,
|
||||
req domain.CreateUpdateConfigRequest,
|
||||
) (*domain.Config, error) {
|
||||
if !req.Unsafe {
|
||||
err := c.validateConfigUpdate(ctx, req.ModuleId, req.Data)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "validate config")
|
||||
}
|
||||
}
|
||||
|
||||
if req.Id == "" {
|
||||
return c.insertNewConfig(ctx, adminId, req)
|
||||
}
|
||||
|
||||
oldConfig, err := c.configRepo.GetById(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get old config")
|
||||
}
|
||||
if oldConfig == nil {
|
||||
return nil, entity.ErrConfigNotFound
|
||||
}
|
||||
|
||||
config := entity.Config{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Data: req.Data,
|
||||
Version: req.Version,
|
||||
AdminId: adminId,
|
||||
}
|
||||
updated, err := c.configRepo.UpdateByVersion(ctx, config)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "update config")
|
||||
}
|
||||
if !updated {
|
||||
return nil, entity.ErrConfigConflictUpdate
|
||||
}
|
||||
|
||||
err = c.configHistoryService.OnUpdateConfig(ctx, *oldConfig)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "change config history")
|
||||
}
|
||||
|
||||
if oldConfig.Active {
|
||||
err = c.emitChangeActiveConfigEvent(ctx, oldConfig.ModuleId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "emit change active config event")
|
||||
}
|
||||
}
|
||||
|
||||
newConfig := entity.Config{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
ModuleId: req.ModuleId,
|
||||
Data: req.Data,
|
||||
Version: req.Version + 1,
|
||||
Active: oldConfig.Active,
|
||||
}
|
||||
result := configToDto(newConfig, nil)
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c Config) GetConfigById(ctx context.Context, configId string) (*domain.Config, error) {
|
||||
config, err := c.configRepo.GetById(ctx, configId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get config by id")
|
||||
}
|
||||
if config == nil {
|
||||
return nil, entity.ErrConfigNotFound
|
||||
}
|
||||
|
||||
result := configToDto(*config, nil)
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c Config) MarkConfigAsActive(ctx context.Context, configId string) error {
|
||||
cfg, err := c.configRepo.GetById(ctx, configId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get config by id")
|
||||
}
|
||||
if cfg == nil {
|
||||
return entity.ErrConfigNotFound
|
||||
}
|
||||
|
||||
currentActiveConfig, err := c.configRepo.GetActive(ctx, cfg.ModuleId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get active config")
|
||||
}
|
||||
if currentActiveConfig != nil {
|
||||
err := c.configRepo.SetActive(ctx, currentActiveConfig.Id, false)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "deactivate config")
|
||||
}
|
||||
}
|
||||
|
||||
err = c.configRepo.SetActive(ctx, configId, true)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "set active config")
|
||||
}
|
||||
|
||||
err = c.emitChangeActiveConfigEvent(ctx, cfg.ModuleId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "emit change active config event")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) DeleteConfig(ctx context.Context, configId string) error {
|
||||
deleted, err := c.configRepo.DeleteNonActiveById(ctx, configId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete config")
|
||||
}
|
||||
if !deleted {
|
||||
return entity.ErrConfigNotFoundOrActive
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) insertNewConfig(ctx context.Context, adminId int, req domain.CreateUpdateConfigRequest) (*domain.Config, error) {
|
||||
config := entity.Config{
|
||||
Id: uuid.NewString(),
|
||||
Name: req.Name,
|
||||
ModuleId: req.ModuleId,
|
||||
Data: req.Data,
|
||||
Version: 1,
|
||||
Active: false,
|
||||
AdminId: adminId,
|
||||
}
|
||||
err := c.configRepo.Insert(ctx, config)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "insert new config")
|
||||
}
|
||||
result := configToDto(config, nil)
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c Config) validateConfigUpdate(ctx context.Context, moduleId string, configData []byte) error {
|
||||
schema, err := c.schemaRepo.GetByModuleId(ctx, moduleId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get schema by module id")
|
||||
}
|
||||
if schema == nil {
|
||||
return entity.ErrSchemaNotFound
|
||||
}
|
||||
|
||||
details, err := validateConfig(configData, schema.Data)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "validate config")
|
||||
}
|
||||
if len(details) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return domain.NewConfigValidationError(details)
|
||||
}
|
||||
|
||||
func (c Config) emitChangeActiveConfigEvent(ctx context.Context, moduleId string) error {
|
||||
eventPayload := entity.EventPayload{
|
||||
ConfigUpdated: &entity.PayloadConfigUpdated{
|
||||
ModuleId: moduleId,
|
||||
},
|
||||
}
|
||||
err := c.eventRepo.Insert(ctx, entity.NewEvent(eventPayload))
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "insert new event")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func configToDto(config entity.Config, schema []byte) domain.Config {
|
||||
valid := true
|
||||
if schema != nil {
|
||||
errors, _ := validateConfig(config.Data, schema)
|
||||
valid = len(errors) == 0
|
||||
}
|
||||
return domain.Config{
|
||||
Id: config.Id,
|
||||
Name: config.Name,
|
||||
ModuleId: config.ModuleId,
|
||||
Valid: valid,
|
||||
Data: config.Data,
|
||||
Version: config.Version,
|
||||
Active: bool(config.Active),
|
||||
CreatedAt: time.Time(config.CreatedAt),
|
||||
UpdatedAt: time.Time(config.UpdatedAt),
|
||||
}
|
||||
}
|
||||
|
||||
func validateConfig(config []byte, schema []byte) (map[string]string, error) {
|
||||
schemaLoader := gojsonschema.NewBytesLoader(schema)
|
||||
configLoader := gojsonschema.NewBytesLoader(config)
|
||||
result, err := gojsonschema.Validate(schemaLoader, configLoader)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "validate config")
|
||||
}
|
||||
details := map[string]string{}
|
||||
for _, resultError := range result.Errors() {
|
||||
details[resultError.Field()] = resultError.Description()
|
||||
}
|
||||
return details, nil
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type ConfigHistoryRepo interface {
|
||||
Delete(ctx context.Context, id string) error
|
||||
GetByConfigId(ctx context.Context, configId string) ([]entity.ConfigHistory, error)
|
||||
Insert(ctx context.Context, history entity.ConfigHistory) error
|
||||
DeleteOld(ctx context.Context, configId string, keepVersions int) (int, error)
|
||||
}
|
||||
|
||||
type ConfigHistory struct {
|
||||
repo ConfigHistoryRepo
|
||||
keepVersions int
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewConfigHistory(
|
||||
repo ConfigHistoryRepo,
|
||||
keepVersions int,
|
||||
logger log.Logger,
|
||||
) ConfigHistory {
|
||||
return ConfigHistory{
|
||||
repo: repo,
|
||||
keepVersions: keepVersions,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (s ConfigHistory) GetAllVersions(ctx context.Context, configId string) ([]domain.ConfigVersion, error) {
|
||||
versions, err := s.repo.GetByConfigId(ctx, configId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get config versions")
|
||||
}
|
||||
|
||||
result := make([]domain.ConfigVersion, 0, len(versions))
|
||||
for _, version := range versions {
|
||||
result = append(result, domain.ConfigVersion{
|
||||
Id: version.Id,
|
||||
ConfigId: version.ConfigId,
|
||||
ConfigVersion: version.Version,
|
||||
Data: version.Data,
|
||||
CreatedAt: time.Time(version.CreatedAt),
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s ConfigHistory) Delete(ctx context.Context, id string) error {
|
||||
err := s.repo.Delete(ctx, id)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete config version")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s ConfigHistory) OnUpdateConfig(ctx context.Context, oldConfig entity.Config) error {
|
||||
history := entity.ConfigHistory{
|
||||
Id: uuid.NewString(),
|
||||
ConfigId: oldConfig.Id,
|
||||
Data: oldConfig.Data,
|
||||
Version: oldConfig.Version,
|
||||
AdminId: oldConfig.AdminId,
|
||||
}
|
||||
err := s.repo.Insert(ctx, history)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "save config history")
|
||||
}
|
||||
|
||||
if s.keepVersions < 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
go func() {
|
||||
deletedCount, err := s.repo.DeleteOld(context.Background(), oldConfig.Id, s.keepVersions)
|
||||
if err != nil {
|
||||
s.logger.Error(ctx, errors.WithMessage(err, "delete old config versions"))
|
||||
} else {
|
||||
s.logger.Debug(ctx, fmt.Sprintf("delete '%d' old config versions", deletedCount))
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type ConfigSchema struct {
|
||||
schemaRepo SchemaRepo
|
||||
}
|
||||
|
||||
func NewConfigSchema(schemaRepo SchemaRepo) ConfigSchema {
|
||||
return ConfigSchema{
|
||||
schemaRepo: schemaRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s ConfigSchema) SchemaByModuleId(ctx context.Context, moduleId string) (*domain.ConfigSchema, error) {
|
||||
schema, err := s.schemaRepo.GetByModuleId(ctx, moduleId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get config schema")
|
||||
}
|
||||
if schema == nil {
|
||||
return nil, entity.ErrSchemaNotFound
|
||||
}
|
||||
|
||||
result := domain.ConfigSchema{
|
||||
Id: schema.Id,
|
||||
Version: schema.ModuleVersion,
|
||||
ModuleId: schema.ModuleId,
|
||||
Schema: schema.Data,
|
||||
CreatedAt: time.Time(schema.CreatedAt),
|
||||
UpdatedAt: time.Time(schema.UpdatedAt),
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/helpers"
|
||||
)
|
||||
|
||||
type ModuleRepo interface {
|
||||
All(ctx context.Context) ([]entity.Module, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
GetByNames(ctx context.Context, names []string) ([]entity.Module, error)
|
||||
}
|
||||
|
||||
type BackendsRepo interface {
|
||||
All(ctx context.Context) ([]entity.Backend, error)
|
||||
}
|
||||
|
||||
type SchemaRepo interface {
|
||||
All(ctx context.Context) ([]entity.ConfigSchema, error)
|
||||
GetByModuleId(ctx context.Context, moduleId string) (*entity.ConfigSchema, error)
|
||||
}
|
||||
|
||||
type Module struct {
|
||||
moduleRepo ModuleRepo
|
||||
backendsRepo BackendsRepo
|
||||
schemaRepo SchemaRepo
|
||||
}
|
||||
|
||||
func NewModule(
|
||||
moduleRepo ModuleRepo,
|
||||
backendsRepo BackendsRepo,
|
||||
schemaRepo SchemaRepo,
|
||||
) Module {
|
||||
return Module{
|
||||
moduleRepo: moduleRepo,
|
||||
backendsRepo: backendsRepo,
|
||||
schemaRepo: schemaRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Module) Status(ctx context.Context) ([]domain.ModuleInfo, error) {
|
||||
var (
|
||||
modules []entity.Module
|
||||
backends []entity.Backend
|
||||
schemas []entity.ConfigSchema
|
||||
)
|
||||
group, ctx := errgroup.WithContext(ctx)
|
||||
group.Go(func() error {
|
||||
var err error
|
||||
modules, err = s.moduleRepo.All(ctx)
|
||||
return errors.WithMessage(err, "get all modules")
|
||||
})
|
||||
group.Go(func() error {
|
||||
var err error
|
||||
backends, err = s.backendsRepo.All(ctx)
|
||||
return errors.WithMessage(err, "get all backends")
|
||||
})
|
||||
group.Go(func() error {
|
||||
var err error
|
||||
schemas, err = s.schemaRepo.All(ctx)
|
||||
return errors.WithMessage(err, "get all schemas")
|
||||
})
|
||||
err := group.Wait()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "wait")
|
||||
}
|
||||
|
||||
connections := make(map[string][]domain.Connection, len(modules))
|
||||
for _, backend := range backends {
|
||||
conn, err := s.backendToDto(backend)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "backend to dto")
|
||||
}
|
||||
connections[backend.ModuleId] = append(connections[backend.ModuleId], conn)
|
||||
}
|
||||
|
||||
schemasMap := make(map[string]json.RawMessage)
|
||||
for _, schema := range schemas {
|
||||
schemasMap[schema.ModuleId] = schema.Data
|
||||
}
|
||||
|
||||
moduleInfos := make([]domain.ModuleInfo, 0, len(modules))
|
||||
for _, module := range modules {
|
||||
info := domain.ModuleInfo{
|
||||
Id: module.Id,
|
||||
Name: module.Name,
|
||||
Active: len(connections[module.Id]) > 0,
|
||||
LastConnectedAt: (*time.Time)(module.LastConnectedAt),
|
||||
LastDisconnectedAt: (*time.Time)(module.LastDisconnectedAt),
|
||||
ConfigSchema: schemasMap[module.Id],
|
||||
Status: connections[module.Id],
|
||||
CreatedAt: time.Time(module.CreatedAt),
|
||||
}
|
||||
moduleInfos = append(moduleInfos, info)
|
||||
}
|
||||
|
||||
return moduleInfos, nil
|
||||
}
|
||||
|
||||
func (s Module) Delete(ctx context.Context, id string) error {
|
||||
err := s.moduleRepo.Delete(ctx, id)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete modules")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Module) Connections(ctx context.Context) ([]domain.Connection, error) {
|
||||
backends, err := s.backendsRepo.All(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get all backends")
|
||||
}
|
||||
|
||||
connections := make([]domain.Connection, 0, len(backends))
|
||||
for _, backend := range backends {
|
||||
conn, err := s.backendToDto(backend)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "backend to dto")
|
||||
}
|
||||
connections = append(connections, conn)
|
||||
}
|
||||
|
||||
return connections, nil
|
||||
}
|
||||
|
||||
func (s Module) backendToDto(backend entity.Backend) (domain.Connection, error) {
|
||||
addr, err := helpers.SplitAddress(backend)
|
||||
if err != nil {
|
||||
return domain.Connection{}, errors.WithMessage(err, "split address")
|
||||
}
|
||||
|
||||
endpointsDescriptors := make([]domain.EndpointDescriptor, 0)
|
||||
for _, desc := range backend.Endpoints.Value {
|
||||
endpointsDescriptors = append(endpointsDescriptors, domain.EndpointDescriptor{
|
||||
Path: desc.Path,
|
||||
Inner: desc.Inner,
|
||||
})
|
||||
}
|
||||
slices.SortFunc(endpointsDescriptors, func(a, b domain.EndpointDescriptor) int {
|
||||
return cmp.Compare(a.Path, b.Path)
|
||||
})
|
||||
|
||||
conn := domain.Connection{
|
||||
Id: backend.WsConnectionId,
|
||||
ModuleName: backend.ModuleName,
|
||||
LibVersion: backend.LibVersion,
|
||||
Version: backend.Version,
|
||||
Address: domain.Address{
|
||||
Ip: addr.IP,
|
||||
Port: addr.Port,
|
||||
},
|
||||
Endpoints: endpointsDescriptors,
|
||||
EstablishedAt: time.Time(backend.CreatedAt),
|
||||
}
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/log"
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
type LeaderChecker interface {
|
||||
IsLeader() bool
|
||||
}
|
||||
|
||||
type Cleaner struct {
|
||||
repo Repo
|
||||
leaderChecker LeaderChecker
|
||||
eventTtl time.Duration
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewCleaner(
|
||||
repo Repo,
|
||||
leaderChecker LeaderChecker,
|
||||
eventTtl time.Duration,
|
||||
logger log.Logger,
|
||||
) Cleaner {
|
||||
return Cleaner{
|
||||
repo: repo,
|
||||
leaderChecker: leaderChecker,
|
||||
eventTtl: eventTtl,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Cleaner) Do(ctx context.Context) {
|
||||
ctx = log.ToContext(ctx, log.String("worker", "eventCleaner"))
|
||||
if !c.leaderChecker.IsLeader() {
|
||||
c.logger.Debug(ctx, "is not a leader, skip work")
|
||||
return
|
||||
}
|
||||
|
||||
deleteBefore := time.Now().Add(-c.eventTtl)
|
||||
deleted, err := c.repo.DeleteByCreatedAt(ctx, xtypes.Time(deleteBefore))
|
||||
if err != nil {
|
||||
c.logger.Error(ctx, errors.WithMessage(err, "delete old events"))
|
||||
return
|
||||
}
|
||||
c.logger.Debug(ctx, fmt.Sprintf("delete %d old events", deleted))
|
||||
}
|
||||
Loaded 100 of 143 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user