file

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 13 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 file is the file behavior: it deploys the objects of the object store to a host, through the object and managedfile building blocks, and reads how a deployed file is against what osapi wrote. The controller's file endpoints upload, list and delete the objects.

Index

Constants

View Source
const (
	// InSync is a file that holds what osapi deployed.
	InSync = "in-sync"
	// Drifted is a file that something changed after osapi deployed it.
	Drifted = "drifted"
	// Missing is a file that osapi deployed and that is gone.
	Missing = "missing"
	// Unmanaged is a path that osapi did not deploy, or that it undeployed.
	Unmanaged = "unmanaged"
)

The states of a deployed file.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"file", "Files of the object store, deployed to the host",
	behavior.Node,
	behavior.API,
	behavior.Area(area.Config),
	behavior.CLI,
	behavior.Requires(object.Behavior),
	behavior.Requires(managedfile.Behavior),
	behavior.Platform(behavior.PlatformLinux, newLinux),

	behavior.Platform(behavior.PlatformDarwin, newLinux),

	behavior.Writes("*"),
	behavior.Read("get", GetStatus).
		Describe("Show whether a deployed file holds what osapi wrote").
		Explain("Compares the file on the host with the record that osapi keeps of what it "+
			"deployed: in-sync when they agree, drifted when something changed the file, "+
			"missing when osapi deployed the file and it is gone, and unmanaged when osapi "+
			"did not deploy the path or undeployed it. A path that is a directory is refused.").
		Example("A deployed file", StatusInput{Path: path},
			Status{Path: path, State: InSync, SHA256: rawSHA},
			stored,
			behavior.After(deployed),
		).
		Example("A path that osapi did not deploy", StatusInput{Path: path},
			Status{Path: path, State: Unmanaged},
		).
		Example("A file that osapi undeployed", StatusInput{Path: path},
			Status{Path: path, State: Unmanaged},
			stored,
			behavior.After(deployed),
			behavior.After(DeleteInput{Path: path}),
		).
		Fails("A relative path", StatusInput{Path: "etc/example.conf"}, "startswith").
		Fails("A directory", StatusInput{Path: "/tmp"}, "a directory, not a file"),
	behavior.Write("update", Update).
		Describe("Deploy an object of the object store to a path").
		Explain("Writes the object at the path with its mode and ownership, and keeps a record "+
			"of it. A template object, or content_type template, is rendered first with "+
			".Facts, .Vars and .Hostname. The record keeps the SHA-256 of the object as it "+
			"was read. A file that holds the content, mode and owner already, from the same "+
			"object, does not change and reports changed: false. osapi client file stale "+
			"list compares the object now with that SHA-256, so it shows the deployments "+
			"whose object changed since.").
		Example("Deploy a file", deployed,
			UpdateResult{Path: path, SHA256: rawSHA, Changed: true},
			stored,
			behavior.Wrote(path, raw),
			behavior.Reads(StatusInput{Path: "/etc/osapi/file-example.conf"}, Status{Path: "/etc/osapi/file-example.conf", State: "in-sync", SHA256: "0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60"}),
		).
		Example("Render a template",
			UpdateInput{
				ObjectName: "example.conf.tmpl",
				Path:       path,
				Vars:       map[string]string{"port": "8080"},
			},
			UpdateResult{Path: path, SHA256: tmplSHA, Changed: true},
			template,
			behavior.Wrote(path, rendered),
			behavior.Reads(StatusInput{Path: "/etc/osapi/file-example.conf"}, Status{Path: "/etc/osapi/file-example.conf", State: "in-sync"}),
		).
		Example("A file that holds the object", deployed,
			UpdateResult{Path: path, SHA256: rawSHA},
			stored,
			behavior.After(deployed),
			behavior.Reads(StatusInput{Path: "/etc/osapi/file-example.conf"}, Status{Path: "/etc/osapi/file-example.conf", State: "in-sync", SHA256: "0083dacc561dfd01081d8554269e201f4b60fe597ab9892977bfde81da46ef60"}),
		).
		Fails("A relative path", UpdateInput{ObjectName: "example.conf", Path: "etc/x"}, "startswith").
		Fails("No object", UpdateInput{Path: path}, "required").
		Fails("A mode that is not octal",
			UpdateInput{ObjectName: "example.conf", Path: path, Mode: "rw-r--r--"}, "file_mode").
		Fails("An object name longer than 255 characters",
			UpdateInput{ObjectName: strings.Repeat("a", 256), Path: path}, "max").
		Fails("A group that is an option",
			UpdateInput{ObjectName: "example.conf", Path: path, Group: "-r"}, "account_name").
		Fails("An owner that is an option",
			UpdateInput{ObjectName: "example.conf", Path: path, Owner: "-r"}, "account_name").
		Fails("A content type that is neither",
			UpdateInput{
				ObjectName:  "example.conf",
				Path:        path,
				ContentType: notAContentType,
			}, "enum"),
	behavior.Write("delete", Delete).
		Describe("Remove a file that osapi deployed").
		Explain("Removes the file and keeps its record, marked undeployed, so status reports "+
			"unmanaged. A path that osapi did not deploy, or deleted already, does not "+
			"change and reports changed: false. The object stays in the object store.").
		Example("Remove a deployed file", DeleteInput{Path: path},
			DeleteResult{Path: path, Changed: true},
			stored,
			behavior.After(deployed),
			behavior.Removed(path),
			behavior.Reads(StatusInput{Path: "/etc/osapi/file-example.conf"}, Status{Path: "/etc/osapi/file-example.conf", State: "unmanaged"}, "path", "state"),
		).
		Example("A path that osapi did not deploy", DeleteInput{Path: path},
			DeleteResult{Path: path},
			behavior.ReadsNone(StatusInput{Path: "/etc/osapi/file-example.conf"}, Status{Path: "/etc/osapi/file-example.conf", State: "in-sync"}, "path", "state"),
		).
		Fails("A relative path", DeleteInput{Path: "etc/x"}, "startswith"),
))

