core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TrackDir is an externally defined location used to store the TriggerFile
	TrackDir string
	// SysDir is an externally defined location wherein system migration files are stored
	SysDir string
	// UsrDir is an externally defined location wherein user migration files are stored
	UsrDir string
	// TriggerFile is the location of the trigger file, which must be present for migration to occur
	TriggerFile = TrackDir + "/trigger"
)

Functions

func CreateTriggerFile

func CreateTriggerFile() error

CreateTriggerFile creates a trigger file at TriggerFile, along with its parent directories if necessary

func RemoveTriggerFile

func RemoveTriggerFile() (err error)

RemoveTriggerFile facilitates the removal of the file at TriggerFile

func TriggerFileExists

func TriggerFileExists() bool

TriggerFileExists is a convenience function to determine if a file exists at TriggerFile

Types

type Context

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

Context contains contextual system data, such as groups, users, and active shells, along with paths to certain binaries

func NewContext

func NewContext() (ctx *Context, err error)

NewContext creates an initialized instance of a Context object

func (*Context) AddToGroup

func (c *Context) AddToGroup(user *User, group string) (ran bool, err error)

AddToGroup adds a User to a preexisting group. Returns whether or not the modification ran, along with an error in case something went wrong

func (*Context) CreateGroup

func (c *Context) CreateGroup(name string, id string) error

CreateGroup creates a new group with the given name and ID

func (*Context) DeleteGroup added in v1.0.0

func (c *Context) DeleteGroup(name string) error

DeleteGroup deletes a preexisting group with the given name

func (*Context) DeleteUser added in v1.0.0

func (c *Context) DeleteUser(user *User) (ran bool, err error)

DeleteUser deletes a preexisting user with the given user

func (*Context) FilterUsers

func (c *Context) FilterUsers(filters ...string) (filtered []User)

FilterUsers returns users that fit into one or more of the given filters

func (*Context) RemoveFromGroup added in v1.0.0

func (c *Context) RemoveFromGroup(user *User, group string) (ran bool, err error)

RemoveFromGroup removes a User from a preexisting group. Returns whether or not the modification ran, along with an error in case something went wrong

func (*Context) UpdateGroupID

func (c *Context) UpdateGroupID(name string, id string) error

UpdateGroupID finds a group with the given name and changes its ID to the given ID

type DeleteUsers added in v1.0.0

type DeleteUsers struct {
	UserName string `toml:"name"`
}

DeleteUser is a type of modification that attempts to delete a preexisting user from the system

type Migration

type Migration struct {
	Name string
	Path string

	Description string         `toml:"description"`
	UpdateUsers []*UpdateUsers `toml:"users-update"`
	UpdateGroup []*UpdateGroup `toml:"group-update"`
	RemoveUsers []*RemoveUsers `toml:"users-remove"`
	RemoveGroup []*RemoveGroup `toml:"group-delete"`
	DeleteUsers []*DeleteUsers `toml:"users-delete"`
}

Migration contains the information about a migration, including where it is on the system and its requested system modifications

func LoadMigrations

func LoadMigrations() []Migration

LoadMigrations finds migration files in SysDir and UsrDir and attempts to load them

func (*Migration) Run

func (m *Migration) Run(context *Context)

Run applies the modifications contained in a migration

func (*Migration) Validate

func (m *Migration) Validate() error

Validate checks if a migration contains at least one modification

type RemoveGroup added in v1.0.0

type RemoveGroup struct {
	GroupName string `toml:"name"`
}

RemoveGroup is a type of modification that attempts to delete a preexisting group from the given name

type RemoveUsers added in v1.0.0

type RemoveUsers struct {
	UserFilters []string `toml:"only"`
	GroupName   string   `toml:"group"`
}

RemoveUsers is a type of modification that removes a group from a specific set of users

type UpdateGroup

type UpdateGroup struct {
	GroupName  string `toml:"name"`
	NewGroupID int    `toml:"id"`
}

UpdateGroup is a type of modification that attempts to create or update a group to the given name and ID

type UpdateUsers

type UpdateUsers struct {
	UserFilters []string `toml:"only"`
	GroupName   string   `toml:"group"`
}

UpdateUsers is a type of modification that adds a group to a specific set of users

type User

type User struct {
	Name     string
	Groups   []string
	IsActive bool
	IsRoot   bool
	IsAdmin  bool
}

User is a convenience struct with information on a user entry in /etc/passwd

Jump to

Keyboard shortcuts

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