http

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GETParamExtraProperties     = "extraProps"
	GETParamResumable           = "resumable"
	GETParamIncludeProperties   = "includeProps"
	GETParamRaw                 = "raw"
	GETParamReceiveProperties   = "receiveProps"
	GETParamBytesPerSecond      = "bytesPerSecond"
	GETParamEnableDecompression = "enableDecompression"
	GETParamCompressionLevel    = "compressionLevel"
)
View Source
const (
	HeaderResumeReceiveToken  = "X-Receive-Resume-Token"
	HeaderResumeReceivedBytes = "X-Received-Bytes"
)

Variables

View Source
var (
	ErrDatasetNotFound    = errors.New("dataset not found")
	ErrInvalidResumeToken = errors.New("invalid resume token given")
	ErrResumeNotPossible  = errors.New("resume not possible")
)

Functions

func TestHTTPZPool

func TestHTTPZPool(testZPool, prefix, testFs string, fn func(server *httptest.Server))

Types

type Client

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

Client is the struct used to send requests to a zfs http server

func NewClient

func NewClient(server string, logger *slog.Logger) *Client

NewClient creates a new client for a zfs http server

func (*Client) DatasetSnapshots

func (c *Client) DatasetSnapshots(ctx context.Context, dataset string, extraProps []string) ([]zfs.Dataset, error)

DatasetSnapshots requests the snapshots for a remote dataset

func (*Client) ResumableSendToken

func (c *Client) ResumableSendToken(ctx context.Context, dataset string) (token string, curBytes uint64, err error)

ResumableSendToken requests the resume token for a remote dataset, if there is one

func (*Client) ResumeSend

func (c *Client) ResumeSend(ctx context.Context, dataset, resumeToken string, options ResumeSendOptions) (SendResult, error)

ResumeSend resumes a send for a dataset given the resume token

func (*Client) Send

func (c *Client) Send(ctx context.Context, send SnapshotSendOptions) (SendResult, error)

Send sends the snapshot job to the remote server

func (*Client) Server

func (c *Client) Server() string

Server returns the server

func (*Client) SetClient

func (c *Client) SetClient(client *http.Client)

SetClient configures a custom http client for doing requests

func (*Client) SetFilesystemProperties

func (c *Client) SetFilesystemProperties(ctx context.Context, filesystem string, props SetProperties) error

SetFilesystemProperties sets and/or unsets properties on the remote zfs filesystem

func (*Client) SetHeader

func (c *Client) SetHeader(name, value string)

SetHeader configures a header to be sent with all requests

func (*Client) SetSnapshotProperties

func (c *Client) SetSnapshotProperties(ctx context.Context, filesystem, snapshot string, props SetProperties) error

SetSnapshotProperties sets and/or unsets properties on the remote zfs snapshot

type Config

type Config struct {
	HTTPPathPrefix      string `json:"HTTPPathPrefix" yaml:"HTTPPathPrefix"`
	ParentDataset       string `json:"ParentDataset" yaml:"ParentDataset"`
	SpeedBytesPerSecond int64  `json:"SpeedBytesPerSecond" yaml:"SpeedBytesPerSecond"`

	Permissions Permissions `json:"Permissions" yaml:"Permissions"`
}

Config specifies the configuration for the zfs http server

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults sets all config values to their defaults (if they have one)

type HTTP

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

HTTP is the main object for serving the ZFS HTTP server

func NewHTTP

func NewHTTP(ctx context.Context, conf Config, logger *slog.Logger) *HTTP

NewHTTP creates a new HTTP server for ZFS interactions

func (*HTTP) ServeHTTP

func (h *HTTP) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Permissions

type Permissions struct {
	AllowSpeedOverride      bool `json:"AllowSpeedOverride" yaml:"AllowSpeedOverride"`
	AllowNonRaw             bool `json:"AllowNonRaw" yaml:"AllowNonRaw"`
	AllowIncludeProperties  bool `json:"AllowIncludeProperties" yaml:"AllowIncludeProperties"`
	AllowDestroyFilesystems bool `json:"AllowDestroyFilesystems" yaml:"AllowDestroyFilesystems"`
	AllowDestroySnapshots   bool `json:"AllowDestroySnapshots" yaml:"AllowDestroySnapshots"`
}

Permissions specifies permissions for requests over zfs http

type ReceiveProperties

type ReceiveProperties map[string]string

func DecodeReceiveProperties

func DecodeReceiveProperties(in string) (ReceiveProperties, error)

DecodeReceiveProperties decodes receive properties from an URL GET parameter

func (ReceiveProperties) Encode

func (r ReceiveProperties) Encode() string

Encode encodes a set of ReceiveProperties

type ResumeSendOptions

type ResumeSendOptions struct {
	zfs.ResumeSendOptions

	// ProgressFn: Set a callback function to receive updates about progress
	ProgressFn zfs.ProgressCallback
	// ProgressEvery determines progress update interval
	ProgressEvery time.Duration
}

ResumeSendOptions is a struct for a resume of a send job to a remote server using a Client

type SendResult

type SendResult struct {
	BytesSent int64
	TimeTaken time.Duration
}

SendResult contains some statistics from the sending of a snapshot

type SetProperties

type SetProperties struct {
	Set   map[string]string `json:"set,omitempty"`
	Unset []string          `json:"unset,omitempty"`
}

SetProperties is used by the http api to set and unset zfs properties remotely

type SnapshotSendOptions

type SnapshotSendOptions struct {
	zfs.SendOptions

	// Which dataset to send to
	DatasetName string
	// Which snapshot to send to (optional)
	SnapshotName string
	// The snapshot to send
	Snapshot *zfs.Dataset
	// Resumable determines whether the stream can be resumed
	Resumable bool

	Properties ReceiveProperties

	// ProgressFn: Set a callback function to receive updates about progress
	ProgressFn zfs.ProgressCallback
	// ProgressEvery determines progress update interval
	ProgressEvery time.Duration
}

SnapshotSendOptions is a struct for a send job to a remote server using a Client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL