1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-12 02:46:56 +00:00
kyverno/pkg/cel/libs/context/impl.go
Charles-Edouard Brétéché bdc55fbc93
feat: add context cel lib to get config map (#11898)
* feat: add context cel lib to get config map

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* function name

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix type

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2025-01-10 14:19:50 +00:00

28 lines
868 B
Go

package context
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_configmap_string_string(args ...ref.Val) ref.Val {
if self, err := utils.ConvertToNative[Context](args[0]); err != nil {
return types.WrapErr(err)
} else if namespace, err := utils.ConvertToNative[string](args[1]); err != nil {
return types.WrapErr(err)
} else if name, err := utils.ConvertToNative[string](args[2]); err != nil {
return types.WrapErr(err)
} else {
cm, err := self.GetConfigMap(namespace, name)
if err != nil {
// Errors are not expected here since Parse is a more lenient parser than ParseRequestURI.
return types.NewErr("failed to get resource: %v", err)
}
return c.NativeToValue(cm.UnstructuredContent())
}
}