client

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFile = typederror.NewRoot("file resource")

	ErrFileExists = typederror.New("file exists", ErrFile)

	ErrFileNotFound = typederror.New("file not found", ErrFile)

	ErrFileUnexpected = typederror.New("unexpected error", ErrFile)
)
View Source
var (
	ErrFolder = typederror.NewRoot("folder resource")

	ErrFolderPathExists = typederror.New("folder path exists", ErrFile)

	ErrFolderNotFound = typederror.New("folder not found", ErrFile)

	ErrFolderUnexpected = typederror.New("unexpected error", ErrFile)
)
View Source
var (
	ErrGroup = typederror.NewRoot("group resource")

	ErrGroupNotFound = typederror.New("group not found", ErrGroup)

	ErrGroupNameExists = typederror.New("group name exists", ErrGroup)

	ErrGroupGidExists = typederror.New("group gid exists", ErrGroup)

	ErrGroupUnexpected = typederror.New("unexpected error", ErrGroup)
)
View Source
var (
	ErrInfo = typederror.NewRoot("info resource")

	ErrInfoUnexpected = typederror.New("unexpected error", ErrInfo)
)
View Source
var (
	ErrLink = typederror.NewRoot("link resource")

	ErrLinkExists = typederror.New("link exists", ErrLink)

	ErrLinkNotFound = typederror.New("link not found", ErrLink)

	ErrLinkUnexpected = typederror.New("unexpected error", ErrLink)
)
View Source
var (
	ErrApkPackage = typederror.NewRoot("apk package resource")

	ErrApkPackageManagerNotAvailable = typederror.New("apk not available", ErrApkPackage)

	ErrApkPackageManager = typederror.New("apk error", ErrApkPackage)

	ErrApkPackageUnexpected = typederror.New("unexpected error", ErrApkPackage)
)
View Source
var (
	ErrAptPackage = typederror.NewRoot("apt package resource")

	ErrAptPackageManagerNotAvailable = typederror.New("apt not available", ErrAptPackage)

	ErrAptPackageManager = typederror.New("apt error", ErrAptPackage)

	ErrAptPackageUnexpected = typederror.New("unexpected error", ErrAptPackage)
)
View Source
var (
	ErrService = typederror.NewRoot("service resource")

	ErrServiceNotFound = typederror.New("service not found", ErrService)

	ErrServiceRunlevelNotFound = typederror.New("runlevel not found", ErrService)

	ErrServiceOperation = typederror.New("failed service operation", ErrService)

	ErrServiceUnexpected = typederror.New("unexpected error", ErrService)
)
View Source
var (
	ErrUser = typederror.NewRoot("user resource")

	ErrUserNotFound = typederror.New("user not found", ErrUser)

	ErrUserNameExists = typederror.New("user name exists", ErrUser)

	ErrUserUidExists = typederror.New("user uid exists", ErrUser)

	ErrUserGroupNotFound = typederror.New("primary group not found", ErrUser)

	ErrUserUnexpected = typederror.New("unexpected error", ErrUser)
)

Functions

func GetOsReleaseInfo

func GetOsReleaseInfo(ctx context.Context, s system.System) (*osrelease.Info, error)

GetOsReleaseInfo returns an osrelease.Info based on the /etc/os-release of the provided system.System

func PackageNameFilter

func PackageNameFilter(names ...string) func(pkg *Package) bool

func PackageStateFiler

func PackageStateFiler(state PackageState) func(pkg *Package) bool

Types

type CatCommand

type CatCommand struct {
	Path string
}

func (*CatCommand) Command

func (c *CatCommand) Command() string

type ChgrpCommand

type ChgrpCommand struct {
	Path  string
	Group string

	// NoDereference: affect each symbolic link instead of any referenced file
	NoDereference bool
}

func (*ChgrpCommand) Command

func (c *ChgrpCommand) Command() string

type ChmodCommand

type ChmodCommand struct {
	Path string
	Mode fs.FileMode
}

func (*ChmodCommand) Command

func (c *ChmodCommand) Command() string

type ChownCommand

type ChownCommand struct {
	Path  string
	User  string
	Group string

	// NoDereference: affect each symbolic link instead of any referenced file
	NoDereference bool
}

