mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-09 17:37:12 +00:00
* feat: add interface for image verify cache Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: add basic client for cache Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: add ttl to client Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: add flags and flag setup Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: added a default image verify cache Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: add propogation of cache to image verifier Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: add useCache to image verification types Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * bug: add ivcache to image verifier Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: add logger to cache Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * typo: DisabledImageVerfiyCache Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * typo: DisabledImageVerfiyCache Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * Update cmd/internal/flag.go Signed-off-by: shuting <shutting06@gmail.com> * feat: add use cache to v2beta1 crd Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * bug: change public attribute TTL to private Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * fix: replace nil in test with disabled cache Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * fix: convert ttl time to time.Duration Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: update opts to use time.Duration Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat:add policy version and remove delete functions by adding policy version, old entries will automatically become outdated and we will not have to remove them manually Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * feat: remove clear and update get and set to take interface as input Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> * style: fix lint issue Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> --------- Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com> Signed-off-by: shuting <shutting06@gmail.com> Co-authored-by: shuting <shutting06@gmail.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
|
enginecontext "github.com/kyverno/kyverno/pkg/engine/context"
|
|
"github.com/kyverno/kyverno/pkg/engine/factories"
|
|
"github.com/kyverno/kyverno/pkg/engine/jmespath"
|
|
"github.com/kyverno/kyverno/pkg/imageverifycache"
|
|
)
|
|
|
|
func ContextLoaderFactory(cmResolver engineapi.ConfigmapResolver) engineapi.ContextLoaderFactory {
|
|
if !IsLocal() {
|
|
return factories.DefaultContextLoaderFactory(cmResolver)
|
|
}
|
|
return func(policy kyvernov1.PolicyInterface, rule kyvernov1.Rule) engineapi.ContextLoader {
|
|
init := func(jsonContext enginecontext.Interface) error {
|
|
rule := GetPolicyRule(policy.GetName(), rule.Name)
|
|
if rule != nil && len(rule.Values) > 0 {
|
|
variables := rule.Values
|
|
for key, value := range variables {
|
|
if err := jsonContext.AddVariable(key, value); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
if rule != nil && len(rule.ForEachValues) > 0 {
|
|
for key, value := range rule.ForEachValues {
|
|
if err := jsonContext.AddVariable(key, value[GetForeachElement()]); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
factory := factories.DefaultContextLoaderFactory(cmResolver, factories.WithInitializer(init))
|
|
return wrapper{factory(policy, rule)}
|
|
}
|
|
}
|
|
|
|
type wrapper struct {
|
|
inner engineapi.ContextLoader
|
|
}
|
|
|
|
func (w wrapper) Load(
|
|
ctx context.Context,
|
|
jp jmespath.Interface,
|
|
client engineapi.RawClient,
|
|
rclientFactory engineapi.RegistryClientFactory,
|
|
ivCache imageverifycache.Client,
|
|
contextEntries []kyvernov1.ContextEntry,
|
|
jsonContext enginecontext.Interface,
|
|
) error {
|
|
if !IsApiCallAllowed() {
|
|
client = nil
|
|
}
|
|
if !GetRegistryAccess() {
|
|
rclientFactory = nil
|
|
}
|
|
return w.inner.Load(ctx, jp, client, rclientFactory, ivCache, contextEntries, jsonContext)
|
|
}
|