1
0
mirror of https://github.com/ceph/ceph-csi.git synced 2025-06-14 18:53:35 +00:00

build: move e2e dependencies into e2e/go.mod

Several packages are only used while running the e2e suite. These
packages are less important to update, as the they can not influence the
final executable that is part of the Ceph-CSI container-image.

By moving these dependencies out of the main Ceph-CSI go.mod, it is
easier to identify if a reported CVE affects Ceph-CSI, or only the
testing (like most of the Kubernetes CVEs).

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2025-03-04 08:57:28 +01:00
committed by mergify[bot]
parent 15da101b1b
commit bec6090996
8047 changed files with 1407827 additions and 3453 deletions
Makefile
e2e
go.modgo.sum
vendor
cel.dev
github.com
JeffAshton
Microsoft
NYTimes
antlr4-go
asaskevich
beorn7
blang
cenkalti
ceph
ceph-csi
cespare
containerd
coreos
cyphar
davecgh
distribution
docker
emicklei
euank
go-kmsg-parser
felixge
fsnotify
fxamacker
go-logr
go-openapi
go-task
godbus
gogo
golang
google
btree
cadvisor
cel-go
LICENSE
cel
checker
common
ext
interpreter
parser
gnostic-models
go-cmp
gofuzz
pprof
uuid
gorilla
grpc-ecosystem
inconshreveable
josharian
json-iterator
karrick
klauspost
kubernetes-csi
kylelemons
godebug
mailru
mistifyio
moby
modern-go
munnerz
mxk
onsi
ginkgo
v2
.gitignoreCHANGELOG.mdCONTRIBUTING.mdLICENSEMakefileREADME.mdRELEASING.md
config
core_dsl.godecorator_dsl.godeprecated_dsl.go
formatter
ginkgo
ginkgo_cli_dependencies.goginkgo_t_dsl.go
internal
reporters
reporting_dsl.gotable_dsl.go
types
gomega
.gitignoreCHANGELOG.mdCONTRIBUTING.mdLICENSEREADME.mdRELEASING.md
format
gcustom
gomega_dsl.go
internal
matchers.go
matchers
types
opencontainers
pkg
prometheus
client_golang
client_model
common
procfs
sirupsen
spf13
stoewer
x448
go.etcd.io
go.opentelemetry.io
auto
contrib
otel
.codespellignore.codespellrc.gitattributes.gitignore.golangci.yml.lycheeignore.markdownlint.yamlCHANGELOG.mdCODEOWNERSCONTRIBUTING.mdLICENSEMakefileREADME.mdRELEASING.mdVERSIONING.md
attribute
baggage
codes
doc.goerror_handler.go
exporters
get_main_pkgs.shhandler.go
internal
internal_logging.gometric.go
metric
propagation.go
propagation
renovate.jsonrequirements.txt
sdk
semconv
trace.go
trace
verify_readmes.shverify_released_changelog.shversion.goversions.yaml
proto
go.uber.org
golang.org
x
crypto
exp
net
oauth2
sync
sys
LICENSEPATENTS
cpu
plan9
unix
.gitignoreREADME.mdaffinity_linux.goaliases.goasm_aix_ppc64.sasm_bsd_386.sasm_bsd_amd64.sasm_bsd_arm.sasm_bsd_arm64.sasm_bsd_ppc64.sasm_bsd_riscv64.sasm_linux_386.sasm_linux_amd64.sasm_linux_arm.sasm_linux_arm64.sasm_linux_loong64.sasm_linux_mips64x.sasm_linux_mipsx.sasm_linux_ppc64x.sasm_linux_riscv64.sasm_linux_s390x.sasm_openbsd_mips64.sasm_solaris_amd64.sasm_zos_s390x.sauxv.goauxv_unsupported.gobluetooth_linux.gobpxsvc_zos.gobpxsvc_zos.scap_freebsd.goconstants.godev_aix_ppc.godev_aix_ppc64.godev_darwin.godev_dragonfly.godev_freebsd.godev_linux.godev_netbsd.godev_openbsd.godev_zos.godirent.goendian_big.goendian_little.goenv_unix.gofcntl.gofcntl_darwin.gofcntl_linux_32bit.gofdset.gogccgo.gogccgo_c.cgccgo_linux_amd64.goifreq_linux.goioctl_linux.goioctl_signed.goioctl_unsigned.goioctl_zos.gomkall.shmkerrors.shmmap_nomremap.gomremap.gopagesize_unix.gopledge_openbsd.goptrace_darwin.goptrace_ios.gorace.gorace0.goreaddirent_getdents.goreaddirent_getdirentries.gosockcmsg_dragonfly.gosockcmsg_linux.gosockcmsg_unix.gosockcmsg_unix_other.gosockcmsg_zos.gosymaddr_zos_s390x.ssyscall.gosyscall_aix.gosyscall_aix_ppc.gosyscall_aix_ppc64.gosyscall_bsd.gosyscall_darwin.gosyscall_darwin_amd64.gosyscall_darwin_arm64.gosyscall_darwin_libSystem.gosyscall_dragonfly.gosyscall_dragonfly_amd64.gosyscall_freebsd.gosyscall_freebsd_386.gosyscall_freebsd_amd64.gosyscall_freebsd_arm.gosyscall_freebsd_arm64.gosyscall_freebsd_riscv64.gosyscall_hurd.gosyscall_hurd_386.gosyscall_illumos.gosyscall_linux.gosyscall_linux_386.gosyscall_linux_alarm.gosyscall_linux_amd64.gosyscall_linux_amd64_gc.gosyscall_linux_arm.gosyscall_linux_arm64.gosyscall_linux_gc.gosyscall_linux_gc_386.gosyscall_linux_gc_arm.gosyscall_linux_gccgo_386.gosyscall_linux_gccgo_arm.gosyscall_linux_loong64.gosyscall_linux_mips64x.gosyscall_linux_mipsx.gosyscall_linux_ppc.gosyscall_linux_ppc64x.gosyscall_linux_riscv64.gosyscall_linux_s390x.gosyscall_linux_sparc64.gosyscall_netbsd.gosyscall_netbsd_386.gosyscall_netbsd_amd64.gosyscall_netbsd_arm.gosyscall_netbsd_arm64.gosyscall_openbsd.gosyscall_openbsd_386.gosyscall_openbsd_amd64.gosyscall_openbsd_arm.gosyscall_openbsd_arm64.gosyscall_openbsd_libc.gosyscall_openbsd_mips64.gosyscall_openbsd_ppc64.gosyscall_openbsd_riscv64.gosyscall_solaris.gosyscall_solaris_amd64.gosyscall_unix.gosyscall_unix_gc.gosyscall_unix_gc_ppc64x.gosyscall_zos_s390x.gosysvshm_linux.gosysvshm_unix.gosysvshm_unix_other.gotimestruct.gounveil_openbsd.govgetrandom_linux.govgetrandom_unsupported.goxattr_bsd.gozerrors_aix_ppc.gozerrors_aix_ppc64.gozerrors_darwin_amd64.gozerrors_darwin_arm64.gozerrors_dragonfly_amd64.gozerrors_freebsd_386.gozerrors_freebsd_amd64.gozerrors_freebsd_arm.gozerrors_freebsd_arm64.gozerrors_freebsd_riscv64.gozerrors_linux.gozerrors_linux_386.gozerrors_linux_amd64.gozerrors_linux_arm.gozerrors_linux_arm64.gozerrors_linux_loong64.gozerrors_linux_mips.gozerrors_linux_mips64.gozerrors_linux_mips64le.gozerrors_linux_mipsle.gozerrors_linux_ppc.gozerrors_linux_ppc64.gozerrors_linux_ppc64le.gozerrors_linux_riscv64.gozerrors_linux_s390x.gozerrors_linux_sparc64.gozerrors_netbsd_386.gozerrors_netbsd_amd64.gozerrors_netbsd_arm.gozerrors_netbsd_arm64.gozerrors_openbsd_386.gozerrors_openbsd_amd64.gozerrors_openbsd_arm.gozerrors_openbsd_arm64.gozerrors_openbsd_mips64.gozerrors_openbsd_ppc64.gozerrors_openbsd_riscv64.gozerrors_solaris_amd64.gozerrors_zos_s390x.gozptrace_armnn_linux.gozptrace_linux_arm64.gozptrace_mipsnn_linux.gozptrace_mipsnnle_linux.gozptrace_x86_linux.gozsymaddr_zos_s390x.szsyscall_aix_ppc.gozsyscall_aix_ppc64.gozsyscall_aix_ppc64_gc.gozsyscall_aix_ppc64_gccgo.gozsyscall_darwin_amd64.gozsyscall_darwin_amd64.szsyscall_darwin_arm64.gozsyscall_darwin_arm64.szsyscall_dragonfly_amd64.gozsyscall_freebsd_386.gozsyscall_freebsd_amd64.gozsyscall_freebsd_arm.gozsyscall_freebsd_arm64.gozsyscall_freebsd_riscv64.gozsyscall_illumos_amd64.gozsyscall_linux.gozsyscall_linux_386.gozsyscall_linux_amd64.gozsyscall_linux_arm.gozsyscall_linux_arm64.gozsyscall_linux_loong64.gozsyscall_linux_mips.gozsyscall_linux_mips64.gozsyscall_linux_mips64le.gozsyscall_linux_mipsle.gozsyscall_linux_ppc.gozsyscall_linux_ppc64.gozsyscall_linux_ppc64le.gozsyscall_linux_riscv64.gozsyscall_linux_s390x.gozsyscall_linux_sparc64.gozsyscall_netbsd_386.gozsyscall_netbsd_amd64.gozsyscall_netbsd_arm.gozsyscall_netbsd_arm64.gozsyscall_openbsd_386.gozsyscall_openbsd_386.szsyscall_openbsd_amd64.gozsyscall_openbsd_amd64.szsyscall_openbsd_arm.gozsyscall_openbsd_arm.szsyscall_openbsd_arm64.gozsyscall_openbsd_arm64.szsyscall_openbsd_mips64.gozsyscall_openbsd_mips64.szsyscall_openbsd_ppc64.gozsyscall_openbsd_ppc64.szsyscall_openbsd_riscv64.gozsyscall_openbsd_riscv64.szsyscall_solaris_amd64.gozsyscall_zos_s390x.gozsysctl_openbsd_386.gozsysctl_openbsd_amd64.gozsysctl_openbsd_arm.gozsysctl_openbsd_arm64.gozsysctl_openbsd_mips64.gozsysctl_openbsd_ppc64.gozsysctl_openbsd_riscv64.gozsysnum_darwin_amd64.gozsysnum_darwin_arm64.gozsysnum_dragonfly_amd64.gozsysnum_freebsd_386.gozsysnum_freebsd_amd64.gozsysnum_freebsd_arm.gozsysnum_freebsd_arm64.gozsysnum_freebsd_riscv64.gozsysnum_linux_386.gozsysnum_linux_amd64.gozsysnum_linux_arm.gozsysnum_linux_arm64.gozsysnum_linux_loong64.gozsysnum_linux_mips.gozsysnum_linux_mips64.gozsysnum_linux_mips64le.gozsysnum_linux_mipsle.gozsysnum_linux_ppc.gozsysnum_linux_ppc64.gozsysnum_linux_ppc64le.gozsysnum_linux_riscv64.gozsysnum_linux_s390x.gozsysnum_linux_sparc64.gozsysnum_netbsd_386.gozsysnum_netbsd_amd64.gozsysnum_netbsd_arm.gozsysnum_netbsd_arm64.gozsysnum_openbsd_386.gozsysnum_openbsd_amd64.gozsysnum_openbsd_arm.gozsysnum_openbsd_arm64.gozsysnum_openbsd_mips64.gozsysnum_openbsd_ppc64.gozsysnum_openbsd_riscv64.gozsysnum_zos_s390x.goztypes_aix_ppc.goztypes_aix_ppc64.goztypes_darwin_amd64.goztypes_darwin_arm64.goztypes_dragonfly_amd64.goztypes_freebsd_386.goztypes_freebsd_amd64.goztypes_freebsd_arm.goztypes_freebsd_arm64.goztypes_freebsd_riscv64.goztypes_linux.goztypes_linux_386.goztypes_linux_amd64.goztypes_linux_arm.goztypes_linux_arm64.goztypes_linux_loong64.goztypes_linux_mips.goztypes_linux_mips64.goztypes_linux_mips64le.goztypes_linux_mipsle.goztypes_linux_ppc.goztypes_linux_ppc64.goztypes_linux_ppc64le.goztypes_linux_riscv64.goztypes_linux_s390x.goztypes_linux_sparc64.goztypes_netbsd_386.goztypes_netbsd_amd64.goztypes_netbsd_arm.goztypes_netbsd_arm64.goztypes_openbsd_386.goztypes_openbsd_amd64.goztypes_openbsd_arm.goztypes_openbsd_arm64.goztypes_openbsd_mips64.goztypes_openbsd_ppc64.goztypes_openbsd_riscv64.goztypes_solaris_amd64.goztypes_zos_s390x.go
windows
term
text
time
tools
google.golang.org
genproto
grpc
AUTHORSCODE-OF-CONDUCT.mdCONTRIBUTING.mdGOVERNANCE.mdLICENSEMAINTAINERS.mdMakefileNOTICE.txtREADME.mdSECURITY.md
attributes
backoff.go
backoff
balancer
balancer_wrapper.go
binarylog
grpc_binarylog_v1
call.go
channelz
clientconn.gocodec.go
codes
connectivity
credentials
dialoptions.godoc.go
encoding
experimental
grpclog
health
interceptor.go
internal
keepalive
mem
metadata
peer
picker_wrapper.gopreloader.go
resolver
resolver_wrapper.gorpc_util.goserver.goservice_config.go
serviceconfig
stats
status
stream.gostream_interfaces.go
tap
trace.gotrace_notrace.gotrace_withtrace.goversion.go
protobuf
LICENSEPATENTS
encoding
internal
descfmt
descopts
detrand
editiondefaults
editionssupport
encoding
errors
filedesc
filetype
flags
genid
impl
order
pragma
protolazy
set
strs
version
proto
protoadapt
reflect
runtime
types
descriptorpb
dynamicpb
gofeaturespb
known
anypb
durationpb
emptypb
fieldmaskpb
structpb
timestamppb
wrapperspb
gopkg.in
k8s.io
api
LICENSE
admission
admissionregistration
apidiscovery
apiserverinternal
apps
authentication
authorization
autoscaling
batch
certificates
coordination
core
discovery
events
extensions
flowcontrol
imagepolicy
networking
node
policy
rbac
resource
scheduling
storage
storagemigration
apiextensions-apiserver
apimachinery
LICENSE
pkg
api
apis
conversion
fields
labels
runtime
selection
types
util
version
watch
third_party
apiserver
LICENSE
pkg
admission
attributes.goaudit.gochain.goconfig.go
configuration
conversion.godecorator.goerrors.gohandler.go
initializer
interfaces.go
metrics
plugin
plugins.goreinvocation.goutil.go
apis
audit
authentication
authorization
cel
endpoints
features
quota
registry
server
storage
storageversion
util
warning
plugin
pkg
audit
authenticator
authorizer
client-go
LICENSE
applyconfigurations
OWNERS
admissionregistration
apiserverinternal
apps
autoscaling
v1
v2
v2beta1
v2beta2
batch
certificates
coordination
core
v1
affinity.goapparmorprofile.goattachedvolume.goawselasticblockstorevolumesource.goazurediskvolumesource.goazurefilepersistentvolumesource.goazurefilevolumesource.gocapabilities.gocephfspersistentvolumesource.gocephfsvolumesource.gocinderpersistentvolumesource.gocindervolumesource.goclientipconfig.goclustertrustbundleprojection.gocomponentcondition.gocomponentstatus.goconfigmap.goconfigmapenvsource.goconfigmapkeyselector.goconfigmapnodeconfigsource.goconfigmapprojection.goconfigmapvolumesource.gocontainer.gocontainerimage.gocontainerport.gocontainerresizepolicy.gocontainerstate.gocontainerstaterunning.gocontainerstateterminated.gocontainerstatewaiting.gocontainerstatus.gocontaineruser.gocsipersistentvolumesource.gocsivolumesource.godaemonendpoint.godownwardapiprojection.godownwardapivolumefile.godownwardapivolumesource.goemptydirvolumesource.goendpointaddress.goendpointport.goendpoints.goendpointsubset.goenvfromsource.goenvvar.goenvvarsource.goephemeralcontainer.goephemeralcontainercommon.goephemeralvolumesource.goevent.goeventseries.goeventsource.goexecaction.gofcvolumesource.goflexpersistentvolumesource.goflexvolumesource.goflockervolumesource.gogcepersistentdiskvolumesource.gogitrepovolumesource.goglusterfspersistentvolumesource.goglusterfsvolumesource.gogrpcaction.gohostalias.gohostip.gohostpathvolumesource.gohttpgetaction.gohttpheader.goimagevolumesource.goiscsipersistentvolumesource.goiscsivolumesource.gokeytopath.golifecycle.golifecyclehandler.golimitrange.golimitrangeitem.golimitrangespec.golinuxcontaineruser.goloadbalanceringress.goloadbalancerstatus.golocalobjectreference.golocalvolumesource.gomodifyvolumestatus.gonamespace.gonamespacecondition.gonamespacespec.gonamespacestatus.gonfsvolumesource.gonode.gonodeaddress.gonodeaffinity.gonodecondition.gonodeconfigsource.gonodeconfigstatus.gonodedaemonendpoints.gonodefeatures.gonoderuntimehandler.gonoderuntimehandlerfeatures.gonodeselector.gonodeselectorrequirement.gonodeselectorterm.gonodespec.gonodestatus.gonodesysteminfo.goobjectfieldselector.goobjectreference.gopersistentvolume.gopersistentvolumeclaim.gopersistentvolumeclaimcondition.gopersistentvolumeclaimspec.gopersistentvolumeclaimstatus.gopersistentvolumeclaimtemplate.gopersistentvolumeclaimvolumesource.gopersistentvolumesource.gopersistentvolumespec.gopersistentvolumestatus.gophotonpersistentdiskvolumesource.gopod.gopodaffinity.gopodaffinityterm.gopodantiaffinity.gopodcondition.gopoddnsconfig.gopoddnsconfigoption.gopodip.gopodos.gopodreadinessgate.gopodresourceclaim.gopodresourceclaimstatus.gopodschedulinggate.gopodsecuritycontext.gopodspec.gopodstatus.gopodtemplate.gopodtemplatespec.goportstatus.goportworxvolumesource.gopreferredschedulingterm.goprobe.goprobehandler.goprojectedvolumesource.goquobytevolumesource.gorbdpersistentvolumesource.gorbdvolumesource.goreplicationcontroller.goreplicationcontrollercondition.goreplicationcontrollerspec.goreplicationcontrollerstatus.goresourceclaim.goresourcefieldselector.goresourcehealth.goresourcequota.goresourcequotaspec.goresourcequotastatus.goresourcerequirements.goresourcestatus.goscaleiopersistentvolumesource.goscaleiovolumesource.goscopedresourceselectorrequirement.goscopeselector.goseccompprofile.gosecret.gosecretenvsource.gosecretkeyselector.gosecretprojection.gosecretreference.gosecretvolumesource.gosecuritycontext.goselinuxoptions.goservice.goserviceaccount.goserviceaccounttokenprojection.goserviceport.goservicespec.goservicestatus.gosessionaffinityconfig.gosleepaction.gostorageospersistentvolumesource.gostorageosvolumesource.gosysctl.gotaint.gotcpsocketaction.gotoleration.gotopologyselectorlabelrequirement.gotopologyselectorterm.gotopologyspreadconstraint.gotypedlocalobjectreference.gotypedobjectreference.govolume.govolumedevice.govolumemount.govolumemountstatus.govolumenodeaffinity.govolumeprojection.govolumeresourcerequirements.govolumesource.govspherevirtualdiskvolumesource.goweightedpodaffinityterm.gowindowssecuritycontextoptions.go
discovery
doc.go
events
extensions
flowcontrol
v1
v1beta1
v1beta2
v1beta3
imagepolicy
internal
meta
networking
node
policy
rbac
resource
scheduling
storage
storagemigration
utils.go
discovery
dynamic
features
gentype
informers
admissionregistration
apiserverinternal
apps
autoscaling
batch
certificates
coordination
core
discovery
doc.go
events
extensions
factory.go
flowcontrol
generic.go
internalinterfaces
networking
node
policy
rbac
resource
scheduling
storage
storagemigration
kubernetes
clientset.godoc.go
fake
import.go
scheme
typed
admissionregistration
apiserverinternal
apps
authentication
authorization
autoscaling
batch
certificates
coordination
core
discovery
events
extensions
flowcontrol
networking
node
policy
rbac
resource
scheduling
storage
storagemigration
listers
admissionregistration
apiserverinternal
apps
autoscaling
batch
certificates
coordination
core
discovery
doc.go
events
extensions
flowcontrol
generic_helpers.go
networking
node
policy
rbac
resource
scheduling
storage
storagemigration
openapi
pkg
plugin
pkg
client
rest
restmapper
scale
testing
tools
transport
util
cloud-provider
component-base
LICENSE
cli
config
featuregate
logs
metrics
tracing
version
zpages
component-helpers
LICENSE
node
resource
scheduling
storage
controller-manager
cri-api
cri-client
csi-translation-lib
dynamic-resource-allocation
klog
kms
kube-openapi
kube-scheduler
kubectl
LICENSE
pkg
scale
util
podutils
kubelet
kubernetes
LICENSE
pkg
api
apis
capabilities
client
conditions
cluster
controller
features
fieldpath
kubelet
apis
cadvisor
checkpointmanager
cm
.mockery.yamlOWNERS
admission
cgroup_manager_linux.gocgroup_manager_unsupported.gocgroup_v1_manager_linux.gocgroup_v2_manager_linux.gocontainer_manager.gocontainer_manager_linux.gocontainer_manager_stub.gocontainer_manager_unsupported.gocontainer_manager_windows.go
containermap
cpumanager
devicemanager
doc.go
dra
fake_container_manager.gofake_internal_container_lifecycle.gofake_pod_container_manager.gohelpers.gohelpers_linux.gohelpers_unsupported.gointernal_container_lifecycle.gointernal_container_lifecycle_linux.gointernal_container_lifecycle_unsupported.gointernal_container_lifecycle_windows.go
memorymanager
node_container_manager_linux.gopod_container_manager_linux.gopod_container_manager_stub.goqos_container_manager_linux.go
resourceupdates
topologymanager
types.go
util
config
container
events
eviction
kuberuntime
lifecycle
metrics
pluginmanager
server
metrics
stats
status
types
util
winstats
probe
scheduler
OWNERS
apis
backend
eventhandlers.goextender.go
framework
metrics
profile
schedule_one.goscheduler.go
util
security
securitycontext
util
volume
test
e2e
framework
perftype
storage
testing-manifests
README.md
dra
embed.go
flexvolume
gpu
guestbook
kubectl
podrbd-storage-class.yaml
sample-device-plugin
statefulset
storage-csi
utils
third_party
mount-utils
pod-security-admission
utils
modules.txt
sigs.k8s.io
go.modgo.sum
scripts
vendor
gomodules.xyz
jsonpatch
modules.txt

