package http

import "github.com/open-policy-agent/opa/internal/wasm/sdk/opa/loader/http"

Index

Constants

const (
	// MinRetryDelay determines the minimum retry interval in case
	// of an error.
	MinRetryDelay = 100 * time.Millisecond

	// DefaultMinDelay is the default minimum re-downloading
	// interval in case of a previously successful download.
	DefaultMinDelay = 60 * time.Second

	// DefaultMaxDelay is the default maximum re-downloading
	// interval in case of a previously successful download.
	DefaultMaxDelay = 120 * time.Second
)

Types

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader downloads a bundle over HTTP. If started, it downloads the bundle periodically until closed.

func New

func New(o *opa.OPA) *Loader

New constructs a new HTTP loader periodically downloading a bundle over HTTP.

func (*Loader) Close

func (l *Loader) Close()

Close stops the downloading, releasing all resources.

func (*Loader) Init

func (l *Loader) Init() (*Loader, error)

Init initializes the loader after its construction and configuration. If invalid config, will return ErrInvalidConfig.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) error

Load downloads the bundle from a remote location and installs it. The possible returned errors are ErrInvalidBundle (in case of an error in downloading or opening the bundle) and the ones SetPolicyData of OPA returns.

func (*Loader) Start

func (l *Loader) Start(ctx context.Context) error

Start starts the periodic downloads, blocking until the first successful download. If cancelled, will return context.Cancelled.

func (*Loader) WithClient

func (l *Loader) WithClient(client *http.Client) *Loader

WithClient configures the HTTP client to use. If not configured, http.DefaultClient is used.

func (*Loader) WithErrorLogger

func (l *Loader) WithErrorLogger(logger func(error)) *Loader

WithErrorLogger configures an error logger invoked with all the errors.

func (*Loader) WithInterval

func (l *Loader) WithInterval(min, max time.Duration) *Loader

WithInterval configures the minimum and maximum delay between bundle downloads.

func (*Loader) WithPrepareRequest

func (l *Loader) WithPrepareRequest(prepare func(*http.Request) error) *Loader

WithPrepareRequest configures a handler to customize the HTTP requests before their sending. The HTTP request is not modified after the handle invocation.

func (*Loader) WithURL

func (l *Loader) WithURL(url string) *Loader

WithURL configures the URL to download the bundle from.

Source Files

config.go loader.go util.go

Version
v1.5.1 (latest)
Published
Jun 4, 2025
Platform
linux/amd64
Imports
12 packages
Last checked
11 minutes ago

Tools for package owners.