diff --git a/engine/api/grpc_plugin.go b/engine/api/grpc_plugin.go index e93be60621..7e29a64f0e 100644 --- a/engine/api/grpc_plugin.go +++ b/engine/api/grpc_plugin.go @@ -26,6 +26,9 @@ func (api *API) postGRPCluginHandler() service.Handler { if err := service.UnmarshalBody(r, &p); err != nil { return sdk.WithStack(err) } + if err := p.Validate(); err != nil { + return sdk.WithStack(err) + } p.Binaries = nil tx, err := db.Begin() @@ -103,6 +106,9 @@ func (api *API) putGRPCluginHandler() service.Handler { if err := service.UnmarshalBody(r, &p); err != nil { return sdk.WithStack(err) } + if err := p.Validate(); err != nil { + return sdk.WithStack(err) + } var name = mux.Vars(r)["name"] old, err := plugin.LoadByName(api.mustDB(), name) diff --git a/sdk/plugin.go b/sdk/plugin.go index d5ccecf7d6..64b2e73231 100644 --- a/sdk/plugin.go +++ b/sdk/plugin.go @@ -19,6 +19,13 @@ type GRPCPlugin struct { Integration string `json:"integration" db:"-" yaml:"integration" cli:"integration"` } +func (p *GRPCPlugin) Validate() error { + if p.Name == "" || p.Type == "" || p.Author == "" || p.Description == "" { + return NewErrorFrom(ErrPluginInvalid, "Invalid plugin: name, type, author and description are mandatory") + } + return nil +} + // GetBinary returns the binary for a specific os and arch func (p GRPCPlugin) GetBinary(os, arch string) *GRPCPluginBinary { for _, b := range p.Binaries {