resources

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDirectoryPermissions fs.FileMode = os.ModeDir | 0o755
	DefaultFilePermissions      fs.FileMode = 0o644
)

Variables

This section is empty.

Functions

func EmbeddedFile

func EmbeddedFile(files embed.FS, path string) string

EmbeddedFile is a small helper function to helper reading embedded files

func NewTemplate

func NewTemplate(files embed.FS, path string, variables interface{}) string

NewTemplate makes it easier to return the data required to parse a template

Types

type Apt

type Apt struct {
	// Name is the name of the resource, and is what the file written to
	// disk will be based on
	Name string
	// URI is the source URI of the repository
	URI string

	// Distribution is normally the codename of the distribution. Defaults to
	// the Ubuntu codename.
	Distribution string
	// Source is repository type. Defaults to main.
	Source string
	// Parameters is a map of optional parameters that gets represented as key
	// value pairs, eg "[arch=amd64]"
	Parameters map[string]string
	// SigningKey will use the legacy apt-key command to retrieve a key
	SigningKey string
	// SigningKeyURL will retrieve the signing key for the package,
	// and include it as part of the source list
	SigningKeyURL string

	// Delete will remove the apt repository if set to true.
	Delete bool
	// Update will perform an apt update after adding the repository.
	Update bool
	// UpdateOnly will only perform an apt update.
	UpdateOnly bool
	// contains filtered or unexported fields
}

Apt configures Ubuntu apt repositories. It will automatically use sudo if the user is not root.

func AptUpdate

func AptUpdate() *Apt

func (*Apt) OperationName

func (a *Apt) OperationName() string

func (*Apt) Params

func (a *Apt) Params() *viaduct.ResourceParams

Params allows the resource to dynamically set options that will be passed at compile time

func (*Apt) PreflightChecks

func (a *Apt) PreflightChecks(log *viaduct.Logger) error

PreflightChecks sets default values for the parameters for a particular resource

func (*Apt) Run

func (a *Apt) Run(log *viaduct.Logger) error

type Directory

type Directory struct {
	// Path is the path of the directory
	Path string
	// Delete removes the directory if set to true.
	Delete bool

	// Permissions manages permissions for the directory
	Permissions
}

Directory manages a directory on the filesystem

func Dir

func Dir(path string) *Directory

Dir creates a new directory

func (*Directory) OperationName

func (d *Directory) OperationName() string

func (*Directory) Params

func (d *Directory) Params() *viaduct.ResourceParams

func (*Directory) PreflightChecks

func (d *Directory) PreflightChecks(log *viaduct.Logger) error

PreflightChecks sets default values for the parameters for a particular resource

func (*Directory) Run

func (d *Directory) Run(log *viaduct.Logger) error

type Download added in v0.3.1

type Download struct {
	// URL is where to download the data from
	URL string
	// Path is where to store the downloaded data
	Path string

	// NotIfExists will not download the file if it already exists
	NotIfExists bool

	// Permissions manages permissions for the downloaded content
	Permissions
}

Download will fetch data from the given URL, and write it to the given path.

func Wget added in v0.3.1

func Wget(url, path string) *Download

func (*Download) OperationName added in v0.3.1

func (a *Download) OperationName() string

func (*Download) Params added in v0.3.1

func (a *Download) Params() *viaduct.ResourceParams

func (*Download) PreflightChecks added in v0.3.1

func (a *Download) PreflightChecks(log *viaduct.Logger) error

func (*Download) Run added in v0.3.1

func (a *Download) Run(log *viaduct.Logger) error

type Execute

type Execute struct {
	// Command is the command to run
	Command string

	// WorkingDirectory is where to run the command. Optional.
	WorkingDirectory string

	// Unless is another command to run, which if exits cleanly signifies
	// that we should not run the execute command. Optional.
	Unless string
}

func Echo

func Echo(message string) *Execute

func Exec

func Exec(command string) *Execute

Exec is a shortcut for running a command

func ExecUnless

func ExecUnless(command, unless string) *Execute

ExecUnless is like Exec, but will only run conditionally

func (*Execute) OperationName

func (e *Execute) OperationName() string

func (*Execute) Params

func (e *Execute) Params() *viaduct.ResourceParams

func (*Execute) PreflightChecks

