entrypoint

package
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2017 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteImageFor

func DeleteImageFor(def EntityDefinition, dir ImageDir) error

DeleteImageFor deletes the image for this entity from this image directory.

func ExecProgramOrMock

func ExecProgramOrMock(command string, arguments ...string) (err error)

ExecProgramOrMock is a wrapper around exec.Command().Run() that, if run in a test environment, only prints the command line instead of executing the command.

func Getent

func Getent(databaseFile string, predicate func([]string) bool) ([]string, error)

Getent reads entries from a UNIX user/group database (e.g. /etc/passwd or /etc/group) and returns the first entry matching the given predicate. For example, to locate the user with name "foo":

fields, err := Getent("/etc/passwd", func(fields []string) bool {
    return fields[0] == "foo"
})

func Main

func Main() (exitCode int)

Main is the main entry point, but returns the exit code rather than calling os.Exit(). This distinction is useful for testing purposes.

func PrintCommandMessage

func PrintCommandMessage(msg string, arguments ...interface{})

PrintCommandMessage formats and prints a message on file descriptor 3.

func ProvisionedEntityIDs

func ProvisionedEntityIDs() ([]string, error)

ProvisionedEntityIDs returns a list of all entities for which base images exist.

func SerializeDefinition

func SerializeDefinition(def EntityDefinition) ([]byte, error)

SerializeDefinition returns a TOML representation of this EntityDefinition.

func SerializeDefinitionIntoFile

func SerializeDefinitionIntoFile(def EntityDefinition, path string) error

SerializeDefinitionIntoFile writes the given EntityDefinition as a TOML file.

func StoreAppliedState

func StoreAppliedState(def EntityDefinition, previous EntityDefinition)

StoreAppliedState is a no-op during normal operation. During unit tests, it records Apply()ed definitions, so that the next GetProvisionedState() of the same entity will present a consistent result.

The `previous` argument contains the actual state before the apply operation.

Types

type Entity

type Entity struct {
	Definition      EntityDefinition
	DefinitionFiles []string //paths to the files defining this entity
	IsBroken        bool     //whether any of these are invalid (default: false)
}

Entity contains attributes and logic that are shared between entity types.

func Scan

func Scan() ([]*Entity, []error)

Scan returns a slice of all the defined entities.

func (*Entity) Apply

func (e *Entity) Apply(withForce bool) error

Apply performs the complete application algorithm for the given Entity. If the entity does not exist yet, it is created. If it does exist, but some attributes do not match, it will be updated, but only if withForce is given.

func (*Entity) IsOrphaned

func (e *Entity) IsOrphaned() bool

IsOrphaned returns whether all definitions for this entity have been deleted.

func (*Entity) PrepareDiff

func (e *Entity) PrepareDiff() error

PrepareDiff creates temporary files that the frontend can use to generate a diff.

func (*Entity) PrintReport

func (e *Entity) PrintReport()

PrintReport prints the scan report for this entity on stdout.

type EntityDefinition

type EntityDefinition interface {
	//TypeName returns the part of the entity ID before the ":", i.e. either
	//"group" or "user".
	TypeName() string
	//EntityID returns exactly that, e.g. "user:john".
	EntityID() string
	//Attributes returns a human-readable stringification of this definition.
	Attributes() string
	//GetProvisionedState reads the current state of this entity from the
	//system database (/etc/passwd or /etc/group). The return value has the same
	//concrete type as the callee. If no entity with the same ID exists in
	//there, a non-nil instance will be returned for which IsProvisioned()
	//yields false.
	GetProvisionedState() (EntityDefinition, error)
	//IsProvisioned must be called on an instance returned from
	//GetProvisionedState(), and will indicate whether this entity is present
	//in the system database (/etc/passwd or /etc/group).
	IsProvisioned() bool
	//WithSerializableState brings the definition into a safely serializable
	//state, executes the callback, and then restores the original state.
	WithSerializableState(callback func(EntityDefinition))
	//Merge constructs a new EntityDefinition of the same concrete type whose
	//attributes are merged from the callee and the argument. The argument's
	//concrete type must be identical to that of the callee. If both sources
	//have different values set for the same attribute, the callee's value
	//takes precedence, and an error is returned in the second argument.
	//If merge conflicts are not a problem, the error argument may be ignored.
	//
	//The merge `method` tells which attributes may be merged. Possible values
	//are MergeWhereCompatible, MergeEmptyOnly and MergeNumericIDOnly.
	Merge(other EntityDefinition, method MergeMethod) (EntityDefinition, []error)
	//Apply provisions this entity. The argument indicates the currently
	//provisioned state. The argument's concrete type must match the callee.
	Apply(provisioned EntityDefinition) error
	//Cleanup removes the entity from the system.
	Cleanup() error
}

EntityDefinition contains data from a definition file that describes an entity (a user account or group). Definitions can also be obtained by scanning the user/group databases.

type FileInvalidError

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

FileInvalidError contains the set of errors that were encountered while parsing a file.

func (*FileInvalidError) Error

func (e *FileInvalidError) Error() string

Error implements the error interface.

type GroupDefinition

type GroupDefinition struct {
	Name   string `toml:"name"`             //the group name (the first field in /etc/group)
	GID    int    `toml:"gid,omitzero"`     //the GID (the third field in /etc/group), or 0 if no specific GID is enforced
	System bool   `toml:"system,omitempty"` //whether the group is a system group (this influences the GID selection if GID = 0)
}

GroupDefinition represents a UNIX group (as registered in /etc/group).

