mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
caddyhttp: Add time.now placeholder and update cel-go (closes #2594)
This commit is contained in:
parent
bb67e19d7b
commit
0cbf467b3f
4 changed files with 11 additions and 3 deletions
3
go.mod
3
go.mod
|
@ -11,7 +11,8 @@ require (
|
|||
github.com/go-acme/lego/v3 v3.7.0
|
||||
github.com/go-chi/chi v4.1.1+incompatible
|
||||
github.com/gogo/protobuf v1.3.1
|
||||
github.com/google/cel-go v0.5.0
|
||||
github.com/golang/protobuf v1.3.4
|
||||
github.com/google/cel-go v0.5.1
|
||||
github.com/jsternberg/zap-logfmt v1.2.0
|
||||
github.com/klauspost/compress v1.10.5
|
||||
github.com/klauspost/cpuid v1.2.4
|
||||
|
|
4
go.sum
4
go.sum
|
@ -286,8 +286,8 @@ github.com/golangci/revgrep v0.0.0-20180812185044-276a5c0a1039/go.mod h1:qOQCunE
|
|||
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/cel-go v0.5.0 h1:mKsiw/KmT+VlDZnYFd2SE5ULrbe8RPlb0rHBem2Bv7I=
|
||||
github.com/google/cel-go v0.5.0/go.mod h1:9SvtVVTtZV4DTB1/RuAD1D2HhuqEIdmZEE/r/lrFyKE=
|
||||
github.com/google/cel-go v0.5.1 h1:oDsbtAwlwFPEcC8dMoRWNuVzWJUDeDZeHjoet9rXjTs=
|
||||
github.com/google/cel-go v0.5.1/go.mod h1:9SvtVVTtZV4DTB1/RuAD1D2HhuqEIdmZEE/r/lrFyKE=
|
||||
github.com/google/cel-spec v0.4.0/go.mod h1:2pBM5cU4UKjbPDXBgwWkiwBsVgnxknuEJ7C5TDWwORQ=
|
||||
github.com/google/certificate-transparency-go v1.1.0/go.mod h1:i+Q7XY+ArBveOUT36jiHGfuSK1fHICIg6sUkRxPAbCs=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -276,6 +276,8 @@ func globalDefaultReplacements(key string) (interface{}, bool) {
|
|||
return runtime.GOOS, true
|
||||
case "system.arch":
|
||||
return runtime.GOARCH, true
|
||||
case "time.now":
|
||||
return nowFunc(), true
|
||||
case "time.now.common_log":
|
||||
return nowFunc().Format("02/Jan/2006:15:04:05 -0700"), true
|
||||
case "time.now.year":
|
||||
|
|
Loading…
Reference in a new issue