schedule

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: 11 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 schedule is the schedule behavior: the cron entries that osapi deploys.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"schedule", "The cron entries that osapi deploys",
	behavior.Node,
	behavior.API,
	behavior.Area(area.Config),
	behavior.CLI,
	behavior.Requires(object.Behavior),
	behavior.Requires(managedfile.Behavior),
	behavior.Platform(behavior.PlatformDebian, newDebian),
	behavior.Writes(
		"/etc/cron.d/*", "/etc/cron.hourly/*", "/etc/cron.daily/*",
		"/etc/cron.weekly/*", "/etc/cron.monthly/*",
	),
	behavior.Read("list", List).
		Describe("List the cron entries that osapi deployed").
		Explain("Lists each file in /etc/cron.d and in /etc/cron.hourly, daily, weekly and "+
			"monthly that osapi deployed, with its object, its cron expression or interval, "+
			"and its user. A cron file that osapi did not deploy is not listed.").
		Example("An entry that osapi deployed", ListInput{}, []Entry{entry}, stored, deployed).
		Example("A daily script that osapi deployed", ListInput{},
			[]Entry{
				{Name: "osapitest", Object: "osapitest.sh", Interval: "daily", Source: "daily"},
			},
			behavior.Stored("osapitest.sh", scriptText, types.ContentRaw),
			behavior.After(CreateInput{Name: "osapitest", Object: "osapitest.sh", Interval: "daily"}),
		).
		Example("A host where osapi deployed none", ListInput{}, []Entry{}, theirs),
	behavior.Read("get", Get).Key("name").
		Describe("Get one cron entry that osapi deployed").
		Explain("Reads the entry from /etc/cron.d, then from each interval directory. "+
			"An entry that osapi did not deploy is not found.").
		Example("An entry that osapi deployed", GetInput{Name: "osapitest"}, entry, stored, deployed).
		Fails("An entry that osapi did not deploy", GetInput{Name: "osapitest"}, "not found", theirs).
		Fails("A name with a space", GetInput{Name: "a b"}, "Name").
		Fails("A name that is an option", GetInput{Name: "--now"}, "not a valid entry name").
		Fails("A name over 64 characters", GetInput{Name: strings.Repeat("a", 65)}, "Name"),
	behavior.Write("create", Create).
		AdminOnly().
		Describe("Deploy a cron entry").
		Explain("Gets the object from the object store and writes it as /etc/cron.d/backup for "+
			"backup, mode 0644, for a cron expression, or as /etc/cron.daily/backup, mode 0755, "+
			"for a daily interval. An object of content type template, or content_type template, "+
			"is rendered with the agent's facts and the vars. A file that has the content "+
			"does not change. An entry of the name in a different directory does not change: "+
			"move it with delete and create. A file at the path that osapi did not deploy is "+
			"refused. An entry runs as its user, root included, so only admin can deploy one.").
		Example("An entry with a cron expression",
			CreateInput{
				Name:     "osapitest",
				Object:   "osapitest.cron",
				Schedule: "0 2 * * *",
				User:     "root",
			},
			Result{Name: "osapitest", Changed: true},
			stored,
			behavior.Wrote(backupPath, backupText),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest.cron", Schedule: "0 2 * * *", User: "root"}),
		).
		Example("A script that runs daily",
			CreateInput{Name: "osapitest", Object: "osapitest.sh", Interval: "daily"},
			Result{Name: "osapitest", Changed: true},
			behavior.Stored("osapitest.sh", scriptText, types.ContentRaw),
			behavior.Wrote(scriptPath, scriptText),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest.sh", Interval: "daily"}),
		).
		Example("A template, rendered with its vars",
			CreateInput{
				Name:        "osapitest",
				Object:      "osapitest.tmpl",
				Schedule:    "0 2 * * *",
				ContentType: types.ContentTemplate,
				Vars:        map[string]string{"target": "/srv"},
			},
			Result{Name: "osapitest", Changed: true},
			behavior.Stored("osapitest.tmpl", templateText, types.ContentRaw),
			behavior.Wrote(backupPath, "0 2 * * * root /usr/local/bin/backup /srv\n"),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest.tmpl", Schedule: "0 2 * * *"}),
		).
		Example("An entry that has the content",
			CreateInput{
				Name:     "osapitest",
				Object:   "osapitest.cron",
				Schedule: "0 2 * * *",
				User:     "root",
			},
			Result{Name: "osapitest"},
			stored, deployed,
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest.cron", Schedule: "0 2 * * *", User: "root"}),
		).
		Example("An entry of the name in a different directory",
			CreateInput{Name: "osapitest", Object: "osapitest.sh", Interval: "daily"},
			Result{Name: "osapitest"},
			stored, deployed,
			behavior.Stored("osapitest.sh", scriptText, types.ContentRaw),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest.cron", Schedule: "0 2 * * *"}),
		).
		Fails("An object the store does not have",
			CreateInput{Name: "osapitest", Object: "nosuch", Schedule: "0 2 * * *"}, "not found").
		Fails("A template that reads a var the request does not give",
			CreateInput{
				Name: "osapitest", Object: "osapitest.tmpl", Schedule: "0 2 * * *",
				ContentType: types.ContentTemplate,
			},
			"render template",
			behavior.Stored("osapitest.tmpl", templateText, types.ContentRaw)).
		Fails("A file that osapi did not deploy",
			CreateInput{Name: "osapitest", Object: "osapitest.cron", Schedule: "0 2 * * *"},
			"osapi did not deploy it", stored, theirs).
		Fails("No object", CreateInput{Name: "osapitest", Schedule: "0 2 * * *"}, "Object").
		Fails("Neither a cron expression nor an interval",
			CreateInput{Name: "osapitest", Object: "osapitest.cron"}, "Schedule").
		Fails("A cron expression and an interval",
			CreateInput{
				Name:     "osapitest",
				Object:   "osapitest.cron",
				Schedule: "0 2 * * *",
				Interval: "daily",
			},
			"Schedule").
		Fails("A cron expression that does not parse",
			CreateInput{
				Name:     "osapitest",
				Object:   "osapitest.cron",
				Schedule: "every day",
			}, "Schedule").
		Fails("An interval that is not one",
			CreateInput{
				Name:     "osapitest",
				Object:   "osapitest.cron",
				Interval: "yearly",
			}, "Interval").
		Fails("A name with a slash",
			CreateInput{Name: "a/b", Object: "osapitest.cron", Schedule: "0 2 * * *"}, "Name").
		Fails("A name that is an option",
			CreateInput{
				Name:     "--now",
				Object:   "osapitest.cron",
				Schedule: "0 2 * * *",
			}, "not a valid entry name").
		Fails("A name over 64 characters",
			CreateInput{
				Name:     strings.Repeat("a", 65),
				Object:   "osapitest.cron",
				Schedule: "0 2 * * *",
			}, "Name").
		Fails("An object name over 255 characters",
			CreateInput{
				Name:     "osapitest",
				Object:   strings.Repeat("a", 256),
				Schedule: "0 2 * * *",
			}, "Object").
		Fails("A user that is not an account name",
			CreateInput{
				Name:     "osapitest",
				Object:   "osapitest.cron",
				Schedule: "0 2 * * *",
				User:     "a b",
			},
			"User").
		Fails("A content type that is not one",
			CreateInput{
				Name:        "osapitest",
				Object:      "osapitest.cron",
				Schedule:    "0 2 * * *",
				ContentType: notAContentType,
			},
			"ContentType"),
	behavior.Write("update", Update).Key("name").
		AdminOnly().
		Describe("Deploy a cron entry that osapi deployed again").
		Explain("Writes a new object, or the entry's own, at the entry's path, with the "+
			"fields that the request gives and the entry's own for the rest. A file that has "+
			"the content does not change. An entry that osapi did not deploy is not found. "+
			"The entry stays in its directory: an interval does not change with update.").
		Example("A new object",
			UpdateInput{Name: "osapitest", Object: "osapitest-v2.cron"},
			Result{Name: "osapitest", Changed: true},
			stored, deployed, storedV2,
			behavior.Wrote(backupPath, backupV2Text),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest-v2.cron"}),
		).
		Example("A new cron expression, with the same object",
			UpdateInput{Name: "osapitest", Schedule: "30 2 * * *"},
			Result{Name: "osapitest", Changed: true},
			stored, deployed,

			behavior.Wrote(backupPath, backupText),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Schedule: "30 2 * * *"}),
		).
		Example("A new object, cron expression and user",
			UpdateInput{
				Name:     "osapitest",
				Object:   "osapitest-v2.cron",
				Schedule: "30 2 * * *",
				User:     "nobody",
			},
			Result{Name: "osapitest", Changed: true},
			stored, deployed, storedV2,
			behavior.Wrote(backupPath, backupV2Text),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest-v2.cron", Schedule: "30 2 * * *", User: "nobody"}),
		).
		Example("A daily script with a new object",
			UpdateInput{Name: "osapitest", Object: "osapitest-v2.sh"},
			Result{Name: "osapitest", Changed: true},
			behavior.Stored("osapitest.sh", scriptText, types.ContentRaw),
			behavior.After(CreateInput{Name: "osapitest", Object: "osapitest.sh", Interval: "daily"}),
			behavior.Stored("osapitest-v2.sh", scriptText+"/usr/local/bin/prune\n", types.ContentRaw),
			behavior.Wrote(scriptPath, scriptText+"/usr/local/bin/prune\n"),
			behavior.Reads(GetInput{Name: "osapitest"}, Entry{Name: "osapitest", Object: "osapitest-v2.sh", Interval: "daily"}),
		).
		Fails("An entry that osapi did not deploy",
			UpdateInput{Name: "osapitest", Object: "osapitest.cron"}, "not found").
		Fails("A cron expression that does not parse",
			UpdateInput{Name: "osapitest", Schedule: "every day"}, "Schedule").
		Fails("A name with a space", UpdateInput{Name: "a b"}, "Name").
		Fails("A name that is an option", UpdateInput{Name: "--now"}, "not a valid entry name").
		Fails("A name over 64 characters", UpdateInput{Name: strings.Repeat("a", 65)}, "Name").
		Fails("An object name over 255 characters",
			UpdateInput{Name: "osapitest", Object: strings.Repeat("a", 256)}, "Object").
		Fails("A user that is not an account name", UpdateInput{Name: "osapitest", User: "a b"}, "User").
		Fails("A content type that is not one", UpdateInput{Name: "osapitest", ContentType: notAContentType},
			"ContentType"),
	behavior.Write("delete", Delete).Key("name").
		AdminOnly().
		Describe("Remove a cron entry that osapi deployed").
		Explain("Removes the entry's file and its record. An entry that osapi did not "+
			"deploy does not change, and a cron file that osapi did not deploy stays.").
		Example("Remove an entry", DeleteInput{Name: "osapitest"},
			Result{Name: "osapitest", Changed: true},
			stored, deployed,
			behavior.Removed(backupPath),
			behavior.ReadsNone(GetInput{Name: "osapitest"}, Entry{Name: "osapitest"}, "name"),
		).
		Example("An entry that osapi did not deploy", DeleteInput{Name: "osapitest"},
			Result{Name: "osapitest"},
			behavior.ReadsNone(GetInput{Name: "osapitest"}, Entry{Name: "osapitest"}, "name"),
		).
		Fails("A name with a space", DeleteInput{Name: "a b"}, "Name").
		Fails("A name that is an option", DeleteInput{Name: "--now"}, "not a valid entry name").
		Fails("A name over 64 characters", DeleteInput{Name: strings.Repeat("a", 65)}, "Name"),
))

