diff options
author | 2019-09-27 17:09:49 +0200 | |
---|---|---|
committer | 2019-09-27 17:38:49 +0200 | |
commit | cd41e6ad30e6a0a06915b3630b81bb8894ca9b01 (patch) | |
tree | a110d16f061080c8ff4aa83a68a81fa2fe5e7189 /test/security/k8s/src/check/validators/master/boolean/boolean.go | |
parent | 76dd9bfcc14f2a77dd9a8155e66434a304cd0c38 (diff) |
k8s: Extract common validators for DRY code
Issue-ID: SECCOM-235
Change-Id: Ic5997b67d0512bea51c3b4a4c71805987fa6f011
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
Diffstat (limited to 'test/security/k8s/src/check/validators/master/boolean/boolean.go')
-rw-r--r-- | test/security/k8s/src/check/validators/master/boolean/boolean.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/security/k8s/src/check/validators/master/boolean/boolean.go b/test/security/k8s/src/check/validators/master/boolean/boolean.go new file mode 100644 index 000000000..dba73c1e8 --- /dev/null +++ b/test/security/k8s/src/check/validators/master/boolean/boolean.go @@ -0,0 +1,34 @@ +package boolean + +import ( + "strings" +) + +// IsSingleFlagPresent checks presence of selected flag and whether it was used once. +func IsSingleFlagPresent(flag string, params []string) bool { + found := filterFlags(params, flag) + if len(found) != 1 { + return false + } + return true +} + +// IsFlagAbsent checks absence of selected flag in parameters. +func IsFlagAbsent(flag string, params []string) bool { + found := filterFlags(params, flag) + if len(found) != 0 { + return false + } + return true +} + +// filterFlags returns all occurrences of selected flag. +func filterFlags(strs []string, flag string) []string { + var filtered []string + for _, str := range strs { + if strings.HasPrefix(str, flag) { + filtered = append(filtered, str) + } + } + return filtered +} |