MSP-5223 add endpoint /config/config/sync_config
This commit is contained in:
1 parent
a483722e1d
commit
1d3bacd22c
5 files changed
+92
No files matched your search
@@ -21,6 +21,7 @@ type ConfigService interface {
|
||||
MarkConfigAsActive(ctx context.Context, configId string) error
|
||||
DeleteConfig(ctx context.Context, id string) error
|
||||
UpdateConfigName(ctx context.Context, req domain.UpdateConfigNameRequest) error
|
||||
SyncConfig(ctx context.Context, moduleName string) error
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@@ -262,3 +263,30 @@ func (c Config) UpdateConfigName(ctx context.Context, req domain.UpdateConfigNam
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// SyncConfig
|
||||
// @Summary Метод синхронизации актуальной конфигурации пришедешего модуля
|
||||
// @Description Метод синхронизации актуальной конфигурации пришедешего модуля
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.SyncConfigRequest true "название модуля"
|
||||
// @Success 200 {object} domain.Config
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2001` - модуль не найден<br/>`errorCode: 2002` - конфиг не найден"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/sync_config [POST]
|
||||
func (c Config) SyncConfig(ctx context.Context, req domain.SyncConfigRequest) error {
|
||||
err := c.service.SyncConfig(ctx, req.ModuleName)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrModuleNotFound):
|
||||
return apierrors.NewBusinessError(
|
||||
domain.ErrorCodeModuleNotFound,
|
||||
"module not found",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,13 @@ definitions:
|
||||
$ref: '#/definitions/domain.Connection'
|
||||
type: array
|
||||
type: object
|
||||
domain.SyncConfigRequest:
|
||||
properties:
|
||||
moduleName:
|
||||
type: string
|
||||
required:
|
||||
- moduleName
|
||||
type: object
|
||||
domain.UpdateConfigNameRequest:
|
||||
properties:
|
||||
id:
|
||||
@@ -508,6 +515,37 @@ paths:
|
||||
summary: Метод активации конфигурации для модуля
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/sync_config:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Метод синхронизации актуальной конфигурации пришедешего модуля
|
||||
parameters:
|
||||
- description: название модуля
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SyncConfigRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Config'
|
||||
"400":
|
||||
description: '`errorCode: 2001` - модуль не найден<br/>`errorCode: 2002`
|
||||
- конфиг не найден'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод синхронизации актуальной конфигурации пришедешего модуля
|
||||
tags:
|
||||
- Конфигурация
|
||||
/config/update_config_name:
|
||||
post:
|
||||
consumes:
|
||||
|
||||
@@ -29,3 +29,7 @@ type UpdateConfigNameRequest struct {
|
||||
Id string `validate:"required"`
|
||||
NewConfigName string `validate:"required"`
|
||||
}
|
||||
|
||||
type SyncConfigRequest struct {
|
||||
ModuleName string `validate:"required"`
|
||||
}
|
||||
@@ -110,6 +110,10 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||
Path: "config/config/delete_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.DeleteConfigs,
|
||||
}, {
|
||||
Path: "config/config/sync_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.SyncConfig,
|
||||
}, {
|
||||
Path: "config/config/get_all_version",
|
||||
Inner: true,
|
||||
|
||||
@@ -263,6 +263,24 @@ func (c Config) UpdateConfigName(ctx context.Context, req domain.UpdateConfigNam
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) SyncConfig(ctx context.Context, moduleName string) error {
|
||||
modules, err := c.moduleRepo.GetByNames(ctx, []string{moduleName})
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "get config by module name")
|
||||
}
|
||||
if len(modules) == 0 {
|
||||
return entity.ErrModuleNotFound
|
||||
}
|
||||
|
||||
moduleId := modules[0].Id
|
||||
err = c.emitChangeActiveConfigEvent(ctx, moduleId)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "emit change active config event")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) insertNewConfig(ctx context.Context, adminId int, req domain.CreateUpdateConfigRequest) (*domain.Config, error) {
|
||||
config := entity.Config{
|
||||
Id: uuid.NewString(),
|
||||
|
||||
Reference in new issue
Block a user