Behavior is the file definition.

Functions

This section is empty.

Types

type DeleteInput

type DeleteInput struct {
	Path string `json:"path" validate:"required,startswith=/" doc:"Absolute path of the file on the host" telemetry:"attr"`
}

DeleteInput names the file that delete removes.

type DeleteResult

type DeleteResult struct {
	Path    string `json:"path"    doc:"Absolute path of the file"`
	Changed bool   `json:"changed" doc:"Whether the host changed"`
}

DeleteResult is the file that delete removed.

func Delete

func Delete(
	ctx context.Context,
	p Provider,
	in DeleteInput,
) (DeleteResult, error)

Delete removes a file that osapi deployed.

type Provider

type Provider interface {
	// Deploy writes the object at the path and records it, and reports
	// whether the host changed.
	Deploy(ctx context.Context, in UpdateInput) (UpdateResult, error)
	// Undeploy removes a file that osapi deployed, keeping its record.
	Undeploy(ctx context.Context, path string) (bool, error)
	// Status is the file at path against what osapi deployed there.
	Status(ctx context.Context, path string) (Status, error)
}

Provider deploys objects of the object store to a host, and reads how they are.

type Status

type Status struct {
	Path   string `json:"path"             doc:"Absolute path of the file"`
	State  string `json:"state"            doc:"in-sync, drifted, missing or unmanaged"`
	SHA256 string `json:"sha256,omitempty" doc:"SHA-256 of the file on the host, when it is there"`
}

Status is how a file is against what osapi deployed.

func GetStatus

func GetStatus(
	ctx context.Context,
	p Provider,
	in StatusInput,
) (Status, error)

GetStatus is the file at the path against what osapi deployed there.

type StatusInput

type StatusInput struct {
	Path string `json:"path" validate:"required,startswith=/" doc:"Absolute path of the file on the host"`
}

StatusInput names the file that status reads.

type UpdateInput

type UpdateInput struct {
	ObjectName  string            `` /* 129-byte string literal not displayed */
	Path        string            `` /* 210-byte string literal not displayed */
	Mode        string            `` /* 164-byte string literal not displayed */
	Owner       string            `json:"owner,omitempty"        validate:"omitempty,account_name" doc:"User that owns the file; left as written when empty"`
	Group       string            `json:"group,omitempty"        validate:"omitempty,account_name" doc:"Group that owns the file; left as written when empty"`
	ContentType types.ContentType `` /* 193-byte string literal not displayed */
	Vars        map[string]string `json:"vars,omitempty"         validate:"omitempty"              doc:"Variables of a template, as .Vars, each as key=value"`
}

UpdateInput is what update writes: an object of the object store, at a path, with its mode and ownership.

type UpdateResult

type UpdateResult struct {
	Path    string `json:"path"    doc:"Absolute path of the file"`
	SHA256  string `json:"sha256"  doc:"SHA-256 of the content that the file holds"`
	Changed bool   `json:"changed" doc:"Whether the host changed"`
}

UpdateResult is the file that update wrote.

func Update

func Update(
	ctx context.Context,
	p Provider,
	in UpdateInput,
) (UpdateResult, error)

Update writes an object of the object store to the host.

Directories

Path Synopsis
Package mocks holds the generated double of the file provider, for the methods' tests.
Package mocks holds the generated double of the file provider, for the methods' tests.

Jump to

Keyboard shortcuts

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