1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-24 08:36:46 +00:00

fix: providing the http provider in the compiler (#12379)

Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
This commit is contained in:
Frank Jogeleit 2025-03-11 16:00:20 +01:00 committed by GitHub
parent 0d43a2d997
commit 1a7c581220
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 1 deletions

View file

@ -109,3 +109,11 @@ func buildRequestData(data map[string]any) (io.Reader, error) {
return buffer, nil
}
func NewHTTP() HTTP {
return HTTP{
HttpInterface: &HttpProvider{
client: http.DefaultClient,
},
}
}

View file

@ -53,7 +53,7 @@ func (c *compiler) compileForJSON(policy *policiesv1alpha1.ValidatingPolicy, exc
}
options = append(options, declOptions...)
options = append(options, context.Lib())
options = append(options, context.Lib(), http.Lib())
env, err := base.Extend(options...)
if err != nil {
return nil, append(allErrs, field.InternalError(nil, err))

View file

@ -10,6 +10,7 @@ import (
"github.com/google/cel-go/common/types/ref"
policiesv1alpha1 "github.com/kyverno/kyverno/api/policies.kyverno.io/v1alpha1"
contextlib "github.com/kyverno/kyverno/pkg/cel/libs/context"
"github.com/kyverno/kyverno/pkg/cel/libs/http"
"github.com/kyverno/kyverno/pkg/cel/utils"
"go.uber.org/multierr"
admissionv1 "k8s.io/api/admission/v1"
@ -162,6 +163,7 @@ func (p *compiledPolicy) evaluateWithData(
vars := lazy.NewMapValue(VariablesType)
dataNew := map[string]any{
ContextKey: contextlib.Context{ContextInterface: data.Context},
HttpKey: http.NewHTTP(),
NamespaceObjectKey: data.Namespace,
ObjectKey: data.Object,
OldObjectKey: data.OldObject,