2025-02-26 06:26:17 +05:30
|
|
|
package imageverifierfunctions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kyverno/kyverno/api/policies.kyverno.io/v1alpha1"
|
|
|
|
"github.com/kyverno/kyverno/pkg/imageverification/imagedataloader"
|
|
|
|
)
|
|
|
|
|
|
|
|
func attestorMap(ivpol *v1alpha1.ImageVerificationPolicy) map[string]v1alpha1.Attestor {
|
|
|
|
if ivpol == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return arrToMap(ivpol.Spec.Attestors)
|
|
|
|
}
|
|
|
|
|
|
|
|
func attestationMap(ivpol *v1alpha1.ImageVerificationPolicy) map[string]v1alpha1.Attestation {
|
|
|
|
if ivpol == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return arrToMap(ivpol.Spec.Attestations)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ARR_TYPE interface {
|
|
|
|
GetKey() string
|
|
|
|
}
|
|
|
|
|
|
|
|
func arrToMap[T ARR_TYPE](arr []T) map[string]T {
|
|
|
|
m := make(map[string]T)
|
|
|
|
for _, v := range arr {
|
|
|
|
m[v.GetKey()] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2025-02-27 12:49:11 +05:30
|
|
|
func GetRemoteOptsFromPolicy(creds *v1alpha1.Credentials) []imagedataloader.Option {
|
2025-02-26 06:26:17 +05:30
|
|
|
if creds == nil {
|
2025-02-27 12:49:11 +05:30
|
|
|
return []imagedataloader.Option{}
|
2025-02-26 06:26:17 +05:30
|
|
|
}
|
|
|
|
|
2025-02-28 14:39:25 +05:30
|
|
|
providers := make([]string, 0, len(creds.Providers))
|
2025-02-26 06:26:17 +05:30
|
|
|
if len(creds.Providers) != 0 {
|
|
|
|
for _, v := range creds.Providers {
|
|
|
|
providers = append(providers, string(v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-28 14:39:25 +05:30
|
|
|
return imagedataloader.BuildRemoteOpts(creds.Secrets, providers, creds.AllowInsecureRegistry)
|
2025-02-26 06:26:17 +05:30
|
|
|
}
|