Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Add check plugin type as integer
Browse files Browse the repository at this point in the history
  • Loading branch information
janczer committed Apr 11, 2017
1 parent 74b20af commit cb0164e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ func ToPluginType(name string) (PluginType, error) {
return t, nil
}

func CheckPluginType(id PluginType) bool {
pts := map[PluginType]string{
0: "collector",
1: "processor",
2: "publisher",
}

_, ok := pts[id]

return ok
}

func (pt PluginType) String() string {
return []string{
"collector",
Expand Down
4 changes: 4 additions & 0 deletions mgmt/rest/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
package v1

import (
"fmt"
"net/http"
"strconv"

Expand Down Expand Up @@ -148,6 +149,9 @@ func (s *apiV1) setPluginConfigItem(w http.ResponseWriter, r *http.Request, p ht

func getPluginType(t string) (core.PluginType, error) {
if ityp, err := strconv.Atoi(t); err == nil {
if !core.CheckPluginType(core.PluginType(ityp)) {
return core.PluginType(-1), fmt.Errorf("invalid plugin type id given %d", ityp)
}
return core.PluginType(ityp), nil
}
ityp, err := core.ToPluginType(t)
Expand Down

0 comments on commit cb0164e

Please sign in to comment.