khan

package module
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 27 Imported by: 0

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 added in v0.0.12

func SetTitle(s string)

func Warnf

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

Types

type Cmd added in v0.0.12

type Cmd struct {
	Path string
	Args []string
	Env  [][2]string
	Dir  string

	Shell bool // when ssh-ing, try to start a shell instead of just executing a command (gives you working environment vars, etc)

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	Context context.Context
	// contains filtered or unexported fields
}

func (*Cmd) Run added in v0.0.12

func (cmd *Cmd) Run() error

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 User

	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) Apply added in v0.0.12

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

func (*File) Clone added in v0.0.12

func (f *File) Clone() Item

func (*File) ID added in v0.0.12

func (f *File) ID() int

func (*File) Needs added in v0.0.12

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

func (*File) Provides added in v0.0.12

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

func (*File) SetID added in v0.0.12

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 FileInfo added in v0.0.12

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

func (*FileInfo) IsDir added in v0.0.12

func (fi *FileInfo) IsDir() bool

func (*FileInfo) ModTime added in v0.0.12

func (fi *FileInfo) ModTime() time.Time

func (*FileInfo) Mode added in v0.0.12

func (fi *FileInfo) Mode() os.FileMode

func (*FileInfo) Name added in v0.0.12

func (fi *FileInfo) Name() string

func (*FileInfo) Size added in v0.0.12

func (fi *FileInfo) Size() int64

func (*FileInfo) String added in v0.0.12

func (fi *FileInfo) String() string

func (*FileInfo) Sys added in v0.0.12

func (fi *FileInfo) Sys() interface{}

type FuncType added in v0.0.12

type FuncType func(*Host) error

type Function added in v0.0.12

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

func (*Function) Apply added in v0.0.12

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

func (*Function) Clone added in v0.0.12

func (f *Function) Clone() Item

func (*Function) ID added in v0.0.12

func (f *Function) ID() int

func (*Function) Needs added in v0.0.12

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

func (*Function) Provides added in v0.0.12

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

func (*Function) SetID added in v0.0.12

func (f *Function) SetID(id int)

func (*Function) StaticFiles added in v0.0.12

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

func (*Function) String added in v0.0.12

func (f *Function) String() string

func (*Function) Validate added in v0.0.12

func (f *Function) Validate() error

type Group

type Group struct {
	Name string
	Gid  int

	Delete bool
	// contains filtered or unexported fields
}

func (*Group) Apply added in v0.0.12

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

func (*Group) Clone added in v0.0.12

func (g *Group) Clone() Item

func (*Group) ID added in v0.0.12

func (g *Group) ID() int

func (*Group) Needs added in v0.0.12

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

func (*Group) Provides added in v0.0.12

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

func (*Group) SetID added in v0.0.12

func (g *Group) SetID(id int)

func (*Group) String

func (g *Group) String() string

type Host added in v0.0.12

type Host struct {
	Run *Run

	Name string // Friendly name for host

	SSH bool

	Host string // Host for SSH

	VirtMu sync.RWMutex
	Virt   *Virtual // Virtual model of the host
}

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 added in v0.0.12

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

func (*Host) AddFromSource added in v0.0.12

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

func (*Host) Command added in v0.0.12

func (host *Host) Command(ctx context.Context, path string, args ...string) *Cmd

func (*Host) Create added in v0.0.12

func (host *Host) Create(path string) (io.WriteCloser, error)

func (*Host) Key added in v0.0.12

func (host *Host) Key() string

func (*Host) Open added in v0.0.12

func (host *Host) Open(path string) (io.ReadCloser, error)

func (*Host) ReadFile added in v0.0.12

func (host *Host) ReadFile(path string) ([]byte, error)

func (*Host) Remove added in v0.0.12

func (host *Host) Remove(path string) error

func (*Host) Stat added in v0.0.12

func (host *Host) Stat(path string) (os.FileInfo, error)

func (*Host) String added in v0.0.12

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
	Needs() []string
}

func Func added in v0.0.12

func Func(fn FuncType) Item

type Package

type Package struct {
	Name string
}

type Run added in v0.0.12

type Run struct {
	Dry     bool
	Diff    bool
	Verbose bool

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

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

func (*Run) Add added in v0.0.12

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 added in v0.0.12

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

AddFromSource is like Add but with explicit source code path

type SSHWriter added in v0.0.12

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

func (*SSHWriter) Close added in v0.0.12

func (w *SSHWriter) Close() error

func (*SSHWriter) Write added in v0.0.12

func (w *SSHWriter) Write(p []byte) (int, error)

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 int

	// Supplemental groups
	Groups []string

	Gecos string

	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) Apply added in v0.0.12

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

func (*User) Clone added in v0.0.12

func (u *User) Clone() Item

func (*User) ID added in v0.0.12

func (u *User) ID() int

func (*User) Needs added in v0.0.12

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

func (*User) Provides added in v0.0.12

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

func (*User) SetID added in v0.0.12

func (u *User) SetID(id int)

func (*User) String

func (u *User) String() string

type Validator

type Validator interface {
	Validate() error
}

type VaultResponse added in v0.0.9

type VaultResponse struct {
	Data VaultResponseData
}

type VaultResponseData added in v0.0.9

type VaultResponseData struct {
	Data map[string]string
}

type Virtual added in v0.0.12

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
	Contents map[string]string

	// User and group model
	Users  map[string]*User
	Groups map[string]*Group
}

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 added in v0.0.12

func NewVirtual() *Virtual

Directories

Path Synopsis
cmd
package rio is an abstraction for IO operations that may be performed locally, or remotely via golang.org/x/crypto/ssh.
package rio is an abstraction for IO operations that may be performed locally, or remotely via golang.org/x/crypto/ssh.

Jump to

Keyboard shortcuts

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