Merge branch 'api_ext_branch' into 'master'
add valid property to method `/config/get_configs_by_module_id` See merge request integration-system/isp-config-service!6
This commit is contained in:
commit
08b4ee461e
8 files changed
+38
-12
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v2.4.1
|
||||
* updated method `/config/get_configs_by_module_id`
|
||||
### v2.4.0
|
||||
* add method `/config/get_config_by_id`
|
||||
* add method `/config/get_configs_by_module_id`
|
||||
|
||||
+16
-4
@@ -9,6 +9,7 @@ import (
|
||||
"isp-config-service/cluster"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/service"
|
||||
"isp-config-service/store"
|
||||
"isp-config-service/store/state"
|
||||
)
|
||||
@@ -55,22 +56,33 @@ func (c *config) GetActiveConfigByModuleName(request domain.GetByModuleNameReque
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.GetByModuleIdRequest true "ID модуля"
|
||||
// @Success 200 {array} entity.Config
|
||||
// @Success 200 {array} domain.ConfigModuleInfo
|
||||
// @Failure 400 {object} structure.GrpcError "если идентификатор не указан"
|
||||
// @Failure 404 {object} structure.GrpcError "если конфигурация не найдена"
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /config/get_configs_by_module_id [POST]
|
||||
func (c *config) GetConfigsByModuleId(request domain.GetByModuleIdRequest) ([]entity.Config, error) {
|
||||
func (c *config) GetConfigsByModuleId(request domain.GetByModuleIdRequest) ([]domain.ConfigModuleInfo, error) {
|
||||
var config []entity.Config
|
||||
var configInfo []domain.ConfigModuleInfo
|
||||
|
||||
c.rstore.VisitReadonlyState(func(state state.ReadonlyState) {
|
||||
config = state.Configs().GetByModuleIds([]string{request.ModuleId})
|
||||
if len(config) == 0 {
|
||||
return
|
||||
}
|
||||
for _, value := range config {
|
||||
configInfo = append(configInfo, domain.ConfigModuleInfo{
|
||||
Config: value,
|
||||
Valid: service.ModuleRegistry.ValidateConfig(value, state),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if config == nil {
|
||||
if len(configInfo) == 0 {
|
||||
return nil, status.Errorf(codes.NotFound, "configs for module '%s' not found", request.ModuleId)
|
||||
}
|
||||
return config, nil
|
||||
|
||||
return configInfo, nil
|
||||
}
|
||||
|
||||
// @Summary Метод обновления конфигурации
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2020-09-24 15:55:28.673938535 +0300 MSK m=+35.674145313
|
||||
// 2020-09-28 13:28:03.40325566 +0300 MSK m=+35.454929207
|
||||
|
||||
package docs
|
||||
|
||||
@@ -515,7 +515,7 @@ var doc = `{
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.Config"
|
||||
"$ref": "#/definitions/domain.ConfigModuleInfo"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1684,7 +1684,7 @@ var doc = `{
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = docs.SwaggerInfo{
|
||||
Version: "2.3.2",
|
||||
Version: "2.4.1",
|
||||
Host: "localhost:9003",
|
||||
BasePath: "/api/config",
|
||||
Schemes: []string{},
|
||||
|
||||
+2
-2
@@ -605,7 +605,7 @@ info:
|
||||
license:
|
||||
name: GNU GPL v3.0
|
||||
title: ISP configuration service
|
||||
version: 2.3.2
|
||||
version: 2.4.1
|
||||
paths:
|
||||
/common_config/compile:
|
||||
post:
|
||||
@@ -931,7 +931,7 @@ paths:
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/entity.Config'
|
||||
$ref: '#/definitions/domain.ConfigModuleInfo'
|
||||
type: array
|
||||
"400":
|
||||
description: если идентификатор не указан
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ type Handlers struct {
|
||||
|
||||
// ===== CONFIG =====
|
||||
GetActiveConfigByModuleName func(request domain.GetByModuleNameRequest) (*entity.Config, error) `method:"get_active_config_by_module_name" group:"config" inner:"true"`
|
||||
GetConfigsByModuleId func(request domain.GetByModuleIdRequest) ([]entity.Config, error) `method:"get_configs_by_module_id" group:"config" inner:"true"`
|
||||
GetConfigsByModuleId func(request domain.GetByModuleIdRequest) ([]domain.ConfigModuleInfo, error) `method:"get_configs_by_module_id" group:"config" inner:"true"`
|
||||
CreateUpdateConfig func(config domain.CreateUpdateConfigRequest) (*domain.ConfigModuleInfo, error) `method:"create_update_config" group:"config" inner:"true"`
|
||||
MarkConfigAsActive func(identity domain.ConfigIdRequest) (*entity.Config, error) `method:"mark_config_as_active" group:"config" inner:"true"`
|
||||
DeleteConfig func(identities []string) (*domain.DeleteResponse, error) `method:"delete_config" group:"config" inner:"true"`
|
||||
|
||||
@@ -51,7 +51,7 @@ func init() {
|
||||
}
|
||||
|
||||
// @title ISP configuration service
|
||||
// @version 2.4.0
|
||||
// @version 2.4.1
|
||||
// @description Сервис управления конфигурацией модулей ISP кластера
|
||||
|
||||
// @license.name GNU GPL v3.0
|
||||
|
||||
@@ -104,6 +104,18 @@ func (moduleRegistryService) HandleDeleteModulesCommand(deleteModules cluster.De
|
||||
return len(deletedModules)
|
||||
}
|
||||
|
||||
func (moduleRegistryService) ValidateConfig(config entity.Config, state state.ReadonlyState) bool {
|
||||
schemas := state.Schemas().GetByModuleIds([]string{config.ModuleId})
|
||||
valid := false
|
||||
|
||||
for _, s := range schemas {
|
||||
dataForValidate := ConfigService.CompileConfig(config.Data, state, config.CommonConfigs...)
|
||||
valid, _ = ConfigService.validateSchema(s, dataForValidate)
|
||||
}
|
||||
|
||||
return valid
|
||||
}
|
||||
|
||||
//nolint:funlen
|
||||
func (moduleRegistryService) GetAggregatedModuleInfo(state state.ReadonlyState) []domain.ModuleInfo {
|
||||
modules := state.Modules().GetAll()
|
||||
|
||||
Reference in new issue
Block a user