Validate plugin configuration on PUT and POST
@@ -5,6 +5,8 @@ import (
"fmt"
"net/http"
+ "github.com/hellofresh/janus/pkg/plugin"
+
"github.com/hellofresh/janus/pkg/api"
"github.com/hellofresh/janus/pkg/errors"
"github.com/hellofresh/janus/pkg/opentracing"
@@ -85,6 +87,15 @@ func (c *APIHandler) PutBy() http.HandlerFunc {
return
}
+ // Additionally validate plugin configuration
+ for _, plg := range cfg.Plugins {
+ isValid, err := plugin.ValidateConfig(plg.Name, plg.Config)
+ if !isValid || err != nil {
+ errors.Handler(w, errors.New(http.StatusBadRequest, err.Error()))
+ return
+ }
+ }
+
// avoid situation when trying to update existing definition with new path
// that is already registered with another name
span = opentracing.FromContext(r.Context(), "datastore.FindByListenPath")
@@ -124,6 +135,15 @@ func (c *APIHandler) Post() http.HandlerFunc {
return
}
+ // Additionally validate plugin configuration
+ for _, plg := range cfg.Plugins {
+ isValid, err := plugin.ValidateConfig(plg.Name, plg.Config)
+ if !isValid || err != nil {
+ errors.Handler(w, errors.New(http.StatusBadRequest, err.Error()))
+ return
+ }
+ }
+
span := opentracing.FromContext(r.Context(), "datastore.Exists")
exists, err := c.exists(cfg)
span.Finish()
