add 'contain' command for common configs

add flag 'full' for 'get' command
update bash complete
This commit is contained in:
DeniskaRediska committed 2019-10-30 14:58:50 +03:00
1 parent 1a3458ebdd
commit 8b8815d2f2
21 files changed
+348 -54

No files matched your search

+131 -6
View File
@@ -25,11 +25,13 @@ instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
## Использование ## Использование
```bash ```bash
ispctl [flag...] status ispctl [flag...] status
ispctl [flag...] get module_name property_path ispctl [flag...] get module_name property_path [local_flag]
ispctl [flag...] set module_name property_path [new_object] ispctl [flag...] set module_name property_path [new_object]
ispctl [flag...] delete module_name property_path ispctl [flag...] delete module_name property_path
ispctl [flag...] schema module_name [local_flag] ispctl [flag...] schema module_name [local_flag]
ispctl [flag...] common sub_command
``` ```
## Описание ## Описание
| Команды | Описание | | Команды | Описание |
@@ -39,6 +41,7 @@ ispctl [flag...] schema module_name [local_flag]
| `set` | изменяет объект конфигурации указанного модуля | | `set` | изменяет объект конфигурации указанного модуля |
| `delete` | удаляет объект конфигурации указанного модуля | | `delete` | удаляет объект конфигурации указанного модуля |
| `schema` | возвращает схему конфигурации указанного модуля | | `schema` | возвращает схему конфигурации указанного модуля |
| `common` | комманда для взаимодействие с общими конфигурациями |
| | | | | |
| Флаги | Параметры | Описание | | Флаги | Параметры | Описание |
@@ -51,15 +54,37 @@ ispctl [flag...] schema module_name [local_flag]
| Аргументы | Описание | | Аргументы | Описание |
|-----------------|-------------------------------------------------------------------------------------------------------------| |-----------------|-------------------------------------------------------------------------------------------------------------|
| `module_name` | Модуль с которым происходит взаимодействие | | `module_name` | Название модуля с которым происходит взаимодействие |
| `proprtry_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля |
| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin |
| | |
| Локальные флаги | Параметры | Команды | Описание |
|-----------------|-----------|---------|---------------------------------------------------------------------------------------------------------------------------------|
| `-o` | string | schema | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
| `-full` | bool | get | осуществляет взаимодействие с объектами конфигурации модуля с учетом объектом общих конфигураций, которые имеют связь с модулем |
| | | | |
### sub_command
#### common
```bash
ispctl [flag...] common set config_name property_path [new_object]
ispctl [flag...] common get [config_name] property_path
ispctl [flag...] common delete config_name property_path
ispctl [flag...] common remove config_name
ispctl [flag...] common link config_name module_name
ispctl [flag...] common unlink config_name module_name
ispctl [flag...] common contain config_name
```
| Аргументы | Описание |
|-----------------|-------------------------------------------------------------------------------------------------------------|
| `config_name` | Названия конфига с которым происходит взаимодействие |
| `module_name` | Название модуля с которым происходит взаимодействие |
| `proprtry_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля | | `proprtry_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля |
| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin | | `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin |
| | | | | |
| Локальные флаги | Параметры | Описание |
|-----------------|-----------|--------------------------------------------------------------------------------------------------|
| `-o` | string | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
| | | |
## Пример ## Пример
### ispctl status ### ispctl status
@@ -318,6 +343,106 @@ ispctl schema example -o html
``` ```
### ispctl common
#### get
Возвращает список названий общих конфигураций или, если в первом аргументе указано название общей конфигурации, возвращает объект общей конфигурации по указанному пути
Запрос
```bash
ispctl common get
```
Ответ
```bash
test b c
```
Запрос
```bash
ispctl common get test .
```
Ответ
```bash
{
"test": null
}
```
#### set
Добавляет объект в общую конфигурацию по указанному пути
Запрос
```bash
ispctl common set test .test '{"a":"a","b":"b"}'
```
Ответ
```bash
{
"test": {
"a": "a",
"b": "b"
}
}
```
#### delete
Удаляет объект из общей конфигурации по указанному пути
Запрос
```bash
ispctl common delete test .test.a
```
Ответ
```bash
{
"test": {
"b": "b"
}
}
```
#### link
Связывает 'common_config' к конфигурации модуля по 'module_name'. Возвращает список общих конфигураций, которые связаны с модулем
Запрос
```bash
ispctl common link test module_example
```
Ответ
```bash
[test] [second_common_config]
```
#### remove
Удаляет объект общий конфигурации, если он не связан с конфигурациями модулей. Если общая конфигурация имеет связи, выводит список модулей с которыми установлена связь
Запрос
```bash
ispctl common remove test
```
Ответ
```bash
config [test] not deleted, need unlink in next modules:
[module_example]
```
#### unlink
Отвязывает 'common_config' от конфигурации модуля по 'module_name'. Возвращает список общих конфигураций, которые связаны с модулем
Запрос
```bash
ispctl common unlink test module_example
```
Ответ
Ответ
```bash
[second_common_config]
```
#### contain
Возвращает список названий модулей, с которыми имеет связь общая конфигурация
Запрос
```bash
isp-ctl common contain second_common_config
```
Ответ
Ответ
```bash
[module_example]
```
### Запрос с флагами ### Запрос с флагами
Запрос Запрос
+3 -3
View File
@@ -12,7 +12,7 @@ var CommonConfig commonConfig
type commonConfig struct{} type commonConfig struct{}
func (commonConfig) LinkUnlink(ctx *cli.Context) { func (commonConfig) ConfigName_ModuleName(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil { if err := flag.CheckGlobal(ctx); err != nil {
return return
} }
@@ -36,7 +36,7 @@ func (commonConfig) LinkUnlink(ctx *cli.Context) {
} }
} }
func (commonConfig) GetSetDelete(ctx *cli.Context) { func (commonConfig) ConfigName_ConfigData(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil { if err := flag.CheckGlobal(ctx); err != nil {
return return
} }
@@ -58,7 +58,7 @@ func (commonConfig) GetSetDelete(ctx *cli.Context) {
} }
} }
func (commonConfig) Remove(ctx *cli.Context) { func (commonConfig) ConfigName(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil { if err := flag.CheckGlobal(ctx); err != nil {
return return
} }
+4 -3
View File
@@ -12,7 +12,7 @@ var Module module
type module struct{} type module struct{}
func (module) GetSetDelete(ctx *cli.Context) { func (module) ModuleName_ModuleData(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil { if err := flag.CheckGlobal(ctx); err != nil {
return return
} }
@@ -26,7 +26,8 @@ func (module) GetSetDelete(ctx *cli.Context) {
} }
} }
case 1: case 1:
if moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(ctx.Args().Get(1)); err != nil { moduleConfiguration, err := service.Config.GetConfigurationByModuleName(ctx.Args().Get(1))
if err != nil {
return return
} else { } else {
for key, _ := range bellows.Flatten(moduleConfiguration.Data) { for key, _ := range bellows.Flatten(moduleConfiguration.Data) {
@@ -36,7 +37,7 @@ func (module) GetSetDelete(ctx *cli.Context) {
} }
} }
func (module) Schema(ctx *cli.Context) { func (module) ModuleName(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil { if err := flag.CheckGlobal(ctx); err != nil {
return return
} }
+14 -2
View File
@@ -66,6 +66,18 @@ type ConfigSchema struct {
UpdatedAt time.Time UpdatedAt time.Time
} }
type deleted struct { type Deleted struct {
Deleted int Deleted bool
Links Links
}
type Links map[string][]string
type identityRequest struct {
Id string
}
type CompileConfigs struct {
Data map[string]interface{}
CommonConfigsIdList []string
} }
+2
View File
@@ -8,4 +8,6 @@ const (
getCommonConfigs = "config/common_config/get_configs" getCommonConfigs = "config/common_config/get_configs"
createUpdateCommonConfig = "config/common_config/create_update_config" createUpdateCommonConfig = "config/common_config/create_update_config"
deleteCommonConfig = "config/common_config/delete_config" deleteCommonConfig = "config/common_config/delete_config"
getLinksCommonConfig = "config/common_config/get_links"
compileCommonConfigs = "config/common_config/compile"
) )
+27 -5
View File
@@ -104,13 +104,35 @@ func (c *configClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig
} }
} }
func (c *configClient) DeleteCommonConfig(req []string) (int, error) { func (c *configClient) DeleteCommonConfig(id string) (*Deleted, error) {
response := new(deleted) request := identityRequest{Id: id}
err := c.cli.Invoke(deleteCommonConfig, callerId, req, response, backend.WithMetadata(c.headers)) response := new(Deleted)
err := c.cli.Invoke(deleteCommonConfig, callerId, request, response, backend.WithMetadata(c.headers))
if err != nil { if err != nil {
return 0, c.errorHandler(err) return nil, c.errorHandler(err)
} else { } else {
return response.Deleted, nil return response, nil
}
}
func (c *configClient) GetLinksCommonConfig(id string) (*Links, error) {
request := identityRequest{Id: id}
response := new(Links)
err := c.cli.Invoke(getLinksCommonConfig, callerId, request, response, backend.WithMetadata(c.headers))
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
}
}
func (c *configClient) CompileCommonConfigs(request CompileConfigs) (map[string]interface{}, error) {
response := make(map[string]interface{})
err := c.cli.Invoke(compileCommonConfigs, callerId, request, &response, backend.WithMetadata(c.headers))
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
} }
} }
+1
View File
@@ -19,6 +19,7 @@ func CommonConfig() cli.Command {
commonConfig.Remove(), commonConfig.Remove(),
commonConfig.Link(), commonConfig.Link(),
commonConfig.UnLink(), commonConfig.UnLink(),
commonConfig.Contain(),
}, },
} }
} }
+57
View File
@@ -0,0 +1,57 @@
package commonConfig
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Contain() cli.Command {
return cli.Command{
Name: "contain",
Usage: "availability common configuration in module",
Action: contain.action,
BashComplete: bash.CommonConfig.ConfigName,
}
}
var contain containCommand
type containCommand struct{}
func (g containCommand) action(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
}
ccName := ctx.Args().First()
if ccName == "" {
utils.PrintError(errors.New("empty common config name"))
return
}
commonConfigs, err := service.Config.GetMapCommonConfigByName()
if err != nil {
utils.PrintError(err)
return
}
config, ok := commonConfigs[ccName]
if !ok {
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return
}
links, err := service.Config.GetLinksCommonConfig(config.Id)
if err != nil {
utils.PrintError(err)
} else {
fmt.Printf("%v\n", links)
}
}
+2 -2
View File
@@ -16,7 +16,7 @@ func Delete() cli.Command {
Name: "delete", Name: "delete",
Usage: "set common configurations", Usage: "set common configurations",
Action: deleteComm.action, Action: deleteComm.action,
BashComplete: bash.CommonConfig.GetSetDelete, BashComplete: bash.CommonConfig.ConfigName_ConfigData,
} }
} }
@@ -52,7 +52,7 @@ func (g deleteCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[ccName] config, ok := commonConfigs[ccName]
if !ok { if !ok {
utils.PrintError(errors.Errorf("common config %s not found", ccName)) utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return return
} }
+2 -2
View File
@@ -16,7 +16,7 @@ func Get() cli.Command {
Name: "get", Name: "get",
Usage: "get common configurations", Usage: "get common configurations",
Action: get.action, Action: get.action,
BashComplete: bash.CommonConfig.GetSetDelete, BashComplete: bash.CommonConfig.ConfigName_ConfigData,
} }
} }
@@ -55,7 +55,7 @@ func (g getCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[ccName] config, ok := commonConfigs[ccName]
if !ok { if !ok {
utils.PrintError(errors.Errorf("common config %s not found", ccName)) utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return return
} }
+3 -3
View File
@@ -15,7 +15,7 @@ func Link() cli.Command {
Name: "link", Name: "link",
Usage: "link common configurations to module configuration", Usage: "link common configurations to module configuration",
Action: link.action, Action: link.action,
BashComplete: bash.CommonConfig.LinkUnlink, BashComplete: bash.CommonConfig.ConfigName_ModuleName,
} }
} }
@@ -50,11 +50,11 @@ func (g linkCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[configName] config, ok := commonConfigs[configName]
if !ok { if !ok {
utils.PrintError(errors.Errorf("common config %s not found", configName)) utils.PrintError(errors.Errorf("common config [%s] not found", configName))
return return
} }
moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
utils.PrintError(err) utils.PrintError(err)
return return
+9 -4
View File
@@ -15,7 +15,7 @@ func Remove() cli.Command {
Name: "remove", Name: "remove",
Usage: "remove common configurations", Usage: "remove common configurations",
Action: remove.action, Action: remove.action,
BashComplete: bash.CommonConfig.Remove, BashComplete: bash.CommonConfig.ConfigName,
} }
} }
@@ -44,13 +44,18 @@ func (g removeCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[ccName] config, ok := commonConfigs[ccName]
if !ok { if !ok {
utils.PrintError(errors.Errorf("common config %s not found", ccName)) utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return return
} }
if deleted, err := service.Config.DeleteCommonConfig(config.Id); err != nil { links, deleted, err := service.Config.DeleteCommonConfig(config.Id)
if err != nil {
utils.PrintError(err) utils.PrintError(err)
return
}
if deleted {
fmt.Printf("config [%s] deleted", config.Name)
} else { } else {
fmt.Printf("count deleted config: %d\n", deleted) fmt.Printf("config [%s] not deleted, need unlink in next modules:\n%v\n", config.Name, links)
} }
} }
+1 -1
View File
@@ -19,7 +19,7 @@ func Set() cli.Command {
Name: "set", Name: "set",
Usage: "set common configurations", Usage: "set common configurations",
Action: set.action, Action: set.action,
BashComplete: bash.CommonConfig.GetSetDelete, BashComplete: bash.CommonConfig.ConfigName_ConfigData,
} }
} }
+3 -3
View File
@@ -15,7 +15,7 @@ func UnLink() cli.Command {
Name: "unlink", Name: "unlink",
Usage: "unlink common configurations from module configuration", Usage: "unlink common configurations from module configuration",
Action: unlink.action, Action: unlink.action,
BashComplete: bash.CommonConfig.LinkUnlink, BashComplete: bash.CommonConfig.ConfigName_ModuleName,
} }
} }
@@ -50,11 +50,11 @@ func (g unlinkCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[configName] config, ok := commonConfigs[configName]
if !ok { if !ok {
utils.PrintError(errors.Errorf("common config %s not found", configName)) utils.PrintError(errors.Errorf("common config [%s] not found", configName))
return return
} }
moduleConfig, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) moduleConfig, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
utils.PrintError(err) utils.PrintError(err)
return return
+9 -2
View File
@@ -1,6 +1,7 @@
package command package command
import ( import (
"encoding/json"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/tidwall/sjson" "github.com/tidwall/sjson"
"isp-ctl/bash" "isp-ctl/bash"
@@ -14,7 +15,7 @@ func Delete() cli.Command {
Name: "delete", Name: "delete",
Usage: "delete configuration by module_name", Usage: "delete configuration by module_name",
Action: deleteComm.action, Action: deleteComm.action,
BashComplete: bash.Module.GetSetDelete, BashComplete: bash.Module.ModuleName_ModuleData,
} }
} }
@@ -30,7 +31,7 @@ func (d deleteCommand) action(ctx *cli.Context) {
moduleName := ctx.Args().First() moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1) pathObject := ctx.Args().Get(1)
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
utils.PrintError(err) utils.PrintError(err)
return return
@@ -45,6 +46,12 @@ func (d deleteCommand) action(ctx *cli.Context) {
if pathObject == "" { if pathObject == "" {
utils.CreateUpdateConfig("", moduleConfiguration) utils.CreateUpdateConfig("", moduleConfiguration)
} else { } else {
jsonObject, err := json.Marshal(moduleConfiguration.Data)
if err != nil {
utils.PrintError(err)
return
}
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil { if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
utils.PrintError(err) utils.PrintError(err)
return return
+20 -3
View File
@@ -1,6 +1,7 @@
package command package command
import ( import (
"encoding/json"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"isp-ctl/bash" "isp-ctl/bash"
"isp-ctl/command/utils" "isp-ctl/command/utils"
@@ -13,7 +14,10 @@ func Get() cli.Command {
Name: "get", Name: "get",
Usage: "get configuration by module_name", Usage: "get configuration by module_name",
Action: get.action, Action: get.action,
BashComplete: bash.Module.GetSetDelete, BashComplete: bash.Module.ModuleName_ModuleData,
Flags: []cli.Flag{
flag.WithCommonConfig,
},
} }
} }
@@ -29,12 +33,20 @@ func (g getCommand) action(ctx *cli.Context) {
moduleName := ctx.Args().First() moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1) pathObject := ctx.Args().Get(1)
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) config, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
utils.PrintError(err) utils.PrintError(err)
return return
} }
data := config.Data
if ctx.Bool(flag.WithCommonConfig.Name) {
if data, err = service.Config.CompileDataWithCommonConfigs(data, config.CommonConfigs); err != nil {
utils.PrintError(err)
return
}
}
pathObject, err = utils.CheckPath(pathObject) pathObject, err = utils.CheckPath(pathObject)
if err != nil { if err != nil {
utils.PrintError(err) utils.PrintError(err)
@@ -42,8 +54,13 @@ func (g getCommand) action(ctx *cli.Context) {
} }
if pathObject == "" { if pathObject == "" {
utils.PrintAnswer(moduleConfiguration.Data) utils.PrintAnswer(data)
} else { } else {
jsonObject, err := json.Marshal(data)
if err != nil {
utils.PrintError(err)
return
}
utils.CheckObject(jsonObject, pathObject) utils.CheckObject(jsonObject, pathObject)
} }
} }
+3 -3
View File
@@ -20,7 +20,7 @@ func Schema() cli.Command {
Flags: []cli.Flag{ Flags: []cli.Flag{
flag.OutPrint, flag.OutPrint,
}, },
BashComplete: bash.Module.Schema, BashComplete: bash.Module.ModuleName,
} }
} }
@@ -46,13 +46,13 @@ func (s schemaCommand) action(ctx *cli.Context) {
s.printHtml(schema) s.printHtml(schema)
default: default:
utils.PrintError(errors.Errorf( utils.PrintError(errors.Errorf(
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue)) "invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
} }
} }
} }
func (s schemaCommand) getSchemaConfig(moduleName string) interface{} { func (s schemaCommand) getSchemaConfig(moduleName string) interface{} {
if configuration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName); err != nil { if configuration, err := service.Config.GetConfigurationByModuleName(moduleName); err != nil {
utils.PrintError(err) utils.PrintError(err)
return nil return nil
} else if schema, err := service.Config.GetSchemaByModuleId(configuration.ModuleId); err != nil { } else if schema, err := service.Config.GetSchemaByModuleId(configuration.ModuleId); err != nil {
+9 -2
View File
@@ -1,6 +1,7 @@
package command package command
import ( import (
"encoding/json"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/tidwall/sjson" "github.com/tidwall/sjson"
@@ -17,7 +18,7 @@ func Set() cli.Command {
Name: "set", Name: "set",
Usage: "set configuration by module_name", Usage: "set configuration by module_name",
Action: set.action, Action: set.action,
BashComplete: bash.Module.GetSetDelete, BashComplete: bash.Module.ModuleName_ModuleData,
} }
} }
@@ -35,7 +36,7 @@ func (s setCommand) action(ctx *cli.Context) {
pathObject := ctx.Args().Get(1) pathObject := ctx.Args().Get(1)
changeObject := ctx.Args().Get(2) changeObject := ctx.Args().Get(2)
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil { if err != nil {
utils.PrintError(err) utils.PrintError(err)
return return
@@ -64,6 +65,12 @@ func (s setCommand) action(ctx *cli.Context) {
utils.CreateUpdateConfig(changeObject, moduleConfiguration) utils.CreateUpdateConfig(changeObject, moduleConfiguration)
return return
} else { } else {
jsonObject, err := json.Marshal(moduleConfiguration.Data)
if err != nil {
utils.PrintError(err)
return
}
changeArgument := utils.ParseSetObject(changeObject) changeArgument := utils.ParseSetObject(changeObject)
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil { if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
utils.PrintError(err) utils.PrintError(err)
+3
View File
@@ -18,6 +18,9 @@ const (
outPrintName = "o" outPrintName = "o"
OutPrintJsonValue = "json" OutPrintJsonValue = "json"
OutPrintHtmlValue = "html" OutPrintHtmlValue = "html"
withCommonConfigName = "full"
withCommonConfigUsage = "compile data with common configs"
) )
var ( var (
+2 -1
View File
@@ -13,7 +13,8 @@ var (
Color = cli.BoolFlag{Name: colorName, Usage: colorUsage} Color = cli.BoolFlag{Name: colorName, Usage: colorUsage}
Unsafe = cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage} Unsafe = cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
//---local--- //---local---
OutPrint = cli.StringFlag{Name: outPrintName, Usage: outPrintUsage, Value: OutPrintJsonValue} OutPrint = cli.StringFlag{Name: outPrintName, Usage: outPrintUsage, Value: OutPrintJsonValue}
WithCommonConfig = cli.BoolFlag{Name: withCommonConfigName, Usage: withCommonConfigUsage}
) )
func CheckGlobal(c *cli.Context) error { func CheckGlobal(c *cli.Context) error {
+43 -9
View File
@@ -25,23 +25,21 @@ func (c configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
return configClient.GetAvailableConfigs() return configClient.GetAvailableConfigs()
} }
func (c configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cfg.Config, []byte, error) { func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Config, error) {
if moduleName == "" { if moduleName == "" {
return nil, nil, errors.New("need module name") return nil, errors.New("need module name")
} }
if moduleConfiguration, err := configClient.GetConfigByModuleName(moduleName); err != nil { if moduleConfiguration, err := configClient.GetConfigByModuleName(moduleName); err != nil {
if errorStatus, ok := status.FromError(err); ok { if errorStatus, ok := status.FromError(err); ok {
switch errorStatus.Code() { switch errorStatus.Code() {
case codes.NotFound: case codes.NotFound:
return nil, nil, errors.Errorf("module '%s' not found", moduleName) return nil, errors.Errorf("module [%s] not found", moduleName)
} }
} }
return nil, nil, err return nil, err
} else if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil {
return nil, nil, err
} else { } else {
return moduleConfiguration, jsonObject, nil return moduleConfiguration, nil
} }
} }
@@ -112,8 +110,44 @@ func (c configService) CreateUpdateCommonConfig(stringToChange string, config cf
} }
} }
func (c configService) DeleteCommonConfig(configId string) (int, error) { func (c configService) DeleteCommonConfig(configId string) ([]string, bool, error) {
return configClient.DeleteCommonConfig([]string{configId}) 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) checkSchema(moduleId string, object map[string]interface{}) (bool, error) { func (c configService) checkSchema(moduleId string, object map[string]interface{}) (bool, error) {