diff --git a/funcs/aws.go b/funcs/aws.go index 94bcc38f9..e1d8d9b7f 100644 --- a/funcs/aws.go +++ b/funcs/aws.go @@ -11,44 +11,48 @@ import ( var mapStringString = cel.MapType(cel.StringType, cel.StringType) -var arnToMap = cel.Function("aws.arnToMap", - cel.Overload("arnToMap", - []*cel.Type{ - cel.StringType, - }, - mapStringString, - cel.UnaryBinding(func(arg ref.Val) ref.Val { - - split := strings.Split(arg.Value().(string), ":") - m := map[string]string{ - "service": split[2], - "region": split[3], - "account": split[4], - "resource": split[5], - } - return types.DefaultTypeAdapter.NativeToValue(m) - }), - ), -) - -var fromAwsMap = cel.Function("aws.fromAWSMap", - cel.Overload("fromAWSMap_list_map", - []*cel.Type{ - cel.ListType(cel.MapType(cel.StringType, cel.StringType)), - }, - cel.MapType(cel.StringType, cel.StringType), - cel.UnaryBinding(func(arg ref.Val) ref.Val { - list, err := arg.ConvertToNative(reflect.TypeOf([]map[string]string{})) - if err != nil { - return types.WrapErr(err) - } - - var out = make(map[string]string) - for _, i := range list.([]map[string]string) { - out[i["Name"]] = i["Value"] - } - - return types.DefaultTypeAdapter.NativeToValue(out) - }), - ), -) +func arnToMap(fnName string) cel.EnvOption { + return cel.Function(fnName, + cel.Overload(fnName+"_overload", + []*cel.Type{ + cel.StringType, + }, + mapStringString, + cel.UnaryBinding(func(arg ref.Val) ref.Val { + + split := strings.Split(arg.Value().(string), ":") + m := map[string]string{ + "service": split[2], + "region": split[3], + "account": split[4], + "resource": split[5], + } + return types.DefaultTypeAdapter.NativeToValue(m) + }), + ), + ) +} + +func fromAwsMap(fnName string) cel.EnvOption { + return cel.Function(fnName, + cel.Overload(fnName+"_overload", + []*cel.Type{ + cel.ListType(cel.MapType(cel.StringType, cel.StringType)), + }, + cel.MapType(cel.StringType, cel.StringType), + cel.UnaryBinding(func(arg ref.Val) ref.Val { + list, err := arg.ConvertToNative(reflect.TypeOf([]map[string]string{})) + if err != nil { + return types.WrapErr(err) + } + + var out = make(map[string]string) + for _, i := range list.([]map[string]string) { + out[i["Name"]] = i["Value"] + } + + return types.DefaultTypeAdapter.NativeToValue(out) + }), + ), + ) +} diff --git a/funcs/cel_exports.go b/funcs/cel_exports.go index e0ba30ce6..80f205565 100644 --- a/funcs/cel_exports.go +++ b/funcs/cel_exports.go @@ -7,8 +7,8 @@ import ( ) var CelEnvOption = []cel.EnvOption{ - fromAwsMap, - arnToMap, + fromAwsMap("aws.fromAWSMap"), fromAwsMap("fromAWSMap"), + arnToMap("aws.arnToMap"), arnToMap("arnToMap"), // collSliceGen, collHasGen, diff --git a/kubernetes/cel_export.go b/kubernetes/cel_export.go index b12e4c272..b90c67878 100644 --- a/kubernetes/cel_export.go +++ b/kubernetes/cel_export.go @@ -7,9 +7,9 @@ func Library() []cel.EnvOption { Lists(), URLs(), Regex(), - k8sGetHealth(), - k8sGetStatus(), - k8sIsHealthy(), + k8sGetHealth("k8s.getHealth"), k8sGetHealth("GetHealth"), + k8sGetStatus("k8s.getStatus"), k8sGetStatus("GetStatus"), + k8sIsHealthy("k8s.isHealthy"), k8sIsHealthy("IsHealthy"), k8sIsHealthy("k8s.is_healthy"), k8sCPUAsMillicores(), k8sMemoryAsBytes(), } diff --git a/kubernetes/health.go b/kubernetes/health.go index 6699c3efc..0c73823e2 100644 --- a/kubernetes/health.go +++ b/kubernetes/health.go @@ -104,9 +104,9 @@ func GetHealth(in interface{}) HealthStatus { } } -func k8sGetHealth() cel.EnvOption { - return cel.Function("k8s.getHealth", - cel.Overload("GetHealth_any", +func k8sGetHealth(fnName string) cel.EnvOption { + return cel.Function(fnName, + cel.Overload(fnName+"_overload", []*cel.Type{cel.AnyType}, cel.AnyType, cel.UnaryBinding(func(obj ref.Val) ref.Val { @@ -117,9 +117,9 @@ func k8sGetHealth() cel.EnvOption { ) } -func k8sGetStatus() cel.EnvOption { - return cel.Function("k8s.getStatus", - cel.Overload("GetStatus", +func k8sGetStatus(fnName string) cel.EnvOption { + return cel.Function(fnName, + cel.Overload(fnName+"_overload", []*cel.Type{cel.AnyType}, cel.AnyType, cel.UnaryBinding(func(obj ref.Val) ref.Val { @@ -129,9 +129,9 @@ func k8sGetStatus() cel.EnvOption { ) } -func k8sIsHealthy() cel.EnvOption { - return cel.Function("k8s.isHealthy", - cel.Overload("IsHealthy_interface{}", +func k8sIsHealthy(fnName string) cel.EnvOption { + return cel.Function(fnName, + cel.Overload(fnName+"_overload", []*cel.Type{cel.AnyType}, cel.StringType, cel.UnaryBinding(func(obj ref.Val) ref.Val {