func (*ChownCommand) Command

func (c *ChownCommand) Command() string

type Command

type Command interface {
	Command() string
}

func NewCommand

func NewCommand(c string) Command

type CommandResult

type CommandResult struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int
}

func ExecuteCommand

func ExecuteCommand(ctx context.Context, s system.System, c Command) (*CommandResult, error)

func ExecuteCommandWithOptions

func ExecuteCommandWithOptions(ctx context.Context, s system.System, c Command, opts ...ExecuteCommandOption) (*CommandResult, error)

func (*CommandResult) Error

func (c *CommandResult) Error() error

Error returns an error if the CommandResult has a non-negative exit code

func (*CommandResult) StderrString

func (c *CommandResult) StderrString() string

func (*CommandResult) StdoutString

func (c *CommandResult) StdoutString() string

type CompositeCommand

type CompositeCommand []Command

func (CompositeCommand) Command

func (c CompositeCommand) Command() string

type ExecuteCommandOption

type ExecuteCommandOption func(*ExecuteCommandOptions)

func WithStderr

func WithStderr() ExecuteCommandOption

func WithStderrFunc

func WithStderrFunc(f func(writer io.Writer) io.Writer) ExecuteCommandOption

func WithStdout

func WithStdout() ExecuteCommandOption

func WithStdoutFunc

func WithStdoutFunc(f func(writer io.Writer) io.Writer) ExecuteCommandOption

type ExecuteCommandOptions

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

type File

type File struct {
	Path  string
	Mode  fs.FileMode
	User  string
	Uid   int
	Group string
	Gid   int

	// Content optionally contains the file contents when enabled with FileClientIncludeContent
	Content io.Reader
	Md5Sum  string
}

type FileClient

type FileClient interface {
	Get(ctx context.Context, path string) (*File, error)
	Create(ctx context.Context, f File) error
	Update(ctx context.Context, f File) error
	Delete(ctx context.Context, path string) error
}

func NewFileClient

func NewFileClient(s system.System, opts ...FileClientOpt) FileClient

type FileClientOpt

type FileClientOpt func(c *fileClient)

func FileClientCompression

func FileClientCompression(enabled bool) FileClientOpt

func FileClientIncludeContent

func FileClientIncludeContent(include bool) FileClientOpt

type Folder

type Folder struct {
	Path  string
	Mode  fs.FileMode
	User  string
	Uid   int
	Group string
	Gid   int
}

type FolderClient

type FolderClient interface {
	Get(ctx context.Context, path string) (*Folder, error)
	Create(ctx context.Context, folder Folder) error
	Update(ctx context.Context, folder Folder) error
	Delete(ctx context.Context, path string) error
}

func NewFolderClient

func NewFolderClient(s system.System) FolderClient

type Group

type Group struct {
	Gid    int
	Name   string
	System bool
}

type GroupClient

type GroupClient interface {
	Get(ctx context.Context, gid int) (*Group, error)
	Create(ctx context.Context, group Group) (int, error)
	Update(ctx context.Context, group Group) error
	Delete(ctx context.Context, gid int) error
}

func NewGroupClient

func NewGroupClient(s system.System) GroupClient

type IdentityInfo

type IdentityInfo struct {
	Name  string
	Uid   int
	Group string
	Gid   int
}

type InfoClient

type InfoClient interface {
	GetRelease(ctx context.Context) (*ReleaseInfo, error)
	GetIdentity(ctx context.Context) (*IdentityInfo, error)
}

func NewInfoClient

func NewInfoClient(s system.System) InfoClient

type InputCommand

type InputCommand interface {
	Command
	Stdin() io.Reader
}

func NewInputCommand

func NewInputCommand(c string, in io.Reader) InputCommand
type Link struct {
	Path   string
	Target string
	User   string
	Uid    int
	Group  string
	Gid    int
}

type LinkClient

type LinkClient interface {
	Get(ctx context.Context, path string) (*Link, error)
	Create(ctx context.Context, l Link) error
	Update(ctx context.Context, l Link) error
	Delete(ctx context.Context, path string) error
}

func NewLinkClient

func NewLinkClient(s system.System) LinkClient

type MkdirCommand

type MkdirCommand struct {
	Path string
	Mode fs.FileMode
}

