diff options
author | Matthew Holt <[email protected]> | 2020-05-21 18:19:01 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2020-05-21 18:19:01 -0600 |
commit | 0cbf467b3fbde471e5ee67680fb98a9af2a9b16e (patch) | |
tree | bc63554172715f80e074bd8123ef6b9c2232b998 /modules | |
parent | bb67e19d7bacd70a13647538c8e9820eb42090b2 (diff) | |
download | caddy-0cbf467b3fbde471e5ee67680fb98a9af2a9b16e.tar.gz caddy-0cbf467b3fbde471e5ee67680fb98a9af2a9b16e.zip |
caddyhttp: Add time.now placeholder and update cel-go (closes #2594)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/celmatcher.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/modules/caddyhttp/celmatcher.go b/modules/caddyhttp/celmatcher.go index bede78f67..a22635292 100644 --- a/modules/caddyhttp/celmatcher.go +++ b/modules/caddyhttp/celmatcher.go @@ -21,10 +21,12 @@ import ( "reflect" "regexp" "strings" + "time" "github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" "github.com/gogo/protobuf/proto" + "github.com/golang/protobuf/ptypes/timestamp" "github.com/google/cel-go/cel" "github.com/google/cel-go/checker/decls" "github.com/google/cel-go/common/types" @@ -204,6 +206,9 @@ func (celTypeAdapter) NativeToValue(value interface{}) ref.Val { switch v := value.(type) { case celHTTPRequest: return v + case time.Time: + // TODO: eliminate direct protobuf dependency, sigh -- just wrap stdlib time.Time instead... + return types.Timestamp{Timestamp: ×tamp.Timestamp{Seconds: v.Unix(), Nanos: int32(v.Nanosecond())}} case error: types.NewErr(v.Error()) } |