feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
28
vendor/github.com/open-policy-agent/opa/topdown/time.go
generated
vendored
28
vendor/github.com/open-policy-agent/opa/topdown/time.go
generated
vendored
@@ -12,6 +12,7 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
_ "time/tzdata" // this is needed to have LoadLocation when no filesystem tzdata is available
|
||||
|
||||
"github.com/open-policy-agent/opa/ast"
|
||||
"github.com/open-policy-agent/opa/topdown/builtins"
|
||||
@@ -49,7 +50,13 @@ func builtinTimeParseNanos(_ BuiltinContext, operands []*ast.Term, iter func(*as
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := time.Parse(string(format), string(value))
|
||||
formatStr := string(format)
|
||||
// look for the formatStr in our acceptedTimeFormats and
|
||||
// use the constant instead if it matches
|
||||
if f, ok := acceptedTimeFormats[formatStr]; ok {
|
||||
formatStr = f
|
||||
}
|
||||
result, err := time.Parse(formatStr, string(value))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -82,6 +89,20 @@ func builtinParseDurationNanos(_ BuiltinContext, operands []*ast.Term, iter func
|
||||
return iter(ast.NumberTerm(int64ToJSONNumber(int64(value))))
|
||||
}
|
||||
|
||||
// Represent exposed constants for formatting from the stdlib time pkg
|
||||
var acceptedTimeFormats = map[string]string{
|
||||
"ANSIC": time.ANSIC,
|
||||
"UnixDate": time.UnixDate,
|
||||
"RubyDate": time.RubyDate,
|
||||
"RFC822": time.RFC822,
|
||||
"RFC822Z": time.RFC822Z,
|
||||
"RFC850": time.RFC850,
|
||||
"RFC1123": time.RFC1123,
|
||||
"RFC1123Z": time.RFC1123Z,
|
||||
"RFC3339": time.RFC3339,
|
||||
"RFC3339Nano": time.RFC3339Nano,
|
||||
}
|
||||
|
||||
func builtinFormat(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
|
||||
t, layout, err := tzTime(operands[0].Value)
|
||||
if err != nil {
|
||||
@@ -90,7 +111,12 @@ func builtinFormat(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term)
|
||||
// Using RFC3339Nano time formatting as default
|
||||
if layout == "" {
|
||||
layout = time.RFC3339Nano
|
||||
} else if layoutStr, ok := acceptedTimeFormats[layout]; ok {
|
||||
// if we can find a constant specified, use the constant
|
||||
layout = layoutStr
|
||||
}
|
||||
// otherwise try to treat the fmt string as a datetime fmt string
|
||||
|
||||
timestamp := t.Format(layout)
|
||||
return iter(ast.StringTerm(timestamp))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user