UpdateConfig updates Configurer plugin configuration in YAML format. swagger:operation POST /plugin/{id}/config plugin updatePluginConfig Update YAML configuration for Configurer plugin. --- consumes: [application/x-yaml] produces: [application/json] parameters: - name: id in: path desc
(ctx *gin.Context)
| 365 | // schema: |
| 366 | // $ref: "#/definitions/Error" |
| 367 | func (c *PluginAPI) UpdateConfig(ctx *gin.Context) { |
| 368 | withID(ctx, "id", func(id uint) { |
| 369 | conf, err := c.DB.GetPluginConfByID(id) |
| 370 | if success := successOrAbort(ctx, 500, err); !success { |
| 371 | return |
| 372 | } |
| 373 | if conf == nil || !isPluginOwner(ctx, conf) { |
| 374 | ctx.AbortWithError(404, errors.New("unknown plugin")) |
| 375 | return |
| 376 | } |
| 377 | instance, err := c.Manager.Instance(id) |
| 378 | if err != nil { |
| 379 | ctx.AbortWithError(404, errors.New("plugin instance not found")) |
| 380 | return |
| 381 | } |
| 382 | |
| 383 | if aborted := supportOrAbort(ctx, instance, compat.Configurer); aborted { |
| 384 | return |
| 385 | } |
| 386 | |
| 387 | newConf := instance.DefaultConfig() |
| 388 | newconfBytes, err := io.ReadAll(ctx.Request.Body) |
| 389 | if err != nil { |
| 390 | ctx.AbortWithError(500, err) |
| 391 | return |
| 392 | } |
| 393 | if err := yaml.Unmarshal(newconfBytes, newConf); err != nil { |
| 394 | ctx.AbortWithError(400, err) |
| 395 | return |
| 396 | } |
| 397 | if err := instance.ValidateAndSetConfig(newConf); err != nil { |
| 398 | ctx.AbortWithError(400, err) |
| 399 | return |
| 400 | } |
| 401 | conf.Config = newconfBytes |
| 402 | successOrAbort(ctx, 500, c.DB.UpdatePluginConf(conf)) |
| 403 | }) |
| 404 | } |
| 405 | |
| 406 | func isPluginOwner(ctx *gin.Context, conf *model.PluginConf) bool { |
| 407 | return conf.UserID == auth.GetUserID(ctx) |