fix(valid config status after update)
This commit is contained in:
1 parent
f752770788
commit
73515e5179
6 files changed
+111
-48
No files matched your search
@@ -87,8 +87,6 @@ func (c *commonConfig) DeleteConfigs(req domain.ConfigIdRequest) (*domain.Delete
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
type CompiledConfig map[string]interface{}
|
||||
|
||||
// CompileConfigs godoc
|
||||
// @Summary Метод компиляции итоговой конфигурации для модулей
|
||||
// @Description Возвращает скомпилированный объект конфигурации
|
||||
@@ -96,9 +94,9 @@ type CompiledConfig map[string]interface{}
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.CompileConfigsRequest true "перечисление идентификаторов общей конфигурации и исхдных конфиг"
|
||||
// @Success 200 {object} CompiledConfig
|
||||
// @Success 200 {object} domain.CompiledConfigResponse
|
||||
// @Router /common_config/compile [POST]
|
||||
func (c *commonConfig) CompileConfigs(req domain.CompileConfigsRequest) CompiledConfig {
|
||||
func (c *commonConfig) CompileConfigs(req domain.CompileConfigsRequest) domain.CompiledConfigResponse {
|
||||
var result map[string]interface{}
|
||||
c.rstore.VisitReadonlyState(func(state state.ReadonlyState) {
|
||||
result = service.ConfigService.CompileConfig(req.Data, state, req.CommonConfigsIdList...)
|
||||
|
||||
@@ -49,13 +49,13 @@ func (c *config) GetActiveConfigByModuleName(request domain.GetByModuleNameReque
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body entity.Config true "объект для сохранения"
|
||||
// @Success 200 {object} entity.Config
|
||||
// @Param body body domain.CreateUpdateConfigRequest true "объект для сохранения"
|
||||
// @Success 200 {object} domain.ConfigModuleInfo
|
||||
// @Failure 404 {object} structure.GrpcError "если конфигурация не найдена"
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /config/create_update_config [POST]
|
||||
func (c *config) CreateUpdateConfig(config domain.CreateUpdateConfigRequest) (*entity.Config, error) {
|
||||
var response domain.CreateUpdateConfigInvalidResponse
|
||||
func (c *config) CreateUpdateConfig(config domain.CreateUpdateConfigRequest) (*domain.ConfigModuleInfo, error) {
|
||||
var response domain.CreateUpdateConfigResponse
|
||||
now := state.GenerateDate()
|
||||
config.CreatedAt = now
|
||||
config.UpdatedAt = now
|
||||
@@ -71,10 +71,10 @@ func (c *config) CreateUpdateConfig(config domain.CreateUpdateConfigRequest) (*e
|
||||
err := PerformSyncApplyWithError(command, "UpsertConfigCommand", &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if response.Valid {
|
||||
} else if response.Config != nil {
|
||||
return response.Config, nil
|
||||
} else {
|
||||
return nil, utils.CreateValidationErrorDetails(codes.InvalidArgument, utils.ValidationError, response.Details)
|
||||
return nil, utils.CreateValidationErrorDetails(codes.InvalidArgument, utils.ValidationError, response.ErrorDetails)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+71
-7
@@ -13,8 +13,10 @@ definitions:
|
||||
type: array
|
||||
data:
|
||||
type: object
|
||||
required:
|
||||
- commonConfigsIdList
|
||||
type: object
|
||||
domain.CompiledConfigResponse:
|
||||
additionalProperties:
|
||||
type: object
|
||||
type: object
|
||||
domain.ConfigIdRequest:
|
||||
properties:
|
||||
@@ -23,6 +25,37 @@ definitions:
|
||||
required:
|
||||
- id
|
||||
type: object
|
||||
domain.ConfigModuleInfo:
|
||||
properties:
|
||||
active:
|
||||
type: boolean
|
||||
commonConfigs:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
createdAt:
|
||||
type: string
|
||||
data:
|
||||
$ref: '#/definitions/entity.ConfigData'
|
||||
type: object
|
||||
description:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
moduleId:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
updatedAt:
|
||||
type: string
|
||||
valid:
|
||||
type: boolean
|
||||
version:
|
||||
type: integer
|
||||
required:
|
||||
- moduleId
|
||||
- name
|
||||
type: object
|
||||
domain.Connection:
|
||||
properties:
|
||||
address:
|
||||
@@ -39,6 +72,37 @@ definitions:
|
||||
version:
|
||||
type: string
|
||||
type: object
|
||||
domain.CreateUpdateConfigRequest:
|
||||
properties:
|
||||
active:
|
||||
type: boolean
|
||||
commonConfigs:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
createdAt:
|
||||
type: string
|
||||
data:
|
||||
$ref: '#/definitions/entity.ConfigData'
|
||||
type: object
|
||||
description:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
moduleId:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
unsafe:
|
||||
type: boolean
|
||||
updatedAt:
|
||||
type: string
|
||||
version:
|
||||
type: integer
|
||||
required:
|
||||
- moduleId
|
||||
- name
|
||||
type: object
|
||||
domain.DeleteCommonConfigResponse:
|
||||
properties:
|
||||
deleted:
|
||||
@@ -75,7 +139,7 @@ definitions:
|
||||
type: object
|
||||
configs:
|
||||
items:
|
||||
$ref: '#/definitions/entity.Config'
|
||||
$ref: '#/definitions/domain.ConfigModuleInfo'
|
||||
type: array
|
||||
createdAt:
|
||||
type: string
|
||||
@@ -590,7 +654,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/CompiledConfig'
|
||||
$ref: '#/definitions/domain.CompiledConfigResponse'
|
||||
summary: Метод компиляции итоговой конфигурации для модулей
|
||||
tags:
|
||||
- Общие конфигурации
|
||||
@@ -623,7 +687,7 @@ paths:
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
summary: Метод обновления оьщей конфигурации
|
||||
summary: Метод обновления общей конфигурации
|
||||
tags:
|
||||
- Общие конфигурации
|
||||
/common_config/delete_config:
|
||||
@@ -708,7 +772,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/entity.Config'
|
||||
$ref: '#/definitions/domain.CreateUpdateConfigRequest'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -716,7 +780,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/entity.Config'
|
||||
$ref: '#/definitions/domain.ConfigModuleInfo'
|
||||
"404":
|
||||
description: если конфигурация не найдена
|
||||
schema:
|
||||
|
||||
+5
-4
@@ -33,15 +33,16 @@ type Connection struct {
|
||||
|
||||
type CommonConfigLinks map[string][]string
|
||||
|
||||
type CompiledConfigResponse map[string]interface{}
|
||||
|
||||
type DeleteCommonConfigResponse struct {
|
||||
Deleted bool
|
||||
Links CommonConfigLinks
|
||||
}
|
||||
|
||||
type CreateUpdateConfigInvalidResponse struct {
|
||||
Valid bool
|
||||
Details map[string]string
|
||||
Config *entity.Config
|
||||
type CreateUpdateConfigResponse struct {
|
||||
ErrorDetails map[string]string
|
||||
Config *ConfigModuleInfo
|
||||
}
|
||||
|
||||
type ConfigModuleInfo struct {
|
||||
|
||||
+5
-5
@@ -13,16 +13,16 @@ type Handlers struct {
|
||||
GetModulesInfo func() ([]domain.ModuleInfo, error) `method:"get_modules_info" group:"module" inner:"true"`
|
||||
|
||||
// ===== CONFIG =====
|
||||
GetActiveConfigByModuleName func(request domain.GetByModuleNameRequest) (*entity.Config, error) `method:"get_active_config_by_module_name" group:"config" inner:"true"`
|
||||
CreateUpdateConfig func(config domain.CreateUpdateConfigRequest) (*entity.Config, 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"`
|
||||
GetActiveConfigByModuleName func(request domain.GetByModuleNameRequest) (*entity.Config, error) `method:"get_active_config_by_module_name" 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"`
|
||||
|
||||
// ===== COMMON CONFIG =====
|
||||
GetCommonConfigs func(identities []string) []entity.CommonConfig `method:"get_configs" group:"common_config" inner:"true"`
|
||||
CreateUpdateCommonConfig func(config entity.CommonConfig) (*entity.CommonConfig, error) `method:"create_update_config" group:"common_config" inner:"true"`
|
||||
DeleteCommonConfig func(req domain.ConfigIdRequest) (*domain.DeleteCommonConfigResponse, error) `method:"delete_config" group:"common_config" inner:"true"`
|
||||
CompileConfigs func(req domain.CompileConfigsRequest) controller.CompiledConfig `method:"compile" group:"common_config" inner:"true"`
|
||||
CompileConfigs func(req domain.CompileConfigsRequest) domain.CompiledConfigResponse `method:"compile" group:"common_config" inner:"true"`
|
||||
GetLinks func(req domain.ConfigIdRequest) domain.CommonConfigLinks `method:"get_links" group:"common_config" inner:"true"`
|
||||
|
||||
// ===== ROUTING =====
|
||||
|
||||
+22
-22
@@ -105,25 +105,23 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon
|
||||
return cluster.NewResponseErrorf(codes2.NotFound, "moduleId %s not found", config.ModuleId)
|
||||
}
|
||||
|
||||
if !upsertConfig.Unsafe {
|
||||
schemaStorage := state.Schemas().GetByModuleIds([]string{config.ModuleId})
|
||||
if len(schemaStorage) == 0 {
|
||||
return cluster.NewResponseErrorf(codes2.NotFound, "schema for moduleId %s not found", config.ModuleId)
|
||||
}
|
||||
schemaStorage := state.Schemas().GetByModuleIds([]string{config.ModuleId})
|
||||
if len(schemaStorage) == 0 {
|
||||
return cluster.NewResponseErrorf(codes2.NotFound, "schema for moduleId %s not found", config.ModuleId)
|
||||
}
|
||||
dataForValidate := cs.CompileConfig(config.Data, state, config.CommonConfigs...)
|
||||
validSchema, err := cs.validateSchema(schemaStorage[0], dataForValidate)
|
||||
|
||||
dataForValidate := cs.CompileConfig(config.Data, state, config.CommonConfigs...)
|
||||
if _, err := cs.validateSchema(schemaStorage[0], dataForValidate); err != nil {
|
||||
switch err := err.(type) {
|
||||
case validationSchemaError:
|
||||
return cluster.NewResponse(
|
||||
domain.CreateUpdateConfigInvalidResponse{
|
||||
Config: nil,
|
||||
Valid: false,
|
||||
Details: err.Description,
|
||||
})
|
||||
default:
|
||||
return cluster.NewResponseErrorf(codes2.Internal, "%v", err)
|
||||
}
|
||||
if !upsertConfig.Unsafe && err != nil {
|
||||
switch err := err.(type) {
|
||||
case validationSchemaError:
|
||||
return cluster.NewResponse(
|
||||
domain.CreateUpdateConfigResponse{
|
||||
Config: nil,
|
||||
ErrorDetails: err.Description,
|
||||
})
|
||||
default:
|
||||
return cluster.NewResponseErrorf(codes2.Internal, "%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,10 +147,12 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon
|
||||
}
|
||||
}
|
||||
cs.BroadcastNewConfig(state, config)
|
||||
return cluster.NewResponse(domain.CreateUpdateConfigInvalidResponse{
|
||||
Config: &config,
|
||||
Valid: true,
|
||||
Details: nil,
|
||||
return cluster.NewResponse(domain.CreateUpdateConfigResponse{
|
||||
Config: &domain.ConfigModuleInfo{
|
||||
Config: config,
|
||||
Valid: validSchema,
|
||||
},
|
||||
ErrorDetails: nil,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user