Behavior is the cron entries that osapi deploys. Each is an object that a person uploads once with osapi client file upload, written as a file that managedfile keeps a record of: /etc/cron.d/<name> for an entry with a cron expression, /etc/cron.<interval>/<name> for a script that runs hourly, daily, weekly or monthly. A cron file that osapi did not deploy is not osapi's to read or change. A cron entry runs a command as its user, root included, so each write is admin only.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Name        string            `` /* 253-byte string literal not displayed */
	Object      string            `` /* 182-byte string literal not displayed */
	Schedule    string            `` /* 179-byte string literal not displayed */
	Interval    types.Interval    `` /* 197-byte string literal not displayed */
	User        string            `` /* 146-byte string literal not displayed */
	ContentType types.ContentType `` /* 236-byte string literal not displayed */
	Vars        map[string]string `` /* 156-byte string literal not displayed */
}

CreateInput is an entry for osapi to deploy: an object of the object store, written as /etc/cron.d/<name>, or as /etc/cron.<interval>/<name> for an interval.

type DeleteInput

type DeleteInput struct {
	Name string `json:"name" validate:"required,max=64,resource_name" doc:"The entry, such as backup" telemetry:"attr"`
}

DeleteInput names the entry that osapi removes.

type Entry

type Entry struct {
	Name     string `json:"name"               doc:"The entry"`
	Object   string `json:"object"             doc:"The object it was deployed from"`
	Schedule string `json:"schedule,omitempty" doc:"Its cron expression, for an entry in /etc/cron.d"`
	Interval string `json:"interval,omitempty" doc:"Its interval, for a script in /etc/cron.daily and the like"`
	User     string `json:"user,omitempty"     doc:"The user it runs as"`
	Source   string `json:"source"             doc:"Where its file is: cron.d, or the interval"`
}