func (*MkdirCommand) Command

func (c *MkdirCommand) Command() string

type Package

type Package struct {
	// Manager is an id of the responsible package management system
	// Supported values are "apk"
	Manager PackageManager

	// Name is the name of the package
	Name string

	Version PackageVersion

	State PackageState
}

type PackageClient

type PackageClient interface {
	Get(ctx context.Context) (Packages, error)
	Apply(ctx context.Context, pkgs Packages) error
}

func NewApkPackageClient

func NewApkPackageClient(s system.System) PackageClient

func NewAptPackageClient

func NewAptPackageClient(s system.System) PackageClient

type PackageManager

type PackageManager string
const ApkPackageManager PackageManager = "apk"
const AptPackageManager PackageManager = "apt"

type PackageMap

type PackageMap map[string]*Package

PackageMap is a map of *Package indexed by package name

func (PackageMap) ToList

func (p PackageMap) ToList() Packages

ToList returns Packages sorted by package name

type PackageState

type PackageState uint8
const (
	PackageInstalled    PackageState = 0
	PackageNotInstalled PackageState = 1
)

type PackageVersion

type PackageVersion struct {
	Required  string
	Installed string
	Available string
}

type Packages

type Packages []*Package

Packages is a list of *Package

func (Packages) ByName

func (p Packages) ByName() func(i, j int) bool

func (Packages) Filter

func (p Packages) Filter(f func(pkg *Package) bool) Packages

func (Packages) Names

func (p Packages) Names() []string

func (Packages) ToMap

func (p Packages) ToMap() PackageMap

type ReleaseInfo

type ReleaseInfo struct {
	Name    string
	Vendor  string
	Version string
	Release string
}

type Service

type Service struct {
	Supervisor ServiceSupervisor
	Name       string
	Target     string
	Runlevel   string
	Enabled    *bool
	Status     *ServiceStatus
}

type ServiceApplyOption

type ServiceApplyOption func(*ServiceApplyOptions)

func ServiceReload added in v0.2.0

func ServiceReload() ServiceApplyOption

ServiceReload is an option for Apply to ensure a service is reloaded

func ServiceRestart added in v0.2.0

func ServiceRestart() ServiceApplyOption

ServiceRestart is an option for Apply to ensure a service is restarted

type ServiceApplyOptions

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

type ServiceClient

type ServiceClient interface {
	Get(ctx context.Context, args ServiceGetArgs) (*Service, error)
	Apply(ctx context.Context, s Service, opts ...ServiceApplyOption) error
}

func NewOpenRcServiceClient

func NewOpenRcServiceClient(s system.System) ServiceClient

func NewSystemdServiceClient

func NewSystemdServiceClient(s system.System) ServiceClient

type ServiceGetArgs

type ServiceGetArgs struct {
	Name     string
	Runlevel string
}

type ServiceStatus

type ServiceStatus string
const (
	ServiceStatusStarted ServiceStatus = "started"

	ServiceStatusStarting ServiceStatus = "starting"

	ServiceStatusStopped ServiceStatus = "stopped"

	ServiceStatusStopping ServiceStatus = "stopping"

	ServiceStatusUndefined ServiceStatus = "undefined"
)

func ServiceStatusPtr

func ServiceStatusPtr(s ServiceStatus) *ServiceStatus

func (ServiceStatus) IsPending

func (s ServiceStatus) IsPending() bool

type ServiceSupervisor

type ServiceSupervisor string
const ServiceSupervisorOpenRC ServiceSupervisor = "openrc"
const ServiceSupervisorSystemd ServiceSupervisor = "systemd"

type SimpleCommand

type SimpleCommand string

func (SimpleCommand) Command

func (a SimpleCommand) Command() string

type User

type User struct {
	Name   string
	Uid    *int
	Group  string
	Gid    *int
	System *bool
	Home   string
	Shell  string
}

type UserClient

type UserClient interface {
	Get(ctx context.Context, uid int) (*User, error)
	Create(ctx context.Context, user User) (int, error)
	Update(ctx context.Context, user User) error
	Delete(ctx context.Context, uid int) error
}

func NewUserClient

func NewUserClient(s system.System) UserClient

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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