storage

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRoot        = "/var/lib/factum2/storage"
	DefaultHTTPListen  = ":8088"
	DefaultTFTPListen  = ":69"
	DefaultSFTPListen  = ":2222"
	DefaultSFTPUser    = "factum"
	DefaultStorageSock = "/run/factum2-storage/api.sock"
)
View Source
const MaxChunk = 8 << 20

MaxChunk is the largest PUT body the unix API accepts (hub frames stay under 32MiB).

Variables

View Source
var (
	ErrInvalidPath = errors.New("invalid path")
	ErrNotFound    = errors.New("not found")
	ErrExists      = errors.New("already exists")
	ErrNotEmpty    = errors.New("directory not empty")
	ErrIsDir       = errors.New("is a directory")
	ErrNotDir      = errors.New("not a directory")
)

Functions

func ApplyConfigDefaults

func ApplyConfigDefaults(c *Config)

func ApplySettingsDefaults

func ApplySettingsDefaults(s *models.Settings)

ApplySettingsDefaults fills empty storage paths when the feature is on.

func Enabled

func Enabled(db *gorm.DB) bool

Enabled reports Settings.StorageEnabled (nil/false = off). Disabling the flag only hides the Software GUI and /api/software/* routes — it does not delete files on the storage host.

func NewAPIHandler

func NewAPIHandler(repo *Repo) http.Handler

func NewDeviceHTTP

func NewDeviceHTTP(repo *Repo) http.Handler

NewDeviceHTTP serves repository files for device pull (no auth).

func NormalizeProtocol

func NormalizeProtocol(p string) (string, error)

func PullCommands

func PullCommands(platform, protocol, src, dest string) ([]string, error)

PullCommands returns the CLI the device should run to copy src onto dest. src is a full locator (http://…, tftp://…). dest is the on-device path.

func PullToDevice

func PullToDevice(req CopyRequest, src string) (string, error)

PullToDevice SSHes (via the platform driver) and runs the copy-from-URL command.

func PushToDevice

func PushToDevice(repo *Repo, req CopyRequest) error

PushToDevice copies the local file to the device over SCP or SFTP.

func ServeSFTP

func ServeSFTP(ln net.Listener, repo *Repo, user, pass string, hostKey ssh.Signer) error

ServeSFTP is a read-only SSH server (SFTP subsystem plus scp -f) jailed to repo.

func ServeTFTP

func ServeTFTP(ln net.PacketConn, repo *Repo) error

ServeTFTP answers read-only RRQs from repo until ln is closed.

func SourceURL

func SourceURL(cfg *Config, protocol, relPath string) (string, error)

SourceURL is the locator a device uses to pull path over protocol.

func StorageSocketPath

func StorageSocketPath(yamlOverride string) string

StorageSocketPath resolves the daemon unix API path. yamlOverride is ConfigStorage.Socket. "none"/"0" disables the socket. Empty uses DefaultStorageSock.

Types

type Config

type Config struct {
	util.CommonConfig
	Root         string `json:"root"`
	HTTPListen   string `json:"http_listen"`
	HTTPURL      string `json:"http_url"`
	TFTPListen   string `json:"tftp_listen"`
	TFTPHost     string `json:"tftp_host"`
	SFTPListen   string `json:"sftp_listen"`
	SFTPHost     string `json:"sftp_host"`
	SFTPUser     string `json:"sftp_user"`
	SFTPPassword string `json:"sftp_password"`
}

Config is what factum2-storage fetches from the primary (GET /api/storage-config). Paths and listen addresses apply on the storage host, which may be the primary or a remote worker.

func FetchRemoteConfig

func FetchRemoteConfig(factumConfig *util.ConfigFactum) (*Config, error)

type CopyRequest

type CopyRequest struct {
	Path        string `json:"path"`
	Device      string `json:"device"`
	Protocol    string `json:"protocol"` // http, tftp, scp, sftp
	Destination string `json:"destination"`
	Username    string `json:"-"`
	Password    string `json:"-"`
	Platform    string `json:"-"`
	Host        string `json:"-"` // device FQDN/IP to dial for push
}

CopyRequest is a factum→device transfer of one repository file.

type Entry

type Entry struct {
	Name        string    `json:"name"`
	Path        string    `json:"path"`
	IsDir       bool      `json:"is_dir"`
	HasChildren bool      `json:"has_children"`
	Size        int64     `json:"size"`
	ModTime     time.Time `json:"mod_time"`
}

Entry is one file or folder in the software repository.

type Repo

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

Repo is a path-jailed directory tree used as the software image store.

func NewRepo

func NewRepo(root string) (*Repo, error)

func (*Repo) CreateFile

func (r *Repo) CreateFile(relPath string, offset int64) (*os.File, error)

CreateFile opens path for writing. offset 0 truncates (or creates). A non-zero offset writes at that position (chunked upload).

func (*Repo) List

func (r *Repo) List(relPath string) ([]Entry, error)

func (*Repo) Mkdir

func (r *Repo) Mkdir(relPath string) error

func (*Repo) Move

func (r *Repo) Move(from, to string) error

func (*Repo) Open

func (r *Repo) Open(relPath string) (*os.File, Entry, error)

func (*Repo) Remove

func (r *Repo) Remove(relPath string) error

func (*Repo) Root

func (r *Repo) Root() string

func (*Repo) Stat

func (r *Repo) Stat(relPath string) (Entry, error)

func (*Repo) WriteAt

func (r *Repo) WriteAt(relPath string, offset int64, data io.Reader) (int64, error)

type Server

type Server struct {
	Repo   *Repo
	Config Config
	Socket string
}

Server runs the unix control API plus optional device-facing HTTP/TFTP/SFTP.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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