576
e2e/vendor/github.com/google/cel-go/cel/macro.go generated vendored Normal file

@ -0,0 +1,576 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cel
import (
"fmt"
"github.com/google/cel-go/common"
"github.com/google/cel-go/common/ast"
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/parser"
exprpb "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
)
// Macro describes a function signature to match and the MacroExpander to apply.
//
// Note: when a Macro should apply to multiple overloads (based on arg count) of a given function,
// a Macro should be created per arg-count or as a var arg macro.
type Macro = parser.Macro
// MacroFactory defines an expansion function which converts a call and its arguments to a cel.Expr value.
type MacroFactory = parser.MacroExpander
// MacroExprFactory assists with the creation of Expr values in a manner which is consistent
// the internal semantics and id generation behaviors of the parser and checker libraries.
type MacroExprFactory = parser.ExprHelper
// MacroExpander converts a call and its associated arguments into a protobuf Expr representation.
//
// If the MacroExpander determines within the implementation that an expansion is not needed it may return
// a nil Expr value to indicate a non-match. However, if an expansion is to be performed, but the arguments
// are not well-formed, the result of the expansion will be an error.
//
// The MacroExpander accepts as arguments a MacroExprHelper as well as the arguments used in the function call
// and produces as output an Expr ast node.
//
// Note: when the Macro.IsReceiverStyle() method returns true, the target argument will be nil.
type MacroExpander func(eh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error)
// MacroExprHelper exposes helper methods for creating new expressions within a CEL abstract syntax tree.
// ExprHelper assists with the manipulation of proto-based Expr values in a manner which is
// consistent with the source position and expression id generation code leveraged by both
// the parser and type-checker.
type MacroExprHelper interface {
// Copy the input expression with a brand new set of identifiers.
Copy(*exprpb.Expr) *exprpb.Expr
// LiteralBool creates an Expr value for a bool literal.
LiteralBool(value bool) *exprpb.Expr
// LiteralBytes creates an Expr value for a byte literal.
LiteralBytes(value []byte) *exprpb.Expr
// LiteralDouble creates an Expr value for double literal.
LiteralDouble(value float64) *exprpb.Expr
// LiteralInt creates an Expr value for an int literal.
LiteralInt(value int64) *exprpb.Expr
// LiteralString creates am Expr value for a string literal.
LiteralString(value string) *exprpb.Expr
// LiteralUint creates an Expr value for a uint literal.
LiteralUint(value uint64) *exprpb.Expr
// NewList creates a CreateList instruction where the list is comprised of the optional set
// of elements provided as arguments.
NewList(elems ...*exprpb.Expr) *exprpb.Expr
// NewMap creates a CreateStruct instruction for a map where the map is comprised of the
// optional set of key, value entries.
NewMap(entries ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr
// NewMapEntry creates a Map Entry for the key, value pair.
NewMapEntry(key *exprpb.Expr, val *exprpb.Expr, optional bool) *exprpb.Expr_CreateStruct_Entry
// NewObject creates a CreateStruct instruction for an object with a given type name and
// optional set of field initializers.
NewObject(typeName string, fieldInits ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr
// NewObjectFieldInit creates a new Object field initializer from the field name and value.
NewObjectFieldInit(field string, init *exprpb.Expr, optional bool) *exprpb.Expr_CreateStruct_Entry
// Fold creates a fold comprehension instruction.
//
// - iterVar is the iteration variable name.
// - iterRange represents the expression that resolves to a list or map where the elements or
// keys (respectively) will be iterated over.
// - accuVar is the accumulation variable name, typically parser.AccumulatorName.
// - accuInit is the initial expression whose value will be set for the accuVar prior to
// folding.
// - condition is the expression to test to determine whether to continue folding.
// - step is the expression to evaluation at the conclusion of a single fold iteration.
// - result is the computation to evaluate at the conclusion of the fold.
//
// The accuVar should not shadow variable names that you would like to reference within the
// environment in the step and condition expressions. Presently, the name __result__ is commonly
// used by built-in macros but this may change in the future.
Fold(iterVar string,
iterRange *exprpb.Expr,
accuVar string,
accuInit *exprpb.Expr,
condition *exprpb.Expr,
step *exprpb.Expr,
result *exprpb.Expr) *exprpb.Expr
// Ident creates an identifier Expr value.
Ident(name string) *exprpb.Expr
// AccuIdent returns an accumulator identifier for use with comprehension results.
AccuIdent() *exprpb.Expr
// GlobalCall creates a function call Expr value for a global (free) function.
GlobalCall(function string, args ...*exprpb.Expr) *exprpb.Expr
// ReceiverCall creates a function call Expr value for a receiver-style function.
ReceiverCall(function string, target *exprpb.Expr, args ...*exprpb.Expr) *exprpb.Expr
// PresenceTest creates a Select TestOnly Expr value for modelling has() semantics.
PresenceTest(operand *exprpb.Expr, field string) *exprpb.Expr
// Select create a field traversal Expr value.
Select(operand *exprpb.Expr, field string) *exprpb.Expr
// OffsetLocation returns the Location of the expression identifier.
OffsetLocation(exprID int64) common.Location
// NewError associates an error message with a given expression id.
NewError(exprID int64, message string) *Error
}
// GlobalMacro creates a Macro for a global function with the specified arg count.
func GlobalMacro(function string, argCount int, factory MacroFactory) Macro {
return parser.NewGlobalMacro(function, argCount, factory)
}
// ReceiverMacro creates a Macro for a receiver function matching the specified arg count.
func ReceiverMacro(function string, argCount int, factory MacroFactory) Macro {
return parser.NewReceiverMacro(function, argCount, factory)
}
// GlobalVarArgMacro creates a Macro for a global function with a variable arg count.
func GlobalVarArgMacro(function string, factory MacroFactory) Macro {
return parser.NewGlobalVarArgMacro(function, factory)
}
// ReceiverVarArgMacro creates a Macro for a receiver function matching a variable arg count.
func ReceiverVarArgMacro(function string, factory MacroFactory) Macro {
return parser.NewReceiverVarArgMacro(function, factory)
}
// NewGlobalMacro creates a Macro for a global function with the specified arg count.
//
// Deprecated: use GlobalMacro
func NewGlobalMacro(function string, argCount int, expander MacroExpander) Macro {
expand := adaptingExpander{expander}
return parser.NewGlobalMacro(function, argCount, expand.Expander)
}
// NewReceiverMacro creates a Macro for a receiver function matching the specified arg count.
//
// Deprecated: use ReceiverMacro
func NewReceiverMacro(function string, argCount int, expander MacroExpander) Macro {
expand := adaptingExpander{expander}
return parser.NewReceiverMacro(function, argCount, expand.Expander)
}
// NewGlobalVarArgMacro creates a Macro for a global function with a variable arg count.
//
// Deprecated: use GlobalVarArgMacro
func NewGlobalVarArgMacro(function string, expander MacroExpander) Macro {
expand := adaptingExpander{expander}
return parser.NewGlobalVarArgMacro(function, expand.Expander)
}
// NewReceiverVarArgMacro creates a Macro for a receiver function matching a variable arg count.
//
// Deprecated: use ReceiverVarArgMacro
func NewReceiverVarArgMacro(function string, expander MacroExpander) Macro {
expand := adaptingExpander{expander}
return parser.NewReceiverVarArgMacro(function, expand.Expander)
}
// HasMacroExpander expands the input call arguments into a presence test, e.g. has(<operand>.field)
func HasMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) {
ph, err := toParserHelper(meh)
if err != nil {
return nil, err
}
arg, err := adaptToExpr(args[0])
if err != nil {
return nil, err
}
if arg.Kind() == ast.SelectKind {
s := arg.AsSelect()
return adaptToProto(ph.NewPresenceTest(s.Operand(), s.FieldName()))
}
return nil, ph.NewError(arg.ID(), "invalid argument to has() macro")
}
// ExistsMacroExpander expands the input call arguments into a comprehension that returns true if any of the
// elements in the range match the predicate expressions:
// <iterRange>.exists(<iterVar>, <predicate>)
func ExistsMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) {
ph, err := toParserHelper(meh)
if err != nil {
return nil, err
}
out, err := parser.MakeExists(ph, mustAdaptToExpr(target), mustAdaptToExprs(args))
if err != nil {
return nil, err
}
return adaptToProto(out)
}
// ExistsOneMacroExpander expands the input call arguments into a comprehension that returns true if exactly
// one of the elements in the range match the predicate expressions:
// <iterRange>.exists_one(<iterVar>, <predicate>)
func ExistsOneMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) {
ph, err := toParserHelper(meh)
if err != nil {
return nil, err
}
out, err := parser.MakeExistsOne(ph, mustAdaptToExpr(target), mustAdaptToExprs(args))
if err != nil {
return nil, err
}
return adaptToProto(out)
}
// MapMacroExpander expands the input call arguments into a comprehension that transforms each element in the
// input to produce an output list.
//
// There are two call patterns supported by map:
//
// <iterRange>.map(<iterVar>, <transform>)
// <iterRange>.map(<iterVar>, <predicate>, <transform>)
//
// In the second form only iterVar values which return true when provided to the predicate expression
// are transformed.
func MapMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) {
ph, err := toParserHelper(meh)
if err != nil {
return nil, err
}
out, err := parser.MakeMap(ph, mustAdaptToExpr(target), mustAdaptToExprs(args))
if err != nil {
return nil, err
}
return adaptToProto(out)
}
// FilterMacroExpander expands the input call arguments into a comprehension which produces a list which contains
// only elements which match the provided predicate expression:
// <iterRange>.filter(<iterVar>, <predicate>)
func FilterMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) {
ph, err := toParserHelper(meh)
if err != nil {
return nil, err
}
out, err := parser.MakeFilter(ph, mustAdaptToExpr(target), mustAdaptToExprs(args))
if err != nil {
return nil, err
}
return adaptToProto(out)
}
var (
// Aliases to each macro in the CEL standard environment.
// Note: reassigning these macro variables may result in undefined behavior.
// HasMacro expands "has(m.f)" which tests the presence of a field, avoiding the need to
// specify the field as a string.
HasMacro = parser.HasMacro
// AllMacro expands "range.all(var, predicate)" into a comprehension which ensures that all
// elements in the range satisfy the predicate.
AllMacro = parser.AllMacro
// ExistsMacro expands "range.exists(var, predicate)" into a comprehension which ensures that
// some element in the range satisfies the predicate.
ExistsMacro = parser.ExistsMacro
// ExistsOneMacro expands "range.exists_one(var, predicate)", which is true if for exactly one
// element in range the predicate holds.
ExistsOneMacro = parser.ExistsOneMacro
// MapMacro expands "range.map(var, function)" into a comprehension which applies the function
// to each element in the range to produce a new list.
MapMacro = parser.MapMacro
// MapFilterMacro expands "range.map(var, predicate, function)" into a comprehension which
// first filters the elements in the range by the predicate, then applies the transform function
// to produce a new list.
MapFilterMacro = parser.MapFilterMacro
// FilterMacro expands "range.filter(var, predicate)" into a comprehension which filters
// elements in the range, producing a new list from the elements that satisfy the predicate.
FilterMacro = parser.FilterMacro
// StandardMacros provides an alias to all the CEL macros defined in the standard environment.
StandardMacros = []Macro{
HasMacro, AllMacro, ExistsMacro, ExistsOneMacro, MapMacro, MapFilterMacro, FilterMacro,
}
// NoMacros provides an alias to an empty list of macros
NoMacros = []Macro{}
)
type adaptingExpander struct {
legacyExpander MacroExpander
}
func (adapt *adaptingExpander) Expander(eh parser.ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) {
var legacyTarget *exprpb.Expr = nil
var err *Error = nil
if target != nil {
legacyTarget, err = adaptToProto(target)
if err != nil {
return nil, err
}
}
legacyArgs := make([]*exprpb.Expr, len(args))
for i, arg := range args {
legacyArgs[i], err = adaptToProto(arg)
if err != nil {
return nil, err
}
}
ah := &adaptingHelper{modernHelper: eh}
legacyExpr, err := adapt.legacyExpander(ah, legacyTarget, legacyArgs)
if err != nil {
return nil, err
}
ex, err := adaptToExpr(legacyExpr)
if err != nil {
return nil, err
}
return ex, nil
}
func wrapErr(id int64, message string, err error) *common.Error {
return &common.Error{
Location: common.NoLocation,
Message: fmt.Sprintf("%s: %v", message, err),
ExprID: id,
}
}
type adaptingHelper struct {
modernHelper parser.ExprHelper
}
// Copy the input expression with a brand new set of identifiers.
func (ah *adaptingHelper) Copy(e *exprpb.Expr) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.Copy(mustAdaptToExpr(e)))
}
// LiteralBool creates an Expr value for a bool literal.
func (ah *adaptingHelper) LiteralBool(value bool) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewLiteral(types.Bool(value)))
}
// LiteralBytes creates an Expr value for a byte literal.
func (ah *adaptingHelper) LiteralBytes(value []byte) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewLiteral(types.Bytes(value)))
}
// LiteralDouble creates an Expr value for double literal.
func (ah *adaptingHelper) LiteralDouble(value float64) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewLiteral(types.Double(value)))
}
// LiteralInt creates an Expr value for an int literal.
func (ah *adaptingHelper) LiteralInt(value int64) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewLiteral(types.Int(value)))
}
// LiteralString creates am Expr value for a string literal.
func (ah *adaptingHelper) LiteralString(value string) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewLiteral(types.String(value)))
}
// LiteralUint creates an Expr value for a uint literal.
func (ah *adaptingHelper) LiteralUint(value uint64) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewLiteral(types.Uint(value)))
}
// NewList creates a CreateList instruction where the list is comprised of the optional set
// of elements provided as arguments.
func (ah *adaptingHelper) NewList(elems ...*exprpb.Expr) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewList(mustAdaptToExprs(elems)...))
}
// NewMap creates a CreateStruct instruction for a map where the map is comprised of the
// optional set of key, value entries.
func (ah *adaptingHelper) NewMap(entries ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr {
adaptedEntries := make([]ast.EntryExpr, len(entries))
for i, e := range entries {
adaptedEntries[i] = mustAdaptToEntryExpr(e)
}
return mustAdaptToProto(ah.modernHelper.NewMap(adaptedEntries...))
}
// NewMapEntry creates a Map Entry for the key, value pair.
func (ah *adaptingHelper) NewMapEntry(key *exprpb.Expr, val *exprpb.Expr, optional bool) *exprpb.Expr_CreateStruct_Entry {
return mustAdaptToProtoEntry(
ah.modernHelper.NewMapEntry(mustAdaptToExpr(key), mustAdaptToExpr(val), optional))
}
// NewObject creates a CreateStruct instruction for an object with a given type name and
// optional set of field initializers.
func (ah *adaptingHelper) NewObject(typeName string, fieldInits ...*exprpb.Expr_CreateStruct_Entry) *exprpb.Expr {
adaptedEntries := make([]ast.EntryExpr, len(fieldInits))
for i, e := range fieldInits {
adaptedEntries[i] = mustAdaptToEntryExpr(e)
}
return mustAdaptToProto(ah.modernHelper.NewStruct(typeName, adaptedEntries...))
}
// NewObjectFieldInit creates a new Object field initializer from the field name and value.
func (ah *adaptingHelper) NewObjectFieldInit(field string, init *exprpb.Expr, optional bool) *exprpb.Expr_CreateStruct_Entry {
return mustAdaptToProtoEntry(
ah.modernHelper.NewStructField(field, mustAdaptToExpr(init), optional))
}
// Fold creates a fold comprehension instruction.
//
// - iterVar is the iteration variable name.
// - iterRange represents the expression that resolves to a list or map where the elements or
// keys (respectively) will be iterated over.
// - accuVar is the accumulation variable name, typically parser.AccumulatorName.
// - accuInit is the initial expression whose value will be set for the accuVar prior to
// folding.
// - condition is the expression to test to determine whether to continue folding.
// - step is the expression to evaluation at the conclusion of a single fold iteration.
// - result is the computation to evaluate at the conclusion of the fold.
//
// The accuVar should not shadow variable names that you would like to reference within the
// environment in the step and condition expressions. Presently, the name __result__ is commonly
// used by built-in macros but this may change in the future.
func (ah *adaptingHelper) Fold(iterVar string,
iterRange *exprpb.Expr,
accuVar string,
accuInit *exprpb.Expr,
condition *exprpb.Expr,
step *exprpb.Expr,
result *exprpb.Expr) *exprpb.Expr {
return mustAdaptToProto(
ah.modernHelper.NewComprehension(
mustAdaptToExpr(iterRange),
iterVar,
accuVar,
mustAdaptToExpr(accuInit),
mustAdaptToExpr(condition),
mustAdaptToExpr(step),
mustAdaptToExpr(result),
),
)
}
// Ident creates an identifier Expr value.
func (ah *adaptingHelper) Ident(name string) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewIdent(name))
}
// AccuIdent returns an accumulator identifier for use with comprehension results.
func (ah *adaptingHelper) AccuIdent() *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewAccuIdent())
}
// GlobalCall creates a function call Expr value for a global (free) function.
func (ah *adaptingHelper) GlobalCall(function string, args ...*exprpb.Expr) *exprpb.Expr {
return mustAdaptToProto(ah.modernHelper.NewCall(function, mustAdaptToExprs(args)...))
}
// ReceiverCall creates a function call Expr value for a receiver-style function.
func (ah *adaptingHelper) ReceiverCall(function string, target *exprpb.Expr, args ...*exprpb.Expr) *exprpb.Expr {
return mustAdaptToProto(
ah.modernHelper.NewMemberCall(function, mustAdaptToExpr(target), mustAdaptToExprs(args)...))
}
// PresenceTest creates a Select TestOnly Expr value for modelling has() semantics.
func (ah *adaptingHelper) PresenceTest(operand *exprpb.Expr, field string) *exprpb.Expr {
op := mustAdaptToExpr(operand)
return mustAdaptToProto(ah.modernHelper.NewPresenceTest(op, field))
}
// Select create a field traversal Expr value.
func (ah *adaptingHelper) Select(operand *exprpb.Expr, field string) *exprpb.Expr {
op := mustAdaptToExpr(operand)
return mustAdaptToProto(ah.modernHelper.NewSelect(op, field))
}
// OffsetLocation returns the Location of the expression identifier.
func (ah *adaptingHelper) OffsetLocation(exprID int64) common.Location {
return ah.modernHelper.OffsetLocation(exprID)
}
// NewError associates an error message with a given expression id.
func (ah *adaptingHelper) NewError(exprID int64, message string) *Error {
return ah.modernHelper.NewError(exprID, message)
}
func mustAdaptToExprs(exprs []*exprpb.Expr) []ast.Expr {
adapted := make([]ast.Expr, len(exprs))
for i, e := range exprs {
adapted[i] = mustAdaptToExpr(e)
}
return adapted
}
func mustAdaptToExpr(e *exprpb.Expr) ast.Expr {
out, _ := adaptToExpr(e)
return out
}
func adaptToExpr(e *exprpb.Expr) (ast.Expr, *Error) {
if e == nil {
return nil, nil
}
out, err := ast.ProtoToExpr(e)
if err != nil {
return nil, wrapErr(e.GetId(), "proto conversion failure", err)
}
return out, nil
}
func mustAdaptToEntryExpr(e *exprpb.Expr_CreateStruct_Entry) ast.EntryExpr {
out, _ := ast.ProtoToEntryExpr(e)
return out
}
func mustAdaptToProto(e ast.Expr) *exprpb.Expr {
out, _ := adaptToProto(e)
return out
}
func adaptToProto(e ast.Expr) (*exprpb.Expr, *Error) {
if e == nil {
return nil, nil
}
out, err := ast.ExprToProto(e)
if err != nil {
return nil, wrapErr(e.ID(), "expr conversion failure", err)
}
return out, nil
}
func mustAdaptToProtoEntry(e ast.EntryExpr) *exprpb.Expr_CreateStruct_Entry {
out, _ := ast.EntryExprToProto(e)
return out
}
func toParserHelper(meh MacroExprHelper) (parser.ExprHelper, *Error) {
ah, ok := meh.(*adaptingHelper)
if !ok {
return nil, common.NewError(0,
fmt.Sprintf("unsupported macro helper: %v (%T)", meh, meh),
common.NoLocation)
}
return ah.modernHelper, nil
}