diff --git a/controller/api/config.go b/controller/api/config.go
index e2a75bd..a37f0dc 100644
--- a/controller/api/config.go
+++ b/controller/api/config.go
@@ -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` - модуль не найден
`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
+ }
+}
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 770395a..1194966 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -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` - модуль не найден
`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:
diff --git a/domain/request.go b/domain/request.go
index a121ac3..67413c7 100644
--- a/domain/request.go
+++ b/domain/request.go
@@ -29,3 +29,7 @@ type UpdateConfigNameRequest struct {
Id string `validate:"required"`
NewConfigName string `validate:"required"`
}
+
+type SyncConfigRequest struct {
+ ModuleName string `validate:"required"`
+}
diff --git a/routes/routes.go b/routes/routes.go
index 1667ffd..0cfc655 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -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,
diff --git a/service/api/config.go b/service/api/config.go
index 0e85785..e00a7f9 100644
--- a/service/api/config.go
+++ b/service/api/config.go
@@ -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(),