opa: github.com/open-policy-agent/opa/plugins/bundle Index | Files

package bundle

import "github.com/open-policy-agent/opa/plugins/bundle"

Package bundle implements bundle downloading.


Package Files

config.go plugin.go status.go


const Name = "bundle"

Name identifies the plugin on manager.

type Config Uses

type Config struct {
    download.Config // Deprecated: Use `Bundles` map instead

    Bundles map[string]*Source

    Name    string  `json:"name"`    // Deprecated: Use `Bundles` map instead
    Service string  `json:"service"` // Deprecated: Use `Bundles` map instead
    Prefix  *string `json:"prefix"`  // Deprecated: Use `Bundles` map instead

Config represents the configuration of the plugin. The Config can define a single bundle source or a map of `Source` objects defining where/how to download bundles. The older single bundle configuration is deprecated and will be removed in the future in favor of the `Bundles` map.

func ParseBundlesConfig Uses

func ParseBundlesConfig(config []byte, services []string) (*Config, error)

ParseBundlesConfig validates the config and injects default values for the defined `bundles`. This expects a map of bundle names to resource configurations.

func ParseConfig Uses

func ParseConfig(config []byte, services []string) (*Config, error)

ParseConfig validates the config and injects default values. This is for the legacy single bundle configuration. This will add the bundle to the `Bundles` map to provide compatibility with newer clients. Deprecated: Use `ParseBundlesConfig` with `bundles` OPA config option instead

func (*Config) IsMultiBundle Uses

func (c *Config) IsMultiBundle() bool

IsMultiBundle returns whether or not the config is the newer multi-bundle style config that uses `bundles` instead of top level bundle information. If/when we drop support for the older style config we can remove this too.

type Plugin Uses

type Plugin struct {
    // contains filtered or unexported fields

Plugin implements bundle activation.

func Lookup Uses

func Lookup(manager *plugins.Manager) *Plugin

Lookup returns the bundle plugin registered with the manager.

func New Uses

func New(parsedConfig *Config, manager *plugins.Manager) *Plugin

New returns a new Plugin with the given config.

func (*Plugin) Config Uses

func (p *Plugin) Config() *Config

Config returns the plugins current configuration

func (*Plugin) Reconfigure Uses

func (p *Plugin) Reconfigure(ctx context.Context, config interface{})

Reconfigure notifies the plugin that it's configuration has changed. Any bundle configs that have changed or been added/removed will take affect.

func (*Plugin) Register Uses

func (p *Plugin) Register(name interface{}, listener func(Status))

Register a listener to receive status updates. The name must be comparable. The listener will receive a status update for each bundle configured, they are not going to be aggregated. For all status updates use `RegisterBulkListener`.

func (*Plugin) RegisterBulkListener Uses

func (p *Plugin) RegisterBulkListener(name interface{}, listener func(map[string]*Status))

RegisterBulkListener registers a listener to receive bulk (aggregated) status updates. The name must be comparable.

func (*Plugin) Start Uses

func (p *Plugin) Start(ctx context.Context) error

Start runs the plugin. The plugin will periodically try to download bundles from the configured service. When a new bundle is downloaded, the data and policies are extracted and inserted into storage.

func (*Plugin) Stop Uses

func (p *Plugin) Stop(ctx context.Context)

Stop stops the plugin.

func (*Plugin) Unregister Uses

func (p *Plugin) Unregister(name interface{})

Unregister a listener to stop receiving status updates.

func (*Plugin) UnregisterBulkListener Uses

func (p *Plugin) UnregisterBulkListener(name interface{})

UnregisterBulkListener unregisters a listener to stop receiving aggregated status updates.

type Source Uses

type Source struct {

    Service  string `json:"service"`
    Resource string `json:"resource"`

Source is a configured bundle source to download bundles from

type Status Uses

type Status struct {
    Name                     string          `json:"name"`
    ActiveRevision           string          `json:"active_revision,omitempty"`
    LastSuccessfulActivation time.Time       `json:"last_successful_activation,omitempty"`
    LastSuccessfulDownload   time.Time       `json:"last_successful_download,omitempty"`
    LastSuccessfulRequest    time.Time       `json:"last_successful_request,omitempty"`
    LastRequest              time.Time       `json:"last_request,omitempty"`
    Code                     string          `json:"code,omitempty"`
    Message                  string          `json:"message,omitempty"`
    Errors                   []error         `json:"errors,omitempty"`
    Metrics                  metrics.Metrics `json:"metrics,omitempty"`

Status represents the status of processing a bundle.

func (*Status) SetActivateSuccess Uses

func (s *Status) SetActivateSuccess(revision string)

SetActivateSuccess updates the status object to reflect a successful activation.

func (*Status) SetDownloadSuccess Uses

func (s *Status) SetDownloadSuccess()

SetDownloadSuccess updates the status object to reflect a successful download.

func (*Status) SetError Uses

func (s *Status) SetError(err error)

SetError updates the status object to reflect a failure to download or activate. If err is nil, the error status is cleared.

func (*Status) SetRequest Uses

func (s *Status) SetRequest()

SetRequest updates the status object to reflect a download attempt.

Package bundle imports 18 packages (graph) and is imported by 10 packages. Updated 2020-02-07. Refresh now. Tools for package owners.