6 Commits
42 changed files with 1265 additions and 1443 deletions

No files matched your search

+3 -22
View File
@@ -1,23 +1,4 @@
docker-build: include:
image: docker:latest - project: '$CI_PROJECT_PATH'
stage: build file: '/ci-isp-utils.yml'
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
+1 -1
View File
@@ -1 +1 @@
3.2.1 3.3.1
+6
View File
@@ -1,3 +1,9 @@
### v3.3.1
* увеличены таймауты обращения к `isp-config-service`
### v3.3.0
* Добавлены команды `vars get`, `vars list`, `vars set`, `vars delete`, `vars upload`
* Обновлены зависимости
* Обновлена версия Go до `1.24`
### v3.2.1 ### v3.2.1
* обновлены зависимости * обновлены зависимости
### v3.2.0 ### v3.2.0
+2 -2
View File
@@ -1,4 +1,4 @@
FROM golang:1.23-alpine3.20 as builder FROM golang:1.24-alpine3.21 as builder
WORKDIR /build WORKDIR /build
ARG version ARG version
ENV version_env=$version ENV version_env=$version
@@ -13,7 +13,7 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \ --mount=type=bind,target=. \
go build -ldflags="-X 'main.version=$version_env'" -o /main . 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 apk add --no-cache tzdata bash-completion jq
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
+1 -1
View File
@@ -1,5 +1,5 @@
FROM dockerhub.mos.ru/mosos/arbat:15.5 as builder 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 WORKDIR /build
ARG version ARG version
ENV version_env=$version ENV version_env=$version
+164 -45
View File
@@ -15,7 +15,12 @@
- [ispctl schema](#ispctl-schema) - [ispctl schema](#ispctl-schema)
- [ispctl merge](#ispctl-merge) - [ispctl merge](#ispctl-merge)
- [ispctl gitget](#ispctl-gitget) - [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 * 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...] set module_name property_path [new_object]
ispctl [flag...] delete module_name property_path ispctl [flag...] delete module_name property_path
ispctl [flag...] schema module_name [local_flag] 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` | возвращает доступные конфигурации модулей, их состояния и подключения | | `status` | возвращает доступные конфигурации модулей, их состояния и подключения |
| `get` | возвращает объект конфигурации указанного модуля | | `get` | возвращает объект конфигурации указанного модуля |
| `set` | изменяет объект конфигурации указанного модуля | | `set` | изменяет объект конфигурации указанного модуля |
| `delete` | удаляет объект конфигурации указанного модуля | | `delete` | удаляет объект конфигурации указанного модуля |
| `merge` | поблочно производит слияние конфигурации модуля с json конфигом через stdin | | `merge` | поблочно производит слияние конфигурации модуля с json конфигом через stdin |
| `gitget` | скачивает из репозитория указанный файлы с указанного комита | | `gitget` | скачивает из репозитория указанный файлы с указанного комита |
| `schema` | возвращает схему конфигурации указанного модуля | | `schema` | возвращает схему конфигурации указанного модуля |
| | | | `vars get` | выводит информацию о переменной в json формате |
| `vars list` | выводит список переменных в виде ASCII-таблицы |
| `vars set` | изменяет значение переменной |
| `vars delete` | удаляет переменную по имени |
| `vars upload` | загружает переменные из csv файла |
| | |
| Флаги | Параметры | Описание | | Флаги | Параметры | Описание |
|-------------|-----------|--------------------------------------------------------| | --------- | --------- | ------------------------------------------------------ |
| `-g` | string | адрес isp-config-service | | `-g` | string | адрес isp-config-service |
| `-unsafe` | | отключает проверку схемы перед изменением конфигурации | | `-unsafe` | | отключает проверку схемы перед изменением конфигурации |
| | | | | | | |
| Аргументы | Описание | | Аргументы | Описание |
|-----------------|-------------------------------------------------------------------------------------------------------------| | ----------------- | ------------------------------------------------------------------------------------------------------ |
| `module_name` | Название модуля с которым происходит взаимодействие | | `module_name` | Название модуля с которым происходит взаимодействие |
| `property_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля | | `property_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля |
| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin | | `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin |
| | | | `variable_name` | Название переменной с которой происходит взаимодействие |
| `variable_value` | Значение переменной |
| `csv_filepath` | Путь к csv файлу с переменными для загрузки |
| | |
| Локальные флаги | Параметры | Команды | Описание | | Локальные флаги | Параметры | Команды | Описание |
|-----------------|-----------|---------|---------------------------------------------------------------------------------------------------------------------------------| | --------------- | --------- | -------- |------------------------------------------------------------------------------------------------------------------------------- |
| `-o` | string | schema | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` | | `-o` | string | schema | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
| `-full` | bool | get | осуществляет взаимодействие с объектами конфигурации модуля с учетом объектом общих конфигураций, которые имеют связь с модулем | | `-full` | bool | get | осуществляет взаимодействие с объектами конфигурации модуля с учетом объектом общих конфигураций, которые имеют связь с модулем |
| | | | | | `-secret` | bool | vars set | устанавливает тип переменной в SECRET |
| | | | |
## Пример ## Пример
### ispctl status ### ispctl status
`ispctl [flag...] status [local_flag]` `ispctl [flag...] status [local_flag]`
@@ -353,14 +373,14 @@ ispctl merge example < example.json
Результат в конфигурации модуля Результат в конфигурации модуля
```json ```json
{ {
"metrics": { "metrics": {
"gc": 1, "gc": 1,
"memory": false "memory": false
}, },
"property": "replaced", "property": "replaced",
"database": { "database": {
"host": "127.0.0.1" "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 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 ```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}}' 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 ```json
{ {
"metrics": { "metrics": {
"address": { "address": {
"ip": "127.0.0.1", "ip": "127.0.0.1",
"newField": "100", "newField": "100",
"port": 1 "port": 1
}, },
"gc": 1, "gc": 1,
"memory": false "memory": false
} }
} }
``` ```
1
+2 -2
View File
@@ -16,9 +16,9 @@ for status in $statusResponse; do
read -ra ADDR <<<"$status" read -ra ADDR <<<"$status"
for module_name in "${ADDR[0]}"; do for module_name in "${ADDR[0]}"; do
if [ -n "$*" ]; then if [ -n "$*" ]; then
ispctl $* schema $module_name -o html > schemas/$module_name.html ispctl $* schema -o html $module_name > schemas/$module_name.html
else else
ispctl schema $module_name -o html > schemas/$module_name.html ispctl schema -o html $module_name > schemas/$module_name.html
fi fi
break break
done done
+84 -61
View File
@@ -2,83 +2,106 @@ package bash
import ( import (
"fmt" "fmt"
"ispctl/model"
"ispctl/service"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"github.com/txix-open/bellows" "github.com/txix-open/bellows"
"ispctl/flag"
"ispctl/service"
) )
const ( const (
CommonConfigName bashArg = "config_name" CommonConfigName = "config_name"
CommonConfigData bashArg = "config_data" ModuleName = "module_name"
ModuleName bashArg = "module_name" ModuleData = "module_data"
ModuleData bashArg = "module_data"
Empty bashArg = "empty" VariableName = "variable_name"
Empty = "empty"
) )
type bashArg string type BashService interface {
GetAllVariables() ([]model.Variable, error)
type bashCommand struct { GetAvailableConfigs() ([]model.ModuleInfo, error)
first bashArg GetConfigurationByModuleName(moduleName string) (*model.Config, error)
second bashArg
} }
func Get(first bashArg, second bashArg) *bashCommand { type BeforeComplete func(ctx *cli.Context) (service.Config, error)
return &bashCommand{
first: first, type Autocomplete struct {
second: second, beforeComplete BeforeComplete
service BashService
}
func NewAutocomplete(beforeComplete BeforeComplete) Autocomplete {
return Autocomplete{
beforeComplete: beforeComplete,
} }
} }
func (c bashCommand) Complete(ctx *cli.Context) { func (c Autocomplete) Complete(first string, second string) cli.BashCompleteFunc {
if err := flag.CheckGlobal(ctx); err != nil { return func(ctx *cli.Context) {
return 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 { if err != nil {
return return
} }
switch ctx.NArg() { for _, v := range vars {
case 0: fmt.Println(v.Name)
switch c.first { }
case ModuleName: }
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
return func (c Autocomplete) printAvailableModules() {
} else { modules, err := c.service.GetAvailableConfigs()
for _, module := range arrayOfModules { if err != nil {
fmt.Println(module.Name) return
} }
} for _, module := range modules {
case CommonConfigName: fmt.Println(module.Name)
for _, config := range commonConfigs { }
fmt.Println(config.Name) }
}
} func (c Autocomplete) printModuleData(moduleName string) {
case 1: config, err := c.service.GetConfigurationByModuleName(moduleName)
switch c.second { if err != nil {
case CommonConfigData: return
if config, ok := commonConfigs[ctx.Args().First()]; ok { }
for key, _ := range bellows.Flatten(config.Data) { for key := range bellows.Flatten(config.Data) {
fmt.Printf(".%v\n", key) 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)
}
}
}
} }
} }
-13
View File
@@ -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
View File
@@ -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)
}
+61
View File
@@ -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
}
-47
View File
@@ -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)
}
}
-53
View File
@@ -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
}
-63
View File
@@ -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)
}
}
}
-68
View File
@@ -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
}
-35
View File
@@ -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
}
-53
View File
@@ -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
}
-78
View File
@@ -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)
}
}
}
-35
View File
@@ -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
View File
@@ -3,35 +3,45 @@ package command
import ( import (
"encoding/json" "encoding/json"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"ispctl/bash" "ispctl/bash"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/flag" "ispctl/model"
"ispctl/service"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
) )
func Delete() *cli.Command { type DeleteService interface {
return &cli.Command{ GetConfigurationByModuleName(moduleName string) (*model.Config, error)
Name: "delete", CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
Usage: "delete configuration by module_name", }
Action: deleteComm.action,
BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, type Delete struct {
service DeleteService
autoComplete AutoComplete
}
func NewDelete(service DeleteService, autoComplete AutoComplete) Delete {
return Delete{
service: service,
autoComplete: autoComplete,
} }
} }
var deleteComm deleteCommand func (c Delete) Command() *cli.Command {
return &cli.Command{
type deleteCommand struct{} Name: "delete",
Usage: "delete configuration by module_name",
func (d deleteCommand) action(ctx *cli.Context) error { Action: c.action,
if err := flag.CheckGlobal(ctx); err != nil { BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.ModuleData),
return err
} }
}
func (c Delete) action(ctx *cli.Context) error {
moduleName := ctx.Args().First() moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1) pathObject := ctx.Args().Get(1)
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName) moduleConfiguration, err := c.service.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
return err return err
} }
@@ -40,19 +50,18 @@ func (d deleteCommand) action(ctx *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
if pathObject == "" { if pathObject == "" {
return utils.CreateUpdateConfig("", moduleConfiguration) return CreateUpdateConfig("", moduleConfiguration, c.service)
} 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)
}
} }
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)
} }
+23
View File
@@ -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
View File
@@ -3,47 +3,48 @@ package command
import ( import (
"encoding/json" "encoding/json"
"github.com/urfave/cli/v2"
"ispctl/bash" "ispctl/bash"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/flag" "ispctl/model"
"ispctl/service"
"github.com/urfave/cli/v2"
) )
func Get() *cli.Command { type GetService interface {
return &cli.Command{ GetConfigurationByModuleName(moduleName string) (*model.Config, error)
Name: "get", }
Usage: "get configuration by module_name",
Action: get.action, type Get struct {
BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, service SetService
Flags: []cli.Flag{ autoComplete AutoComplete
flag.WithCommonConfig, }
},
func NewGet(service SetService, autoComplete AutoComplete) Get {
return Get{
service: service,
autoComplete: autoComplete,
} }
} }
var get getCommand func (c Get) Command() *cli.Command {
return &cli.Command{
type getCommand struct{} Name: "get",
Usage: "get configuration by module_name",
func (g getCommand) action(ctx *cli.Context) error { Action: c.action,
if err := flag.CheckGlobal(ctx); err != nil { BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.ModuleData),
return err
} }
}
func (c Get) action(ctx *cli.Context) error {
moduleName := ctx.Args().First() moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1) pathObject := ctx.Args().Get(1)
config, err := service.Config.GetConfigurationByModuleName(moduleName) config, err := c.service.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
return err return err
} }
data := config.Data 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) pathObject, err = utils.CheckPath(pathObject)
if err != nil { if err != nil {
@@ -51,13 +52,12 @@ func (g getCommand) action(ctx *cli.Context) error {
} }
if pathObject == "" { if pathObject == "" {
utils.PrintAnswer(data) return utils.PrintAnswer(data)
} else {
jsonObject, err := json.Marshal(data)
if err != nil {
return err
}
utils.CheckObject(jsonObject, pathObject)
} }
return nil
jsonObject, err := json.Marshal(data)
if err != nil {
return err
}
return utils.CheckObject(jsonObject, pathObject)
} }
+55 -47
View File
@@ -13,57 +13,65 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var ( type GitGet struct {
semverRegexp = regexp.MustCompile("v([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$") 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{ return &cli.Command{
Name: "gitget", Name: "gitget",
Usage: "gitget [repository] [file] (commit|tag)", Usage: "gitget [repository] [file] (commit|tag)",
Description: "clone and print specified file from specified repository and specified commit hash or tag", Description: "clone and print specified file from specified repository and specified commit hash or tag",
Action: func(context *cli.Context) error { Action: c.action,
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
},
} }
} }
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
View File
@@ -4,46 +4,60 @@ import (
"encoding/json" "encoding/json"
"os" "os"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"ispctl/bash" "ispctl/bash"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/flag" "ispctl/model"
"ispctl/service"
"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{ return &cli.Command{
Name: "merge", Name: "merge",
Usage: "merge actual config with config from stdin", Usage: "merge actual config with config from stdin",
BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete, BashComplete: c.autoComplete.Complete(bash.CommonConfigName, bash.Empty),
Action: func(context *cli.Context) error { Action: c.action,
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
},
} }
} }
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
View File
@@ -4,73 +4,81 @@ import (
"html/template" "html/template"
"os" "os"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"ispctl/bash" "ispctl/bash"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/flag" "ispctl/model"
"ispctl/service"
"ispctl/tmpl" "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{ return &cli.Command{
Name: "schema", Name: "schema",
Usage: "get schema configuration by module_name", Usage: "get schema configuration by module_name",
Action: schema.action, Action: c.action,
Flags: []cli.Flag{ 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 func (c Schema) action(ctx *cli.Context) error {
moduleName := ctx.Args().First()
type schemaCommand struct{} schemaConfig, err := c.getSchemaConfig(moduleName)
if err != nil {
func (s schemaCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
return err return err
} }
moduleName := ctx.Args().First()
if schemaConfig := s.getSchemaConfig(moduleName); schemaConfig != nil { schema := make(map[string]any)
schema := make(map[string]interface{}) schema["title"] = moduleName
schema["title"] = moduleName schema["schema"] = schemaConfig
schema["schema"] = schemaConfig switch ctx.String(OutPrintFlagName) {
switch ctx.String(flag.OutPrintSchema.Name) { case OutPrintJsonValue:
case flag.OutPrintJsonValue: return utils.PrintAnswer(schema)
utils.PrintAnswer(schema) case OutPrintHtmlValue:
case flag.OutPrintHtmlValue: return c.printHtml(schema)
s.printHtml(schema) default:
default: return errors.Errorf("invalid flag value, expected [%s] or [%s]", OutPrintJsonValue, OutPrintHtmlValue)
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
} }
} }
func (s schemaCommand) printHtml(schema map[string]interface{}) { func (c Schema) getSchemaConfig(moduleName string) (schema.Schema, error) {
if temp, err := template.New("template").Parse(tmpl.HtmlFile); err != nil { configuration, err := c.service.GetConfigurationByModuleName(moduleName)
utils.PrintError(err) if err != nil {
return return nil, err
} else {
if err := temp.ExecuteTemplate(os.Stdout, "template", schema); err != nil {
utils.PrintError(err)
return
}
} }
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
View File
@@ -3,37 +3,46 @@ package command
import ( import (
"encoding/json" "encoding/json"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"ispctl/bash" "ispctl/bash"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/flag" "ispctl/model"
"ispctl/service"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
) )
func Set() *cli.Command { type SetService interface {
return &cli.Command{ GetConfigurationByModuleName(moduleName string) (*model.Config, error)
Name: "set", CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
Usage: "set configuration by module_name", }
Action: set.action,
BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, type Set struct {
service SetService
autoComplete AutoComplete
}
func NewSet(service SetService, autoComplete AutoComplete) Set {
return Set{
service: service,
autoComplete: autoComplete,
} }
} }
var set setCommand func (c Set) Command() *cli.Command {
return &cli.Command{
type setCommand struct{} Name: "set",
Usage: "set configuration by module_name",
func (s setCommand) action(ctx *cli.Context) error { Action: c.action,
if err := flag.CheckGlobal(ctx); err != nil { BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.ModuleData),
return err
} }
}
func (c Set) action(ctx *cli.Context) error {
moduleName := ctx.Args().First() moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1) pathObject := ctx.Args().Get(1)
changeObject := ctx.Args().Get(2) changeObject := ctx.Args().Get(2)
config, err := service.Config.GetConfigurationByModuleName(moduleName) config, err := c.service.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
return err return err
} }
@@ -49,18 +58,17 @@ func (s setCommand) action(ctx *cli.Context) error {
} }
if pathObject == "" { if pathObject == "" {
return utils.CreateUpdateConfig(changeObject, config) return CreateUpdateConfig(changeObject, config, c.service)
} 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)
}
} }
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
View File
@@ -5,11 +5,11 @@ import (
"os" "os"
"strings" "strings"
"ispctl/command/utils"
"ispctl/model"
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
) )
const ( const (
@@ -21,50 +21,55 @@ const (
tableConnectedStatus = "CONNECTED" 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{ return &cli.Command{
Name: "status", Name: "status",
Usage: "get available configs", Usage: "get available configs",
Action: status.action, Action: c.action,
Flags: []cli.Flag{ Flags: []cli.Flag{
flag.OutPrintStatus, &cli.StringFlag{Name: OutPrintFlagName, Usage: outPrintStatusUsage},
}, },
} }
} }
var status statusCommand func (c Status) action(ctx *cli.Context) error {
arrayOfModules, err := c.service.GetAvailableConfigs()
type statusCommand struct{} if err != nil {
func (statusCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
return err return err
} }
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil { switch ctx.String(OutPrintFlagName) {
return err case OutPrintJsonValue:
} else { return utils.PrintAnswer(arrayOfModules)
switch ctx.String(flag.OutPrintStatus.Name) { default:
case flag.OutPrintJsonValue: table := tablewriter.NewWriter(os.Stdout)
utils.PrintAnswer(arrayOfModules) table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
default: table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses})
table := tablewriter.NewWriter(os.Stdout) for _, module := range arrayOfModules {
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false}) addresses := ""
table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses}) connection := tableNotConnectedStatus
for _, module := range arrayOfModules { instanceList := make([]string, 0, len(module.Status))
addresses := "" for _, value := range module.Status {
connection := tableNotConnectedStatus instanceList = append(instanceList, fmt.Sprintf("%s:%s %s", value.Address.IP, value.Address.Port, value.Version))
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})
} }
table.Render() addresses = strings.Join(instanceList, "\n")
if addresses != "" {
connection = tableConnectedStatus
}
table.Append([]string{module.Name, connection, addresses})
} }
table.Render()
} }
return nil return nil
} }
+17 -26
View File
@@ -2,7 +2,7 @@ package utils
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"strings" "strings"
@@ -22,7 +22,7 @@ func CheckPath(pathObject string) (string, error) {
continue continue
} }
if key == 1 { if key == 1 {
pathObject = fmt.Sprintf("%s", value) pathObject = value
continue continue
} }
pathObject = fmt.Sprintf("%s.%s", pathObject, value) pathObject = fmt.Sprintf("%s.%s", pathObject, value)
@@ -32,7 +32,7 @@ func CheckPath(pathObject string) (string, error) {
func CheckChangeObject(changeObject string) (string, error) { func CheckChangeObject(changeObject string) (string, error) {
if changeObject == "" { if changeObject == "" {
bytes, err := ioutil.ReadAll(os.Stdin) bytes, err := io.ReadAll(os.Stdin)
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -40,26 +40,18 @@ func CheckChangeObject(changeObject string) (string, error) {
} }
if changeObject == "" { if changeObject == "" {
return "", errors.New("expected argument") 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 := json.NewEncoder(os.Stdout)
encoder.SetEscapeHTML(false) encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ") encoder.SetIndent("", " ")
if err := encoder.Encode(data); err != nil { return encoder.Encode(data)
PrintError(err)
}
} }
func PrintError(err error) { func ParseSetObject(argument string) any {
fmt.Println("ERROR:", err)
os.Exit(-1)
}
func ParseSetObject(argument string) interface{} {
tryParse := []byte(argument) tryParse := []byte(argument)
if tryParse[0] == '"' && tryParse[len(tryParse)-1] == '"' { if tryParse[0] == '"' && tryParse[len(tryParse)-1] == '"' {
tryParse = tryParse[1 : len(tryParse)-1] tryParse = tryParse[1 : len(tryParse)-1]
@@ -70,12 +62,12 @@ func ParseSetObject(argument string) interface{} {
return nil return nil
} }
mapStringInterface := make(map[string]interface{}) mapStringInterface := make(map[string]any)
if err := json.Unmarshal(tryParse, &mapStringInterface); err == nil { if err := json.Unmarshal(tryParse, &mapStringInterface); err == nil {
return mapStringInterface return mapStringInterface
} }
arrayOfObject := make([]interface{}, 0) arrayOfObject := make([]any, 0)
if err := json.Unmarshal(tryParse, &arrayOfObject); err == nil { if err := json.Unmarshal(tryParse, &arrayOfObject); err == nil {
return arrayOfObject return arrayOfObject
} }
@@ -98,16 +90,15 @@ func ParseSetObject(argument string) interface{} {
return argument return argument
} }
func CheckObject(jsonObject []byte, depth string) { func CheckObject(jsonObject []byte, depth string) error {
jsonString := gjson.GetBytes(jsonObject, depth) jsonString := gjson.GetBytes(jsonObject, depth)
if jsonString.Raw == "" { if jsonString.Raw == "" {
PrintError(errors.Errorf("path '%s' not found\n", depth)) return 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)
}
} }
var data any
err := json.Unmarshal([]byte(jsonString.Raw), &data)
if err != nil {
return err
}
return PrintAnswer(data)
} }
-15
View File
@@ -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
}
-15
View File
@@ -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
View File
@@ -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
}
-23
View File
@@ -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)
)
-36
View File
@@ -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)
}
+22 -21
View File
@@ -1,6 +1,6 @@
module ispctl module ispctl
go 1.23 go 1.24
require ( require (
github.com/go-git/go-billy/v5 v5.6.0 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/gjson v1.17.3
github.com/tidwall/sjson v1.2.5 github.com/tidwall/sjson v1.2.5
github.com/txix-open/bellows v1.2.0 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 github.com/urfave/cli/v2 v2.27.5
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422
google.golang.org/grpc v1.67.1 google.golang.org/grpc v1.69.4
) )
require ( require (
@@ -35,12 +35,12 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/uuid v1.6.0 // 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/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.11 // 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/mattn/go-runewidth v0.0.9 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // 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/skeema/knownhosts v1.2.2 // indirect
github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // 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/txix-open/jsonschema v1.2.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 // indirect
go.opentelemetry.io/otel/sdk v1.31.0 // indirect go.opentelemetry.io/otel/metric v1.33.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect go.opentelemetry.io/otel/sdk v1.33.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // 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/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.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/mod v0.17.0 // indirect
golang.org/x/net v0.30.0 // indirect golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.8.0 // indirect golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.26.0 // indirect golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // 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/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
google.golang.org/protobuf v1.35.1 // indirect google.golang.org/protobuf v1.36.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
+54 -48
View File
@@ -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/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 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= 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.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA= github.com/getsentry/sentry-go v0.31.1 h1:ELVc0h7gwyhnXHDouXkhqTFSO5oslsRDk0++eyE0KJ4=
github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0= 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 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= 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= 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/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 h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 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 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 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/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 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 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.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= 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 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= 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 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= 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/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 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= 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.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= 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 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 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= 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.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.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.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.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.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 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94=
github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= 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/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 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o= 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/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA=
github.com/txix-open/etp/v3 v3.2.0/go.mod h1:lgen0TJmiturgBhvlxH1/PQ7iLL/OebKbxPAQYkuKI0= github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
github.com/txix-open/isp-kit v1.39.0 h1:NBV2oJJefH/qt2pcPrqEmYccJedjPaVCwr6Z955C+pg= github.com/txix-open/isp-kit v1.44.0 h1:ao16vgZ/cdbO4sZWYXD4VcJQ+984IQvb/A80mEjU504=
github.com/txix-open/isp-kit v1.39.0/go.mod h1:R4vwujGjMXLQir8MDDCfsDQa0CWGuZBSMakt5qcybgM= 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 h1:B8TrdSsPhDvYv67oi/LVqf7/+PuqFlMsNwUzGeHfl1s=
github.com/txix-open/jsonschema v1.2.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00= github.com/txix-open/jsonschema v1.2.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 h1:Z0Sqf+U+Sc6hfIXtRCIZlbJprkCjwMFbS4ZbEPQ44To= github.com/txix-open/validator/v10 v10.0.0-20240401163703-e83541b40f99 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 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= 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= 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/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 h1:K0XaT3DwHAcV4nKLzcQvwAgSyisUghWoY20I7huthMk= go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0/go.mod h1:B5Ki776z/MBnVha1Nzwp5arlzBbE3+1jk+pGmaP5HME= go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0 h1:lUsI2TYsQw2r1IASwoROaCnjdj2cvC2+Jbxvk6nHnWU= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 h1:Vh5HayB/0HHfOQA7Ctx69E/Y/DcQSMPpKANYVMQ7fBA=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0/go.mod h1:2HpZxxQurfGxJlJDblybejHB6RX6pmExPNe517hREw4= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0/go.mod h1:cpgtDBaqD/6ok/UG0jT15/uKjAY8mRA53diogHBg3UI=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 h1:wpMfgF8E1rkrT1Z6meFh1NDtownE9Ii3n3X2GJYjsaU=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0/go.mod h1:wAy0T/dUbs468uOlkT31xjvqQgEVXv58BRFWEgn5v/0=
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk= go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ=
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0= go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= 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 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0 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.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.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.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= 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 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= 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= 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.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.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.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= 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-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.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.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 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-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-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/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.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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-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.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.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 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.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= 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.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.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/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.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.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.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= 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-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.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/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 h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= 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= 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-20250106144421-5f5ef82da422 h1:GVIKPyP/kLIyVOgOnTwFOrvQaQUzOzGMCxgFUOEmm24=
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38/go.mod h1:vuAjtvlwkDKF6L1GQ0SokiRLCGFfeBUXWr/aFFkHACc= 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-20241021214115-324edc3d5d38 h1:zciRKQ4kBpFgpfC5QQCVtnnNAcLIqweL7plyZRQHVpI= google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 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 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-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
+44 -13
View File
@@ -4,10 +4,14 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"strings"
"ispctl/bash"
"ispctl/command"
"ispctl/repository"
"ispctl/service"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"ispctl/command"
"ispctl/flag"
) )
var version = "1.1.0" var version = "1.1.0"
@@ -22,20 +26,33 @@ func initCommands() {
app.Version = version app.Version = version
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
flag.Host, &cli.StringFlag{
flag.Unsafe, 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.EnableBashCompletion = true
app.Commands = []*cli.Command{
command.Status(), var configService service.Config
command.Get(), var autoComplete bash.Autocomplete
command.Set(), app.Before = func(ctx *cli.Context) error {
command.Delete(), service, err := configServiceFromGlobalFlags(ctx)
command.Schema(), if err != nil {
command.CommonConfig(), return err
command.Merge(), }
command.GitGet(), configService = service
return nil
} }
autoComplete = bash.NewAutocomplete(configServiceFromGlobalFlags)
app.Commands = command.AllCommands(&configService, autoComplete)
app.BashComplete = func(context *cli.Context) { app.BashComplete = func(context *cli.Context) {
for _, appCommand := range app.Commands { for _, appCommand := range app.Commands {
fmt.Println(appCommand.Name) fmt.Println(appCommand.Name)
@@ -47,3 +64,17 @@ func initCommands() {
log.Fatal(err) 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
}
+5 -21
View File
@@ -1,4 +1,4 @@
package cfg package model
import ( import (
"time" "time"
@@ -7,12 +7,12 @@ import (
"github.com/txix-open/isp-kit/rc/schema" "github.com/txix-open/isp-kit/rc/schema"
) )
type getModuleByUuidAndNameRequest struct { type GetModuleByUuidAndNameRequest struct {
ModuleName string ModuleName string
Uuid string Uuid string
} }
type getSchemaByModuleIdRequest struct { type GetSchemaByModuleIdRequest struct {
ModuleId string ModuleId string
} }
@@ -24,7 +24,7 @@ type Config struct {
ModuleId string ModuleId string
Version int32 Version int32
Active bool Active bool
Data map[string]interface{} Data map[string]any
Unsafe bool Unsafe bool
} }
@@ -34,7 +34,7 @@ type CommonConfig struct {
Description string Description string
CreatedAt time.Time CreatedAt time.Time
UpdatedAt time.Time UpdatedAt time.Time
Data map[string]interface{} Data map[string]any
} }
type Connection struct { type Connection struct {
@@ -62,19 +62,3 @@ type ConfigSchema struct {
CreatedAt time.Time CreatedAt time.Time
UpdatedAt 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
}
+40
View File
@@ -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"`
}
+14
View File
@@ -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
}
+181
View File
@@ -0,0 +1,181 @@
package repository
import (
"context"
"fmt"
"ispctl/model"
"strings"
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).
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).
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).
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).
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).
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).
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).
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).
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())
}
-7
View File
@@ -1,7 +0,0 @@
package service
import "ispctl/cfg"
var (
ConfigClient = cfg.NewConfigClient()
)
+57 -216
View File
@@ -2,61 +2,57 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt"
"os" "ispctl/model"
"ispctl/repository"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/rc/schema" "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 Config struct {
enableUnsafe bool
type configService struct { configRepo repository.Config
UnsafeEnable bool
} }
func (c configService) ReceiveConfiguration(host string) error { func NewConfig(enableUnsafe bool, configRepo repository.Config) Config {
return ConfigClient.ReceiveConfig(host) return Config{
enableUnsafe: enableUnsafe,
configRepo: configRepo,
}
} }
func (c configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) { func (c Config) GetAvailableConfigs() ([]model.ModuleInfo, error) {
return ConfigClient.GetAvailableConfigs() return c.configRepo.GetAvailableConfigs()
} }
func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Config, error) { func (c Config) GetConfigurationByModuleName(moduleName string) (*model.Config, error) {
if moduleName == "" { if moduleName == "" {
return nil, errors.New("need module name") return nil, errors.New("need module name")
} }
if moduleConfiguration, err := ConfigClient.GetConfigByModuleName(moduleName); err != nil { moduleConfiguration, err := c.configRepo.GetConfigByModuleName(moduleName)
if errorStatus, ok := status.FromError(err); ok { switch {
switch errorStatus.Code() { case errors.Is(err, model.ErrModuleNotFound):
case codes.NotFound: return nil, errors.Errorf("module [%s] not found", moduleName)
return nil, errors.Errorf("module [%s] not found", moduleName) default:
} return moduleConfiguration, err
}
return nil, err
} else {
return moduleConfiguration, nil
} }
} }
func (c configService) GetSchemaByModuleId(moduleId string) (schema.Schema, error) { func (c Config) GetSchemaByModuleId(moduleId string) (schema.Schema, error) {
if configSchema, err := ConfigClient.GetSchemaByModuleId(moduleId); err != nil { configSchema, err := c.configRepo.GetSchemaByModuleId(moduleId)
if err != nil {
return nil, err 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) { func (c Config) CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error) {
newData := make(map[string]interface{}) newData := make(map[string]any)
if stringToChange != "" { if stringToChange != "" {
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil { err := json.Unmarshal([]byte(stringToChange), &newData)
if err != nil {
return nil, err return nil, err
} }
} }
@@ -65,204 +61,49 @@ func (c configService) CreateUpdateConfig(stringToChange string, configuration *
return c.CreateUpdateConfigV2(configuration) return c.CreateUpdateConfigV2(configuration)
} }
func (c configService) CreateUpdateConfigV2(configuration *cfg.Config) (map[string]interface{}, error) { func (c Config) CreateUpdateConfigV2(configuration *model.Config) (map[string]any, error) {
configuration.Unsafe = c.UnsafeEnable configuration.Unsafe = c.enableUnsafe
if resp, err := ConfigClient.CreateUpdateConfig(*configuration); err != nil { resp, err := c.configRepo.CreateUpdateConfig(*configuration)
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{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
response := make(map[string]cfg.CommonConfig) return resp.Data, nil
for _, config := range collection {
response[config.Name] = config
}
return response, nil
} }
func (c configService) CreateUpdateCommonConfig(stringToChange string, config cfg.CommonConfig) (map[string]interface{}, error) { func (c Config) GetAllVariables() ([]model.Variable, error) {
newData := make(map[string]interface{}) return c.configRepo.GetAllVariables()
if stringToChange != "" { }
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
return nil, err func (c Config) GetVariableByName(variableName string) (*model.Variable, error) {
} if variableName == "" {
return nil, errors.New("need variable name")
} }
config.Data = newData variable, err := c.configRepo.GetVariableByName(variableName)
if resp, err := ConfigClient.CreateUpdateCommonConfig(config); err != nil { switch {
case errors.Is(err, model.ErrVariableNotFound):
return nil, errors.Errorf("variable [%s] not found", variableName)
case err != nil:
return nil, err return nil, err
} else { default:
return resp.Data, nil return variable, nil
} }
} }
func (c configService) DeleteCommonConfig(configId string) ([]string, bool, error) { func (c Config) DeleteVariable(variableName string) error {
deletedInfo, err := ConfigClient.DeleteCommonConfig(configId) if variableName == "" {
if err != nil { return errors.New("need variable name")
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")
} }
if moduleName == "" { err := c.configRepo.DeleteVariable(variableName)
return errors.New("empty module name") switch {
} case errors.Is(err, model.ErrVariableNotFound):
return errors.Errorf("variable [%s] not found", variableName)
commonConfigs, err := c.GetMapNameCommonConfig() default:
if err != nil {
return err return err
} }
}
config, ok := commonConfigs[configName] func (c Config) UpsertVariables(vars []model.UpsertVariableRequest) error {
if !ok { return c.configRepo.UpsertVariables(vars)
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
} }