provider

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package provider defines the contract every cloud backup provider plugin must satisfy. "Config" is non-secret and returned in plain text on GET; "credentials" are secret, encrypted at rest, accepted only on create/update and never returned.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig indicates a required config field was missing or
	// out of range.
	ErrInvalidConfig = errors.New("provider: invalid config")
	// ErrInvalidCredentials indicates the provider rejected the credentials.
	ErrInvalidCredentials = errors.New("provider: invalid credentials")
	// ErrPermissionDenied indicates the credentials authenticated but do not
	// have the necessary permissions (e.g. cannot write to the bucket).
	ErrPermissionDenied = errors.New("provider: permission denied")
	// ErrNotFound indicates the configured location (bucket, container, etc.)
	// does not exist.
	ErrNotFound = errors.New("provider: not found")
	// ErrTransient indicates a transient remote failure that may succeed on retry.
	ErrTransient = errors.New("provider: transient failure")
)

Common provider errors. Wrap with fmt.Errorf("%w: ...") for additional context. The service surfaces these as 4xx/5xx where appropriate.

Functions

This section is empty.

Types

type Config

type Config map[string]any

Config holds non-secret provider-specific configuration (e.g. bucket name, region, prefix).

type Credentials

type Credentials map[string]any

Credentials holds secret provider-specific values (e.g. access keys).

type Field

type Field struct {
	Name        string
	Label       string
	Type        FieldType
	Required    bool
	Help        string
	Placeholder string
	// Sensitive marks credential-bearing fields. The service refuses to log
	// or return these in API responses.
	Sensitive bool
}

Field describes one field of a provider's config or credentials schema.

type FieldType

type FieldType string

FieldType enumerates the input widget kinds presented to the frontend. Strings match the OpenAPI BackupFieldType schema.

const (
	FieldTypeString   FieldType = "string"
	FieldTypePassword FieldType = "password"
	FieldTypeRegion   FieldType = "region"
	FieldTypeURL      FieldType = "url"
	// FieldTypeBool is rendered as a checkbox/toggle.
	FieldTypeBool FieldType = "bool"
)

type Provider

type Provider interface {
	// Name returns the stable identifier (e.g. "s3"). Must be unique across
	// providers and match the value persisted in backup_destinations.provider.
	Name() string

	// DisplayName returns a human-readable label (e.g. "Amazon S3").
	DisplayName() string

	// Description returns user-facing copy describing the provider.
	Description() string

	// ConfigSchema describes non-secret fields shown on the create form.
	ConfigSchema() []Field

	// CredentialSchema describes secret fields shown on the create form.
	CredentialSchema() []Field

	// Validate authenticates against the provider and verifies the supplied
	// config/credentials can perform a list-and-write operation against the
	// configured location. It MUST NOT mutate user data permanently; if
	// writing a probe is necessary, the probe must be cleaned up.
	Validate(ctx context.Context, cfg Config, creds Credentials) error

	// Upload streams a backup blob to the provider and returns the path.
	Upload(ctx context.Context, cfg Config, creds Credentials, in UploadInput) (*UploadResult, error)

	// List enumerates backups previously written by NinerLog to this
	// destination. Implementations scope the listing to the configured prefix
	// and the well-known filename convention.
	List(ctx context.Context, cfg Config, creds Credentials) ([]RemoteBackup, error)

	// Delete removes one object at path.
	Delete(ctx context.Context, cfg Config, creds Credentials, path string) error
}

Provider is the contract for a cloud storage backend.

type Registry

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

Registry holds the set of providers known to this binary. It is intended to be constructed once at startup and treated as read-only thereafter.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) All

func (r *Registry) All() []Provider

All returns the registered providers in stable (name-sorted) order.

func (*Registry) Get

func (r *Registry) Get(name string) (Provider, bool)

Get returns the provider by name, or (nil, false) if absent.

func (*Registry) MustGet

func (r *Registry) MustGet(name string) Provider

MustGet panics if the provider is not registered. Use only in code paths where the name has already been validated against the registry.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the registered provider names sorted alphabetically. The slice is a fresh copy and safe to mutate.

func (*Registry) Register

func (r *Registry) Register(p Provider)

Register adds a provider. Duplicate names panic.

type RemoteBackup

type RemoteBackup struct {
	Path         string
	SizeBytes    int64
	LastModified time.Time
}

RemoteBackup represents one previously-uploaded backup object as listed by the provider. Path uniquely identifies the object within the destination so the service can delete it during retention pruning.

type UploadInput

type UploadInput struct {
	// Reader yields the backup contents (gzipped JSON in the current
	// implementation, though the provider treats it as opaque bytes).
	Reader io.Reader
	// Size is the exact number of bytes in Reader; required for many SDKs.
	Size int64
	// Filename is a suggestion; the provider may prepend a prefix derived from
	// Config. Example: "ninerlog-backup-2025-11-19T03-00-00Z.json.gz".
	Filename string
	// ContentType describes the payload; typically "application/gzip" or
	// "application/json".
	ContentType string
}

UploadInput is the payload passed to Provider.Upload.

type UploadResult

type UploadResult struct {
	// RemotePath uniquely identifies the uploaded object within the destination.
	RemotePath string
}

UploadResult is returned from Provider.Upload.

Directories

Path Synopsis
Package s3 implements the cloud backup provider contract against Amazon S3 and S3-compatible object stores (MinIO, Backblaze B2, Cloudflare R2, Wasabi, etc.) using the minio-go client.
Package s3 implements the cloud backup provider contract against Amazon S3 and S3-compatible object stores (MinIO, Backblaze B2, Cloudflare R2, Wasabi, etc.) using the minio-go client.
Package sftp implements the cloud backup provider contract against any SSH server with SFTP enabled (OpenSSH, Dropbear, atmoz/sftp, hosting providers offering SFTP-only accounts, etc.) using golang.org/x/crypto/ssh and github.com/pkg/sftp.
Package sftp implements the cloud backup provider contract against any SSH server with SFTP enabled (OpenSSH, Dropbear, atmoz/sftp, hosting providers offering SFTP-only accounts, etc.) using golang.org/x/crypto/ssh and github.com/pkg/sftp.
Package webdav implements the cloud backup provider contract against any RFC 4918 compliant WebDAV server (Nextcloud, ownCloud, mailbox.org, Box, Apache mod_dav, …) using the studio-b12/gowebdav client.
Package webdav implements the cloud backup provider contract against any RFC 4918 compliant WebDAV server (Nextcloud, ownCloud, mailbox.org, Box, Apache mod_dav, …) using the studio-b12/gowebdav client.

Jump to

Keyboard shortcuts

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