mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
ee4e0422ed
* 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>
27 lines
701 B
Go
27 lines
701 B
Go
package policy
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/log"
|
|
"github.com/kyverno/kyverno/pkg/engine/variables/regex"
|
|
)
|
|
|
|
func ExtractVariables(policy kyvernov1.PolicyInterface) ([]string, error) {
|
|
var variables []string
|
|
raw, err := json.Marshal(policy)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, match := range regex.RegexVariables.FindAllStringSubmatch(string(raw), -1) {
|
|
if len(match) != 3 {
|
|
err := errors.New("extract variables match has wrong elements number")
|
|
log.Log.Error(err, err.Error())
|
|
} else {
|
|
variables = append(variables, match[2])
|
|
}
|
|
}
|
|
return variables, nil
|
|
}
|