func (e *Execute) PreflightChecks(log *viaduct.Logger) error

func (*Execute) Run

func (e *Execute) Run(log *viaduct.Logger) error

type File

type File struct {
	// Path is the path of the file
	Path string
	// Content is the content of the file
	Content string
	// Delete will delete the file rather than create it if set to true.
	Delete bool

	// Permissions manages permissions for the file
	Permissions
}

File manages files on the filesystem

func CreateFile

func CreateFile(path, content string) *File

CreateFile writes content to the specified path

func DeleteFile

func DeleteFile(path string) *File

DeleteFile will delete the specified file

func Touch

func Touch(path string) *File

Touch simply touches an empty file to disk

func (*File) OperationName

func (f *File) OperationName() string

func (*File) Params

func (f *File) Params() *viaduct.ResourceParams

func (*File) PreflightChecks

func (f *File) PreflightChecks(log *viaduct.Logger) error

func (*File) Run

func (f *File) Run(log *viaduct.Logger) error

type Git

type Git struct {
	// Path specifies where to clone the repository to. Required.
	Path string
	// URL is the URL of the Git repository. Required.
	URL string

	// Reference specifies the reference to fetch. Defaults to "refs/heads/main".
	Reference string
	// Remote specifies the remote name. Defaults to "origin".
	RemoteName string
	// Ensure will continue to pull the latest changes. Optional.
	Ensure bool
	// Delete will remove the Git directory.
	Delete bool

	// Permissions manages permissions for the repository
	Permissions
}

Git manages a Git repository

func Repo

func Repo(path, url string) *Git

Repo will add a new repository, and ensure that it stays up to date.

func (*Git) OperationName

func (g *Git) OperationName() string

func (*Git) Params

func (g *Git) Params() *viaduct.ResourceParams

func (*Git) PreflightChecks

func (g *Git) PreflightChecks(log *viaduct.Logger) error

PreflightChecks sets default values for the parameters for a particular resource

func (*Git) Run

func (g *Git) Run(log *viaduct.Logger) error
type Link struct {
	// Path is the path of the symlinked file/directory
	Path string
	// Source is the original file/directory we are linking to
	Source string
	// Delete will delete the symlink.
	Delete bool
}

Link creates a symlink. If the file exists and is not a symlink, it will be created and replaced with the link. If the file exists, is a symlink but does not have the right source, it will be replaced.

func CreateLink(path, source string) *Link

CreateLink will create a new symlink.

func DeleteLink(path, source string) *Link

CreateLink will delete a symlink if it exists.

func (*Link) OperationName

func (l *Link) OperationName() string

func (*Link) Params

func (l *Link) Params() *viaduct.ResourceParams

func (*Link) PreflightChecks

func (l *Link) PreflightChecks(log *viaduct.Logger) error

PreflightChecks sets default values for the parameters for a particular resource

func (*Link) Run

func (l *Link) Run(log *viaduct.Logger) error

type Package

type Package struct {
	// Names are the package names
	Names []string

	// Verbose displays output from STDOUT. Optional.
	Verbose bool

	// Uninstall will uninstall the specified packages.
	Uninstall bool
}

Package installs one or more packages. Specify the package names.

func Pkg

func Pkg(name string) *Package

P is shortcut for declaring a new Package resource

func Pkgs

func Pkgs(names ...string) *Package

Ps is a shortcut for declaring a new Package resource with multiple packages

func (*Package) OperationName

func (p *Package) OperationName() string

func (*Package) Params

func (p *Package) Params() *viaduct.ResourceParams

func (*Package) PreflightChecks

func (p *Package) PreflightChecks(log *viaduct.Logger) error

PreflightChecks sets default values for the parameters for a particular resource

func (*Package) Run

func (p *Package) Run(log *viaduct.Logger) error

type Permissions added in v0.3.3

type Permissions struct {
	// Mode is the permissions set of the file
	Mode os.FileMode
	// User sets the user permissions by user name
	User string
	// Group sets the group permissions by group name
	Group string
	// UID sets the user permissions by UID
	UID int
	// GID sets the group permissions by GID
	GID int
	// Root enforces using the root user
	Root bool
}

Permissions can be used with some resources to manage how they set permissions on files

Jump to

Keyboard shortcuts

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