mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Use sets
instead of for
statement in "IsValidAuthorizationMode"
This commit is contained in:
parent
d6325933e1
commit
96e2610a55
@ -17,6 +17,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["modes.go"],
|
srcs = ["modes.go"],
|
||||||
importpath = "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes",
|
importpath = "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes",
|
||||||
|
deps = ["//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library"],
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
@ -16,6 +16,8 @@ limitations under the License.
|
|||||||
|
|
||||||
package modes
|
package modes
|
||||||
|
|
||||||
|
import "k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModeAlwaysAllow string = "AlwaysAllow"
|
ModeAlwaysAllow string = "AlwaysAllow"
|
||||||
ModeAlwaysDeny string = "AlwaysDeny"
|
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
|
// IsValidAuthorizationMode returns true if the given authorization mode is a valid one for the apiserver
|
||||||
func IsValidAuthorizationMode(authzMode string) bool {
|
func IsValidAuthorizationMode(authzMode string) bool {
|
||||||
for _, validMode := range AuthorizationModeChoices {
|
return sets.NewString(AuthorizationModeChoices...).Has(authzMode)
|
||||||
if authzMode == validMode {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user