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/store/store.go
Charles-Edouard Brétéché 6b62358dae
refactore: move utils store package (#8293)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-06 15:17:12 +00:00

98 lines
1.7 KiB
Go

package store
import (
"github.com/kyverno/kyverno/pkg/registryclient"
)
type Context struct {
Policies []Policy `json:"policies"`
}
type Policy struct {
Name string `json:"name"`
Rules []Rule `json:"rules"`
}
type Rule struct {
Name string `json:"name"`
Values map[string]interface{} `json:"values"`
ForEachValues map[string][]interface{} `json:"foreachValues"`
}
var (
local bool
registryClient registryclient.Client
allowApiCalls bool
policies []Policy
foreachElement int
)
// SetLocal sets local (clusterless) execution for the CLI
func SetLocal(m bool) {
local = m
}
// IsLocal returns 'true' if the CLI is in local (clusterless) execution
func IsLocal() bool {
return local
}
func SetForEachElement(element int) {
foreachElement = element
}
func GetForeachElement() int {
return foreachElement
}
func SetRegistryAccess(access bool) {
if access {
registryClient = registryclient.NewOrDie(registryclient.WithLocalKeychain())
}
}
func GetRegistryAccess() bool {
return registryClient != nil
}
func GetRegistryClient() registryclient.Client {
return registryClient
}
func SetPolicies(p ...Policy) {
policies = p
}
func HasPolicies() bool {
return len(policies) != 0
}
func GetPolicy(policyName string) *Policy {
for _, policy := range policies {
if policy.Name == policyName {
return &policy
}
}
return nil
}
func GetPolicyRule(policyName string, ruleName string) *Rule {
for _, policy := range policies {
if policy.Name == policyName {
for _, rule := range policy.Rules {
if rule.Name == ruleName {
return &rule
}
}
}
}
return nil
}
func AllowApiCall(allow bool) {
allowApiCalls = allow
}
func IsApiCallAllowed() bool {
return allowApiCalls
}