chore(deps): Bump github.com/hashicorp/go-secure-stdlib/parseutil from 0.1.8 to 0.1.9 #4103
Annotations
3 errors and 1 warning
Run chainguard-dev/actions/nodiff@4ba8d060251254fc0e65500a8d3a90013a22a8d7:
third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parsepath.go#L1
Please run ./hack/update-codegen.sh.
diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parsepath.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parsepath.go
index ec812367..46ccbe77 100644
--- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parsepath.go
+++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parsepath.go
@@ -17,6 +17,15 @@ var (
ErrNotParsed = errors.New("not a parsed value")
)
+type options struct {
+ errorOnMissingEnv bool
+ noTrimSpaces bool
+}
+
+type option func() optionFunc
+
+type optionFunc func(*options)
+
// ParsePath parses a URL with schemes file://, env://, or any other. Depending
// on the scheme it will return specific types of data:
//
@@ -34,31 +43,60 @@ var (
// step that errored or something else (such as a file not found). This is
// useful to attempt to read a non-URL string from some resource, but where the
// original input may simply be a valid string of that type.
-func ParsePath(path string) (string, error) {
- return parsePath(path, false)
+func ParsePath(path string, options ...option) (string, error) {
+ return parsePath(path, false, options)
}
// MustParsePath behaves like ParsePath but will return ErrNotAUrl if the value
// is not a URL with a scheme that can be parsed by this function.
-func MustParsePath(path string) (string, error) {
- return parsePath(path, true)
+func MustParsePath(path string, options ...option) (string, error) {
+ return parsePath(path, true, options)
}
-func parsePath(path string, mustParse bool) (string, error) {
- path = strings.TrimSpace(path)
- parsed, err := url.Parse(path)
+func parsePath(path string, mustParse bool, passedOptions []option) (string, error) {
+ var opts options
+ for _, o := range passedOptions {
+ of := o()
+ of(&opts)
+ }
+
+ trimmedPath := strings.TrimSpace(path)
+ parsed, err := url.Parse(trimmedPath)
if err != nil {
- return path, fmt.Errorf("error parsing url (%q): %w", err.Error(), ErrNotAUrl)
+ err = fmt.Errorf("error parsing url (%q): %w", err.Error(), ErrNotAUrl)
+ if opts.noTrimSpaces {
+ return path, err
+ }
+ return trimmedPath, err
}
switch parsed.Scheme {
case "file":
- contents, err := ioutil.ReadFile(strings.TrimPrefix(path, "file://"))
+ contents, err := ioutil.ReadFile(strings.TrimPrefix(trimmedPath, "file://"))
if err != nil {
- return path, fmt.Errorf("error reading file at %s: %w", path, err)
+ return trimmedPath, fmt.Errorf("error reading file at %s: %w", trimmedPath, err)
+ }
+ if opts.noTrimSpaces {
+ return string(contents), nil
}
return strings.TrimSpace(string(contents)), nil
case "env":
- return strings.TrimSpace(os.Getenv(strings.TrimPrefix(path, "env://"))), nil
+ envKey := strings.TrimPrefix(trimmedPath, "env://")
+ envVal, ok := os.LookupEnv(envKey)
+ if opts.errorOnMissingEnv && !ok {
+ return "", fmt.Errorf("environment variable %s unset", envKey)
+ }
+ if opts.noTrimSpaces {
+ return envVal, nil
+ }
+ return strings.TrimSpace(envVal), nil
+ case "string":
+ // Meant if there is a need to provide a string literal that is prefixed by one of these URL schemes but want to "escape" it,
+ // e.g. "string://env://foo", in order to get the value "env://foo"
+ val := strings.TrimPrefix(trimmedPath, "string://")
+ if opts.noTrimSpaces {
+ return val, nil
+ }
+ return strings.TrimSpace(val), nil
default:
if mustParse {
return "", ErrNotParsed
@@ -66,3 +104,21 @@ func parsePath(path string, mustParse bool) (string, error) {
return path, nil
}
}
+
+// When true, values returned from ParsePath won't have leading/trailing spaces trimmed.
+func WithNoTrimSpaces(noTrim bool) option {
+ return func() optionFunc {
+ return optionFunc(func(o *options) {
+ o.noTrimSpaces = noTrim
+ })
+ }
+}
+
+// When true, if an environment variable is unset, an error will be returned rather than the empty string.
+func WithErrorOnMissingEnv(errorOnMissingEnv bool) option {
+ return func() optionFunc {
+
|
Run chainguard-dev/actions/nodiff@4ba8d060251254fc0e65500a8d3a90013a22a8d7:
third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parseutil.go#L1
Please run ./hack/update-codegen.sh.
diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parseutil.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parseutil.go
index eb3c0a50..815c993b 100644
--- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parseutil.go
+++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/parseutil/parseutil.go
@@ -18,7 +18,10 @@ import (
"github.com/mitchellh/mapstructure"
)
-var validCapacityString = regexp.MustCompile("^[\t ]*([0-9]+)[\t ]?([kmgtKMGT][iI]?[bB])?[\t ]*$")
+var (
+ validCapacityString = regexp.MustCompile("^[\t ]*([0-9]+)[\t ]?([kmgtKMGT][iI]?[bB])?[\t ]*$")
+ ErrDurationMultiplicationOverflow = errors.New("multiplication of durations resulted in overflow, one operand may be too large")
+)
// ParseCapacityString parses a capacity string and returns the number of bytes it represents.
// Capacity strings are things like 5gib or 10MB. Supported prefixes are kb, kib, mb, mib, gb,
@@ -105,6 +108,7 @@ func ParseDurationSecond(in interface{}) (time.Duration, error) {
if ok {
in = jsonIn.String()
}
+ var err error
switch inp := in.(type) {
case nil:
// return default of zero
@@ -114,7 +118,7 @@ func ParseDurationSecond(in interface{}) (time.Duration, error) {
}
if v, err := strconv.ParseInt(inp, 10, 64); err == nil {
- return time.Duration(v) * time.Second, nil
+ return overflowMul(time.Duration(v), time.Second)
}
if strings.HasSuffix(inp, "d") {
@@ -122,7 +126,7 @@ func ParseDurationSecond(in interface{}) (time.Duration, error) {
if err != nil {
return dur, err
}
- return time.Duration(v) * 24 * time.Hour, nil
+ return overflowMul(time.Duration(v), 24*time.Hour)
}
var err error
@@ -130,28 +134,39 @@ func ParseDurationSecond(in interface{}) (time.Duration, error) {
return dur, err
}
case int:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case int32:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case int64:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case uint:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case uint32:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case uint64:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case float32:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case float64:
- dur = time.Duration(inp) * time.Second
+ dur, err = overflowMul(time.Duration(inp), time.Second)
case time.Duration:
dur = inp
default:
return 0, errors.New("could not parse duration from input")
}
+ if err != nil {
+ dur = time.Duration(0)
+ }
+ return dur, err
+}
- return dur, nil
+// Multiplication of durations could overflow, this performs multiplication while erroring out if an overflow occurs
+func overflowMul(a time.Duration, b time.Duration) (time.Duration, error) {
+ x := a * b
+ if a != 0 && x/a != b {
+ return time.Duration(0), ErrDurationMultiplicationOverflow
+ }
+ return x, nil
}
// Parse an absolute timestamp from the provided arbitrary value (string or
|
Run chainguard-dev/actions/nodiff@4ba8d060251254fc0e65500a8d3a90013a22a8d7
Process completed with exit code 1.
|
Run actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a
Restore cache failed: Dependencies file is not found in /home/runner/work/policy-controller/policy-controller. Supported file pattern: go.sum
|
Loading