Skip to content

Commit

Permalink
feat(api): validate yml plugin before import it (#5378)
Browse files Browse the repository at this point in the history
* feat(api): validate yml plugin before import it

close #5329

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault committed Aug 18, 2020
1 parent 7cf81cc commit 6beace0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions engine/api/grpc_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions sdk/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6beace0

Please sign in to comment.