package bundle
import "github.com/open-policy-agent/opa/bundle"
Package bundle implements bundle loading.
Index ¶
- Constants
- func Activate(opts *ActivateOpts) error
- func ActivateLegacy(opts *ActivateOpts) error
- func Deactivate(opts *DeactivateOpts) error
- func EraseManifestFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) error
- func LegacyEraseManifestFromStore(ctx context.Context, store storage.Store, txn storage.Transaction) error
- func LegacyReadRevisionFromStore(ctx context.Context, store storage.Store, txn storage.Transaction) (string, error)
- func LegacyWriteManifestToStore(ctx context.Context, store storage.Store, txn storage.Transaction, manifest Manifest) error
- func ManifestStoragePath(name string) storage.Path
- func ReadBundleNamesFromStore(ctx context.Context, store storage.Store, txn storage.Transaction) ([]string, error)
- func ReadBundleRevisionFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) (string, error)
- func ReadBundleRootsFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) ([]string, error)
- func RootPathsContain(roots []string, path string) bool
- func RootPathsOverlap(pathA string, pathB string) bool
- func Write(w io.Writer, bundle Bundle) error
- func WriteManifestToStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string, manifest Manifest) error
- type ActivateOpts
- type Bundle
- func Merge(bundles []*Bundle) (*Bundle, error)
- func (b Bundle) Copy() Bundle
- func (b Bundle) Equal(other Bundle) bool
- func (b *Bundle) ParsedModules(bundleName string) map[string]*ast.Module
- type DeactivateOpts
- type Descriptor
- func (d *Descriptor) Close() error
- func (d *Descriptor) Path() string
- func (d *Descriptor) Read(dest io.Writer, n int64) (int64, error)
- func (d *Descriptor) URL() string
- type DirectoryLoader
- func NewDirectoryLoader(root string) DirectoryLoader
- func NewTarballLoader(r io.Reader) DirectoryLoader
- func NewTarballLoaderWithBaseURL(r io.Reader, baseURL string) DirectoryLoader
- type Manifest
- func (m *Manifest) AddRoot(r string)
- func (m Manifest) Copy() Manifest
- func (m Manifest) Equal(other Manifest) bool
- func (m *Manifest) Init()
- func (m Manifest) String() string
- type ModuleFile
- type Reader
- func NewCustomReader(loader DirectoryLoader) *Reader
- func NewReader(r io.Reader) *Reader
- func (r *Reader) IncludeManifestInData(includeManifestInData bool) *Reader
- func (r *Reader) Read() (Bundle, error)
- func (r *Reader) WithBaseDir(dir string) *Reader
- func (r *Reader) WithMetrics(m metrics.Metrics) *Reader
- type Writer
Constants ¶
const ( RegoExt = ".rego" WasmFile = "/policy.wasm" )
Common file extensions and file names.
Functions ¶
func Activate ¶
func Activate(opts *ActivateOpts) error
Activate the bundle(s) by loading into the given Store. This will load policies, data, and record the manifest in storage. The compiler provided will have had the polices compiled on it.
func ActivateLegacy ¶
func ActivateLegacy(opts *ActivateOpts) error
ActivateLegacy calls Activate for the bundles but will also write their manifest to the older unnamed store location. Deprecated: Use Activate with named bundles instead.
func Deactivate ¶
func Deactivate(opts *DeactivateOpts) error
Deactivate the bundle(s). This will erase associated data, policies, and the manifest entry from the store.
func EraseManifestFromStore ¶
func EraseManifestFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) error
EraseManifestFromStore will remove the manifest from storage. This function is called when the bundle is deactivated.
func LegacyEraseManifestFromStore ¶
func LegacyEraseManifestFromStore(ctx context.Context, store storage.Store, txn storage.Transaction) error
LegacyEraseManifestFromStore will erase the bundle manifest from the older single (unnamed) bundle manifest location. Deprecated: Use WriteManifestToStore and named bundles instead.
func LegacyReadRevisionFromStore ¶
func LegacyReadRevisionFromStore(ctx context.Context, store storage.Store, txn storage.Transaction) (string, error)
LegacyReadRevisionFromStore will read the bundle manifest revision from the older single (unnamed) bundle manifest location. Deprecated: Use ReadBundleRevisionFromStore and named bundles instead.
func LegacyWriteManifestToStore ¶
func LegacyWriteManifestToStore(ctx context.Context, store storage.Store, txn storage.Transaction, manifest Manifest) error
LegacyWriteManifestToStore will write the bundle manifest to the older single (unnamed) bundle manifest location. Deprecated: Use WriteManifestToStore and named bundles instead.
func ManifestStoragePath ¶
ManifestStoragePath is the storage path used for the given named bundle manifest.
func ReadBundleNamesFromStore ¶
func ReadBundleNamesFromStore(ctx context.Context, store storage.Store, txn storage.Transaction) ([]string, error)
ReadBundleNamesFromStore will return a list of bundle names which have had their metadata stored.
func ReadBundleRevisionFromStore ¶
func ReadBundleRevisionFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) (string, error)
ReadBundleRevisionFromStore returns the revision in the specified bundle. If the bundle is not activated, this function will return storage NotFound error.
func ReadBundleRootsFromStore ¶
func ReadBundleRootsFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) ([]string, error)
ReadBundleRootsFromStore returns the roots in the specified bundle. If the bundle is not activated, this function will return storage NotFound error.
func RootPathsContain ¶
RootPathsContain takes a set of bundle root paths and returns true if the path is contained.
func RootPathsOverlap ¶
RootPathsOverlap takes in two bundle root paths and returns true if they overlap.
func Write ¶
Write is deprecated. Use NewWriter instead.
func WriteManifestToStore ¶
func WriteManifestToStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string, manifest Manifest) error
WriteManifestToStore will write the manifest into the storage. This function is called when the bundle is activated.
Types ¶
type ActivateOpts ¶
type ActivateOpts struct { Ctx context.Context Store storage.Store Txn storage.Transaction Compiler *ast.Compiler Metrics metrics.Metrics Bundles map[string]*Bundle // Optional ExtraModules map[string]*ast.Module // Optional // contains filtered or unexported fields }
ActivateOpts defines options for the Activate API call.
type Bundle ¶
type Bundle struct { Manifest Manifest Data map[string]interface{} Modules []ModuleFile Wasm []byte }
Bundle represents a loaded bundle. The bundle can contain data and policies.
func Merge ¶
Merge accepts a set of bundles and merges them into a single result bundle. If there are any conflicts during the merge (e.g., with roots) an error is returned. The result bundle will have an empty revision except in the special case where a single bundle is provided (and in that case the bundle is just returned unmodified.) Merge currently returns an error if multiple bundles are provided and any of those bundles contain wasm modules (because wasm module merging is not implemented.)
func (Bundle) Copy ¶
Copy returns a deep copy of the bundle.
func (Bundle) Equal ¶
Equal returns true if this bundle's contents equal the other bundle's contents.
func (*Bundle) ParsedModules ¶
ParsedModules returns a map of parsed modules with names that are unique and human readable for the given a bundle name.
type DeactivateOpts ¶
type DeactivateOpts struct { Ctx context.Context Store storage.Store Txn storage.Transaction BundleNames map[string]struct{} }
DeactivateOpts defines options for the Deactivate API call
type Descriptor ¶
type Descriptor struct {
// contains filtered or unexported fields
}
Descriptor contains information about a file and can be used to read the file contents.
func (*Descriptor) Close ¶
func (d *Descriptor) Close() error
Close the file, on some Loader implementations this might be a no-op. It should *always* be called regardless of file.
func (*Descriptor) Path ¶
func (d *Descriptor) Path() string
Path returns the path of the file.
func (*Descriptor) Read ¶
Read will read all the contents from the file the Descriptor refers to into the dest writer up n bytes. Will return an io.EOF error if EOF is encountered before n bytes are read.
func (*Descriptor) URL ¶
func (d *Descriptor) URL() string
URL returns the url of the file.
type DirectoryLoader ¶
type DirectoryLoader interface { // NextFile must return io.EOF if there is no next value. The returned // descriptor should *always* be closed when no longer needed. NextFile() (*Descriptor, error) }
DirectoryLoader defines an interface which can be used to load files from a directory by iterating over each one in the tree.
func NewDirectoryLoader ¶
func NewDirectoryLoader(root string) DirectoryLoader
NewDirectoryLoader returns a basic DirectoryLoader implementation that will load files from a given root directory path.
func NewTarballLoader ¶
func NewTarballLoader(r io.Reader) DirectoryLoader
NewTarballLoader is deprecated. Use NewTarballLoaderWithBaseURL instead.
func NewTarballLoaderWithBaseURL ¶
func NewTarballLoaderWithBaseURL(r io.Reader, baseURL string) DirectoryLoader
NewTarballLoaderWithBaseURL returns a new DirectoryLoader that reads files out of a gzipped tar archive. The file URLs will be prefixed with the baseURL.
type Manifest ¶
Manifest represents the manifest from a bundle. The manifest may contain metadata such as the bundle revision.
func (*Manifest) AddRoot ¶
AddRoot adds r to the roots of m. This function is idempotent.
func (Manifest) Copy ¶
Copy returns a deep copy of the manifest.
func (Manifest) Equal ¶
Equal returns true if m is semantically equivalent to other.
func (*Manifest) Init ¶
func (m *Manifest) Init()
Init initializes the manifest. If you instantiate a manifest manually, call Init to ensure that the roots are set properly.
func (Manifest) String ¶
type ModuleFile ¶
ModuleFile represents a single module contained a bundle.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader contains the reader to load the bundle from.
func NewCustomReader ¶
func NewCustomReader(loader DirectoryLoader) *Reader
NewCustomReader returns a new Reader configured to use the specified DirectoryLoader.
func NewReader ¶
NewReader is deprecated. Use NewCustomReader instead.
func (*Reader) IncludeManifestInData ¶
IncludeManifestInData sets whether the manifest metadata should be included in the bundle's data.
func (*Reader) Read ¶
Read returns a new Bundle loaded from the reader.
func (*Reader) WithBaseDir ¶
WithBaseDir sets a base directory for file paths of loaded Rego modules. This will *NOT* affect the loaded path of data files.
func (*Reader) WithMetrics ¶
WithMetrics sets the metrics object to be used while loading bundles
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements bundle serialization.
func NewWriter ¶
NewWriter returns a bundle writer that writes to w.
func (*Writer) DisableFormat ¶
DisableFormat configures the writer to just write out raw bytes instead of formatting modules before serialization.
func (*Writer) UseModulePath ¶
UseModulePath configures the writer to use the module file path instead of the module file URL during serialization. This is for backwards compatibility.
func (*Writer) Write ¶
Write writes the bundle to the writer's output stream.
Source Files ¶
- Version
- v0.20.4
- Published
- May 22, 2020
- Platform
- linux/amd64
- Imports
- 22 packages
- Last checked
- 53 minutes ago –
Tools for package owners.