1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-27 18:13:17 +00:00
kyverno/pkg/cel/libs/globalcontext/impl.go
Charles-Edouard Brétéché e785ee4882
feat: add globalcontext CEL lib (#12425)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2025-03-17 16:53:32 +01:00

31 lines
961 B
Go

package globalcontext
import (
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/ref"
"github.com/kyverno/kyverno/pkg/cel/utils"
)
type impl struct {
types.Adapter
}
func (c *impl) get_string_string(args ...ref.Val) ref.Val {
if len(args) != 3 {
return types.NewErr("expected 3 arguments, got %d", len(args))
}
if self, err := utils.ConvertToNative[Context](args[0]); err != nil {
return types.WrapErr(err)
} else if name, err := utils.ConvertToNative[string](args[1]); err != nil {
return types.WrapErr(err)
} else if projection, err := utils.ConvertToNative[string](args[2]); err != nil {
return types.WrapErr(err)
} else {
globalRef, err := self.GetGlobalReference(name, projection)
if err != nil {
// Errors are not expected here since Parse is a more lenient parser than ParseRequestURI.
return types.NewErr("failed to get global reference: %v", err)
}
return c.NativeToValue(globalRef)
}
}