()
| 94 | } |
| 95 | |
| 96 | func (lib *encoderLib) CompileOptions() []cel.EnvOption { |
| 97 | opts := []cel.EnvOption{ |
| 98 | cel.Function("base64.decode", |
| 99 | cel.Overload("base64_decode_string", []*cel.Type{cel.StringType}, cel.BytesType, |
| 100 | cel.UnaryBinding(func(str ref.Val) ref.Val { |
| 101 | s := str.(types.String) |
| 102 | return bytesOrError(base64DecodeString(string(s))) |
| 103 | }))), |
| 104 | cel.Function("base64.encode", |
| 105 | cel.Overload("base64_encode_bytes", []*cel.Type{cel.BytesType}, cel.StringType, |
| 106 | cel.UnaryBinding(func(bytes ref.Val) ref.Val { |
| 107 | b := bytes.(types.Bytes) |
| 108 | return stringOrError(base64EncodeBytes([]byte(b))) |
| 109 | }))), |
| 110 | } |
| 111 | if lib.version >= 1 { |
| 112 | estimators := []checker.CostOption{ |
| 113 | checker.OverloadCostEstimate("base64_decode_string", estimateDecode), |
| 114 | checker.OverloadCostEstimate("base64_encode_bytes", estimateEncode), |
| 115 | checker.OverloadCostEstimate("json_encode_dyn", estimateJSONEncode), |
| 116 | } |
| 117 | opts = append(opts, cel.CostEstimatorOptions(estimators...)) |
| 118 | opts = append(opts, |
| 119 | cel.Function("json.encode", |
| 120 | cel.Overload("json_encode_dyn", []*cel.Type{cel.DynType}, cel.StringType, |
| 121 | cel.UnaryBinding(func(val ref.Val) ref.Val { |
| 122 | return stringOrError(jsonEncodeValue(val)) |
| 123 | }))), |
| 124 | ) |
| 125 | } |
| 126 | return opts |
| 127 | } |
| 128 | |
| 129 | func (lib *encoderLib) ProgramOptions() []cel.ProgramOption { |
| 130 | var opts []cel.ProgramOption |
nothing calls this directly
no test coverage detected