khan

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 29 Imported by: 0

README

KHAN

Khan is a super speedy khanfiguration management tool. It generates a statically compiled binary that applies your configuration locally or remotely via SSH. It is tightly coupled with the Go programming language.

Demo

Instead of using a crappy template system with YAML files, khan directly converts yaml files into Go code which is then compiled. This means many errors are caught at compile time.

More documentation forthcoming!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(add ...Item)

Add to the default run context

func AddFromSource

func AddFromSource(source string, add ...Item)

Add to the default run context with explicit source path

func Apply

func Apply() error

func RedError

func RedError(e error) string

func RedPrintln

func RedPrintln(s string)

func SetAssetLoader

func SetAssetLoader(fn func(string) (io.ReadCloser, error))

func SetDescribe

func SetDescribe(s string)

func SetSourcePrefix

func SetSourcePrefix(s string)

func SetTitle

func SetTitle(s string)

func Warnf

func Warnf(str string, args ...interface{})

Types

type Color

type Color int
const (
	Black Color = iota + 1
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

type File

type File struct {
	Path string `khan:"path,shortkey"`

	User  string
	Group string
	Mode  os.FileMode

	// Content specifies a static string for the content of the file.
	Content string

	// Src is a path on the configurer for the source of the file.
	// This will be bundled into your khan build output.
	Src string `khan:"src,shortvalue"`

	// Local is a path on the configuree for the source of the file
	Local string

	// Template execution mode. Leave blank for no templating. Special
	// value "1" is the same as the default templating engine "pongo2",
	// a jinja2 style template engine. (See https://github.com/flosch/pongo2)
	Template string

	Delete bool
	// contains filtered or unexported fields
}

func (*File) After

func (f *File) After() []string

func (*File) Apply

func (f *File) Apply(host *Host) (itemStatus, error)

func (*File) Before

func (f *File) Before() []string

func (*File) Clone

func (f *File) Clone() Item

func (*File) ID

func (f *File) ID() int

func (*File) Provides

func (f *File) Provides() []string

func (*File) SetID

func (f *File) SetID(id int)

func (*File) StaticFiles

func (f *File) StaticFiles() []string

func (*File) String

func (f *File) String() string

func (*File) Validate

func (f *File) Validate() error

type FuncType

type FuncType func(*Host) error

type Function

type Function struct {
	Fn FuncType
	// contains filtered or unexported fields
}

func (*Function) After

func (f *Function) After() []string

func (*Function) Apply

func (f *Function) Apply(host *Host) (itemStatus, error)

func (*Function) Before

func (f *Function) Before() []string

func (*Function) Clone

func (f *Function) Clone() Item

func (*Function) ID

func (f *Function) ID() int

func (*Function) Provides

func (f *Function) Provides() []string

func (*Function) SetID

func (f *Function) SetID(id int)

func (*Function) StaticFiles

func (f *Function) StaticFiles() []string

func (*Function) String

func (f *Function) String() string

func (*Function) Validate

func (f *Function) Validate() error

type Group

type Group struct {
	Name string
	Gid  uint32

	Delete bool
	// contains filtered or unexported fields
}

func (*Group) After

func (g *Group) After() []string

func (*Group) Apply

func (g *Group) Apply(host *Host) (itemStatus, error)

func (*Group) Before

func (g *Group) Before() []string

func (*Group) Clone

func (g *Group) Clone() Item

func (*Group) ID

func (g *Group) ID() int

func (*Group) Provides

func (g *Group) Provides() []string

func (*Group) SetID

func (g *Group) SetID(id int)

func (*Group) String

func (g *Group) String() string

type Host

type Host struct {
	Run *Run

	Name string // Friendly name for host
	SSH  bool
	Host string // Host for SSH
	// contains filtered or unexported fields
}

Host is the context for an execution run on a specific server. It contains a virtual model of all changes we are capable of making on a server, including service status and a filesystem. This way a dry run can be pixel-perfect.

func (*Host) Add

func (host *Host) Add(add ...Item) error

func (*Host) AddFromSource

func (host *Host) AddFromSource(source string, add ...Item) error

func (*Host) Key

func (host *Host) Key() string

func (*Host) OS added in v0.0.16

func (host *Host) OS() (string, error)

func (*Host) String

func (host *Host) String() string

type Item

type Item interface {
	SetID(id int)
	ID() int

	Clone() Item
	String() string

	Apply(host *Host) (itemStatus, error)

	Provides() []string
	After() []string
	Before() []string
}

func Func

func Func(fn FuncType) Item

type Package

type Package struct {
	Name string
}

type Run

type Run struct {
	Dry     bool
	Diff    bool
	Verbose bool

	Pool  *sshpool.Pool
	Hosts []*Host
	// contains filtered or unexported fields
}

Run is the context for an execution run, on one or more servers.

func (*Run) Add

func (r *Run) Add(add ...Item) error

Add will clone items for each configured host and add them to the run graph

func (*Run) AddFromSource

func (r *Run) AddFromSource(source string, add ...Item) error

AddFromSource is like Add but with explicit source code path

type StaticFiler

type StaticFiler interface {
	StaticFiles() []string
}

type User

type User struct {
	Name string

	// Primary group. If not specified, user name is used
	Group string

	Uid uint32

	// Supplemental groups
	Groups []string

	Comment string // Gecos field

	Home  string
	Shell string

	// Password is the passord encrypted with libcrypt.
	// Password if blank will actually be set to "!". If "!", "!!", or "x" are found
	// in /etc/shadow, it will be translated to a blank password. If you want an actually
	// blank password (not safe) use BlankPassword: true (blank_password: true in yaml).
	Password      string
	BlankPassword bool `khan:"blank_password"`

	Delete bool
	// contains filtered or unexported fields
}

func (*User) After

func (u *User) After() []string

func (*User) Apply

func (u *User) Apply(host *Host) (itemStatus, error)

func (*User) Before

func (u *User) Before() []string

func (*User) Clone

func (u *User) Clone() Item

func (*User) ID

func (u *User) ID() int

func (*User) Provides

func (u *User) Provides() []string

func (*User) SetID

func (u *User) SetID(id int)

func (*User) String

func (u *User) String() string

type Validator

type Validator interface {
	Validate() error
}

type VaultResponse

type VaultResponse struct {
	Data VaultResponseData
}

type VaultResponseData

type VaultResponseData struct {
	Data map[string]string
}

type Virtual

type Virtual struct {
	// Host metadata extracted from uname command
	Uname    string
	Hostname string
	Kernel   string
	OS       string
	Arch     string

	// File system model
	Files   map[string]os.FileInfo
	Content map[string]string

	// User and group model
	Users  map[string]*User
	Groups map[string]*Group
	// contains filtered or unexported fields
}

Virtual is an in-memory model for all changes we are capable of making on a server, including service status and a filesystem. This way a dry run can be pixel-perfect.

If you start managing files with contents too large for RAM, this will need to be improved. (Currently all managed files, including contents, are in kept in memory in their entirety.)

func NewVirtual

func NewVirtual() *Virtual

Directories

Path Synopsis
cmd
demo
rio
dry

Jump to

Keyboard shortcuts

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