Documentation
¶
Overview ¶
Package florist helps to create non-idempotent, one-file-contains-everything installers/provisioners.
Index ¶
- Constants
- func CacheValidity() time.Duration
- func Chown(fpath string, username string) error
- func CmdRun(log *slog.Logger, cmd *exec.Cmd) error
- func CopyFile(srcPath string, dstPath string, mode os.FileMode, owner string) error
- func CopyFileFs(srcFs fs.FS, srcPath string, dstPath string, mode os.FileMode, owner string) error
- func FileExists(fpath string) (bool, error)
- func GroupSystemAdd(groupname string) error
- func JoinErrors(errs ...error) error
- func ListFs(fsys fs.FS) []string
- func ListeningSockets() (*sets.Set[string], error)
- func Log() *slog.Logger
- func LowLevelInit(logOutput io.Writer, logLevel string, cacheValidity time.Duration) error
- func MainErr[T *struct{}](opts *Options) error
- func MainInt(opts *Options) int
- func MakeTmplData(secrets fs.FS, keys ...string) (map[string]string, error)
- func NetFetch(client *http.Client, url string, hashType Hash, hash string, dstDir string) (string, error)
- func PrivateIPs() ([]string, error)
- func PublicIPs() ([]string, error)
- func SkipIfNotDisposableHost(t *testing.T)
- func SupplementaryGroups(username string, groups ...string) error
- func TemplateFromFs(srcFs fs.FS, srcPath string, tmplData any) (string, error)
- func TemplateFromFsWithDelims(srcFs fs.FS, srcPath string, tmplData any) (string, error)
- func TemplateFromText(tmplText string, tmplData any, tmplName string) (string, error)
- func UntarOne(tarPath string, name string, dstPath string) error
- func UnzipOne(zipPath string, name string, dstPath string) error
- func User() *user.User
- func UserAdd(username string) error
- func UserSystemAdd(username string, homedir string) error
- func WriteFile(fname string, data string, mode os.FileMode, owner string) error
- type Config
- type Configurer
- type Flower
- type Hash
- type Installer
- type Options
- type Provisioner
Constants ¶
const (
DefOsPkgCacheValidity = 1 * time.Hour
)
const (
WorkDir = "/tmp/florist.work"
)
Variables ¶
This section is empty.
Functions ¶
func CacheValidity ¶
func CmdRun ¶
CmdRun runs 'cmd', redirecting its stdout and stderr to 'log'. CmdRun blocks until 'cmd' terminates.
func CopyFile ¶
CopyFile copies file srcPath to dstPath, with mode and owner. The source and destination files reside in the "real" filesystem. Notes: - If dstPath exists, it will be overwritten. - Setting an owner different that the current user requires elevated privileges.
func CopyFileFs ¶
func CopyFileFs( srcFs fs.FS, srcPath string, dstPath string, mode os.FileMode, owner string, ) error
CopyFileFs copies file srcPath to dstPath, with mode and owner. The source file resides in the srcFs filesystem (for example, via go:embed), while the destination file resides in the "real" filesystem. Notes: - If dstPath exists, it will be overwritten. - Setting an owner different that the current user requires elevated privileges.
func FileExists ¶ added in v0.3.3
Return true if file 'fpath' exists. WARNING Checking for file existence is racy and in certain cases can lead to security vulnerabilities. Think twice before using this. In the majority of cases, you can simply skip the existence check, since the next operation will fail in any case if the file doesn't exist.
Explanation of the TOCTOU vulnerability: https://wiki.sei.cmu.edu/confluence/display/c/FIO45-C.+Avoid+TOCTOU+race+conditions+while+accessing+files
func GroupSystemAdd ¶
GroupSystemAdd adds group 'groupname'. It is not an error if 'groupname' already exists.
func JoinErrors ¶
Return an error containing the joined error messages of errs. If all elements of errs are nil, return nil. Does not preserve the error types nor provides Unwrap.
func ListFs ¶
ListFs returns a list of the files (not directories) in fsys. In case of error, it encodes the error in a file name in the list.
func LowLevelInit ¶
LowLevelInit should be called only by low-level test code. Absolutely do not call in non-test code! Call florist.MainInt instead!
func MainInt ¶
MainInt is a ready-made function for the main() of your installer.
Usage:
func main() { os.Exit(florist.MainInt(&florist.Options{ SetupFn: setup, ConfigureFn: configure, })) }
func MakeTmplData ¶
MakeTmplData returns a map, where each key is a path in the secrets FS and each value is the contents of the corresponding path.
func NetFetch ¶
func NetFetch(client *http.Client, url string, hashType Hash, hash string, dstDir string) (string, error)
NetFetch uses client to download url to dstDir, returning the path of the downloaded file. Directory dstDir must exist. If after the download the hash doesn't match, it will return an error. If the file in dstDir exists and the hash matches, it will not be redownloaded.
func PrivateIPs ¶
func SkipIfNotDisposableHost ¶
SkipIfNotDisposableHost skips the test if it is running on a precious host.
func SupplementaryGroups ¶
SupplementaryGroups adds 'username' to the supplementary groups 'groups'. It is an error if any of 'groups' does not exist (create them beforehand with GroupSystemAdd).
func TemplateFromFs ¶
TemplateFromFs reads file srcPath in filesystem srcFs and renders its contents // as a template with data tmplData.
func TemplateFromFsWithDelims ¶
TemplateFromFsWithDelims reads file srcPath in filesystem srcFs and renders its contents as a template with data tmplData, with "<<", ">>" as template delimiters. This is useful to escape the default delimiters "{{", "}}" in the template.
func TemplateFromText ¶
TemplateFromText renders the template 'tmplText' with data 'tmplData'. Parameter 'tmplName' is used for debugging purposes, a typical example is the template file name.
func UntarOne ¶ added in v0.3.3
UntarOne extracts file 'name' from tar file 'tarPath', expected to be compressed with gzip, and saves it to 'dstPath'.
func UserAdd ¶
Add user and create home directory. Do nothing if user already present. Password login is disabled (use SSH public key or use passwd)
func UserSystemAdd ¶
UserSystemAdd adds the system user 'username' and group 'username', with home directory 'homedir' and mode 0o755.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func (*Config) Get ¶
Get returns the value of key k if found. If the key is missing, it returns the empty string and adds the error to the list returned by Errors. This allows a simple sequence of calling Get multiple times and checking for all the keys that were missing keys only once at the end, by calling Errors.
If on the other end you want to know immediately if the key is missing, use Lookup.
type Configurer ¶
type Configurer interface {
Configure() error
}
type Flower ¶
type Flower interface { Installer Configurer }
type Options ¶
type Options struct { // Output for the logger. Defaults to os.Stdout. Before changing to os.Stderr, // consider that HashiCorp Packer renders any output to stderr in red, thus // making everything look like an error. // The default log level is INFO; it can be changed to DEBUG via the --log-level // command-line flag. LogOutput io.Writer // Optimization to avoid refreshing the OS package manager cache each time before // installing an OS package. Defaults to DefOsPkgCacheValidity. OsPkgCacheValidity time.Duration // The setup function, called before any command-line subcommand. Mandatory. SetupFn func(prov *Provisioner) error // The preConfigure function, called before the command-line configure // subcommand. Mandatory. PreConfigureFn func(prov *Provisioner, config *Config) (any, error) // The postConfigure function, called after the command-line configure // subcommand. Optional. PostConfigureFn func(prov *Provisioner, config *Config, bag any) error }
The Options passed to MainInt. For an example, see florist/example/main.go
type Provisioner ¶
type Provisioner struct {
// contains filtered or unexported fields
}
func (*Provisioner) AddFlowers ¶
func (prov *Provisioner) AddFlowers(flowers ...Flower) error