Entry is an entry that osapi deployed.

func Get

func Get(
	ctx context.Context,
	p Provider,
	in GetInput,
) (Entry, error)

Get reads one entry that osapi deployed.

func List

func List(
	ctx context.Context,
	p Provider,
	_ ListInput,
) ([]Entry, error)

List reads the entries that osapi deployed.

type GetInput

type GetInput struct {
	Name string `json:"name" validate:"required,max=64,resource_name" doc:"The entry, such as backup"`
}

GetInput names the entry to read.

type ListInput

type ListInput struct{}

ListInput takes nothing: list reads every entry that osapi deployed.

type Provider

type Provider interface {
	List(ctx context.Context) ([]Entry, error)
	Get(ctx context.Context, name string) (Entry, error)
	Create(ctx context.Context, in CreateInput) (bool, error)
	Update(ctx context.Context, in UpdateInput) (bool, error)
	Delete(ctx context.Context, name string) (bool, error)
}

Provider reads and writes the cron entries that osapi deploys. debian.go is the Debian family's.

type Result

type Result struct {
	Name    string `json:"name"    doc:"The entry"`
	Changed bool   `json:"changed" doc:"Whether the host changed"`
}

Result is an entry after a write.

func Create

func Create(
	ctx context.Context,
	p Provider,
	in CreateInput,
) (Result, error)

Create deploys an entry.

func Delete

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

Delete removes an entry that osapi deployed.

func Update

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

Update deploys an entry that osapi deployed again.

type UpdateInput

type UpdateInput struct {
	Name        string            `` /* 156-byte string literal not displayed */
	Object      string            `json:"object,omitempty"       validate:"omitempty,min=1,max=255"       doc:"The object to deploy; the entry's own when empty"`
	Schedule    string            `` /* 126-byte string literal not displayed */
	User        string            `` /* 131-byte string literal not displayed */
	ContentType types.ContentType `` /* 139-byte string literal not displayed */
	Vars        map[string]string `json:"vars,omitempty"         validate:"omitempty"                     doc:"The vars of a template, as key=value"`
}

UpdateInput is a new object, or new settings, for an entry that osapi deployed. An empty field keeps what the entry has.

Directories

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

Jump to

Keyboard shortcuts

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