Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aff6aefec6 | ||
|
|
b7b9a303ba | ||
|
|
791c9c4b95 | ||
|
|
0ebfca905d | ||
|
|
922641647a |
No files matched your search
+3
-22
@@ -1,23 +1,4 @@
|
||||
docker-build:
|
||||
image: docker:latest
|
||||
stage: build
|
||||
services:
|
||||
- docker:dind
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
- export VERSION=`cat .version `
|
||||
- echo $VERSION
|
||||
- echo $CI_DOCKER_FILE
|
||||
- echo $CI_REGISTRY
|
||||
script:
|
||||
- set
|
||||
- mkdir -p migrations
|
||||
- docker build -f "$CI_DOCKER_FILE" --force-rm --build-arg="version=$VERSION" --build-arg="app_name=$CI_PROJECT_NAME" --pull -t "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION" .
|
||||
- |
|
||||
docker tag "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION" "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
|
||||
docker push "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION"
|
||||
docker push "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
|
||||
docker rmi -f "$CI_REGISTRY/$CI_PROJECT_NAME:$VERSION"
|
||||
docker rmi -f "$CI_REGISTRY/$CI_PROJECT_NAME:latest"
|
||||
- docker logout $CI_REGISTRY
|
||||
include:
|
||||
- project: '$CI_PROJECT_PATH'
|
||||
file: '/ci-isp-utils.yml'
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
### v3.3.0
|
||||
* Добавлены команды `vars get`, `vars list`, `vars set`, `vars delete`, `vars upload`
|
||||
* Обновлены зависимости
|
||||
* Обновлена версия Go до `1.24`
|
||||
### v3.2.1
|
||||
* обновлены зависимости
|
||||
### v3.2.0
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.23-alpine3.20 as builder
|
||||
FROM golang:1.24-alpine3.21 as builder
|
||||
WORKDIR /build
|
||||
ARG version
|
||||
ENV version_env=$version
|
||||
@@ -13,7 +13,7 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
|
||||
--mount=type=bind,target=. \
|
||||
go build -ldflags="-X 'main.version=$version_env'" -o /main .
|
||||
|
||||
FROM alpine:3.20
|
||||
FROM alpine:3.21
|
||||
|
||||
RUN apk add --no-cache tzdata bash-completion jq
|
||||
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
FROM dockerhub.mos.ru/mosos/arbat:15.5 as builder
|
||||
RUN zypper --no-gpg-checks update -y && zypper --no-gpg-checks install -y go1.23 git
|
||||
RUN zypper --no-gpg-checks update -y && zypper --no-gpg-checks install -y go1.24 git
|
||||
WORKDIR /build
|
||||
ARG version
|
||||
ENV version_env=$version
|
||||
|
||||
@@ -15,7 +15,12 @@
|
||||
- [ispctl schema](#ispctl-schema)
|
||||
- [ispctl merge](#ispctl-merge)
|
||||
- [ispctl gitget](#ispctl-gitget)
|
||||
|
||||
- [ispctl vars](#ispctl-vars)
|
||||
- [ispctl vars get](#ispctl-vars-get)
|
||||
- [ispctl vars list](#ispctl-vars-list)
|
||||
- [ispctl vars set](#ispctl-vars-set)
|
||||
- [ispctl vars delete](#ispctl-vars-delete)
|
||||
- [ispctl vars upload](#ispctl-vars-upload)
|
||||
|
||||
## Требования
|
||||
* Linux
|
||||
@@ -32,41 +37,56 @@ ispctl [flag...] get module_name property_path [local_flag]
|
||||
ispctl [flag...] set module_name property_path [new_object]
|
||||
ispctl [flag...] delete module_name property_path
|
||||
ispctl [flag...] schema module_name [local_flag]
|
||||
ispctl [flag...] vars get variable_name
|
||||
ispctl [flag...] vars list
|
||||
ispctl [flag...] vars set [local_flag] variable_name variable_value
|
||||
ispctl [flag...] vars delete variable_name
|
||||
ispctl [flag...] vars upload csv_filepath
|
||||
```
|
||||
|
||||
## Описание
|
||||
|
||||
| Команды | Описание |
|
||||
|----------|-----------------------------------------------------------------------------|
|
||||
| `status` | возвращает доступные конфигурации модулей, их состояния и подключения |
|
||||
| `get` | возвращает объект конфигурации указанного модуля |
|
||||
| `set` | изменяет объект конфигурации указанного модуля |
|
||||
| `delete` | удаляет объект конфигурации указанного модуля |
|
||||
| `merge` | поблочно производит слияние конфигурации модуля с json конфигом через stdin |
|
||||
| `gitget` | скачивает из репозитория указанный файлы с указанного комита |
|
||||
| `schema` | возвращает схему конфигурации указанного модуля |
|
||||
| | |
|
||||
| Команды | Описание |
|
||||
| ------------- | --------------------------------------------------------------------------- |
|
||||
| `status` | возвращает доступные конфигурации модулей, их состояния и подключения |
|
||||
| `get` | возвращает объект конфигурации указанного модуля |
|
||||
| `set` | изменяет объект конфигурации указанного модуля |
|
||||
| `delete` | удаляет объект конфигурации указанного модуля |
|
||||
| `merge` | поблочно производит слияние конфигурации модуля с json конфигом через stdin |
|
||||
| `gitget` | скачивает из репозитория указанный файлы с указанного комита |
|
||||
| `schema` | возвращает схему конфигурации указанного модуля |
|
||||
| `vars get` | выводит информацию о переменной в json формате |
|
||||
| `vars list` | выводит список переменных в виде ASCII-таблицы |
|
||||
| `vars set` | изменяет значение переменной |
|
||||
| `vars delete` | удаляет переменную по имени |
|
||||
| `vars upload` | загружает переменные из csv файла |
|
||||
| | |
|
||||
|
||||
| Флаги | Параметры | Описание |
|
||||
|-------------|-----------|--------------------------------------------------------|
|
||||
| `-g` | string | адрес isp-config-service |
|
||||
| `-unsafe` | | отключает проверку схемы перед изменением конфигурации |
|
||||
| | | |
|
||||
| Флаги | Параметры | Описание |
|
||||
| --------- | --------- | ------------------------------------------------------ |
|
||||
| `-g` | string | адрес isp-config-service |
|
||||
| `-unsafe` | | отключает проверку схемы перед изменением конфигурации |
|
||||
| | | |
|
||||
|
||||
| Аргументы | Описание |
|
||||
|-----------------|-------------------------------------------------------------------------------------------------------------|
|
||||
| `module_name` | Название модуля с которым происходит взаимодействие |
|
||||
| `property_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля |
|
||||
| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin |
|
||||
| | |
|
||||
| Аргументы | Описание |
|
||||
| ----------------- | ------------------------------------------------------------------------------------------------------ |
|
||||
| `module_name` | Название модуля с которым происходит взаимодействие |
|
||||
| `property_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля |
|
||||
| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin |
|
||||
| `variable_name` | Название переменной с которой происходит взаимодействие |
|
||||
| `variable_value` | Значение переменной |
|
||||
| `csv_filepath` | Путь к csv файлу с переменными для загрузки |
|
||||
| | |
|
||||
|
||||
| Локальные флаги | Параметры | Команды | Описание |
|
||||
|-----------------|-----------|---------|---------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `-o` | string | schema | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
|
||||
| `-full` | bool | get | осуществляет взаимодействие с объектами конфигурации модуля с учетом объектом общих конфигураций, которые имеют связь с модулем |
|
||||
| | | | |
|
||||
| Локальные флаги | Параметры | Команды | Описание |
|
||||
| --------------- | --------- | -------- |------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `-o` | string | schema | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
|
||||
| `-full` | bool | get | осуществляет взаимодействие с объектами конфигурации модуля с учетом объектом общих конфигураций, которые имеют связь с модулем |
|
||||
| `-secret` | bool | vars set | устанавливает тип переменной в SECRET |
|
||||
| | | | |
|
||||
|
||||
## Пример
|
||||
|
||||
### ispctl status
|
||||
`ispctl [flag...] status [local_flag]`
|
||||
|
||||
@@ -353,14 +373,14 @@ ispctl merge example < example.json
|
||||
Результат в конфигурации модуля
|
||||
```json
|
||||
{
|
||||
"metrics": {
|
||||
"gc": 1,
|
||||
"memory": false
|
||||
},
|
||||
"property": "replaced",
|
||||
"database": {
|
||||
"host": "127.0.0.1"
|
||||
}
|
||||
"metrics": {
|
||||
"gc": 1,
|
||||
"memory": false
|
||||
},
|
||||
"property": "replaced",
|
||||
"database": {
|
||||
"host": "127.0.0.1"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -369,22 +389,121 @@ ispctl merge example < example.json
|
||||
ispctl gitget git@github.com:integration-system/ispctl.git main.go d4d7c679aad47ae204c2b3a4587b032a723fe315
|
||||
```
|
||||
|
||||
### Запрос с флагами
|
||||
### ispctl vars
|
||||
#### ispctl vars get
|
||||
|
||||
`ispctl [flag...] vars get variable_name`
|
||||
|
||||
Запрос
|
||||
|
||||
```bash
|
||||
ispctl vars get example_variable
|
||||
```
|
||||
|
||||
Ответ
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "example_variable",
|
||||
"description": "example description text",
|
||||
"type": "TEXT",
|
||||
"value": "some variable value",
|
||||
"containsInConfigs": []
|
||||
}
|
||||
```
|
||||
|
||||
#### ispctl vars list
|
||||
|
||||
`ispctl [flag...] vars list`
|
||||
|
||||
Запрос
|
||||
|
||||
```bash
|
||||
ispctl vars list
|
||||
```
|
||||
|
||||
Ответ
|
||||
|
||||
```bash
|
||||
+--------+-------------+--------+-----------------+---------+
|
||||
| NAME | DESCRIPTION | TYPE | VALUE | CONFIGS |
|
||||
+--------+-------------+--------+-----------------+---------+
|
||||
| var-99 | описание | SECRET | | |
|
||||
+--------+-------------+--------+-----------------+---------+
|
||||
| var-6 | описание | SECRET | | |
|
||||
+--------+-------------+--------+-----------------+---------+
|
||||
| var-2 | описание | TEXT | 1131231-2131231 | |
|
||||
+--------+-------------+--------+-----------------+---------+
|
||||
| var-1 | описание | SECRET | | |
|
||||
+--------+-------------+--------+-----------------+---------+
|
||||
```
|
||||
|
||||
#### ispctl vars set
|
||||
|
||||
`ispctl [flag...] vars set variable_name variable_value`
|
||||
|
||||
Запрос на изменение значения переменной и установку типа TEXT
|
||||
|
||||
```bash
|
||||
ispctl vars set example_variable value
|
||||
```
|
||||
|
||||
Запрос на изменение значения переменной и установку типа SECRET
|
||||
|
||||
```bash
|
||||
ispctl vars set -secret example_variable value
|
||||
```
|
||||
|
||||
#### ispctl vars delete
|
||||
|
||||
`ispctl [flag...] vars delete variable_name`
|
||||
|
||||
Запрос
|
||||
|
||||
```bash
|
||||
ispctl vars delete example_variable
|
||||
```
|
||||
|
||||
#### ispctl vars upload
|
||||
|
||||
`ispctl [flag...] vars upload csv_filepath`
|
||||
|
||||
Запрос
|
||||
|
||||
```bash
|
||||
ispctl vars upload example.csv
|
||||
```
|
||||
|
||||
CSV должен иметь поля `name`, `type`, `value`, `description`
|
||||
пример CSV файла:
|
||||
|
||||
```csv
|
||||
name,type,value,description
|
||||
variable-1,SECRET,var 1 value,Описание 1 переменной
|
||||
variable-2,TEXT,plaintext value,Описание 2 переменной
|
||||
```
|
||||
|
||||
### Запрос с флагами
|
||||
|
||||
Запрос
|
||||
|
||||
```bash
|
||||
ispctl -g '127.0.0.1:9002' set example . '{"metrics":{"address":{"ip":"127.0.0.1","newField":"100","port":1},"gc":1,"memory":false}}'
|
||||
```
|
||||
|
||||
Ответ
|
||||
|
||||
```json
|
||||
{
|
||||
"metrics": {
|
||||
"address": {
|
||||
"ip": "127.0.0.1",
|
||||
"newField": "100",
|
||||
"port": 1
|
||||
},
|
||||
"gc": 1,
|
||||
"memory": false
|
||||
}
|
||||
"metrics": {
|
||||
"address": {
|
||||
"ip": "127.0.0.1",
|
||||
"newField": "100",
|
||||
"port": 1
|
||||
},
|
||||
"gc": 1,
|
||||
"memory": false
|
||||
}
|
||||
}
|
||||
```
|
||||
1
|
||||
+2
-2
@@ -16,9 +16,9 @@ for status in $statusResponse; do
|
||||
read -ra ADDR <<<"$status"
|
||||
for module_name in "${ADDR[0]}"; do
|
||||
if [ -n "$*" ]; then
|
||||
ispctl $* schema $module_name -o html > schemas/$module_name.html
|
||||
ispctl $* schema -o html $module_name > schemas/$module_name.html
|
||||
else
|
||||
ispctl schema $module_name -o html > schemas/$module_name.html
|
||||
ispctl schema -o html $module_name > schemas/$module_name.html
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
+84
-61
@@ -2,83 +2,106 @@ package bash
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ispctl/model"
|
||||
"ispctl/service"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/txix-open/bellows"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
const (
|
||||
CommonConfigName bashArg = "config_name"
|
||||
CommonConfigData bashArg = "config_data"
|
||||
ModuleName bashArg = "module_name"
|
||||
ModuleData bashArg = "module_data"
|
||||
Empty bashArg = "empty"
|
||||
CommonConfigName = "config_name"
|
||||
ModuleName = "module_name"
|
||||
ModuleData = "module_data"
|
||||
|
||||
VariableName = "variable_name"
|
||||
Empty = "empty"
|
||||
)
|
||||
|
||||
type bashArg string
|
||||
|
||||
type bashCommand struct {
|
||||
first bashArg
|
||||
second bashArg
|
||||
type BashService interface {
|
||||
GetAllVariables() ([]model.Variable, error)
|
||||
GetAvailableConfigs() ([]model.ModuleInfo, error)
|
||||
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
|
||||
}
|
||||
|
||||
func Get(first bashArg, second bashArg) *bashCommand {
|
||||
return &bashCommand{
|
||||
first: first,
|
||||
second: second,
|
||||
type BeforeComplete func(ctx *cli.Context) (service.Config, error)
|
||||
|
||||
type Autocomplete struct {
|
||||
beforeComplete BeforeComplete
|
||||
service BashService
|
||||
}
|
||||
|
||||
func NewAutocomplete(beforeComplete BeforeComplete) Autocomplete {
|
||||
return Autocomplete{
|
||||
beforeComplete: beforeComplete,
|
||||
}
|
||||
}
|
||||
|
||||
func (c bashCommand) Complete(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
func (c Autocomplete) Complete(first string, second string) cli.BashCompleteFunc {
|
||||
return func(ctx *cli.Context) {
|
||||
cfgService, err := c.beforeComplete(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.service = cfgService
|
||||
c.complete(ctx, first, second)
|
||||
}
|
||||
commonConfigs, err := service.Config.GetMapNameCommonConfig()
|
||||
}
|
||||
|
||||
func (c Autocomplete) complete(ctx *cli.Context, first string, second string) {
|
||||
switch ctx.NArg() {
|
||||
case 0:
|
||||
c.completeFirstArg(ctx, first)
|
||||
case 1:
|
||||
c.completeSecondArg(ctx, second)
|
||||
}
|
||||
}
|
||||
|
||||
func (c Autocomplete) completeFirstArg(ctx *cli.Context, first string) {
|
||||
switch first {
|
||||
case ModuleName:
|
||||
c.printAvailableModules()
|
||||
case VariableName:
|
||||
c.printAvailableVariables()
|
||||
}
|
||||
}
|
||||
|
||||
func (c Autocomplete) completeSecondArg(ctx *cli.Context, second string) {
|
||||
switch second {
|
||||
case ModuleName:
|
||||
c.printAvailableModules()
|
||||
case ModuleData:
|
||||
c.printModuleData(ctx.Args().First())
|
||||
}
|
||||
}
|
||||
|
||||
func (c Autocomplete) printAvailableVariables() {
|
||||
vars, err := c.service.GetAllVariables()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch ctx.NArg() {
|
||||
case 0:
|
||||
switch c.first {
|
||||
case ModuleName:
|
||||
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
|
||||
return
|
||||
} else {
|
||||
for _, module := range arrayOfModules {
|
||||
fmt.Println(module.Name)
|
||||
}
|
||||
}
|
||||
case CommonConfigName:
|
||||
for _, config := range commonConfigs {
|
||||
fmt.Println(config.Name)
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
switch c.second {
|
||||
case CommonConfigData:
|
||||
if config, ok := commonConfigs[ctx.Args().First()]; ok {
|
||||
for key, _ := range bellows.Flatten(config.Data) {
|
||||
fmt.Printf(".%v\n", key)
|
||||
}
|
||||
}
|
||||
case ModuleName:
|
||||
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
|
||||
return
|
||||
} else {
|
||||
for _, module := range arrayOfModules {
|
||||
fmt.Println(module.Name)
|
||||
}
|
||||
}
|
||||
case ModuleData:
|
||||
if moduleConfiguration, err := service.Config.GetConfigurationByModuleName(ctx.Args().First()); err != nil {
|
||||
return
|
||||
} else {
|
||||
for key, _ := range bellows.Flatten(moduleConfiguration.Data) {
|
||||
fmt.Printf(".%v\n", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range vars {
|
||||
fmt.Println(v.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (c Autocomplete) printAvailableModules() {
|
||||
modules, err := c.service.GetAvailableConfigs()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, module := range modules {
|
||||
fmt.Println(module.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (c Autocomplete) printModuleData(moduleName string) {
|
||||
config, err := c.service.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for key := range bellows.Flatten(config.Data) {
|
||||
fmt.Printf(".%v\n", key)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package cfg
|
||||
|
||||
const (
|
||||
getAvailableConfigs = "config/module/get_modules_info"
|
||||
getConfigByModuleName = "config/config/get_active_config_by_module_name"
|
||||
createUpdateConfig = "config/config/create_update_config"
|
||||
getSchemaByModuleId = "config/schema/get_by_module_id"
|
||||
getCommonConfigs = "config/common_config/get_configs"
|
||||
createUpdateCommonConfig = "config/common_config/create_update_config"
|
||||
deleteCommonConfig = "config/common_config/delete_config"
|
||||
getLinksCommonConfig = "config/common_config/get_links"
|
||||
compileCommonConfigs = "config/common_config/compile"
|
||||
)
|
||||
-163
@@ -1,163 +0,0 @@
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
cli *client.Client
|
||||
address string
|
||||
}
|
||||
|
||||
func NewConfigClient() *ConfigClient {
|
||||
return &ConfigClient{}
|
||||
}
|
||||
|
||||
func (c *ConfigClient) ReceiveConfig(address string) error {
|
||||
cli, err := client.Default()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.cli = cli
|
||||
cli.Upgrade([]string{address})
|
||||
|
||||
c.address = address
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetAvailableConfigs() ([]ModuleInfo, error) {
|
||||
response := make([]ModuleInfo, 0)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getAvailableConfigs).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getAvailableConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetConfigByModuleName(name string) (*Config, error) {
|
||||
request := &getModuleByUuidAndNameRequest{ModuleName: name}
|
||||
response := new(Config)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getConfigByModuleName).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) CreateUpdateConfig(request Config) (*Config, error) {
|
||||
response := new(Config)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(createUpdateConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", createUpdateConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetSchemaByModuleId(moduleId string) (*ConfigSchema, error) {
|
||||
request := getSchemaByModuleIdRequest{ModuleId: moduleId}
|
||||
response := new(ConfigSchema)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getSchemaByModuleId).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getSchemaByModuleId)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetCommonConfigs(req []string) ([]CommonConfig, error) {
|
||||
response := make([]CommonConfig, 0)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getCommonConfigs).
|
||||
JsonRequestBody(req).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getCommonConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig, error) {
|
||||
response := new(CommonConfig)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(createUpdateCommonConfig).
|
||||
JsonRequestBody(req).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", createUpdateCommonConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) DeleteCommonConfig(id string) (*Deleted, error) {
|
||||
request := identityRequest{Id: id}
|
||||
response := new(Deleted)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(deleteCommonConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", deleteCommonConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetLinksCommonConfig(id string) (*Links, error) {
|
||||
request := identityRequest{Id: id}
|
||||
response := new(Links)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getLinksCommonConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getLinksCommonConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) CompileCommonConfigs(request CompileConfigs) (map[string]interface{}, error) {
|
||||
response := make(map[string]interface{})
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(compileCommonConfigs).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", compileCommonConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) errorHandler(err error) error {
|
||||
return errors.WithMessagef(err, "isp-config-service: %s", c.address)
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"ispctl/command/utils"
|
||||
"ispctl/model"
|
||||
|
||||
"github.com/txix-open/isp-kit/rc/schema"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type AutoComplete interface {
|
||||
Complete(first string, second string) cli.BashCompleteFunc
|
||||
}
|
||||
|
||||
type ConfigService interface {
|
||||
CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
|
||||
CreateUpdateConfigV2(configuration *model.Config) (map[string]any, error)
|
||||
DeleteVariable(variableName string) error
|
||||
GetAllVariables() ([]model.Variable, error)
|
||||
GetAvailableConfigs() ([]model.ModuleInfo, error)
|
||||
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
|
||||
GetSchemaByModuleId(moduleId string) (schema.Schema, error)
|
||||
GetVariableByName(variableName string) (*model.Variable, error)
|
||||
UpsertVariables(vars []model.UpsertVariableRequest) error
|
||||
}
|
||||
|
||||
type UpdateConfigService interface {
|
||||
CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
|
||||
}
|
||||
|
||||
func AllCommands(configService ConfigService, autoComplete AutoComplete) []*cli.Command {
|
||||
status := NewStatus(configService)
|
||||
get := NewGet(configService, autoComplete)
|
||||
set := NewSet(configService, autoComplete)
|
||||
delete := NewDelete(configService, autoComplete)
|
||||
schema := NewSchema(configService, autoComplete)
|
||||
merge := NewMerge(configService, autoComplete)
|
||||
gitGet := NewGitGet()
|
||||
variables := NewVariables(configService, autoComplete)
|
||||
return []*cli.Command{
|
||||
status.Command(),
|
||||
get.Command(),
|
||||
set.Command(),
|
||||
delete.Command(),
|
||||
schema.Command(),
|
||||
merge.Command(),
|
||||
gitGet.Command(),
|
||||
variables.Command(),
|
||||
}
|
||||
}
|
||||
|
||||
func CreateUpdateConfig(stringToChange string, configuration *model.Config, service UpdateConfigService) error {
|
||||
answer, err := service.CreateUpdateConfig(stringToChange, configuration)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if answer != nil {
|
||||
return utils.PrintAnswer(answer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/command/common_config"
|
||||
)
|
||||
|
||||
func CommonConfig() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "common",
|
||||
Usage: "access to common configs commands",
|
||||
Action: cc.action,
|
||||
BashComplete: cc.bachComplete,
|
||||
Subcommands: []*cli.Command{
|
||||
common_config.Get(),
|
||||
common_config.Set(),
|
||||
common_config.Delete(),
|
||||
common_config.Remove(),
|
||||
common_config.Link(),
|
||||
common_config.UnLink(),
|
||||
common_config.Contain(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var cc commonConfigCommand
|
||||
|
||||
type commonConfigCommand struct{}
|
||||
|
||||
func (g commonConfigCommand) action(ctx *cli.Context) error {
|
||||
if ctx.Args().First() == "" {
|
||||
fmt.Print("need use command: ")
|
||||
for _, comm := range CommonConfig().Subcommands {
|
||||
fmt.Printf("[%s] ", comm.Name)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g commonConfigCommand) bachComplete(ctx *cli.Context) {
|
||||
for _, command := range CommonConfig().Subcommands {
|
||||
fmt.Println(command.Name)
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func Contain() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "contain",
|
||||
Usage: "availability common configuration in module",
|
||||
Action: contain.action,
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete,
|
||||
}
|
||||
}
|
||||
|
||||
var contain containCommand
|
||||
|
||||
type containCommand struct{}
|
||||
|
||||
func (g containCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
|
||||
if configName == "" {
|
||||
return errors.New("empty common config name")
|
||||
}
|
||||
|
||||
config, err := service.Config.GetCommonConfigByName(configName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
links, err := service.Config.GetLinksCommonConfig(config.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("config [%s] linked with next modules:\n", configName)
|
||||
for _, link := range links {
|
||||
fmt.Printf("[%s] ", link)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func Delete() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "set common configurations",
|
||||
Action: deleteComm.action,
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.CommonConfigData).Complete,
|
||||
}
|
||||
}
|
||||
|
||||
var deleteComm deleteCommand
|
||||
|
||||
type deleteCommand struct{}
|
||||
|
||||
func (g deleteCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
|
||||
if configName == "" {
|
||||
return errors.New("empty config name")
|
||||
}
|
||||
|
||||
pathObject, err := utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config, err := service.Config.GetCommonConfigByName(configName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
return utils.CreateUpdateCommonConfig("", config)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(config.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return utils.CreateUpdateCommonConfig(stringToChange, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func Get() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "get",
|
||||
Usage: "get common configurations",
|
||||
Action: get.action,
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.CommonConfigData).Complete,
|
||||
}
|
||||
}
|
||||
|
||||
var get getCommand
|
||||
|
||||
type getCommand struct{}
|
||||
|
||||
func (g getCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
|
||||
commonConfigs, err := service.Config.GetMapNameCommonConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if configName == "" {
|
||||
fmt.Printf("available next common configs:\n")
|
||||
for name := range commonConfigs {
|
||||
fmt.Printf("[%s] ", name)
|
||||
}
|
||||
fmt.Println()
|
||||
return nil
|
||||
}
|
||||
|
||||
pathObject, err = utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config, ok := commonConfigs[configName]
|
||||
if !ok {
|
||||
return errors.Errorf("common config [%s] not found", configName)
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
utils.PrintAnswer(config.Data)
|
||||
} else if jsonObject, err := json.Marshal(config.Data); err != nil {
|
||||
return err
|
||||
} else {
|
||||
utils.CheckObject(jsonObject, pathObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func Link() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "link",
|
||||
Usage: "link common configurations to module configuration",
|
||||
Action: link.action,
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.ModuleName).Complete,
|
||||
}
|
||||
}
|
||||
|
||||
var link linkCommand
|
||||
|
||||
type linkCommand struct{}
|
||||
|
||||
func (g linkCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
moduleName := ctx.Args().Get(1)
|
||||
|
||||
if err := service.Config.LinkCommonConfigToModule(configName, moduleName); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func Remove() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "remove",
|
||||
Usage: "remove common configurations",
|
||||
Action: remove.action,
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete,
|
||||
}
|
||||
}
|
||||
|
||||
var remove removeCommand
|
||||
|
||||
type removeCommand struct{}
|
||||
|
||||
func (g removeCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
|
||||
if configName == "" {
|
||||
return errors.New("empty common config name")
|
||||
}
|
||||
|
||||
config, err := service.Config.GetCommonConfigByName(configName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
links, deleted, err := service.Config.DeleteCommonConfig(config.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if deleted {
|
||||
fmt.Printf("config [%s] deleted\n", config.Name)
|
||||
} else {
|
||||
fmt.Printf("config [%s] not deleted, need unlink in next modules:\n%v\n", config.Name, links)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/cfg"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func Set() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "set",
|
||||
Usage: "set common configurations",
|
||||
Action: set.action,
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.CommonConfigData).Complete,
|
||||
}
|
||||
}
|
||||
|
||||
var set setCommand
|
||||
|
||||
type setCommand struct{}
|
||||
|
||||
func (g setCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
changeObject := ctx.Args().Get(2)
|
||||
|
||||
if configName == "" {
|
||||
return errors.New("empty config name")
|
||||
}
|
||||
|
||||
mapConfigByName, err := service.Config.GetMapNameCommonConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config, ok := mapConfigByName[configName]
|
||||
if !ok {
|
||||
config = cfg.CommonConfig{
|
||||
Name: configName,
|
||||
}
|
||||
}
|
||||
|
||||
pathObject, err = utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
changeObject, err = utils.CheckChangeObject(changeObject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
return utils.CreateUpdateCommonConfig(changeObject, config)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(config.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
changeArgument := utils.ParseSetObject(changeObject)
|
||||
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return utils.CreateUpdateCommonConfig(stringToChange, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func UnLink() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "unlink",
|
||||
Usage: "unlink common configurations from module configuration",
|
||||
Action: unlink.action,
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.ModuleName).Complete,
|
||||
}
|
||||
}
|
||||
|
||||
var unlink unlinkCommand
|
||||
|
||||
type unlinkCommand struct{}
|
||||
|
||||
func (g unlinkCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
moduleName := ctx.Args().Get(1)
|
||||
|
||||
if err := service.Config.UnlinkCommonConfigFromModule(configName, moduleName); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+40
-31
@@ -3,35 +3,45 @@ package command
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
"ispctl/model"
|
||||
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Delete() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "delete configuration by module_name",
|
||||
Action: deleteComm.action,
|
||||
BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete,
|
||||
type DeleteService interface {
|
||||
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
|
||||
CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
|
||||
}
|
||||
|
||||
type Delete struct {
|
||||
service DeleteService
|
||||
autoComplete AutoComplete
|
||||
}
|
||||
|
||||
func NewDelete(service DeleteService, autoComplete AutoComplete) Delete {
|
||||
return Delete{
|
||||
service: service,
|
||||
autoComplete: autoComplete,
|
||||
}
|
||||
}
|
||||
|
||||
var deleteComm deleteCommand
|
||||
|
||||
type deleteCommand struct{}
|
||||
|
||||
func (d deleteCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
func (c Delete) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "delete configuration by module_name",
|
||||
Action: c.action,
|
||||
BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.ModuleData),
|
||||
}
|
||||
}
|
||||
|
||||
func (c Delete) action(ctx *cli.Context) error {
|
||||
moduleName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
|
||||
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
moduleConfiguration, err := c.service.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -40,19 +50,18 @@ func (d deleteCommand) action(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
return utils.CreateUpdateConfig("", moduleConfiguration)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(moduleConfiguration.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return utils.CreateUpdateConfig(stringToChange, moduleConfiguration)
|
||||
}
|
||||
return CreateUpdateConfig("", moduleConfiguration, c.service)
|
||||
}
|
||||
|
||||
jsonObject, err := json.Marshal(moduleConfiguration.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stringToChange, err := sjson.Delete(string(jsonObject), pathObject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return CreateUpdateConfig(stringToChange, moduleConfiguration, c.service)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package command
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
HostFlagName = "gateHost"
|
||||
HostFlagUsage = "isp-config-service address"
|
||||
|
||||
UnsafeFlagName = "unsafe"
|
||||
UnsafeFlagUsage = "disable checking schema for set configuration"
|
||||
|
||||
OutPrintFlagName = "o"
|
||||
OutPrintJsonValue = "json"
|
||||
OutPrintHtmlValue = "html"
|
||||
|
||||
SecretFlagName = "secret"
|
||||
secretVariableFlagUsage = "set variable as secret"
|
||||
)
|
||||
|
||||
var (
|
||||
outPrintStatusUsage = fmt.Sprintf("out print for status; %s", OutPrintJsonValue)
|
||||
outPrintSchemaUsage = fmt.Sprintf("out print for schema; %s or %s", OutPrintJsonValue, OutPrintHtmlValue)
|
||||
)
|
||||
+33
-33
@@ -3,47 +3,48 @@ package command
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
"ispctl/model"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Get() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "get",
|
||||
Usage: "get configuration by module_name",
|
||||
Action: get.action,
|
||||
BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete,
|
||||
Flags: []cli.Flag{
|
||||
flag.WithCommonConfig,
|
||||
},
|
||||
type GetService interface {
|
||||
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
|
||||
}
|
||||
|
||||
type Get struct {
|
||||
service SetService
|
||||
autoComplete AutoComplete
|
||||
}
|
||||
|
||||
func NewGet(service SetService, autoComplete AutoComplete) Get {
|
||||
return Get{
|
||||
service: service,
|
||||
autoComplete: autoComplete,
|
||||
}
|
||||
}
|
||||
|
||||
var get getCommand
|
||||
|
||||
type getCommand struct{}
|
||||
|
||||
func (g getCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
func (c Get) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "get",
|
||||
Usage: "get configuration by module_name",
|
||||
Action: c.action,
|
||||
BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.ModuleData),
|
||||
}
|
||||
}
|
||||
|
||||
func (c Get) action(ctx *cli.Context) error {
|
||||
moduleName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
|
||||
config, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
config, err := c.service.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := config.Data
|
||||
if ctx.Bool(flag.WithCommonConfig.Name) {
|
||||
if data, err = service.Config.CompileDataWithCommonConfigs(data, config.CommonConfigs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
pathObject, err = utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
@@ -51,13 +52,12 @@ func (g getCommand) action(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
utils.PrintAnswer(data)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
utils.CheckObject(jsonObject, pathObject)
|
||||
return utils.PrintAnswer(data)
|
||||
}
|
||||
return nil
|
||||
|
||||
jsonObject, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return utils.CheckObject(jsonObject, pathObject)
|
||||
}
|
||||
+55
-47
@@ -13,57 +13,65 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
semverRegexp = regexp.MustCompile("v([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$")
|
||||
)
|
||||
type GitGet struct {
|
||||
semverRegexp *regexp.Regexp
|
||||
}
|
||||
|
||||
func GitGet() *cli.Command {
|
||||
func NewGitGet() GitGet {
|
||||
return GitGet{
|
||||
semverRegexp: regexp.MustCompile(`v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$`),
|
||||
}
|
||||
}
|
||||
|
||||
func (c GitGet) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "gitget",
|
||||
Usage: "gitget [repository] [file] (commit|tag)",
|
||||
Description: "clone and print specified file from specified repository and specified commit hash or tag",
|
||||
Action: func(context *cli.Context) error {
|
||||
storage := memory.NewStorage()
|
||||
repo := context.Args().Get(0)
|
||||
|
||||
file := context.Args().Get(1)
|
||||
commit := context.Args().Get(2)
|
||||
|
||||
repository, err := git.Clone(storage, memfs.New(), &git.CloneOptions{
|
||||
URL: repo,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "clone %s", repo)
|
||||
}
|
||||
tree, err := repository.Worktree()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get worktree")
|
||||
}
|
||||
|
||||
if commit != "" {
|
||||
checkoutOpts := git.CheckoutOptions{}
|
||||
if semverRegexp.MatchString(commit) {
|
||||
checkoutOpts.Branch = plumbing.NewTagReferenceName(commit)
|
||||
} else {
|
||||
checkoutOpts.Hash = plumbing.NewHash(commit)
|
||||
}
|
||||
err = tree.Checkout(&checkoutOpts)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "checkout: %s", commit)
|
||||
}
|
||||
}
|
||||
|
||||
f, err := tree.Filesystem.Open(file)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "open %s", file)
|
||||
}
|
||||
|
||||
_, err = io.Copy(os.Stdout, f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Action: c.action,
|
||||
}
|
||||
}
|
||||
|
||||
func (c GitGet) action(ctx *cli.Context) error {
|
||||
storage := memory.NewStorage()
|
||||
repo := ctx.Args().Get(0)
|
||||
|
||||
file := ctx.Args().Get(1)
|
||||
commit := ctx.Args().Get(2)
|
||||
|
||||
repository, err := git.Clone(storage, memfs.New(), &git.CloneOptions{
|
||||
URL: repo,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "clone %s", repo)
|
||||
}
|
||||
tree, err := repository.Worktree()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get worktree")
|
||||
}
|
||||
|
||||
if commit != "" {
|
||||
checkoutOpts := git.CheckoutOptions{}
|
||||
if c.semverRegexp.MatchString(commit) {
|
||||
checkoutOpts.Branch = plumbing.NewTagReferenceName(commit)
|
||||
} else {
|
||||
checkoutOpts.Hash = plumbing.NewHash(commit)
|
||||
}
|
||||
err = tree.Checkout(&checkoutOpts)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "checkout: %s", commit)
|
||||
}
|
||||
}
|
||||
|
||||
f, err := tree.Filesystem.Open(file)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "open %s", file)
|
||||
}
|
||||
|
||||
_, err = io.Copy(os.Stdout, f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+48
-34
@@ -4,46 +4,60 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
"ispctl/model"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Merge() *cli.Command {
|
||||
type MergeService interface {
|
||||
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
|
||||
CreateUpdateConfigV2(configuration *model.Config) (map[string]any, error)
|
||||
}
|
||||
|
||||
type Merge struct {
|
||||
service MergeService
|
||||
autoComplete AutoComplete
|
||||
}
|
||||
|
||||
func NewMerge(service MergeService, autoComplete AutoComplete) Merge {
|
||||
return Merge{
|
||||
service: service,
|
||||
autoComplete: autoComplete,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Merge) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "merge",
|
||||
Usage: "merge actual config with config from stdin",
|
||||
BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete,
|
||||
Action: func(context *cli.Context) error {
|
||||
err := flag.CheckGlobal(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
moduleName := context.Args().First()
|
||||
config, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "get module config '%s'", moduleName)
|
||||
}
|
||||
|
||||
inputConfig := make(map[string]any)
|
||||
err = json.NewDecoder(os.Stdin).Decode(&inputConfig)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "json unmarshal input config")
|
||||
}
|
||||
for key, value := range inputConfig {
|
||||
config.Data[key] = value
|
||||
}
|
||||
|
||||
result, err := service.Config.CreateUpdateConfigV2(config)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "update module config '%s'", moduleName)
|
||||
}
|
||||
utils.PrintAnswer(result)
|
||||
|
||||
return nil
|
||||
},
|
||||
BashComplete: c.autoComplete.Complete(bash.CommonConfigName, bash.Empty),
|
||||
Action: c.action,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Merge) action(ctx *cli.Context) error {
|
||||
moduleName := ctx.Args().First()
|
||||
config, err := c.service.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "get module config '%s'", moduleName)
|
||||
}
|
||||
|
||||
inputConfig := make(map[string]any)
|
||||
err = json.NewDecoder(os.Stdin).Decode(&inputConfig)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "json unmarshal input config")
|
||||
}
|
||||
for key, value := range inputConfig {
|
||||
config.Data[key] = value
|
||||
}
|
||||
|
||||
result, err := c.service.CreateUpdateConfigV2(config)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "update module config '%s'", moduleName)
|
||||
}
|
||||
|
||||
return utils.PrintAnswer(result)
|
||||
}
|
||||
+57
-49
@@ -4,73 +4,81 @@ import (
|
||||
"html/template"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
"ispctl/model"
|
||||
"ispctl/tmpl"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/rc/schema"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Schema() *cli.Command {
|
||||
type SchemaService interface {
|
||||
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
|
||||
GetSchemaByModuleId(moduleId string) (schema.Schema, error)
|
||||
}
|
||||
|
||||
type Schema struct {
|
||||
service SchemaService
|
||||
autoComplete AutoComplete
|
||||
}
|
||||
|
||||
func NewSchema(service SchemaService, autoComplete AutoComplete) Schema {
|
||||
return Schema{
|
||||
service: service,
|
||||
autoComplete: autoComplete,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Schema) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "schema",
|
||||
Usage: "get schema configuration by module_name",
|
||||
Action: schema.action,
|
||||
Action: c.action,
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrintSchema,
|
||||
&cli.StringFlag{Name: OutPrintFlagName, Usage: outPrintSchemaUsage, Value: OutPrintJsonValue},
|
||||
},
|
||||
BashComplete: bash.Get(bash.ModuleName, bash.Empty).Complete,
|
||||
BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.Empty),
|
||||
}
|
||||
}
|
||||
|
||||
var schema schemaCommand
|
||||
|
||||
type schemaCommand struct{}
|
||||
|
||||
func (s schemaCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
func (c Schema) action(ctx *cli.Context) error {
|
||||
moduleName := ctx.Args().First()
|
||||
schemaConfig, err := c.getSchemaConfig(moduleName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
moduleName := ctx.Args().First()
|
||||
|
||||
if schemaConfig := s.getSchemaConfig(moduleName); schemaConfig != nil {
|
||||
schema := make(map[string]interface{})
|
||||
schema["title"] = moduleName
|
||||
schema["schema"] = schemaConfig
|
||||
switch ctx.String(flag.OutPrintSchema.Name) {
|
||||
case flag.OutPrintJsonValue:
|
||||
utils.PrintAnswer(schema)
|
||||
case flag.OutPrintHtmlValue:
|
||||
s.printHtml(schema)
|
||||
default:
|
||||
return errors.Errorf("invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s schemaCommand) getSchemaConfig(moduleName string) interface{} {
|
||||
if configuration, err := service.Config.GetConfigurationByModuleName(moduleName); err != nil {
|
||||
utils.PrintError(err)
|
||||
return nil
|
||||
} else if schema, err := service.Config.GetSchemaByModuleId(configuration.ModuleId); err != nil {
|
||||
utils.PrintError(err)
|
||||
return nil
|
||||
} else {
|
||||
return schema
|
||||
schema := make(map[string]any)
|
||||
schema["title"] = moduleName
|
||||
schema["schema"] = schemaConfig
|
||||
switch ctx.String(OutPrintFlagName) {
|
||||
case OutPrintJsonValue:
|
||||
return utils.PrintAnswer(schema)
|
||||
case OutPrintHtmlValue:
|
||||
return c.printHtml(schema)
|
||||
default:
|
||||
return errors.Errorf("invalid flag value, expected [%s] or [%s]", OutPrintJsonValue, OutPrintHtmlValue)
|
||||
}
|
||||
}
|
||||
|
||||
func (s schemaCommand) printHtml(schema map[string]interface{}) {
|
||||
if temp, err := template.New("template").Parse(tmpl.HtmlFile); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
} else {
|
||||
if err := temp.ExecuteTemplate(os.Stdout, "template", schema); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
func (c Schema) getSchemaConfig(moduleName string) (schema.Schema, error) {
|
||||
configuration, err := c.service.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
schema, err := c.service.GetSchemaByModuleId(configuration.ModuleId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return schema, nil
|
||||
}
|
||||
|
||||
func (c Schema) printHtml(schema map[string]any) error {
|
||||
temp, err := template.New("template").Parse(tmpl.HtmlFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return temp.ExecuteTemplate(os.Stdout, "template", schema)
|
||||
}
|
||||
+39
-31
@@ -3,37 +3,46 @@ package command
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
"ispctl/model"
|
||||
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Set() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "set",
|
||||
Usage: "set configuration by module_name",
|
||||
Action: set.action,
|
||||
BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete,
|
||||
type SetService interface {
|
||||
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
|
||||
CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
|
||||
}
|
||||
|
||||
type Set struct {
|
||||
service SetService
|
||||
autoComplete AutoComplete
|
||||
}
|
||||
|
||||
func NewSet(service SetService, autoComplete AutoComplete) Set {
|
||||
return Set{
|
||||
service: service,
|
||||
autoComplete: autoComplete,
|
||||
}
|
||||
}
|
||||
|
||||
var set setCommand
|
||||
|
||||
type setCommand struct{}
|
||||
|
||||
func (s setCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return err
|
||||
func (c Set) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "set",
|
||||
Usage: "set configuration by module_name",
|
||||
Action: c.action,
|
||||
BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.ModuleData),
|
||||
}
|
||||
}
|
||||
|
||||
func (c Set) action(ctx *cli.Context) error {
|
||||
moduleName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
changeObject := ctx.Args().Get(2)
|
||||
|
||||
config, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
config, err := c.service.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -49,18 +58,17 @@ func (s setCommand) action(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
return utils.CreateUpdateConfig(changeObject, config)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(config.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
changeArgument := utils.ParseSetObject(changeObject)
|
||||
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
|
||||
return err
|
||||
} else {
|
||||
return utils.CreateUpdateConfig(stringToChange, config)
|
||||
}
|
||||
return CreateUpdateConfig(changeObject, config, c.service)
|
||||
}
|
||||
jsonObject, err := json.Marshal(config.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
changeArgument := utils.ParseSetObject(changeObject)
|
||||
stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return CreateUpdateConfig(stringToChange, config, c.service)
|
||||
}
|
||||
+40
-35
@@ -5,11 +5,11 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"ispctl/command/utils"
|
||||
"ispctl/model"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/flag"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -21,50 +21,55 @@ const (
|
||||
tableConnectedStatus = "CONNECTED"
|
||||
)
|
||||
|
||||
func Status() *cli.Command {
|
||||
type StatusService interface {
|
||||
GetAvailableConfigs() ([]model.ModuleInfo, error)
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
service StatusService
|
||||
}
|
||||
|
||||
func NewStatus(service StatusService) Status {
|
||||
return Status{service: service}
|
||||
}
|
||||
|
||||
func (c Status) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "status",
|
||||
Usage: "get available configs",
|
||||
Action: status.action,
|
||||
Action: c.action,
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrintStatus,
|
||||
&cli.StringFlag{Name: OutPrintFlagName, Usage: outPrintStatusUsage},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var status statusCommand
|
||||
|
||||
type statusCommand struct{}
|
||||
|
||||
func (statusCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
func (c Status) action(ctx *cli.Context) error {
|
||||
arrayOfModules, err := c.service.GetAvailableConfigs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
switch ctx.String(flag.OutPrintStatus.Name) {
|
||||
case flag.OutPrintJsonValue:
|
||||
utils.PrintAnswer(arrayOfModules)
|
||||
default:
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
|
||||
table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses})
|
||||
for _, module := range arrayOfModules {
|
||||
addresses := ""
|
||||
connection := tableNotConnectedStatus
|
||||
instanceList := make([]string, 0, len(module.Status))
|
||||
for _, value := range module.Status {
|
||||
instanceList = append(instanceList, fmt.Sprintf("%s:%s %s", value.Address.IP, value.Address.Port, value.Version))
|
||||
}
|
||||
addresses = strings.Join(instanceList, "\n")
|
||||
if addresses != "" {
|
||||
connection = tableConnectedStatus
|
||||
}
|
||||
table.Append([]string{module.Name, connection, addresses})
|
||||
switch ctx.String(OutPrintFlagName) {
|
||||
case OutPrintJsonValue:
|
||||
return utils.PrintAnswer(arrayOfModules)
|
||||
default:
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
|
||||
table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses})
|
||||
for _, module := range arrayOfModules {
|
||||
addresses := ""
|
||||
connection := tableNotConnectedStatus
|
||||
instanceList := make([]string, 0, len(module.Status))
|
||||
for _, value := range module.Status {
|
||||
instanceList = append(instanceList, fmt.Sprintf("%s:%s %s", value.Address.IP, value.Address.Port, value.Version))
|
||||
}
|
||||
table.Render()
|
||||
addresses = strings.Join(instanceList, "\n")
|
||||
if addresses != "" {
|
||||
connection = tableConnectedStatus
|
||||
}
|
||||
table.Append([]string{module.Name, connection, addresses})
|
||||
}
|
||||
table.Render()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+17
-26
@@ -2,7 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -22,7 +22,7 @@ func CheckPath(pathObject string) (string, error) {
|
||||
continue
|
||||
}
|
||||
if key == 1 {
|
||||
pathObject = fmt.Sprintf("%s", value)
|
||||
pathObject = value
|
||||
continue
|
||||
}
|
||||
pathObject = fmt.Sprintf("%s.%s", pathObject, value)
|
||||
@@ -32,7 +32,7 @@ func CheckPath(pathObject string) (string, error) {
|
||||
|
||||
func CheckChangeObject(changeObject string) (string, error) {
|
||||
if changeObject == "" {
|
||||
bytes, err := ioutil.ReadAll(os.Stdin)
|
||||
bytes, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -40,26 +40,18 @@ func CheckChangeObject(changeObject string) (string, error) {
|
||||
}
|
||||
if changeObject == "" {
|
||||
return "", errors.New("expected argument")
|
||||
} else {
|
||||
return changeObject, nil
|
||||
}
|
||||
return changeObject, nil
|
||||
}
|
||||
|
||||
func PrintAnswer(data interface{}) {
|
||||
func PrintAnswer(data any) error {
|
||||
encoder := json.NewEncoder(os.Stdout)
|
||||
encoder.SetEscapeHTML(false)
|
||||
encoder.SetIndent("", " ")
|
||||
if err := encoder.Encode(data); err != nil {
|
||||
PrintError(err)
|
||||
}
|
||||
return encoder.Encode(data)
|
||||
}
|
||||
|
||||
func PrintError(err error) {
|
||||
fmt.Println("ERROR:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
func ParseSetObject(argument string) interface{} {
|
||||
func ParseSetObject(argument string) any {
|
||||
tryParse := []byte(argument)
|
||||
if tryParse[0] == '"' && tryParse[len(tryParse)-1] == '"' {
|
||||
tryParse = tryParse[1 : len(tryParse)-1]
|
||||
@@ -70,12 +62,12 @@ func ParseSetObject(argument string) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
mapStringInterface := make(map[string]interface{})
|
||||
mapStringInterface := make(map[string]any)
|
||||
if err := json.Unmarshal(tryParse, &mapStringInterface); err == nil {
|
||||
return mapStringInterface
|
||||
}
|
||||
|
||||
arrayOfObject := make([]interface{}, 0)
|
||||
arrayOfObject := make([]any, 0)
|
||||
if err := json.Unmarshal(tryParse, &arrayOfObject); err == nil {
|
||||
return arrayOfObject
|
||||
}
|
||||
@@ -98,16 +90,15 @@ func ParseSetObject(argument string) interface{} {
|
||||
return argument
|
||||
}
|
||||
|
||||
func CheckObject(jsonObject []byte, depth string) {
|
||||
func CheckObject(jsonObject []byte, depth string) error {
|
||||
jsonString := gjson.GetBytes(jsonObject, depth)
|
||||
if jsonString.Raw == "" {
|
||||
PrintError(errors.Errorf("path '%s' not found\n", depth))
|
||||
} else {
|
||||
var data interface{}
|
||||
if err := json.Unmarshal([]byte(jsonString.Raw), &data); err != nil {
|
||||
PrintError(err)
|
||||
} else {
|
||||
PrintAnswer(data)
|
||||
}
|
||||
return errors.Errorf("path '%s' not found\n", depth)
|
||||
}
|
||||
var data any
|
||||
err := json.Unmarshal([]byte(jsonString.Raw), &data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return PrintAnswer(data)
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"ispctl/cfg"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func CreateUpdateCommonConfig(stringToChange string, configuration cfg.CommonConfig) error {
|
||||
if answer, err := service.Config.CreateUpdateCommonConfig(stringToChange, configuration); err != nil {
|
||||
return err
|
||||
} else if answer != nil {
|
||||
PrintAnswer(answer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"ispctl/cfg"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
func CreateUpdateConfig(stringToChange string, configuration *cfg.Config) error {
|
||||
if answer, err := service.Config.CreateUpdateConfig(stringToChange, configuration); err != nil {
|
||||
return err
|
||||
} else if answer != nil {
|
||||
PrintAnswer(answer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/model"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type VariablesService interface {
|
||||
GetAllVariables() ([]model.Variable, error)
|
||||
GetVariableByName(variableName string) (*model.Variable, error)
|
||||
DeleteVariable(variableName string) error
|
||||
UpsertVariables(vars []model.UpsertVariableRequest) error
|
||||
}
|
||||
|
||||
type Variables struct {
|
||||
service VariablesService
|
||||
autoComplete AutoComplete
|
||||
}
|
||||
|
||||
func NewVariables(service VariablesService, autoComplete AutoComplete) Variables {
|
||||
return Variables{
|
||||
service: service,
|
||||
autoComplete: autoComplete,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Variables) Command() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "vars",
|
||||
Usage: "manage variables",
|
||||
Subcommands: []*cli.Command{
|
||||
{
|
||||
Name: "get",
|
||||
Usage: "vars get <name>",
|
||||
Action: c.getByName,
|
||||
BashComplete: c.autoComplete.Complete(bash.VariableName, bash.Empty),
|
||||
},
|
||||
{
|
||||
Name: "list",
|
||||
Usage: "list all variables",
|
||||
Action: c.list,
|
||||
},
|
||||
{
|
||||
Name: "set",
|
||||
Usage: "vars set <name> <value>",
|
||||
Action: c.set,
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{Name: SecretFlagName, Usage: secretVariableFlagUsage},
|
||||
},
|
||||
BashComplete: c.autoComplete.Complete(bash.VariableName, bash.Empty),
|
||||
},
|
||||
{
|
||||
Name: "delete",
|
||||
Usage: "vars delete <name>",
|
||||
Action: c.delete,
|
||||
BashComplete: c.autoComplete.Complete(bash.VariableName, bash.Empty),
|
||||
},
|
||||
{
|
||||
Name: "upload",
|
||||
Usage: "vars upload <filepath>",
|
||||
Action: c.upload,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (c Variables) list(ctx *cli.Context) error {
|
||||
vars, err := c.service.GetAllVariables()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetHeader([]string{"Name", "Description", "Type", "Value", "Configs"})
|
||||
for _, v := range vars {
|
||||
configs := make([]string, 0, len(v.ContainsInConfigs))
|
||||
for _, c := range v.ContainsInConfigs {
|
||||
configs = append(configs, c.Name)
|
||||
}
|
||||
table.Append([]string{v.Name, v.Description, v.Type, v.Value, strings.Join(configs, ",")})
|
||||
}
|
||||
table.SetBorder(true)
|
||||
table.SetRowLine(true)
|
||||
table.Render()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Variables) getByName(ctx *cli.Context) error {
|
||||
variableName := ctx.Args().Get(0)
|
||||
variable, err := c.service.GetVariableByName(variableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return utils.PrintAnswer(variable)
|
||||
}
|
||||
|
||||
func (c Variables) set(ctx *cli.Context) error {
|
||||
variableName := ctx.Args().Get(0)
|
||||
variableValue := ctx.Args().Get(1)
|
||||
variableType := model.TextVariableType
|
||||
if ctx.Bool(SecretFlagName) {
|
||||
variableType = model.SecretVariableType
|
||||
}
|
||||
return c.service.UpsertVariables([]model.UpsertVariableRequest{{
|
||||
Name: variableName,
|
||||
Value: variableValue,
|
||||
Type: variableType,
|
||||
}})
|
||||
}
|
||||
|
||||
func (c Variables) delete(ctx *cli.Context) error {
|
||||
return c.service.DeleteVariable(ctx.Args().Get(0))
|
||||
}
|
||||
|
||||
func (c Variables) upload(ctx *cli.Context) error {
|
||||
variables, err := c.readVariablesFromCsv(ctx.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.service.UpsertVariables(variables)
|
||||
}
|
||||
|
||||
func (c Variables) readVariablesFromCsv(filepath string) ([]model.UpsertVariableRequest, error) {
|
||||
file, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "failed to open file %s", filepath)
|
||||
}
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
reader := csv.NewReader(file)
|
||||
reader.TrimLeadingSpace = true
|
||||
records, err := reader.ReadAll()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "failed to read CSV file")
|
||||
}
|
||||
if len(records) < 2 {
|
||||
return nil, errors.New("CSV file must have a header and at least one data row")
|
||||
}
|
||||
|
||||
header := records[0]
|
||||
columnIndexes := map[string]int{}
|
||||
for i, col := range header {
|
||||
columnIndexes[strings.ToLower(col)] = i
|
||||
}
|
||||
|
||||
for _, columnName := range []string{"name", "type", "value", "description"} {
|
||||
_, ok := columnIndexes[columnName]
|
||||
if !ok {
|
||||
return nil, errors.Errorf("column '%s' is required", columnName)
|
||||
}
|
||||
}
|
||||
|
||||
variables := make([]model.UpsertVariableRequest, 0, len(records)-1)
|
||||
for _, row := range records[1:] {
|
||||
variables = append(variables, model.UpsertVariableRequest{
|
||||
Name: row[columnIndexes["name"]],
|
||||
Type: row[columnIndexes["type"]],
|
||||
Value: row[columnIndexes["value"]],
|
||||
Description: row[columnIndexes["description"]],
|
||||
})
|
||||
}
|
||||
return variables, nil
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package flag
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
hostName = "gateHost"
|
||||
hostUsage = "isp-config-service address"
|
||||
|
||||
unsafeName = "unsafe"
|
||||
unsafeUsage = "disable checking schema for set configuration"
|
||||
|
||||
outPrintName = "o"
|
||||
OutPrintJsonValue = "json"
|
||||
OutPrintHtmlValue = "html"
|
||||
|
||||
withCommonConfigName = "full"
|
||||
withCommonConfigUsage = "compile data with common configs"
|
||||
)
|
||||
|
||||
var (
|
||||
outPrintStatusUsage = fmt.Sprintf("out print for status; %s", OutPrintJsonValue)
|
||||
outPrintSchemaUsage = fmt.Sprintf("out print for schema; %s or %s", OutPrintJsonValue, OutPrintHtmlValue)
|
||||
)
|
||||
@@ -1,36 +0,0 @@
|
||||
package flag
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/service"
|
||||
)
|
||||
|
||||
var (
|
||||
//---global---
|
||||
Host = &cli.StringFlag{
|
||||
Name: hostName,
|
||||
Usage: hostUsage,
|
||||
Value: "127.0.0.1:9002",
|
||||
Required: false,
|
||||
Aliases: []string{"g", "configAddr"},
|
||||
}
|
||||
Unsafe = &cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
|
||||
//---local---
|
||||
OutPrintStatus = &cli.StringFlag{Name: outPrintName, Usage: outPrintStatusUsage}
|
||||
OutPrintSchema = &cli.StringFlag{Name: outPrintName, Usage: outPrintSchemaUsage, Value: OutPrintJsonValue}
|
||||
WithCommonConfig = &cli.BoolFlag{Name: withCommonConfigName, Usage: withCommonConfigUsage}
|
||||
)
|
||||
|
||||
func CheckGlobal(c *cli.Context) error {
|
||||
var (
|
||||
host string
|
||||
)
|
||||
service.Config.UnsafeEnable = c.Bool(Unsafe.Name)
|
||||
|
||||
host = c.String(Host.Name)
|
||||
host = strings.Replace(host, "'", "", -1)
|
||||
|
||||
return service.Config.ReceiveConfiguration(host)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
module ispctl
|
||||
|
||||
go 1.23
|
||||
go 1.24
|
||||
|
||||
require (
|
||||
github.com/go-git/go-billy/v5 v5.6.0
|
||||
@@ -10,10 +10,10 @@ require (
|
||||
github.com/tidwall/gjson v1.17.3
|
||||
github.com/tidwall/sjson v1.2.5
|
||||
github.com/txix-open/bellows v1.2.0
|
||||
github.com/txix-open/isp-kit v1.39.0
|
||||
github.com/txix-open/isp-kit v1.44.0
|
||||
github.com/urfave/cli/v2 v2.27.5
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38
|
||||
google.golang.org/grpc v1.67.1
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422
|
||||
google.golang.org/grpc v1.69.4
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -35,12 +35,12 @@ require (
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mailru/easyjson v0.9.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
@@ -55,29 +55,30 @@ require (
|
||||
github.com/skeema/knownhosts v1.2.2 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/txix-open/etp/v3 v3.2.0 // indirect
|
||||
github.com/txix-open/etp/v4 v4.0.1 // indirect
|
||||
github.com/txix-open/jsonschema v1.2.0 // indirect
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||
github.com/xanzy/ssh-agent v0.3.3 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // 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.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.33.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/crypto v0.32.0 // indirect
|
||||
golang.org/x/mod v0.17.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
|
||||
golang.org/x/net v0.34.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/sys v0.29.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
|
||||
google.golang.org/protobuf v1.36.2 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@@ -36,10 +36,10 @@ github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcej
|
||||
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
|
||||
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||
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/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/getsentry/sentry-go v0.31.1 h1:ELVc0h7gwyhnXHDouXkhqTFSO5oslsRDk0++eyE0KJ4=
|
||||
github.com/getsentry/sentry-go v0.31.1/go.mod h1:CYNcMMz73YigoHljQRG+qPF+eMq8gG72XcGN/p71BAY=
|
||||
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
|
||||
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
|
||||
@@ -61,16 +61,17 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.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/grpc-ecosystem/grpc-gateway/v2 v2.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1/go.mod h1:RBRO7fro65R6tjKzYgLAFo0t1QEXY1Dp+i/bvpRiqiQ=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
||||
@@ -88,8 +89,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
|
||||
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
@@ -136,8 +137,9 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.17.3 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94=
|
||||
github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
@@ -149,10 +151,10 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
|
||||
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
|
||||
github.com/txix-open/etp/v3 v3.2.0 h1:EgTchT8VtCYV1iEo/y4jII3/NybrXiQDE0y6pmS350M=
|
||||
github.com/txix-open/etp/v3 v3.2.0/go.mod h1:lgen0TJmiturgBhvlxH1/PQ7iLL/OebKbxPAQYkuKI0=
|
||||
github.com/txix-open/isp-kit v1.39.0 h1:NBV2oJJefH/qt2pcPrqEmYccJedjPaVCwr6Z955C+pg=
|
||||
github.com/txix-open/isp-kit v1.39.0/go.mod h1:R4vwujGjMXLQir8MDDCfsDQa0CWGuZBSMakt5qcybgM=
|
||||
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.44.0 h1:ao16vgZ/cdbO4sZWYXD4VcJQ+984IQvb/A80mEjU504=
|
||||
github.com/txix-open/isp-kit v1.44.0/go.mod h1:BHRF3AYRcQtEtNvoQZXxTVj/CYOVMKhOcCD3n8CdsxE=
|
||||
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=
|
||||
@@ -166,20 +168,24 @@ github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
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.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
|
||||
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 h1:Vh5HayB/0HHfOQA7Ctx69E/Y/DcQSMPpKANYVMQ7fBA=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0/go.mod h1:cpgtDBaqD/6ok/UG0jT15/uKjAY8mRA53diogHBg3UI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 h1:wpMfgF8E1rkrT1Z6meFh1NDtownE9Ii3n3X2GJYjsaU=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0/go.mod h1:wAy0T/dUbs468uOlkT31xjvqQgEVXv58BRFWEgn5v/0=
|
||||
go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ=
|
||||
go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M=
|
||||
go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM=
|
||||
go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
|
||||
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
|
||||
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
|
||||
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
|
||||
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
@@ -191,8 +197,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
|
||||
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
@@ -206,13 +212,13 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
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/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/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.1.0/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/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -226,15 +232,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/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/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.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/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
|
||||
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
|
||||
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
|
||||
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
@@ -242,8 +248,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
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=
|
||||
@@ -251,14 +257,14 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/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=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 h1:GVIKPyP/kLIyVOgOnTwFOrvQaQUzOzGMCxgFUOEmm24=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422/go.mod h1:b6h1vNKhxaSoEI+5jc3PJUCustfli/mRab7295pY7rw=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
|
||||
google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=
|
||||
google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
|
||||
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
|
||||
google.golang.org/protobuf v1.36.2/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-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
|
||||
@@ -4,10 +4,14 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"ispctl/bash"
|
||||
"ispctl/command"
|
||||
"ispctl/repository"
|
||||
"ispctl/service"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"ispctl/command"
|
||||
"ispctl/flag"
|
||||
)
|
||||
|
||||
var version = "1.1.0"
|
||||
@@ -22,20 +26,33 @@ func initCommands() {
|
||||
|
||||
app.Version = version
|
||||
app.Flags = []cli.Flag{
|
||||
flag.Host,
|
||||
flag.Unsafe,
|
||||
&cli.StringFlag{
|
||||
Name: command.HostFlagName,
|
||||
Usage: command.HostFlagUsage,
|
||||
Value: "127.0.0.1:9002",
|
||||
Required: false,
|
||||
Aliases: []string{"g", "configAddr"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: command.UnsafeFlagName,
|
||||
Usage: command.UnsafeFlagUsage,
|
||||
},
|
||||
}
|
||||
app.EnableBashCompletion = true
|
||||
app.Commands = []*cli.Command{
|
||||
command.Status(),
|
||||
command.Get(),
|
||||
command.Set(),
|
||||
command.Delete(),
|
||||
command.Schema(),
|
||||
command.CommonConfig(),
|
||||
command.Merge(),
|
||||
command.GitGet(),
|
||||
|
||||
var configService service.Config
|
||||
var autoComplete bash.Autocomplete
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
service, err := configServiceFromGlobalFlags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configService = service
|
||||
return nil
|
||||
}
|
||||
autoComplete = bash.NewAutocomplete(configServiceFromGlobalFlags)
|
||||
app.Commands = command.AllCommands(&configService, autoComplete)
|
||||
|
||||
app.BashComplete = func(context *cli.Context) {
|
||||
for _, appCommand := range app.Commands {
|
||||
fmt.Println(appCommand.Name)
|
||||
@@ -47,3 +64,17 @@ func initCommands() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func configServiceFromGlobalFlags(ctx *cli.Context) (service.Config, error) {
|
||||
enableUnsafe := ctx.Bool(command.UnsafeFlagName)
|
||||
|
||||
host := ctx.String(command.HostFlagName)
|
||||
host = strings.ReplaceAll(host, "'", "")
|
||||
|
||||
configCli, err := repository.NewGrpcClientWithHost(host)
|
||||
if err != nil {
|
||||
return service.Config{}, err
|
||||
}
|
||||
configRepo := repository.NewConfig(configCli)
|
||||
return service.NewConfig(enableUnsafe, configRepo), nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cfg
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/txix-open/isp-kit/rc/schema"
|
||||
)
|
||||
|
||||
type getModuleByUuidAndNameRequest struct {
|
||||
type GetModuleByUuidAndNameRequest struct {
|
||||
ModuleName string
|
||||
Uuid string
|
||||
}
|
||||
|
||||
type getSchemaByModuleIdRequest struct {
|
||||
type GetSchemaByModuleIdRequest struct {
|
||||
ModuleId string
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type Config struct {
|
||||
ModuleId string
|
||||
Version int32
|
||||
Active bool
|
||||
Data map[string]interface{}
|
||||
Data map[string]any
|
||||
Unsafe bool
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ type CommonConfig struct {
|
||||
Description string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Data map[string]interface{}
|
||||
Data map[string]any
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
@@ -62,19 +62,3 @@ type ConfigSchema struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type Deleted struct {
|
||||
Deleted bool
|
||||
Links Links
|
||||
}
|
||||
|
||||
type Links map[string][]string
|
||||
|
||||
type identityRequest struct {
|
||||
Id string
|
||||
}
|
||||
|
||||
type CompileConfigs struct {
|
||||
Data map[string]interface{}
|
||||
CommonConfigsIdList []string
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
var (
|
||||
ErrModuleNotFound = errors.New("module not found")
|
||||
ErrVariableNotFound = errors.New("variable not found")
|
||||
)
|
||||
|
||||
const (
|
||||
SecretVariableType = "SECRET"
|
||||
TextVariableType = "TEXT"
|
||||
|
||||
ErrCodeVariableNotFound = 2006
|
||||
)
|
||||
|
||||
type Variable struct {
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Value string
|
||||
ContainsInConfigs []LinkedConfig
|
||||
}
|
||||
|
||||
type LinkedConfig struct {
|
||||
Id string
|
||||
ModuleId string
|
||||
Name string
|
||||
}
|
||||
|
||||
type UpsertVariableRequest struct {
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
Type string `validate:"required,oneof=SECRET TEXT"`
|
||||
Value string `validate:"required"`
|
||||
}
|
||||
|
||||
type VariableByNameRequest struct {
|
||||
Name string `validate:"required"`
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
)
|
||||
|
||||
func NewGrpcClientWithHost(host string) (*client.Client, error) {
|
||||
cli, err := client.Default()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cli.Upgrade([]string{host})
|
||||
return cli, nil
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"ispctl/model"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
epb "google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const (
|
||||
getAvailableConfigs = "config/module/get_modules_info"
|
||||
getConfigByModuleName = "config/config/get_active_config_by_module_name"
|
||||
createUpdateConfig = "config/config/create_update_config"
|
||||
getSchemaByModuleId = "config/schema/get_by_module_id"
|
||||
|
||||
getAllVariables = "config/variable/all"
|
||||
getVariableByName = "config/variable/get_by_name"
|
||||
upsertVariable = "config/variable/upsert"
|
||||
deleteVariable = "config/variable/delete"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
cli *client.Client
|
||||
baseCtx context.Context
|
||||
}
|
||||
|
||||
func NewConfig(cli *client.Client) Config {
|
||||
return Config{
|
||||
cli: cli,
|
||||
baseCtx: context.Background(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c Config) GetAvailableConfigs() ([]model.ModuleInfo, error) {
|
||||
response := make([]model.ModuleInfo, 0)
|
||||
err := c.cli.Invoke(getAvailableConfigs).
|
||||
JsonResponseBody(&response).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getAvailableConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c Config) GetConfigByModuleName(name string) (*model.Config, error) {
|
||||
request := &model.GetModuleByUuidAndNameRequest{ModuleName: name}
|
||||
response := new(model.Config)
|
||||
err := c.cli.Invoke(getConfigByModuleName).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
switch {
|
||||
case status.Code(err) == codes.NotFound:
|
||||
return nil, model.ErrModuleNotFound
|
||||
case err != nil:
|
||||
return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName)
|
||||
default:
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c Config) CreateUpdateConfig(request model.Config) (*model.Config, error) {
|
||||
response := new(model.Config)
|
||||
err := c.cli.Invoke(createUpdateConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
if err != nil {
|
||||
return nil, c.handleCreateUpdateConfigError(err)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c Config) GetSchemaByModuleId(moduleId string) (*model.ConfigSchema, error) {
|
||||
request := model.GetSchemaByModuleIdRequest{ModuleId: moduleId}
|
||||
response := new(model.ConfigSchema)
|
||||
err := c.cli.Invoke(getSchemaByModuleId).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getSchemaByModuleId)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c Config) GetAllVariables() ([]model.Variable, error) {
|
||||
response := make([]model.Variable, 0)
|
||||
err := c.cli.Invoke(getAllVariables).
|
||||
JsonResponseBody(&response).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getAllVariables)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c Config) GetVariableByName(variableName string) (*model.Variable, error) {
|
||||
request := model.VariableByNameRequest{Name: variableName}
|
||||
response := new(model.Variable)
|
||||
err := c.cli.Invoke(getVariableByName).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
if err != nil {
|
||||
return nil, c.handleVariableError(err, getVariableByName)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c Config) UpsertVariables(request []model.UpsertVariableRequest) error {
|
||||
err := c.cli.Invoke(upsertVariable).
|
||||
JsonRequestBody(request).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "call %s", upsertVariable)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) DeleteVariable(variableName string) error {
|
||||
request := model.VariableByNameRequest{Name: variableName}
|
||||
err := c.cli.Invoke(deleteVariable).
|
||||
JsonRequestBody(request).
|
||||
Timeout(time.Second).
|
||||
Do(c.baseCtx)
|
||||
if err != nil {
|
||||
return c.handleVariableError(err, deleteVariable)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) handleVariableError(err error, endpoint string) error {
|
||||
apiError := apierrors.FromError(err)
|
||||
if apiError == nil {
|
||||
return errors.WithMessagef(err, "call %s", endpoint)
|
||||
}
|
||||
switch apiError.ErrorCode {
|
||||
case model.ErrCodeVariableNotFound:
|
||||
return model.ErrVariableNotFound
|
||||
default:
|
||||
return errors.WithMessagef(err, "call %s", endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
func (c Config) handleCreateUpdateConfigError(err error) error {
|
||||
errorStatus, ok := status.FromError(err)
|
||||
if !ok || errorStatus.Code() != codes.InvalidArgument {
|
||||
return errors.WithMessagef(err, "call %s", createUpdateConfig)
|
||||
}
|
||||
|
||||
stringBuilder := strings.Builder{}
|
||||
stringBuilder.WriteString("doesn't match with schema:\n")
|
||||
|
||||
apiErr := apierrors.FromError(err)
|
||||
if apiErr != nil {
|
||||
for field, desc := range apiErr.Details {
|
||||
stringBuilder.WriteString(fmt.Sprintf("%s | %s\n", field, desc))
|
||||
}
|
||||
} else {
|
||||
for _, detail := range errorStatus.Details() {
|
||||
switch d := detail.(type) {
|
||||
case *epb.BadRequest:
|
||||
for _, violation := range d.FieldViolations {
|
||||
stringBuilder.WriteString(fmt.Sprintf("%s | %s\n", violation.Field, violation.Description))
|
||||
}
|
||||
default:
|
||||
stringBuilder.WriteString(fmt.Sprint(d))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors.New(stringBuilder.String())
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package service
|
||||
|
||||
import "ispctl/cfg"
|
||||
|
||||
var (
|
||||
ConfigClient = cfg.NewConfigClient()
|
||||
)
|
||||
+57
-216
@@ -2,61 +2,57 @@ package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"ispctl/model"
|
||||
"ispctl/repository"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/rc/schema"
|
||||
epb "google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"ispctl/cfg"
|
||||
)
|
||||
|
||||
var Config configService
|
||||
|
||||
type configService struct {
|
||||
UnsafeEnable bool
|
||||
type Config struct {
|
||||
enableUnsafe bool
|
||||
configRepo repository.Config
|
||||
}
|
||||
|
||||
func (c configService) ReceiveConfiguration(host string) error {
|
||||
return ConfigClient.ReceiveConfig(host)
|
||||
func NewConfig(enableUnsafe bool, configRepo repository.Config) Config {
|
||||
return Config{
|
||||
enableUnsafe: enableUnsafe,
|
||||
configRepo: configRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
|
||||
return ConfigClient.GetAvailableConfigs()
|
||||
func (c Config) GetAvailableConfigs() ([]model.ModuleInfo, error) {
|
||||
return c.configRepo.GetAvailableConfigs()
|
||||
}
|
||||
|
||||
func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Config, error) {
|
||||
func (c Config) GetConfigurationByModuleName(moduleName string) (*model.Config, error) {
|
||||
if moduleName == "" {
|
||||
return nil, errors.New("need module name")
|
||||
}
|
||||
|
||||
if moduleConfiguration, err := ConfigClient.GetConfigByModuleName(moduleName); err != nil {
|
||||
if errorStatus, ok := status.FromError(err); ok {
|
||||
switch errorStatus.Code() {
|
||||
case codes.NotFound:
|
||||
return nil, errors.Errorf("module [%s] not found", moduleName)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
return moduleConfiguration, nil
|
||||
moduleConfiguration, err := c.configRepo.GetConfigByModuleName(moduleName)
|
||||
switch {
|
||||
case errors.Is(err, model.ErrModuleNotFound):
|
||||
return nil, errors.Errorf("module [%s] not found", moduleName)
|
||||
default:
|
||||
return moduleConfiguration, err
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) GetSchemaByModuleId(moduleId string) (schema.Schema, error) {
|
||||
if configSchema, err := ConfigClient.GetSchemaByModuleId(moduleId); err != nil {
|
||||
func (c Config) GetSchemaByModuleId(moduleId string) (schema.Schema, error) {
|
||||
configSchema, err := c.configRepo.GetSchemaByModuleId(moduleId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return configSchema.Schema, nil
|
||||
}
|
||||
return configSchema.Schema, nil
|
||||
}
|
||||
|
||||
func (c configService) CreateUpdateConfig(stringToChange string, configuration *cfg.Config) (map[string]interface{}, error) {
|
||||
newData := make(map[string]interface{})
|
||||
func (c Config) CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error) {
|
||||
newData := make(map[string]any)
|
||||
if stringToChange != "" {
|
||||
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
|
||||
err := json.Unmarshal([]byte(stringToChange), &newData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -65,204 +61,49 @@ func (c configService) CreateUpdateConfig(stringToChange string, configuration *
|
||||
return c.CreateUpdateConfigV2(configuration)
|
||||
}
|
||||
|
||||
func (c configService) CreateUpdateConfigV2(configuration *cfg.Config) (map[string]interface{}, error) {
|
||||
configuration.Unsafe = c.UnsafeEnable
|
||||
if resp, err := ConfigClient.CreateUpdateConfig(*configuration); err != nil {
|
||||
if errorStatus, ok := status.FromError(err); ok {
|
||||
switch errorStatus.Code() {
|
||||
case codes.InvalidArgument:
|
||||
fmt.Print("doesn't match with schema:\n")
|
||||
defer func() {
|
||||
os.Exit(1)
|
||||
}()
|
||||
for _, value := range errorStatus.Details() {
|
||||
if a, ok := value.(*epb.BadRequest); ok {
|
||||
for _, value := range a.FieldViolations {
|
||||
fmt.Printf("%s | %s\n", value.Field, value.Description)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(value)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
return resp.Data, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) UpdateConfigAndGetLinkCommon(configuration cfg.Config) ([]string, error) {
|
||||
if resp, err := ConfigClient.CreateUpdateConfig(configuration); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return resp.CommonConfigs, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) GetCommonConfigByName(configName string) (cfg.CommonConfig, error) {
|
||||
if commonConfigs, err := c.GetMapNameCommonConfig(); err != nil {
|
||||
return cfg.CommonConfig{}, err
|
||||
} else if config, ok := commonConfigs[configName]; !ok {
|
||||
return cfg.CommonConfig{}, errors.Errorf("common config [%s] not found", configName)
|
||||
} else {
|
||||
return config, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) GetMapNameCommonConfig() (map[string]cfg.CommonConfig, error) {
|
||||
collection, err := ConfigClient.GetCommonConfigs([]string{})
|
||||
func (c Config) CreateUpdateConfigV2(configuration *model.Config) (map[string]any, error) {
|
||||
configuration.Unsafe = c.enableUnsafe
|
||||
resp, err := c.configRepo.CreateUpdateConfig(*configuration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response := make(map[string]cfg.CommonConfig)
|
||||
for _, config := range collection {
|
||||
response[config.Name] = config
|
||||
}
|
||||
return response, nil
|
||||
return resp.Data, nil
|
||||
}
|
||||
|
||||
func (c configService) CreateUpdateCommonConfig(stringToChange string, config cfg.CommonConfig) (map[string]interface{}, error) {
|
||||
newData := make(map[string]interface{})
|
||||
if stringToChange != "" {
|
||||
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func (c Config) GetAllVariables() ([]model.Variable, error) {
|
||||
return c.configRepo.GetAllVariables()
|
||||
}
|
||||
|
||||
func (c Config) GetVariableByName(variableName string) (*model.Variable, error) {
|
||||
if variableName == "" {
|
||||
return nil, errors.New("need variable name")
|
||||
}
|
||||
|
||||
config.Data = newData
|
||||
if resp, err := ConfigClient.CreateUpdateCommonConfig(config); err != nil {
|
||||
variable, err := c.configRepo.GetVariableByName(variableName)
|
||||
switch {
|
||||
case errors.Is(err, model.ErrVariableNotFound):
|
||||
return nil, errors.Errorf("variable [%s] not found", variableName)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
} else {
|
||||
return resp.Data, nil
|
||||
default:
|
||||
return variable, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) DeleteCommonConfig(configId string) ([]string, bool, error) {
|
||||
deletedInfo, err := ConfigClient.DeleteCommonConfig(configId)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
arrayOfModuleName := make([]string, 0)
|
||||
for moduleName := range deletedInfo.Links {
|
||||
arrayOfModuleName = append(arrayOfModuleName, moduleName)
|
||||
}
|
||||
return arrayOfModuleName, deletedInfo.Deleted, nil
|
||||
}
|
||||
|
||||
func (c configService) GetLinksCommonConfig(configId string) ([]string, error) {
|
||||
link, err := ConfigClient.GetLinksCommonConfig(configId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arrayOfModuleName := make([]string, 0)
|
||||
for moduleName := range *link {
|
||||
arrayOfModuleName = append(arrayOfModuleName, moduleName)
|
||||
}
|
||||
return arrayOfModuleName, nil
|
||||
}
|
||||
|
||||
func (c configService) CompileDataWithCommonConfigs(
|
||||
data map[string]interface{}, commonConfigs []string) (map[string]interface{}, error) {
|
||||
|
||||
req := cfg.CompileConfigs{
|
||||
Data: data,
|
||||
CommonConfigsIdList: commonConfigs,
|
||||
}
|
||||
var err error
|
||||
data, err = ConfigClient.CompileCommonConfigs(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) UnlinkCommonConfigFromModule(configName, moduleName string) error {
|
||||
return c.linked(configName, moduleName,
|
||||
func(configId string, configIdentities []string) (bool, []string) {
|
||||
needUnlink := false
|
||||
for i, id := range configIdentities {
|
||||
if configId == id {
|
||||
copy(configIdentities[i:], configIdentities[i+1:])
|
||||
configIdentities[len(configIdentities)-1] = ""
|
||||
configIdentities = configIdentities[:len(configIdentities)-1]
|
||||
needUnlink = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return needUnlink, configIdentities
|
||||
})
|
||||
}
|
||||
|
||||
func (c configService) LinkCommonConfigToModule(configName, moduleName string) error {
|
||||
return c.linked(configName, moduleName,
|
||||
func(configId string, configIdentities []string) (bool, []string) {
|
||||
needLink := true
|
||||
for _, id := range configIdentities {
|
||||
if configId == id {
|
||||
needLink = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if needLink {
|
||||
configIdentities = append(configIdentities, configId)
|
||||
}
|
||||
return needLink, configIdentities
|
||||
})
|
||||
}
|
||||
|
||||
func (c configService) linked(configName, moduleName string,
|
||||
linkHandler func(configId string, configIdentities []string) (bool, []string)) error {
|
||||
|
||||
if configName == "" {
|
||||
return errors.New("empty config name")
|
||||
func (c Config) DeleteVariable(variableName string) error {
|
||||
if variableName == "" {
|
||||
return errors.New("need variable name")
|
||||
}
|
||||
|
||||
if moduleName == "" {
|
||||
return errors.New("empty module name")
|
||||
}
|
||||
|
||||
commonConfigs, err := c.GetMapNameCommonConfig()
|
||||
if err != nil {
|
||||
err := c.configRepo.DeleteVariable(variableName)
|
||||
switch {
|
||||
case errors.Is(err, model.ErrVariableNotFound):
|
||||
return errors.Errorf("variable [%s] not found", variableName)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
config, ok := commonConfigs[configName]
|
||||
if !ok {
|
||||
return errors.Errorf("common config [%s] not found", configName)
|
||||
}
|
||||
|
||||
moduleConfig, err := c.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configIdConfigNameMap := make(map[string]string)
|
||||
for name, value := range commonConfigs {
|
||||
configIdConfigNameMap[value.Id] = name
|
||||
}
|
||||
|
||||
needUpdate, newCommonConfigs := linkHandler(config.Id, moduleConfig.CommonConfigs)
|
||||
|
||||
if needUpdate {
|
||||
moduleConfig.CommonConfigs = newCommonConfigs
|
||||
if linked, err := c.UpdateConfigAndGetLinkCommon(*moduleConfig); err != nil {
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("module [%s] have next link:\n", moduleName)
|
||||
for _, name := range linked {
|
||||
fmt.Printf("[%s] ", configIdConfigNameMap[name])
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("module [%s] have next link:\n", moduleName)
|
||||
for _, name := range moduleConfig.CommonConfigs {
|
||||
fmt.Printf("[%s] ", configIdConfigNameMap[name])
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
return nil
|
||||
func (c Config) UpsertVariables(vars []model.UpsertVariableRequest) error {
|
||||
return c.configRepo.UpsertVariables(vars)
|
||||
}
|
||||
Reference in new issue
Block a user