* chore(deps): consolidate dependency and security bumps Dependabot PRs applied: - #12878 qs 6.15.2 -> 6.16.0 (web/web-runtime) - #13013 alpine 3.24.1 -> 3.24.2 - #13061 actions/checkout -> v7.0.1 (missed instance in k8s.yml) - #13062 actions/setup-node -> v7.0.0 (missed instance in k8s.yml) - #13075 simple-git 3.36.0 -> 4.0.1 (security) - #13076 katex 0.16.45 -> 0.18.2+ (security) - #13077 dompurify 3.4.13 -> 3.4.16 (security) - #13079 go deps minor-and-patch group, 18 updates (opa 1.19.0 -> 1.21.1, otel 1.46 -> 1.47, bleve, govips, grpc-gateway, lico, tablewriter, logrus, gjson, x/exp, x/image, genproto, etc.) Skipped (already satisfied on master): #12513, #12624, #12625, #12633 Manual security bumps via pnpm.overrides (no dependabot PR existed): - axios -> 1.20.0 - smol-toml -> 1.9.0 - postcss -> 8.5.23 - postcss-selector-parser -> 7.1.6 - colord -> 2.9.4 - unhead -> 2.1.13 - markdown-it -> 14.3.1 - esbuild -> 0.28.1 - brace-expansion 5.0.11 -> 5.0.12 Not fixable: sprintf-js and elliptic have no patched version released upstream yet; left as-is. go build and pnpm install verified clean. * chore(deps): fix residual transitive vulns found by trivy trivy flagged duplicate/stale resolutions that survived the earlier override pass: dompurify (3.4.12 -> 3.4.16), qs (6.14.2 -> 6.16.0), and fast-uri (3.1.7 -> 3.1.8, CVE-2026-86472). Added/bumped pnpm.overrides accordingly. trivy fs scan of web/pnpm-lock.yaml now clean. * chore(deps): bump reva to bac0e1ee144ab853a81c6b02142032f102dd245a Pins github.com/owncloud/reva/v2 to bac0e1ee144ab853a81c6b02142032f102dd245a, pulling in its go-playground/locales and huandu/xstrings version bumps. Appends this PR to changelog/unreleased/bump-reva.md. go build ./... verified clean after go mod vendor resync. * fix(ci): revert unhead override, breaks web build * revert: keep k8s.yml actions/checkout and setup-node pinned
156 lines
5.6 KiB
Go
156 lines
5.6 KiB
Go
// Copyright 2026 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended.
|
|
// For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the [github.com/open-policy-agent/opa/v1] package instead.
|
|
// See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.
|
|
//
|
|
// Package loader contains utilities for loading files into OPA.
|
|
package loader
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/open-policy-agent/opa/ast"
|
|
"github.com/open-policy-agent/opa/bundle"
|
|
v1 "github.com/open-policy-agent/opa/v1/loader"
|
|
)
|
|
|
|
// Errors is a wrapper for multiple loader errors.
|
|
type Errors = v1.Errors
|
|
|
|
// Result represents the result of successfully loading zero or more files.
|
|
type Result = v1.Result
|
|
|
|
// RegoFile represents the result of loading a single Rego source file.
|
|
type RegoFile = v1.RegoFile
|
|
|
|
// Filter defines the interface for filtering files during loading. If the
|
|
// filter returns true, the file should be excluded from the result.
|
|
type Filter = v1.Filter
|
|
|
|
// GlobExcludeName excludes files and directories whose names do not match the
|
|
// shell style pattern at minDepth or greater.
|
|
func GlobExcludeName(pattern string, minDepth int) Filter {
|
|
return v1.GlobExcludeName(pattern, minDepth)
|
|
}
|
|
|
|
// FileLoader defines an interface for loading OPA data files
|
|
// and Rego policies.
|
|
type FileLoader = v1.FileLoader
|
|
|
|
// NewFileLoader returns a new FileLoader instance.
|
|
func NewFileLoader() FileLoader {
|
|
return v1.NewFileLoader().WithRegoVersion(ast.DefaultRegoVersion)
|
|
}
|
|
|
|
// GetBundleDirectoryLoader returns a bundle directory loader which can be used to load
|
|
// files in the directory
|
|
func GetBundleDirectoryLoader(path string) (bundle.DirectoryLoader, bool, error) {
|
|
return v1.GetBundleDirectoryLoader(path)
|
|
}
|
|
|
|
// GetBundleDirectoryLoaderWithFilter returns a bundle directory loader which can be used to load
|
|
// files in the directory after applying the given filter.
|
|
func GetBundleDirectoryLoaderWithFilter(path string, filter Filter) (bundle.DirectoryLoader, bool, error) {
|
|
return v1.GetBundleDirectoryLoaderWithFilter(path, filter)
|
|
}
|
|
|
|
// GetBundleDirectoryLoaderFS returns a bundle directory loader which can be used to load
|
|
// files in the directory.
|
|
func GetBundleDirectoryLoaderFS(fsys fs.FS, path string, filter Filter) (bundle.DirectoryLoader, bool, error) {
|
|
return v1.GetBundleDirectoryLoaderFS(fsys, path, filter)
|
|
}
|
|
|
|
// FilteredPaths is the same as FilterPathsFS using the current diretory file
|
|
// system
|
|
func FilteredPaths(paths []string, filter Filter) ([]string, error) {
|
|
return v1.FilteredPaths(paths, filter)
|
|
}
|
|
|
|
// FilteredPathsFS return a list of files from the specified
|
|
// paths while applying the given filters. If any filter returns true, the
|
|
// file/directory is excluded.
|
|
func FilteredPathsFS(fsys fs.FS, paths []string, filter Filter) ([]string, error) {
|
|
return v1.FilteredPathsFS(fsys, paths, filter)
|
|
}
|
|
|
|
// Schemas loads a schema set from the specified file path.
|
|
func Schemas(schemaPath string) (*ast.SchemaSet, error) {
|
|
return v1.Schemas(schemaPath)
|
|
}
|
|
|
|
// All returns a Result object loaded (recursively) from the specified paths.
|
|
//
|
|
// Deprecated: Use FileLoader.Filtered() instead.
|
|
func All(paths []string) (*Result, error) {
|
|
return NewFileLoader().Filtered(paths, nil)
|
|
}
|
|
|
|
// Filtered returns a Result object loaded (recursively) from the specified
|
|
// paths while applying the given filters. If any filter returns true, the
|
|
// file/directory is excluded.
|
|
//
|
|
// Deprecated: Use FileLoader.Filtered() instead.
|
|
func Filtered(paths []string, filter Filter) (*Result, error) {
|
|
return NewFileLoader().Filtered(paths, filter)
|
|
}
|
|
|
|
// AsBundle loads a path as a bundle. If it is a single file
|
|
// it will be treated as a normal tarball bundle. If a directory
|
|
// is supplied it will be loaded as an unzipped bundle tree.
|
|
//
|
|
// Deprecated: Use FileLoader.AsBundle() instead.
|
|
func AsBundle(path string) (*bundle.Bundle, error) {
|
|
return NewFileLoader().AsBundle(path)
|
|
}
|
|
|
|
// AllRegos returns a Result object loaded (recursively) with all Rego source
|
|
// files from the specified paths.
|
|
func AllRegos(paths []string) (*Result, error) {
|
|
return NewFileLoader().Filtered(paths, func(_ string, info os.FileInfo, _ int) bool {
|
|
return !info.IsDir() && !strings.HasSuffix(info.Name(), bundle.RegoExt)
|
|
})
|
|
}
|
|
|
|
// Rego is deprecated. Use RegoWithOpts instead.
|
|
func Rego(path string) (*RegoFile, error) {
|
|
return RegoWithOpts(path, ast.ParserOptions{})
|
|
}
|
|
|
|
// RegoWithOpts returns a RegoFile object loaded from the given path.
|
|
func RegoWithOpts(path string, opts ast.ParserOptions) (*RegoFile, error) {
|
|
if opts.RegoVersion == ast.RegoUndefined {
|
|
opts.RegoVersion = ast.DefaultRegoVersion
|
|
}
|
|
|
|
return v1.RegoWithOpts(path, opts)
|
|
}
|
|
|
|
// CleanPath returns the normalized version of a path that can be used as an identifier.
|
|
func CleanPath(path string) string {
|
|
return v1.CleanPath(path)
|
|
}
|
|
|
|
// Paths returns a sorted list of files contained at path. If recurse is true
|
|
// and path is a directory, then Paths will walk the directory structure
|
|
// recursively and list files at each level.
|
|
func Paths(path string, recurse bool) (paths []string, err error) {
|
|
return v1.Paths(path, recurse)
|
|
}
|
|
|
|
// Dirs resolves filepaths to directories. It will return a list of unique
|
|
// directories.
|
|
func Dirs(paths []string) []string {
|
|
return v1.Dirs(paths)
|
|
}
|
|
|
|
// SplitPrefix returns a tuple specifying the document prefix and the file
|
|
// path.
|
|
func SplitPrefix(path string) ([]string, string) {
|
|
return v1.SplitPrefix(path)
|
|
}
|