func (*GroupDefinition) Apply

func (g *GroupDefinition) Apply(theProvisioned EntityDefinition) error

Apply implements the EntityDefinition interface.

func (*GroupDefinition) Attributes

func (g *GroupDefinition) Attributes() string

Attributes implements the EntityDefinition interface.

func (*GroupDefinition) Cleanup

func (g *GroupDefinition) Cleanup() error

Cleanup implements the EntityDefinition interface.

func (*GroupDefinition) EntityID

func (g *GroupDefinition) EntityID() string

EntityID implements the EntityDefinition interface.

func (*GroupDefinition) GetProvisionedState

func (g *GroupDefinition) GetProvisionedState() (EntityDefinition, error)

GetProvisionedState implements the EntityDefinition interface.

func (*GroupDefinition) IsProvisioned

func (g *GroupDefinition) IsProvisioned() bool

IsProvisioned implements the EntityDefinition interface.

func (*GroupDefinition) Merge

func (g *GroupDefinition) Merge(other EntityDefinition, method MergeMethod) (EntityDefinition, []error)

Merge implements the EntityDefinition interface.

func (*GroupDefinition) TypeName

func (g *GroupDefinition) TypeName() string

TypeName implements the EntityDefinition interface.

func (*GroupDefinition) WithSerializableState

func (g *GroupDefinition) WithSerializableState(callback func(EntityDefinition))

WithSerializableState implements the EntityDefinition interface.

type ImageDir

type ImageDir string

ImageDir is a path to a directory containing serialized entity definitions.

var BaseImageDir ImageDir

BaseImageDir is usually /var/lib/holo/users-groups/base.

var ProvisionedImageDir ImageDir

ProvisionedImageDir is usually /var/lib/holo/users-groups/provisioned.

func (ImageDir) ImagePathFor

func (dir ImageDir) ImagePathFor(def EntityDefinition) string

ImagePathFor returns the path where an image of the given entity definition will be stored in this directory.

func (ImageDir) LoadImageFor

func (dir ImageDir) LoadImageFor(def EntityDefinition) (EntityDefinition, error)

LoadImageFor retrieves a stored image for this entity, which was previously written by SaveImage.

func (ImageDir) SaveImage

func (dir ImageDir) SaveImage(def EntityDefinition) error

SaveImage writes an image for this entity to the specified image directory.

type MergeError

type MergeError struct {
	Field    string
	EntityID string
	Value1   interface{}
	Value2   interface{}
}

MergeError is used by Merge().

func (MergeError) Error

func (e MergeError) Error() string

MergeError implements the error interface.

type MergeMethod

type MergeMethod uint

MergeMethod is the second argument for EntityDefinition.Merge().

const (
	//MergeWhereCompatible merges as much as possible.
	MergeWhereCompatible MergeMethod = iota
	//MergeEmptyOnly merges only those attributes where one side has an empty
	//value.
	MergeEmptyOnly
	//MergeNumericIDOnly is like MergeEmptyOnly, but merges only the numeric ID
	//attribute, using the left side for all other attributes.
	MergeNumericIDOnly
)

type UserDefinition

type UserDefinition struct {
	Name    string   `toml:"name"`              //the user name (the first field in /etc/passwd)
	Comment string   `toml:"comment,omitempty"` //the full name (sometimes also called "comment"; the fifth field in /etc/passwd)
	UID     int      `toml:"uid,omitzero"`      //the user ID (the third field in /etc/passwd), or 0 if no specific UID is enforced
	System  bool     `toml:"system,omitempty"`  //whether the group is a system group (this influences the GID selection if gid = 0)
	Home    string   `toml:"home,omitempty"`    //path to the user's home directory (or empty to use the default)
	Group   string   `toml:"group,omitempty"`   //the name of the user's initial login group (or empty to use the default)
	Groups  []string `toml:"groups,omitempty"`  //the names of supplementary groups which the user is also a member of
	Shell   string   `toml:"shell,omitempty"`   //path to the user's login shell (or empty to use the default)
}

UserDefinition represents a UNIX user account (as registered in /etc/passwd).

func (*UserDefinition) Apply

func (u *UserDefinition) Apply(theProvisioned EntityDefinition) error

Apply implements the EntityDefinition interface.

func (*UserDefinition) Attributes

func (u *UserDefinition) Attributes() string

Attributes implements the EntityDefinition interface.

func (*UserDefinition) Cleanup

func (u *UserDefinition) Cleanup() error

Cleanup implements the EntityDefinition interface.

func (*UserDefinition) EntityID

func (u *UserDefinition) EntityID() string

EntityID implements the EntityDefinition interface.

func (*UserDefinition) GetProvisionedState

func (u *UserDefinition) GetProvisionedState() (EntityDefinition, error)

GetProvisionedState implements the EntityDefinition interface.

func (*UserDefinition) IsProvisioned

func (u *UserDefinition) IsProvisioned() bool

IsProvisioned implements the EntityDefinition interface.

func (*UserDefinition) Merge

func (u *UserDefinition) Merge(other EntityDefinition, method MergeMethod) (EntityDefinition, []error)

Merge implements the EntityDefinition interface.

func (*UserDefinition) TypeName

func (u *UserDefinition) TypeName() string

TypeName implements the EntityDefinition interface.

func (*UserDefinition) WithSerializableState

func (u *UserDefinition) WithSerializableState(callback func(EntityDefinition))

WithSerializableState implements the EntityDefinition interface.

Jump to

Keyboard shortcuts

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