diff --git a/.gitignore b/.gitignore index f1c181e..fd2fff0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,59 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +/.idea/ +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries +*.iml +convert_service +convert-service + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### Go template # Binaries for programs and plugins *.exe *.exe~ @@ -10,3 +66,9 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out + +/node_modules/ +/vendor/ +google/ +package.json +yarn.lock diff --git a/.version b/.version new file mode 100644 index 0000000..94ff29c --- /dev/null +++ b/.version @@ -0,0 +1 @@ +3.1.1 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..810ae8a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,40 @@ +### v3.1.1 +* добавлена совместимость isp-config-service 3.x.x +### v2.2.3 +* updated dependencies +### v2.2.2 +* updated isp-lib +### v2.2.1 +* updated isp-lib +* updated isp-event-lib +## v2.2.0 +* fix json output +* migrate to go mod +* update libs +## v2.1.2 +* fix output '\u0026' instead '&' +## v2.1.0 +* add output format for `status` +## v2.0.1 +* print module version in `status` command +## v2.0.0 +* add integration with isp-config-service 2.0 +## v1.2.4 +* migrate invoke to config service +## v1.2.3 +* read configuration from `stdin` till `EOF` +## v1.2.2 +* fix stack overflow +## v1.2.1 +* fix bash complete with flag +* fix schema display to html +## v1.2.0 +* add new command `schema` +* add bash complete +## v1.1.0 +* fix status response +* add checking schema to set configuration +* add unsafe flag +* update readme +## v1.0.1 +* fix spaces in strings diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md new file mode 100644 index 0000000..04a5e12 --- /dev/null +++ b/README.md @@ -0,0 +1,390 @@ +# ispctl + +Консольная утилита для получения и переопределения конфигруации модулей isp + +* [Требования](#Требования) +* [Установка](#Установка) +* [Конфигурация](#Конфигурация) +* [Использование](#Использование) +* [Описание](#Описание) +* [Примеры](#Пример) + - [ispctl status](#ispctl-status) + - [ispctl get](#ispctl-get) + - [ispctl set](#ispctl-set) + - [ispctl delete](#ispctl-delete) + - [ispctl schema](#ispctl-schema) + - [ispctl merge](#ispctl-merge) + - [ispctl gitget](#ispctl-gitget) + + +## Требования +* Linux + +## Установка +```bash +yum install ispctl +``` + +## Использование +```bash +ispctl [flag...] status [local_flag] +ispctl [flag...] get module_name property_path [local_flag] +ispctl [flag...] set module_name property_path [new_object] +ispctl [flag...] delete module_name property_path +ispctl [flag...] schema module_name [local_flag] +``` + +## Описание + +| Команды | Описание | +|----------|-----------------------------------------------------------------------------| +| `status` | возвращает доступные конфигурации модулей, их состояния и подключения | +| `get` | возвращает объект конфигурации указанного модуля | +| `set` | изменяет объект конфигурации указанного модуля | +| `delete` | удаляет объект конфигурации указанного модуля | +| `merge` | поблочно производит слияние конфигурации модуля с json конфигом через stdin | +| `gitget` | скачивает из репозитория указанный файлы с указанного комита | +| `schema` | возвращает схему конфигурации указанного модуля | +| | | + +| Флаги | Параметры | Описание | +|-------------|-----------|--------------------------------------------------------| +| `-g` | string | адрес isp-config-service | +| `-unsafe` | | отключает проверку схемы перед изменением конфигурации | +| | | | + +| Аргументы | Описание | +|-----------------|-------------------------------------------------------------------------------------------------------------| +| `module_name` | Название модуля с которым происходит взаимодействие | +| `property_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля | +| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin | +| | | + +| Локальные флаги | Параметры | Команды | Описание | +|-----------------|-----------|---------|---------------------------------------------------------------------------------------------------------------------------------| +| `-o` | string | schema | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` | +| `-full` | bool | get | осуществляет взаимодействие с объектами конфигурации модуля с учетом объектом общих конфигураций, которые имеют связь с модулем | +| | | | | + +## Пример +### ispctl status +`ispctl [flag...] status [local_flag]` + +`[local_flag]` - локальный флаг `-o` определяет формат вывода доступных конфигураций и состояний модулей. Доступные значения: `json`. +По умолчанию вывод осуществляется в виде таблицы. + +Запрос +```bash +ispctl status +``` +Ответ +```bash + MODULE NAME | STATUS | ADDRESSES ++------------------------+---------------+-------------------------+ + admin | CONNECTED | 127.0.0.1 + auth | NOT_CONNECTED | + config | CONNECTED | 127.0.0.1 + converter | CONNECTED | 127.0.0.1 + journal | NOT_CONNECTED | +``` + +### ispctl get +`ispctl [flag...] get module_name property_path` +* Получение полной конфигурации + +Запрос +```bash +ispctl get example . +``` +Ответ +```bash +{ + "journal": { + "bufferSize": 4092, + "compress": true, + "enable": false, + "enableRemoteTransfer": true, + "filename": "/var/log/example-service/runtime.log", + "maxSizeMb": 512, + "rotateTimeoutMs": 86400000 + }, + "metrics": { + "address": { + "ip": "127.0.0.1", + "path": "/metrics", + "port": 1 + }, + "gc": 2, + "memory": true + } +} +``` + +* Получение конкретного объекта конфигурации + +Запрос +```bash +ispctl get example .metrics.address +``` +Ответ +```bash +{ + "ip": "127.0.0.1", + "path": "/metrics", + "port": 1 +} +``` + +### ispctl set +`ispctl [flag...] set module_name property_path [new_object]` + +При указании `new_object` необходимо его экранировать. При его отсутсвии ожидается ввод из `stdin` до `EOF` + +* Вставка нового поля в объект конфигурации + +Запрос +```bash +ispctl set example .metrics.newField '"1000"' +``` +Ответ +```bash +{ + "journal": { + "bufferSize": 4092, + "compress": true, + "enable": false, + "enableRemoteTransfer": true, + "filename": "/var/log/example-service/runtime.log", + "maxSizeMb": 512, + "rotateTimeoutMs": 86400000 + }, + "metrics": { + "address": { + "ip": "127.0.0.1", + "path": "/metrics", + "port": 1 + }, + "gc": 2, + "memory": true, + "newField": "1000" + } +} +``` +* Изменение объекта конфигурации + +Запрос +```bash +ispctl set example .metrics '{"address":{"ip":"198.0.0.1","newField":"100","port":1},"gc":1,"memory":false}' +``` +Ответ +```bash +{ + "journal": { + "bufferSize": 4092, + "compress": true, + "enable": false, + "enableRemoteTransfer": true, + "filename": "/var/log/example-service/runtime.log", + "maxSizeMb": 512, + "rotateTimeoutMs": 86400000 + }, + "metrics": { + "address": { + "ip": "198.0.0.1", + "newField": "100", + "port": 1 + }, + "gc": 1, + "memory": false + } +} +``` +* Полное обновление конфигурации + +Запрос +```bash +ispctl set example . '{"journal":{"bufferSize":1111,"compress":false,"enable":true,"filename":"/var/log/example-service/runtime.log","newField":"1000"},"metrics":{"address":{"ip":"198.0.0.1","newField":"100","port":1},"gc":1,"memory":false}}' +``` +Ответ +```bash +{ + "journal": { + "bufferSize": 1111, + "compress": false, + "enable": true, + "filename": "/var/log/example-service/runtime.log", + "newField": "1000" + }, + "metrics": { + "address": { + "ip": "198.0.0.1", + "newField": "100", + "port": 1 + }, + "gc": 1, + "memory": false + } +} +``` +### ispctl delete +`ispctl [flag...] delete module_name property_path` +* Удаление объекта конфигурации + +Запрос +```bash +ispctl delete example .journal +``` +Ответ +```bash +{ + "metrics": { + "address": { + "ip": "198.0.0.1", + "newField": "100", + "port": 1 + }, + "gc": 1, + "memory": false + } +} +``` +* Удаление поля из конфигурации + +Запрос +```bash +ispctl delete example .metrics.address.ip +``` +Ответ +```bash +{ + "metrics": { + "address": { + "newField": "100", + "port": 1 + }, + "gc": 1, + "memory": false + } +} +``` +* Удаление конфигурации + +Запрос +```bash +ispctl delete example . +``` +Ответ +```bash +{} +``` + +### ispctl schema +`ispctl [flag...] schema module_name [local_flag]` +* Получение схемы конфигурации + +Запрос +```bash +ispctl schema example +``` +Ответ +```bash +{ + "title": "example" + "schema": { + "title": "Remote config", + "type": "object", + "required": [ + "journal", + ], + ... + ... + ... + } +} +``` +Запрос +```bash +ispctl schema example -o html +``` +Ответ +```bash + + + ... + ... + ... + +
+ + + + +``` + +### ispctl merge +Содержание файла `example.json` +```json +{ + "metrics": { + "gc": 1, + "memory": false + }, + "property": "replaced" +} +``` +Конфигурация модуля `example` +```json +{ + "database": { + "host": "127.0.0.1" + }, + "property": "original" +} +``` + +```bash +ispctl merge example < example.json +``` +Результат в конфигурации модуля +```json +{ + "metrics": { + "gc": 1, + "memory": false + }, + "property": "replaced", + "database": { + "host": "127.0.0.1" + } +} +``` + +### ispctl gitget +```bash +ispctl gitget git@github.com:integration-system/ispctl.git main.go d4d7c679aad47ae204c2b3a4587b032a723fe315 +``` + +### Запрос с флагами +Запрос +```bash +ispctl -g '127.0.0.1:9002' set example . '{"metrics":{"address":{"ip":"127.0.0.1","newField":"100","port":1},"gc":1,"memory":false}}' +``` +Ответ +```json +{ + "metrics": { + "address": { + "ip": "127.0.0.1", + "newField": "100", + "port": 1 + }, + "gc": 1, + "memory": false + } +} +``` diff --git a/allconfig.sh b/allconfig.sh new file mode 100755 index 0000000..ea88da9 --- /dev/null +++ b/allconfig.sh @@ -0,0 +1,26 @@ +#!/bin/bash +mkdir -p configs +if [ -n "$*" ]; then + statusResponse=$(ispctl $* status) +else + statusResponse=$(ispctl status) +fi + +i=0 +IFS=$'\n' +for status in $statusResponse; do + if [ $i -ne 2 ]; then + i=$((i + 1)) + else + IFS=$' ' + read -ra ADDR <<<"$status" + for module_name in "${ADDR[0]}"; do + if [ -n "$*" ]; then + ispctl $* get $module_name . > configs/$module_name.json + else + ispctl get $module_name . > configs/$module_name.json + fi + break + done + fi +done diff --git a/allschema.sh b/allschema.sh new file mode 100755 index 0000000..a9951cb --- /dev/null +++ b/allschema.sh @@ -0,0 +1,26 @@ +#!/bin/bash +mkdir -p schemas +if [ -n "$*" ]; then + statusResponse=$(ispctl $* status) +else + statusResponse=$(ispctl status) +fi + +i=0 +IFS=$'\n' +for status in $statusResponse; do + if [ $i -ne 2 ]; then + i=$(( i + 1 )) + else + IFS=$' ' + read -ra ADDR <<<"$status" + for module_name in "${ADDR[0]}"; do + if [ -n "$*" ]; then + ispctl $* schema $module_name -o html > schemas/$module_name.html + else + ispctl schema $module_name -o html > schemas/$module_name.html + fi + break + done + fi +done diff --git a/bash/autocomplete.go b/bash/autocomplete.go new file mode 100644 index 0000000..d93aa57 --- /dev/null +++ b/bash/autocomplete.go @@ -0,0 +1,84 @@ +package bash + +import ( + "fmt" + + "github.com/integration-system/bellows" + "github.com/urfave/cli/v2" + "ispctl/flag" + "ispctl/service" +) + +const ( + CommonConfigName bashArg = "config_name" + CommonConfigData bashArg = "config_data" + ModuleName bashArg = "module_name" + ModuleData bashArg = "module_data" + Empty bashArg = "empty" +) + +type bashArg string + +type bashCommand struct { + first bashArg + second bashArg +} + +func Get(first bashArg, second bashArg) *bashCommand { + return &bashCommand{ + first: first, + second: second, + } +} + +func (c bashCommand) Complete(ctx *cli.Context) { + if err := flag.CheckGlobal(ctx); err != nil { + return + } + commonConfigs, err := service.Config.GetMapNameCommonConfig() + if err != nil { + return + } + switch ctx.NArg() { + case 0: + switch c.first { + case ModuleName: + if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil { + return + } else { + for _, module := range arrayOfModules { + fmt.Println(module.Name) + } + } + case CommonConfigName: + for _, config := range commonConfigs { + fmt.Println(config.Name) + } + } + case 1: + switch c.second { + case CommonConfigData: + if config, ok := commonConfigs[ctx.Args().First()]; ok { + for key, _ := range bellows.Flatten(config.Data) { + fmt.Printf(".%v\n", key) + } + } + case ModuleName: + if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil { + return + } else { + for _, module := range arrayOfModules { + fmt.Println(module.Name) + } + } + case ModuleData: + if moduleConfiguration, err := service.Config.GetConfigurationByModuleName(ctx.Args().First()); err != nil { + return + } else { + for key, _ := range bellows.Flatten(moduleConfiguration.Data) { + fmt.Printf(".%v\n", key) + } + } + } + } +} diff --git a/cfg/domain.go b/cfg/domain.go new file mode 100644 index 0000000..c68357f --- /dev/null +++ b/cfg/domain.go @@ -0,0 +1,80 @@ +package cfg + +import ( + "time" + + "github.com/integration-system/isp-kit/cluster" + "github.com/integration-system/isp-kit/rc/schema" +) + +type getModuleByUuidAndNameRequest struct { + ModuleName string + Uuid string +} + +type getSchemaByModuleIdRequest struct { + ModuleId string +} + +type Config struct { + Id string + Name string + CommonConfigs []string + Description string + ModuleId string + Version int32 + Active bool + Data map[string]interface{} + Unsafe bool +} + +type CommonConfig struct { + Id string + Name string + Description string + CreatedAt time.Time + UpdatedAt time.Time + Data map[string]interface{} +} + +type Connection struct { + LibVersion string + Version string + Address cluster.AddressConfiguration + Endpoints []cluster.EndpointDescriptor `json:",omitempty"` + EstablishedAt time.Time +} + +type ModuleInfo struct { + Id string + Name string + Active bool + CreatedAt time.Time + ConfigSchema *schema.Schema `json:",omitempty"` + Status []Connection `json:",omitempty"` +} + +type ConfigSchema struct { + Id string + Version string + ModuleId string + Schema schema.Schema + CreatedAt time.Time + UpdatedAt time.Time +} + +type Deleted struct { + Deleted bool + Links Links +} + +type Links map[string][]string + +type identityRequest struct { + Id string +} + +type CompileConfigs struct { + Data map[string]interface{} + CommonConfigsIdList []string +} diff --git a/cfg/method_name.go b/cfg/method_name.go new file mode 100644 index 0000000..730a1ad --- /dev/null +++ b/cfg/method_name.go @@ -0,0 +1,13 @@ +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" +) diff --git a/cfg/methods.go b/cfg/methods.go new file mode 100644 index 0000000..4f5529b --- /dev/null +++ b/cfg/methods.go @@ -0,0 +1,163 @@ +package cfg + +import ( + "context" + "time" + + "github.com/integration-system/isp-kit/grpc/client" + "github.com/pkg/errors" +) + +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) +} diff --git a/command/common.go b/command/common.go new file mode 100644 index 0000000..78d7248 --- /dev/null +++ b/command/common.go @@ -0,0 +1,47 @@ +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) + } +} diff --git a/command/common_config/contain.go b/command/common_config/contain.go new file mode 100644 index 0000000..3f64508 --- /dev/null +++ b/command/common_config/contain.go @@ -0,0 +1,53 @@ +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 +} diff --git a/command/common_config/delete.go b/command/common_config/delete.go new file mode 100644 index 0000000..ce51d55 --- /dev/null +++ b/command/common_config/delete.go @@ -0,0 +1,63 @@ +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) + } + } +} diff --git a/command/common_config/get.go b/command/common_config/get.go new file mode 100644 index 0000000..c7be507 --- /dev/null +++ b/command/common_config/get.go @@ -0,0 +1,68 @@ +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 +} diff --git a/command/common_config/link.go b/command/common_config/link.go new file mode 100644 index 0000000..00a662a --- /dev/null +++ b/command/common_config/link.go @@ -0,0 +1,35 @@ +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 +} diff --git a/command/common_config/remove.go b/command/common_config/remove.go new file mode 100644 index 0000000..f053506 --- /dev/null +++ b/command/common_config/remove.go @@ -0,0 +1,53 @@ +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 +} diff --git a/command/common_config/set.go b/command/common_config/set.go new file mode 100644 index 0000000..38c1aa0 --- /dev/null +++ b/command/common_config/set.go @@ -0,0 +1,78 @@ +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) + } + } +} diff --git a/command/common_config/unlink.go b/command/common_config/unlink.go new file mode 100644 index 0000000..4c95202 --- /dev/null +++ b/command/common_config/unlink.go @@ -0,0 +1,35 @@ +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 +} diff --git a/command/delete.go b/command/delete.go new file mode 100644 index 0000000..6ff61c6 --- /dev/null +++ b/command/delete.go @@ -0,0 +1,58 @@ +package command + +import ( + "encoding/json" + + "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: "delete configuration by module_name", + Action: deleteComm.action, + BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, + } +} + +var deleteComm deleteCommand + +type deleteCommand struct{} + +func (d deleteCommand) action(ctx *cli.Context) error { + if err := flag.CheckGlobal(ctx); err != nil { + return err + } + moduleName := ctx.Args().First() + pathObject := ctx.Args().Get(1) + + moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName) + if err != nil { + return err + } + + pathObject, err = utils.CheckPath(pathObject) + if err != nil { + return err + } + + if pathObject == "" { + return utils.CreateUpdateConfig("", moduleConfiguration) + } else { + jsonObject, err := json.Marshal(moduleConfiguration.Data) + if err != nil { + return err + } + + if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil { + return err + } else { + return utils.CreateUpdateConfig(stringToChange, moduleConfiguration) + } + } +} diff --git a/command/get.go b/command/get.go new file mode 100644 index 0000000..b97d264 --- /dev/null +++ b/command/get.go @@ -0,0 +1,63 @@ +package command + +import ( + "encoding/json" + + "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 configuration by module_name", + Action: get.action, + BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, + Flags: []cli.Flag{ + flag.WithCommonConfig, + }, + } +} + +var get getCommand + +type getCommand struct{} + +func (g getCommand) action(ctx *cli.Context) error { + if err := flag.CheckGlobal(ctx); err != nil { + return err + } + moduleName := ctx.Args().First() + pathObject := ctx.Args().Get(1) + + config, err := service.Config.GetConfigurationByModuleName(moduleName) + if err != nil { + return err + } + + data := config.Data + if ctx.Bool(flag.WithCommonConfig.Name) { + if data, err = service.Config.CompileDataWithCommonConfigs(data, config.CommonConfigs); err != nil { + return err + } + } + + pathObject, err = utils.CheckPath(pathObject) + if err != nil { + return err + } + + if pathObject == "" { + utils.PrintAnswer(data) + } else { + jsonObject, err := json.Marshal(data) + if err != nil { + return err + } + utils.CheckObject(jsonObject, pathObject) + } + return nil +} diff --git a/command/gitget.go b/command/gitget.go new file mode 100644 index 0000000..baf9bd7 --- /dev/null +++ b/command/gitget.go @@ -0,0 +1,60 @@ +package command + +import ( + "io" + "os" + + "github.com/go-git/go-billy/v5/memfs" + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/storage/memory" + "github.com/pkg/errors" + "github.com/urfave/cli/v2" +) + +func GitGet() *cli.Command { + return &cli.Command{ + Name: "gitget", + Usage: "gitget [repository] [file] (commit)", + Description: "clone and print specified file from specified repository and specified commit hash", + Action: func(context *cli.Context) error { + storage := memory.NewStorage() + repo := context.Args().Get(0) + + file := context.Args().Get(1) + commit := context.Args().Get(2) + + repository, err := git.Clone(storage, memfs.New(), &git.CloneOptions{ + URL: repo, + }) + if err != nil { + return errors.WithMessagef(err, "clone %s", repo) + } + tree, err := repository.Worktree() + if err != nil { + return errors.WithMessage(err, "get worktree") + } + + if commit != "" { + err = tree.Checkout(&git.CheckoutOptions{ + Hash: plumbing.NewHash(commit), + }) + 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 + }, + } +} diff --git a/command/merge.go b/command/merge.go new file mode 100644 index 0000000..fe7ba56 --- /dev/null +++ b/command/merge.go @@ -0,0 +1,49 @@ +package command + +import ( + "encoding/json" + "os" + + "github.com/pkg/errors" + "github.com/urfave/cli/v2" + "ispctl/bash" + "ispctl/command/utils" + "ispctl/flag" + "ispctl/service" +) + +func Merge() *cli.Command { + return &cli.Command{ + Name: "merge", + Usage: "merge actual config with config from stdin", + BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete, + Action: func(context *cli.Context) error { + err := flag.CheckGlobal(context) + if err != nil { + return err + } + moduleName := context.Args().First() + config, err := service.Config.GetConfigurationByModuleName(moduleName) + if err != nil { + return errors.WithMessagef(err, "get module config '%s'", moduleName) + } + + inputConfig := make(map[string]any) + err = json.NewDecoder(os.Stdin).Decode(&inputConfig) + if err != nil { + return errors.WithMessage(err, "json unmarshal input config") + } + for key, value := range inputConfig { + config.Data[key] = value + } + + result, err := service.Config.CreateUpdateConfigV2(config) + if err != nil { + return errors.WithMessagef(err, "update module config '%s'", moduleName) + } + utils.PrintAnswer(result) + + return nil + }, + } +} diff --git a/command/schema.go b/command/schema.go new file mode 100644 index 0000000..80920b9 --- /dev/null +++ b/command/schema.go @@ -0,0 +1,76 @@ +package command + +import ( + "html/template" + "os" + + "github.com/pkg/errors" + "github.com/urfave/cli/v2" + "ispctl/bash" + "ispctl/command/utils" + "ispctl/flag" + "ispctl/service" + "ispctl/tmpl" +) + +func Schema() *cli.Command { + return &cli.Command{ + Name: "schema", + Usage: "get schema configuration by module_name", + Action: schema.action, + Flags: []cli.Flag{ + flag.OutPrintSchema, + }, + BashComplete: bash.Get(bash.ModuleName, bash.Empty).Complete, + } +} + +var schema schemaCommand + +type schemaCommand struct{} + +func (s schemaCommand) action(ctx *cli.Context) error { + if err := flag.CheckGlobal(ctx); err != nil { + return err + } + moduleName := ctx.Args().First() + + if schemaConfig := s.getSchemaConfig(moduleName); schemaConfig != nil { + schema := make(map[string]interface{}) + schema["title"] = moduleName + schema["schema"] = schemaConfig + switch ctx.String(flag.OutPrintSchema.Name) { + case flag.OutPrintJsonValue: + utils.PrintAnswer(schema) + case flag.OutPrintHtmlValue: + s.printHtml(schema) + default: + return errors.Errorf("invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue) + } + } + return nil +} + +func (s schemaCommand) getSchemaConfig(moduleName string) interface{} { + if configuration, err := service.Config.GetConfigurationByModuleName(moduleName); err != nil { + utils.PrintError(err) + return nil + } else if schema, err := service.Config.GetSchemaByModuleId(configuration.ModuleId); err != nil { + utils.PrintError(err) + return nil + } else { + return schema + } +} + +func (s schemaCommand) printHtml(schema map[string]interface{}) { + if temp, err := template.New("template").Parse(tmpl.HtmlFile); err != nil { + utils.PrintError(err) + return + } else { + if err := temp.ExecuteTemplate(os.Stdout, "template", schema); err != nil { + utils.PrintError(err) + return + } + } +} diff --git a/command/set.go b/command/set.go new file mode 100644 index 0000000..0991031 --- /dev/null +++ b/command/set.go @@ -0,0 +1,66 @@ +package command + +import ( + "encoding/json" + + "github.com/tidwall/sjson" + "github.com/urfave/cli/v2" + "ispctl/bash" + "ispctl/command/utils" + "ispctl/flag" + "ispctl/service" +) + +func Set() *cli.Command { + return &cli.Command{ + Name: "set", + Usage: "set configuration by module_name", + Action: set.action, + BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, + } +} + +var set setCommand + +type setCommand struct{} + +func (s setCommand) action(ctx *cli.Context) error { + if err := flag.CheckGlobal(ctx); err != nil { + return err + } + + moduleName := ctx.Args().First() + pathObject := ctx.Args().Get(1) + changeObject := ctx.Args().Get(2) + + config, err := service.Config.GetConfigurationByModuleName(moduleName) + if err != nil { + return err + } + + pathObject, err = utils.CheckPath(pathObject) + if err != nil { + return err + } + + changeObject, err = utils.CheckChangeObject(changeObject) + if err != nil { + return err + } + + if pathObject == "" { + return utils.CreateUpdateConfig(changeObject, config) + } else { + jsonObject, err := json.Marshal(config.Data) + if err != nil { + return err + } + + changeArgument := utils.ParseSetObject(changeObject) + if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil { + return err + } else { + return utils.CreateUpdateConfig(stringToChange, config) + } + } +} diff --git a/command/status.go b/command/status.go new file mode 100644 index 0000000..9990ced --- /dev/null +++ b/command/status.go @@ -0,0 +1,70 @@ +package command + +import ( + "fmt" + "os" + "strings" + + "github.com/olekukonko/tablewriter" + "github.com/urfave/cli/v2" + "ispctl/command/utils" + "ispctl/flag" + "ispctl/service" +) + +const ( + tableHeaderModuleName = "MODULE_NAME" + tableHeaderStatus = "STATUS" + tableHeaderAddresses = "ADDRESSES" + + tableNotConnectedStatus = "NOT_CONNECTED" + tableConnectedStatus = "CONNECTED" +) + +func Status() *cli.Command { + return &cli.Command{ + Name: "status", + Usage: "get available configs", + Action: status.action, + Flags: []cli.Flag{ + flag.OutPrintStatus, + }, + } +} + +var status statusCommand + +type statusCommand struct{} + +func (statusCommand) action(ctx *cli.Context) error { + if err := flag.CheckGlobal(ctx); err != nil { + return err + } + if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil { + return err + } else { + switch ctx.String(flag.OutPrintStatus.Name) { + case flag.OutPrintJsonValue: + utils.PrintAnswer(arrayOfModules) + default: + table := tablewriter.NewWriter(os.Stdout) + table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false}) + table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses}) + for _, module := range arrayOfModules { + addresses := "" + connection := tableNotConnectedStatus + instanceList := make([]string, 0, len(module.Status)) + for _, value := range module.Status { + instanceList = append(instanceList, fmt.Sprintf("%s:%s %s", value.Address.IP, value.Address.Port, value.Version)) + } + addresses = strings.Join(instanceList, "\n") + if addresses != "" { + connection = tableConnectedStatus + } + table.Append([]string{module.Name, connection, addresses}) + } + table.Render() + } + } + return nil +} diff --git a/command/utils/common.go b/command/utils/common.go new file mode 100644 index 0000000..ef5ecae --- /dev/null +++ b/command/utils/common.go @@ -0,0 +1,113 @@ +package utils + +import ( + "fmt" + "io/ioutil" + "os" + "strings" + + "github.com/integration-system/isp-kit/json" + "github.com/pkg/errors" + "github.com/tidwall/gjson" +) + +func CheckPath(pathObject string) (string, error) { + str := strings.Split(pathObject, ".") + pathObject = "" + if len(str) == 1 || str[0] != "" { + return pathObject, errors.New("path must start with '.'") + } + for key, value := range str { + if key == 0 { + continue + } + if key == 1 { + pathObject = fmt.Sprintf("%s", value) + continue + } + pathObject = fmt.Sprintf("%s.%s", pathObject, value) + } + return pathObject, nil +} + +func CheckChangeObject(changeObject string) (string, error) { + if changeObject == "" { + bytes, err := ioutil.ReadAll(os.Stdin) + if err != nil { + return "", err + } + changeObject = string(bytes) + } + if changeObject == "" { + return "", errors.New("expected argument") + } else { + return changeObject, nil + } +} + +func PrintAnswer(data interface{}) { + encoder := json.NewEncoder(os.Stdout) + encoder.SetEscapeHTML(false) + encoder.SetIndent("", " ") + if err := encoder.Encode(data); err != nil { + PrintError(err) + } +} + +func PrintError(err error) { + fmt.Println("ERROR:", err) + os.Exit(-1) +} + +func ParseSetObject(argument string) interface{} { + tryParse := []byte(argument) + if tryParse[0] == '"' && tryParse[len(tryParse)-1] == '"' { + tryParse = tryParse[1 : len(tryParse)-1] + return string(tryParse) + } + + if argument == "null" { + return nil + } + + mapStringInterface := make(map[string]interface{}) + if err := json.Unmarshal(tryParse, &mapStringInterface); err == nil { + return mapStringInterface + } + + arrayOfObject := make([]interface{}, 0) + if err := json.Unmarshal(tryParse, &arrayOfObject); err == nil { + return arrayOfObject + } + + var integer int64 + if err := json.Unmarshal(tryParse, &integer); err == nil { + return integer + } + + var float float64 + if err := json.Unmarshal(tryParse, &float); err == nil { + return float + } + + var flag bool + if err := json.Unmarshal(tryParse, &flag); err == nil { + return flag + } + + return argument +} + +func CheckObject(jsonObject []byte, depth string) { + jsonString := gjson.GetBytes(jsonObject, depth) + if jsonString.Raw == "" { + PrintError(errors.Errorf("path '%s' not found\n", depth)) + } else { + var data interface{} + if err := json.Unmarshal([]byte(jsonString.Raw), &data); err != nil { + PrintError(err) + } else { + PrintAnswer(data) + } + } +} diff --git a/command/utils/common_config.go b/command/utils/common_config.go new file mode 100644 index 0000000..dd1df9b --- /dev/null +++ b/command/utils/common_config.go @@ -0,0 +1,15 @@ +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 +} diff --git a/command/utils/config.go b/command/utils/config.go new file mode 100644 index 0000000..ef699d4 --- /dev/null +++ b/command/utils/config.go @@ -0,0 +1,15 @@ +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 +} diff --git a/conf/config.yml b/conf/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/flag/description.go b/flag/description.go new file mode 100644 index 0000000..55bce5a --- /dev/null +++ b/flag/description.go @@ -0,0 +1,23 @@ +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) +) diff --git a/flag/structure.go b/flag/structure.go new file mode 100644 index 0000000..af02f98 --- /dev/null +++ b/flag/structure.go @@ -0,0 +1,36 @@ +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) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8e79bf1 --- /dev/null +++ b/go.mod @@ -0,0 +1,69 @@ +module ispctl + +go 1.21 + +require ( + github.com/go-git/go-billy/v5 v5.5.0 + github.com/go-git/go-git/v5 v5.10.0 + github.com/integration-system/bellows v1.0.1 + github.com/integration-system/isp-kit v1.24.2 + github.com/olekukonko/tablewriter v0.0.5 + github.com/pkg/errors v0.9.1 + github.com/tidwall/gjson v1.17.0 + github.com/tidwall/sjson v1.2.5 + github.com/urfave/cli/v2 v2.25.7 + google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b + google.golang.org/grpc v1.59.0 +) + +require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect + github.com/acomagu/bufpipe v1.0.4 // indirect + github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cloudflare/circl v1.3.5 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/integration-system/isp-etp-go/v2 v2.1.3 // indirect + github.com/integration-system/jsonschema v1.0.1 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/prometheus/client_golang v1.17.0 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.45.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/sergi/go-diff v1.3.1 // indirect + github.com/skeema/knownhosts v1.2.1 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.1 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.26.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/mod v0.13.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect + golang.org/x/tools v0.14.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect + nhooyr.io/websocket v1.8.10 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2bd65c1 --- /dev/null +++ b/go.sum @@ -0,0 +1,267 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX7IL/m9Y5LO+KQYv+t1CQOiFe6+SV2J7bE= +github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= +github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.5 h1:g+wWynZqVALYAlpSQFAa7TscDnUK8mKYtrxMpw6AUKo= +github.com/cloudflare/circl v1.3.5/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= +github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4= +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/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= +github.com/go-git/go-git/v5 v5.10.0 h1:F0x3xXrAWmhwtzoCokU4IMPcBdncG+HAAqi9FcOOjbQ= +github.com/go-git/go-git/v5 v5.10.0/go.mod h1:1FOZ/pQnqw24ghP2n7cunVl0ON55BsjPYvhWHvZGhoo= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= +github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= +github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/integration-system/bellows v1.0.1 h1:7g1lhD/6EcvsSo9iuiFqw98XGS78Sko6kUKPzfte/SY= +github.com/integration-system/bellows v1.0.1/go.mod h1:qHPg1ptN3AHHr0f/wvoicfA2LOCprOyrbXnIa5QIRe0= +github.com/integration-system/isp-etp-go/v2 v2.1.3 h1:vcHP/PE7p1G3rxqoVKrKtXzoSxFA4ryxigd+zPkAb3w= +github.com/integration-system/isp-etp-go/v2 v2.1.3/go.mod h1:ZpB+FIH3hy7md+f8ylVSQx5zwZVjczhkc45f1B2z9nw= +github.com/integration-system/isp-kit v1.24.2 h1:ejjSv+CFlPUGV80lxAAleLSa6T/LRoto7evRjSSUF7c= +github.com/integration-system/isp-kit v1.24.2/go.mod h1:LvqQyw8PCuuo9O8jgvhKBlOP4UEIYRxb9cHWHuYddcQ= +github.com/integration-system/jsonschema v1.0.1 h1:nR78BEDG9djX2uXQ1YP66a/9yQOMmp2HFmw8VPUdAa8= +github.com/integration-system/jsonschema v1.0.1/go.mod h1:EoqDH7RmC8Epg5EgjboIxDo7Udv3WX2exGqtIVB4hI0= +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/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= +github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= +github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= +github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM= +github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= +github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +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-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +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.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/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.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= +nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q= +nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= diff --git a/main.go b/main.go new file mode 100644 index 0000000..5e42bad --- /dev/null +++ b/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/urfave/cli/v2" + "ispctl/command" + "ispctl/flag" +) + +var version = "1.1.0" + +func main() { + initCommands() +} + +func initCommands() { + app := cli.NewApp() + app.Usage = "isp configurations updater" + + app.Version = version + app.Flags = []cli.Flag{ + flag.Host, + flag.Unsafe, + } + app.EnableBashCompletion = true + app.Commands = []*cli.Command{ + command.Status(), + command.Get(), + command.Set(), + command.Delete(), + command.Schema(), + command.CommonConfig(), + command.Merge(), + command.GitGet(), + } + app.BashComplete = func(context *cli.Context) { + for _, appCommand := range app.Commands { + fmt.Println(appCommand.Name) + } + } + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} diff --git a/service/common.go b/service/common.go new file mode 100644 index 0000000..e8a0759 --- /dev/null +++ b/service/common.go @@ -0,0 +1,7 @@ +package service + +import "ispctl/cfg" + +var ( + ConfigClient = cfg.NewConfigClient() +) diff --git a/service/config.go b/service/config.go new file mode 100644 index 0000000..6140c46 --- /dev/null +++ b/service/config.go @@ -0,0 +1,269 @@ +package service + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/integration-system/isp-kit/rc/schema" + "github.com/pkg/errors" + epb "google.golang.org/genproto/googleapis/rpc/errdetails" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "ispctl/cfg" +) + +var Config configService + +type configService struct { + UnsafeEnable bool +} + +func (c configService) ReceiveConfiguration(host string) error { + return ConfigClient.ReceiveConfig(host) +} + +func (c configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) { + return ConfigClient.GetAvailableConfigs() +} + +func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Config, error) { + if moduleName == "" { + return nil, errors.New("need module name") + } + + if moduleConfiguration, err := ConfigClient.GetConfigByModuleName(moduleName); err != nil { + if errorStatus, ok := status.FromError(err); ok { + switch errorStatus.Code() { + case codes.NotFound: + return nil, errors.Errorf("module [%s] not found", moduleName) + } + } + return nil, err + } else { + return moduleConfiguration, nil + } +} + +func (c configService) GetSchemaByModuleId(moduleId string) (schema.Schema, error) { + if configSchema, err := ConfigClient.GetSchemaByModuleId(moduleId); err != nil { + return nil, err + } else { + dereferenceSchema := schema.DereferenceSchema(configSchema.Schema) + return dereferenceSchema, nil + } +} + +func (c configService) CreateUpdateConfig(stringToChange string, configuration *cfg.Config) (map[string]interface{}, error) { + newData := make(map[string]interface{}) + if stringToChange != "" { + if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil { + return nil, err + } + } + + configuration.Data = newData + return c.CreateUpdateConfigV2(configuration) +} + +func (c configService) CreateUpdateConfigV2(configuration *cfg.Config) (map[string]interface{}, error) { + configuration.Unsafe = c.UnsafeEnable + if resp, err := ConfigClient.CreateUpdateConfig(*configuration); err != nil { + if errorStatus, ok := status.FromError(err); ok { + switch errorStatus.Code() { + case codes.InvalidArgument: + fmt.Print("doesn't match with schema:\n") + defer func() { + os.Exit(1) + }() + for _, value := range errorStatus.Details() { + if a, ok := value.(*epb.BadRequest); ok { + for _, value := range a.FieldViolations { + fmt.Printf("%s | %s\n", value.Field, value.Description) + } + } else { + fmt.Println(value) + } + return nil, nil + } + } + } + return nil, err + } else { + return resp.Data, nil + } +} + +func (c configService) UpdateConfigAndGetLinkCommon(configuration cfg.Config) ([]string, error) { + if resp, err := ConfigClient.CreateUpdateConfig(configuration); err != nil { + return nil, err + } else { + return resp.CommonConfigs, nil + } +} + +func (c configService) GetCommonConfigByName(configName string) (cfg.CommonConfig, error) { + if commonConfigs, err := c.GetMapNameCommonConfig(); err != nil { + return cfg.CommonConfig{}, err + } else if config, ok := commonConfigs[configName]; !ok { + return cfg.CommonConfig{}, errors.Errorf("common config [%s] not found", configName) + } else { + return config, nil + } +} + +func (c configService) GetMapNameCommonConfig() (map[string]cfg.CommonConfig, error) { + collection, err := ConfigClient.GetCommonConfigs([]string{}) + if err != nil { + return nil, err + } + response := make(map[string]cfg.CommonConfig) + for _, config := range collection { + response[config.Name] = config + } + return response, nil +} + +func (c configService) CreateUpdateCommonConfig(stringToChange string, config cfg.CommonConfig) (map[string]interface{}, error) { + newData := make(map[string]interface{}) + if stringToChange != "" { + if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil { + return nil, err + } + } + + config.Data = newData + if resp, err := ConfigClient.CreateUpdateCommonConfig(config); err != nil { + return nil, err + } else { + return resp.Data, nil + } +} + +func (c configService) DeleteCommonConfig(configId string) ([]string, bool, error) { + deletedInfo, err := ConfigClient.DeleteCommonConfig(configId) + if err != nil { + return nil, false, err + } + arrayOfModuleName := make([]string, 0) + for moduleName := range deletedInfo.Links { + arrayOfModuleName = append(arrayOfModuleName, moduleName) + } + return arrayOfModuleName, deletedInfo.Deleted, nil +} + +func (c configService) GetLinksCommonConfig(configId string) ([]string, error) { + link, err := ConfigClient.GetLinksCommonConfig(configId) + if err != nil { + return nil, err + } + arrayOfModuleName := make([]string, 0) + for moduleName := range *link { + arrayOfModuleName = append(arrayOfModuleName, moduleName) + } + return arrayOfModuleName, nil +} + +func (c configService) CompileDataWithCommonConfigs( + data map[string]interface{}, commonConfigs []string) (map[string]interface{}, error) { + + req := cfg.CompileConfigs{ + Data: data, + CommonConfigsIdList: commonConfigs, + } + var err error + data, err = ConfigClient.CompileCommonConfigs(req) + if err != nil { + return nil, err + } else { + return data, nil + } +} + +func (c configService) UnlinkCommonConfigFromModule(configName, moduleName string) error { + return c.linked(configName, moduleName, + func(configId string, configIdentities []string) (bool, []string) { + needUnlink := false + for i, id := range configIdentities { + if configId == id { + copy(configIdentities[i:], configIdentities[i+1:]) + configIdentities[len(configIdentities)-1] = "" + configIdentities = configIdentities[:len(configIdentities)-1] + needUnlink = true + break + } + } + return needUnlink, configIdentities + }) +} + +func (c configService) LinkCommonConfigToModule(configName, moduleName string) error { + return c.linked(configName, moduleName, + func(configId string, configIdentities []string) (bool, []string) { + needLink := true + for _, id := range configIdentities { + if configId == id { + needLink = false + break + } + } + if needLink { + configIdentities = append(configIdentities, configId) + } + return needLink, configIdentities + }) +} + +func (c configService) linked(configName, moduleName string, + linkHandler func(configId string, configIdentities []string) (bool, []string)) error { + + if configName == "" { + return errors.New("empty config name") + } + + if moduleName == "" { + return errors.New("empty module name") + } + + commonConfigs, err := c.GetMapNameCommonConfig() + if err != nil { + return err + } + + config, ok := commonConfigs[configName] + if !ok { + return errors.Errorf("common config [%s] not found", configName) + } + + moduleConfig, err := c.GetConfigurationByModuleName(moduleName) + if err != nil { + return err + } + + configIdConfigNameMap := make(map[string]string) + for name, value := range commonConfigs { + configIdConfigNameMap[value.Id] = name + } + + needUpdate, newCommonConfigs := linkHandler(config.Id, moduleConfig.CommonConfigs) + + if needUpdate { + moduleConfig.CommonConfigs = newCommonConfigs + if linked, err := c.UpdateConfigAndGetLinkCommon(*moduleConfig); err != nil { + return err + } else { + fmt.Printf("module [%s] have next link:\n", moduleName) + for _, name := range linked { + fmt.Printf("[%s] ", configIdConfigNameMap[name]) + } + fmt.Printf("\n") + } + } else { + fmt.Printf("module [%s] have next link:\n", moduleName) + for _, name := range moduleConfig.CommonConfigs { + fmt.Printf("[%s] ", configIdConfigNameMap[name]) + } + fmt.Printf("\n") + } + return nil +} diff --git a/static/autocomplete b/static/autocomplete new file mode 100644 index 0000000..ac5df1f --- /dev/null +++ b/static/autocomplete @@ -0,0 +1,21 @@ +#! /bin/bash + +: ${PROG:=$(basename ${BASH_SOURCE})} + +_cli_bash_autocomplete() { + if [[ "${COMP_WORDS[0]}" != "source" ]]; then + local cur opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if [[ "$cur" == "-"* ]]; then + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) + else + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) + fi + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} + +complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG +unset PROG \ No newline at end of file diff --git a/tmpl/html_template.go b/tmpl/html_template.go new file mode 100644 index 0000000..7a90d45 --- /dev/null +++ b/tmpl/html_template.go @@ -0,0 +1,71 @@ +package tmpl + +const HtmlFile = ` + + + + + + + +
+ + + +`