1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/cmd/cli/kubectl-kyverno/variables/parse.go
Charles-Edouard Brétéché ee4e0422ed
refactor: introduce cli variables package (#8285)
* refactor: introduce cli variables package

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-06 14:03:51 +00:00

36 lines
647 B
Go

package variables
import (
"strings"
)
func parse(vars ...string) map[string]string {
result := map[string]string{}
for _, variable := range vars {
variable = strings.TrimSpace(variable)
kvs := strings.Split(variable, "=")
if len(kvs) != 2 {
// TODO warning
continue
}
key := strings.TrimSpace(kvs[0])
value := strings.TrimSpace(kvs[1])
if len(value) == 0 || len(key) == 0 {
// TODO log
continue
}
if strings.Contains(key, "request.object.") {
// TODO log
continue
}
if result[key] != "" {
// TODO log
continue
}
result[key] = value
}
if len(result) == 0 {
return nil
}
return result
}