validate nonResourceURL in create clusterrole

This commit is contained in:
xilabao
2017-06-07 14:04:17 +08:00
committed by Chen Rong
parent 2820b45caa
commit 42c41a07c8
2 changed files with 56 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ package cmd
import (
"fmt"
"io"
"strings"
"github.com/spf13/cobra"
@@ -133,6 +134,20 @@ func (c *CreateClusterRoleOptions) Validate() error {
return fmt.Errorf("invalid verb: '%s' for nonResourceURL", v)
}
}
for _, nonResourceURL := range c.NonResourceURLs {
if nonResourceURL == "*" {
continue
}
if nonResourceURL == "" || !strings.HasPrefix(nonResourceURL, "/") {
return fmt.Errorf("nonResourceURL should start with /")
}
if strings.ContainsRune(nonResourceURL[:len(nonResourceURL)-1], '*') {
return fmt.Errorf("nonResourceURL only supports wildcard matches when '*' is at the end")
}
}
}
return nil