Skip to content

Commit

Permalink
chore: bring back deleted funcs for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Dec 17, 2023
1 parent 6b6061f commit 82ece68
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 55 deletions.
86 changes: 45 additions & 41 deletions funcs/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}),
),
)
}
4 changes: 2 additions & 2 deletions funcs/cel_exports.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions kubernetes/cel_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
18 changes: 9 additions & 9 deletions kubernetes/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 82ece68

Please sign in to comment.