From 8b8815d2f2995bfc8cd7d0c593d5a3ef96c9c914 Mon Sep 17 00:00:00 2001 From: DeniskaRediska Date: Wed, 30 Oct 2019 14:58:50 +0300 Subject: [PATCH] add 'contain' command for common configs add flag 'full' for 'get' command update bash complete --- README.md | 137 ++++++++++++++++++++++++++++++-- bash/common_config.go | 6 +- bash/module.go | 7 +- cfg/domain.go | 16 +++- cfg/method_name.go | 2 + cfg/methods.go | 32 ++++++-- command/common.go | 1 + command/commonConfig/contain.go | 57 +++++++++++++ command/commonConfig/delete.go | 4 +- command/commonConfig/get.go | 4 +- command/commonConfig/link.go | 6 +- command/commonConfig/remove.go | 13 ++- command/commonConfig/set.go | 2 +- command/commonConfig/unlink.go | 6 +- command/delete.go | 11 ++- command/get.go | 23 +++++- command/schema.go | 6 +- command/set.go | 11 ++- flag/description.go | 3 + flag/structure.go | 3 +- service/config.go | 52 +++++++++--- 21 files changed, 348 insertions(+), 54 deletions(-) create mode 100644 command/commonConfig/contain.go diff --git a/README.md b/README.md index b8bc2aa..cb3e70f 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,13 @@ instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ## Использование ```bash 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...] delete module_name property_path ispctl [flag...] schema module_name [local_flag] +ispctl [flag...] common sub_command ``` + ## Описание | Команды | Описание | @@ -39,6 +41,7 @@ ispctl [flag...] schema module_name [local_flag] | `set` | изменяет объект конфигурации указанного модуля | | `delete` | удаляет объект конфигурации указанного модуля | | `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` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля | | `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin | | | | -| Локальные флаги | Параметры | Описание | -|-----------------|-----------|--------------------------------------------------------------------------------------------------| -| `-o` | string | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` | -| | | | ## Пример ### 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] +``` ### Запрос с флагами Запрос diff --git a/bash/common_config.go b/bash/common_config.go index 2bb43ee..bb31dea 100644 --- a/bash/common_config.go +++ b/bash/common_config.go @@ -12,7 +12,7 @@ var CommonConfig commonConfig type commonConfig struct{} -func (commonConfig) LinkUnlink(ctx *cli.Context) { +func (commonConfig) ConfigName_ModuleName(ctx *cli.Context) { if err := flag.CheckGlobal(ctx); err != nil { 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 { 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 { return } diff --git a/bash/module.go b/bash/module.go index cfac811..64f088a 100644 --- a/bash/module.go +++ b/bash/module.go @@ -12,7 +12,7 @@ var Module module type module struct{} -func (module) GetSetDelete(ctx *cli.Context) { +func (module) ModuleName_ModuleData(ctx *cli.Context) { if err := flag.CheckGlobal(ctx); err != nil { return } @@ -26,7 +26,8 @@ func (module) GetSetDelete(ctx *cli.Context) { } } 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 } else { 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 { return } diff --git a/cfg/domain.go b/cfg/domain.go index a1fd25d..4702fe0 100644 --- a/cfg/domain.go +++ b/cfg/domain.go @@ -66,6 +66,18 @@ type ConfigSchema struct { UpdatedAt time.Time } -type deleted struct { - Deleted int +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 index 3de4830..730a1ad 100644 --- a/cfg/method_name.go +++ b/cfg/method_name.go @@ -8,4 +8,6 @@ const ( 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 index 078cfbc..7f4f0b0 100644 --- a/cfg/methods.go +++ b/cfg/methods.go @@ -104,13 +104,35 @@ func (c *configClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig } } -func (c *configClient) DeleteCommonConfig(req []string) (int, error) { - response := new(deleted) - err := c.cli.Invoke(deleteCommonConfig, callerId, req, response, backend.WithMetadata(c.headers)) +func (c *configClient) DeleteCommonConfig(id string) (*Deleted, error) { + request := identityRequest{Id: id} + response := new(Deleted) + err := c.cli.Invoke(deleteCommonConfig, callerId, request, response, backend.WithMetadata(c.headers)) if err != nil { - return 0, c.errorHandler(err) + return nil, c.errorHandler(err) } 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 } } diff --git a/command/common.go b/command/common.go index 0a98384..f20c8b2 100644 --- a/command/common.go +++ b/command/common.go @@ -19,6 +19,7 @@ func CommonConfig() cli.Command { commonConfig.Remove(), commonConfig.Link(), commonConfig.UnLink(), + commonConfig.Contain(), }, } } diff --git a/command/commonConfig/contain.go b/command/commonConfig/contain.go new file mode 100644 index 0000000..4054157 --- /dev/null +++ b/command/commonConfig/contain.go @@ -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) + } +} diff --git a/command/commonConfig/delete.go b/command/commonConfig/delete.go index 054aaea..bd4eaf3 100644 --- a/command/commonConfig/delete.go +++ b/command/commonConfig/delete.go @@ -16,7 +16,7 @@ func Delete() cli.Command { Name: "delete", Usage: "set common configurations", 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] if !ok { - utils.PrintError(errors.Errorf("common config %s not found", ccName)) + utils.PrintError(errors.Errorf("common config [%s] not found", ccName)) return } diff --git a/command/commonConfig/get.go b/command/commonConfig/get.go index 2b3eb3b..0c1f264 100644 --- a/command/commonConfig/get.go +++ b/command/commonConfig/get.go @@ -16,7 +16,7 @@ func Get() cli.Command { Name: "get", Usage: "get common configurations", 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] if !ok { - utils.PrintError(errors.Errorf("common config %s not found", ccName)) + utils.PrintError(errors.Errorf("common config [%s] not found", ccName)) return } diff --git a/command/commonConfig/link.go b/command/commonConfig/link.go index a30ed53..869e879 100644 --- a/command/commonConfig/link.go +++ b/command/commonConfig/link.go @@ -15,7 +15,7 @@ func Link() cli.Command { Name: "link", Usage: "link common configurations to module configuration", 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] if !ok { - utils.PrintError(errors.Errorf("common config %s not found", configName)) + utils.PrintError(errors.Errorf("common config [%s] not found", configName)) return } - moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) + moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName) if err != nil { utils.PrintError(err) return diff --git a/command/commonConfig/remove.go b/command/commonConfig/remove.go index c9d24b6..3f7e288 100644 --- a/command/commonConfig/remove.go +++ b/command/commonConfig/remove.go @@ -15,7 +15,7 @@ func Remove() cli.Command { Name: "remove", Usage: "remove common configurations", 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] if !ok { - utils.PrintError(errors.Errorf("common config %s not found", ccName)) + utils.PrintError(errors.Errorf("common config [%s] not found", ccName)) 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) + return + } + if deleted { + fmt.Printf("config [%s] deleted", config.Name) } 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) } } diff --git a/command/commonConfig/set.go b/command/commonConfig/set.go index 4e35ed8..c3a544b 100644 --- a/command/commonConfig/set.go +++ b/command/commonConfig/set.go @@ -19,7 +19,7 @@ func Set() cli.Command { Name: "set", Usage: "set common configurations", Action: set.action, - BashComplete: bash.CommonConfig.GetSetDelete, + BashComplete: bash.CommonConfig.ConfigName_ConfigData, } } diff --git a/command/commonConfig/unlink.go b/command/commonConfig/unlink.go index 9c2a4e3..d3977c6 100644 --- a/command/commonConfig/unlink.go +++ b/command/commonConfig/unlink.go @@ -15,7 +15,7 @@ func UnLink() cli.Command { Name: "unlink", Usage: "unlink common configurations from module configuration", 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] if !ok { - utils.PrintError(errors.Errorf("common config %s not found", configName)) + utils.PrintError(errors.Errorf("common config [%s] not found", configName)) return } - moduleConfig, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) + moduleConfig, err := service.Config.GetConfigurationByModuleName(moduleName) if err != nil { utils.PrintError(err) return diff --git a/command/delete.go b/command/delete.go index 3071682..d488260 100644 --- a/command/delete.go +++ b/command/delete.go @@ -1,6 +1,7 @@ package command import ( + "encoding/json" "github.com/codegangsta/cli" "github.com/tidwall/sjson" "isp-ctl/bash" @@ -14,7 +15,7 @@ func Delete() cli.Command { Name: "delete", Usage: "delete configuration by module_name", 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() pathObject := ctx.Args().Get(1) - moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) + moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName) if err != nil { utils.PrintError(err) return @@ -45,6 +46,12 @@ func (d deleteCommand) action(ctx *cli.Context) { if pathObject == "" { utils.CreateUpdateConfig("", moduleConfiguration) } else { + jsonObject, err := json.Marshal(moduleConfiguration.Data) + if err != nil { + utils.PrintError(err) + return + } + if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil { utils.PrintError(err) return diff --git a/command/get.go b/command/get.go index d8dcf09..d14d9ac 100644 --- a/command/get.go +++ b/command/get.go @@ -1,6 +1,7 @@ package command import ( + "encoding/json" "github.com/codegangsta/cli" "isp-ctl/bash" "isp-ctl/command/utils" @@ -13,7 +14,10 @@ func Get() cli.Command { Name: "get", Usage: "get configuration by module_name", 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() pathObject := ctx.Args().Get(1) - moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) + config, err := service.Config.GetConfigurationByModuleName(moduleName) if err != nil { utils.PrintError(err) 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) if err != nil { utils.PrintError(err) @@ -42,8 +54,13 @@ func (g getCommand) action(ctx *cli.Context) { } if pathObject == "" { - utils.PrintAnswer(moduleConfiguration.Data) + utils.PrintAnswer(data) } else { + jsonObject, err := json.Marshal(data) + if err != nil { + utils.PrintError(err) + return + } utils.CheckObject(jsonObject, pathObject) } } diff --git a/command/schema.go b/command/schema.go index 7f4b91c..0c3f3d1 100644 --- a/command/schema.go +++ b/command/schema.go @@ -20,7 +20,7 @@ func Schema() cli.Command { Flags: []cli.Flag{ flag.OutPrint, }, - BashComplete: bash.Module.Schema, + BashComplete: bash.Module.ModuleName, } } @@ -46,13 +46,13 @@ func (s schemaCommand) action(ctx *cli.Context) { s.printHtml(schema) default: 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{} { - if configuration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName); err != nil { + 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 { diff --git a/command/set.go b/command/set.go index 9367840..e7cdd2c 100644 --- a/command/set.go +++ b/command/set.go @@ -1,6 +1,7 @@ package command import ( + "encoding/json" "github.com/codegangsta/cli" "github.com/pkg/errors" "github.com/tidwall/sjson" @@ -17,7 +18,7 @@ func Set() cli.Command { Name: "set", Usage: "set configuration by module_name", 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) changeObject := ctx.Args().Get(2) - moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName) + moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName) if err != nil { utils.PrintError(err) return @@ -64,6 +65,12 @@ func (s setCommand) action(ctx *cli.Context) { utils.CreateUpdateConfig(changeObject, moduleConfiguration) return } else { + jsonObject, err := json.Marshal(moduleConfiguration.Data) + if err != nil { + utils.PrintError(err) + return + } + changeArgument := utils.ParseSetObject(changeObject) if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil { utils.PrintError(err) diff --git a/flag/description.go b/flag/description.go index 85a792d..5330fbd 100644 --- a/flag/description.go +++ b/flag/description.go @@ -18,6 +18,9 @@ const ( outPrintName = "o" OutPrintJsonValue = "json" OutPrintHtmlValue = "html" + + withCommonConfigName = "full" + withCommonConfigUsage = "compile data with common configs" ) var ( diff --git a/flag/structure.go b/flag/structure.go index 0dbeab2..f13e081 100644 --- a/flag/structure.go +++ b/flag/structure.go @@ -13,7 +13,8 @@ var ( Color = cli.BoolFlag{Name: colorName, Usage: colorUsage} Unsafe = cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage} //---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 { diff --git a/service/config.go b/service/config.go index 79294bb..bfeae1e 100644 --- a/service/config.go +++ b/service/config.go @@ -25,23 +25,21 @@ func (c configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) { return configClient.GetAvailableConfigs() } -func (c configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cfg.Config, []byte, error) { +func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Config, error) { 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 errorStatus, ok := status.FromError(err); ok { switch errorStatus.Code() { 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 - } else if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil { - return nil, nil, err + return nil, err } 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) { - return configClient.DeleteCommonConfig([]string{configId}) +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) checkSchema(moduleId string, object map[string]interface{}) (bool, error) {