Use sets instead of for statement in "IsValidAuthorizationMode"

This commit is contained in:
Yanqiang Miao 2017-11-16 15:41:49 +08:00
parent d6325933e1
commit 96e2610a55
2 changed files with 4 additions and 6 deletions

View File

@ -17,6 +17,7 @@ go_library(
name = "go_default_library",
srcs = ["modes.go"],
importpath = "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes",
deps = ["//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library"],
)
filegroup(

View File

@ -16,6 +16,8 @@ limitations under the License.
package modes
import "k8s.io/apimachinery/pkg/util/sets"
const (
ModeAlwaysAllow string = "AlwaysAllow"
ModeAlwaysDeny string = "AlwaysDeny"
@ -29,10 +31,5 @@ var AuthorizationModeChoices = []string{ModeAlwaysAllow, ModeAlwaysDeny, ModeABA
// IsValidAuthorizationMode returns true if the given authorization mode is a valid one for the apiserver
func IsValidAuthorizationMode(authzMode string) bool {
for _, validMode := range AuthorizationModeChoices {
if authzMode == validMode {
return true
}
}
return false
return sets.NewString(AuthorizationModeChoices...).Has(authzMode)
}