chore(deps): bump github.com/open-policy-agent/opa from 0.65.0 to 0.67.1
Bumps [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) from 0.65.0 to 0.67.1. - [Release notes](https://github.com/open-policy-agent/opa/releases) - [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-policy-agent/opa/compare/v0.65.0...v0.67.1) --- updated-dependencies: - dependency-name: github.com/open-policy-agent/opa dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
Ralf Haferkamp
parent
a381a3a0e8
commit
4d155475fe
+53
-3
@@ -15,6 +15,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -449,6 +450,7 @@ type Reader struct {
|
||||
name string
|
||||
persist bool
|
||||
regoVersion ast.RegoVersion
|
||||
followSymlinks bool
|
||||
}
|
||||
|
||||
// NewReader is deprecated. Use NewCustomReader instead.
|
||||
@@ -537,6 +539,11 @@ func (r *Reader) WithBundleName(name string) *Reader {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Reader) WithFollowSymlinks(yes bool) *Reader {
|
||||
r.followSymlinks = yes
|
||||
return r
|
||||
}
|
||||
|
||||
// WithLazyLoadingMode sets the bundle loading mode. If true,
|
||||
// bundles will be read in lazy mode. In this mode, data files in the bundle will not be
|
||||
// deserialized and the check to validate that the bundle data does not contain paths
|
||||
@@ -1190,7 +1197,8 @@ func (b *Bundle) SetRegoVersion(v ast.RegoVersion) {
|
||||
// If there is no defined version for the given path, the default version def is returned.
|
||||
// If the version does not correspond to ast.RegoV0 or ast.RegoV1, an error is returned.
|
||||
func (b *Bundle) RegoVersionForFile(path string, def ast.RegoVersion) (ast.RegoVersion, error) {
|
||||
if version, err := b.Manifest.numericRegoVersionForFile(path); err != nil {
|
||||
version, err := b.Manifest.numericRegoVersionForFile(path)
|
||||
if err != nil {
|
||||
return def, err
|
||||
} else if version == nil {
|
||||
return def, nil
|
||||
@@ -1198,9 +1206,8 @@ func (b *Bundle) RegoVersionForFile(path string, def ast.RegoVersion) (ast.RegoV
|
||||
return ast.RegoV0, nil
|
||||
} else if *version == 1 {
|
||||
return ast.RegoV1, nil
|
||||
} else {
|
||||
return def, fmt.Errorf("unknown bundle rego-version %d for file '%s'", *version, path)
|
||||
}
|
||||
return def, fmt.Errorf("unknown bundle rego-version %d for file '%s'", *version, path)
|
||||
}
|
||||
|
||||
func (m *Manifest) numericRegoVersionForFile(path string) (*int, error) {
|
||||
@@ -1667,6 +1674,7 @@ func preProcessBundle(loader DirectoryLoader, skipVerify bool, sizeLimitBytes in
|
||||
}
|
||||
|
||||
func readFile(f *Descriptor, sizeLimitBytes int64) (bytes.Buffer, error) {
|
||||
// Case for pre-loaded byte buffers, like those from the tarballLoader.
|
||||
if bb, ok := f.reader.(*bytes.Buffer); ok {
|
||||
_ = f.Close() // always close, even on error
|
||||
|
||||
@@ -1678,6 +1686,37 @@ func readFile(f *Descriptor, sizeLimitBytes int64) (bytes.Buffer, error) {
|
||||
return *bb, nil
|
||||
}
|
||||
|
||||
// Case for *lazyFile readers:
|
||||
if lf, ok := f.reader.(*lazyFile); ok {
|
||||
var buf bytes.Buffer
|
||||
if lf.file == nil {
|
||||
var err error
|
||||
if lf.file, err = os.Open(lf.path); err != nil {
|
||||
return buf, fmt.Errorf("failed to open file %s: %w", f.path, err)
|
||||
}
|
||||
}
|
||||
// Bail out if we can't read the whole file-- there's nothing useful we can do at that point!
|
||||
fileSize, _ := fstatFileSize(lf.file)
|
||||
if fileSize > sizeLimitBytes {
|
||||
return buf, fmt.Errorf(maxSizeLimitBytesErrMsg, strings.TrimPrefix(f.Path(), "/"), fileSize, sizeLimitBytes-1)
|
||||
}
|
||||
// Prealloc the buffer for the file read.
|
||||
buffer := make([]byte, fileSize)
|
||||
_, err := io.ReadFull(lf.file, buffer)
|
||||
if err != nil {
|
||||
return buf, err
|
||||
}
|
||||
_ = lf.file.Close() // always close, even on error
|
||||
|
||||
// Note(philipc): Replace the lazyFile reader in the *Descriptor with a
|
||||
// pointer to the wrapping bytes.Buffer, so that we don't re-read the
|
||||
// file on disk again by accident.
|
||||
buf = *bytes.NewBuffer(buffer)
|
||||
f.reader = &buf
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
// Fallback case:
|
||||
var buf bytes.Buffer
|
||||
n, err := f.Read(&buf, sizeLimitBytes)
|
||||
_ = f.Close() // always close, even on error
|
||||
@@ -1691,6 +1730,17 @@ func readFile(f *Descriptor, sizeLimitBytes int64) (bytes.Buffer, error) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
// Takes an already open file handle and invokes the os.Stat system call on it
|
||||
// to determine the file's size. Passes any errors from *File.Stat on up to the
|
||||
// caller.
|
||||
func fstatFileSize(f *os.File) (int64, error) {
|
||||
fileInfo, err := f.Stat()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return fileInfo.Size(), nil
|
||||
}
|
||||
|
||||
func normalizePath(p string) string {
|
||||
return filepath.ToSlash(p)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user