Documentation ¶
Index ¶
- Constants
- Variables
- func ArrayContains(arr []string, str string) bool
- func ErrInvalidSession(sessionID string) error
- func GetHostAndSession(sessionID, hostID string) (Session, *Host, error)
- func HasLabel(h *pb.HostInfo, l string) bool
- func LockForInteraction()
- func MapYaml(in interface{}) interface{}
- func NewInventoryID() string
- func ParseFileMode(str string) os.FileMode
- func RegisterBackend(name string, b func(*Host) HostBackend)
- func RegisterModule(name string, m Module)
- func UnlockForInteraction()
- func Words(in string) []string
- type CmdErr
- type CommonFileInfo
- type Ctx
- type Dispatcher
- type FileDesc
- type FileOwner
- type Funcdef
- type Host
- func (h *Host) Chmod(ctx Ctx, s Session, path string, mode int) (CmdErr, error)
- func (h *Host) Chown(ctx Ctx, s Session, path string, user, group string) (CmdErr, error)
- func (h *Host) Defaults()
- func (h *Host) DiscoverIPs() error
- func (h *Host) Ensure(ctx Ctx, s Session, path string, desc FileDesc) (bool, CmdErr, error)
- func (h *Host) GetAuth() ([]ssh.AuthMethod, error)
- func (h *Host) GetFileInfo(ctx Ctx, s Session, file string) (FileOwner, os.FileInfo, CmdErr, error)
- func (h *Host) GetHostAndPort() string
- func (h *Host) GetNetwork() string
- func (h *Host) GetUserName() string
- func (h *Host) MkDir(ctx Ctx, s Session, path string) (CmdErr, error)
- func (h *Host) NewCtx() Ctx
- func (h *Host) ReadFile(ctx Ctx, s Session, name string) (os.FileInfo, []byte, CmdErr, error)
- func (h *Host) RunCmd(ctx Ctx, s Session, cmd string, env map[string]string) (HostCommandResponse, error)
- func (h *Host) Via() sshdial.Host
- func (h *Host) WriteFile(ctx Ctx, s Session, name string, perms os.FileMode, content []byte) (CmdErr, error)
- type HostBackend
- type HostCommandResponse
- type HostSession
- type InternalInventory
- type Inventory
- type InventoryConfiguration
- type Logger
- type Logging
- type Module
- type ModuleMgr
- type Response
- type Session
Constants ¶
const Primary = "primary"
Primary interface name.
const Primary4 = "primary4"
Primary4 IP4 interface name
const Primary6 = "primary6"
Primary6 IP6 interface name
Variables ¶
var AllHosts = "all"
AllHosts is the inventory that contains all known hosts
var LocalModules = map[string]Module{}
LocalModules keeps a map of all local modules
var Localhost = &Host{HostInfo: pb.HostInfo{ID: LocalhostID, Labels: make([]string, 0), Properties: make(map[string]string)}}
Localhost is the localhost
var LocalhostID = "localhost"
LocalhostID is the "localhost"
var SessionFactory func() Session
SessionFactory should be set in main to create new instances of session configured using the flags or config file(s)
var Sessions = sessionRegistry{Sessions: map[string]Session{}}
Sessions keeps all active sessions
Functions ¶
func ArrayContains ¶
ArrayContains returns if the array contains the string
func ErrInvalidSession ¶
ErrInvalidSession returns invalid session error
func GetHostAndSession ¶
GetHostAndSession returns a host from the session
func LockForInteraction ¶
func LockForInteraction()
LockForInteraction prevents multiple goroutines from entering user interaction
func MapYaml ¶
func MapYaml(in interface{}) interface{}
MapYaml converts map[interface{}]interface{} to map[string]interface{}
func NewInventoryID ¶
func NewInventoryID() string
NewInventoryID returns a new inventory ID. It skips AllHosts.
func ParseFileMode ¶
ParseFileMode parses -rwxrwxrwx string
func RegisterBackend ¶
func RegisterBackend(name string, b func(*Host) HostBackend)
RegisterBackend registers a new backend
func RegisterModule ¶
RegisterModule registers a local module
func UnlockForInteraction ¶
func UnlockForInteraction()
UnlockForInteraction unlocks the interaction lock
Types ¶
type CmdErr ¶
type CmdErr interface { Error() string Host() string Msg() string ToPb() *pb.CommandError }
CmdErr is used for command errors. Regular go errors are used for fatal infrastructure errors
func CmdErrFromErr ¶
CmdErrFromErr returns a CmdErr from error. if err is nil, returns nil
type CommonFileInfo ¶
type CommonFileInfo struct { FileName string FileSize int64 FileMode os.FileMode FileModTime time.Time FileIsDir bool }
CommonFileInfo is an os.FileInfo
func (CommonFileInfo) IsDir ¶
func (c CommonFileInfo) IsDir() bool
IsDir returns true if this is a directory
func (CommonFileInfo) ModTime ¶
func (c CommonFileInfo) ModTime() time.Time
ModTime returns the file modification time
type Ctx ¶
type Ctx interface { New(Session) (HostSession, error) Close() }
Ctx is host session context
type Dispatcher ¶
type Dispatcher struct { Name string // contains filtered or unexported fields }
Dispatcher is the default module function dispatcher
func NewDispatcher ¶
func NewDispatcher(name string) *Dispatcher
NewDispatcher returns a new dispatcher with the given module name
func (*Dispatcher) Add ¶
func (d *Dispatcher) Add(name string, f Funcdef) *Dispatcher
Add adds a new function to dispatcher
type Funcdef ¶
type Funcdef struct { // ParamsFactory returns an object instance that will be unmarshaled // from json. It should me a pointer. ParamsFactory func() interface{} // This is the actual implementation function. The input interface // is what's returned from ParamsFactory Impl func(Session, interface{}) (Response, error) }
Funcdef describes an implementation of the function
type Host ¶
type Host struct { sync.Mutex pb.HostInfo Configuration interface{} // The bastion host to use to connect this host Bastion *Host // SSH hostname Hostname string Network string Port int // If nonempty, this user is used to login LoginUser string // Password of the user LoginPassword string // If non-nil, the public key signer derived from the private key will be used KeyAuth *sshdial.RawPrivateKey // HostPublicKey is initialized if empty, validated if nonempty HostPublicKey ssh.PublicKey // Become user methos Become string Backend HostBackend }
Host contains information about a host in the inventory
func GetHostFromSession ¶
GetHostFromSession returns a host from the session
func (*Host) Defaults ¶
func (h *Host) Defaults()
Defaults initializes uninitialized host fields with defaults
func (*Host) GetAuth ¶
func (h *Host) GetAuth() ([]ssh.AuthMethod, error)
GetAuth returns the supported SSH auth methods
func (*Host) GetFileInfo ¶
GetFileInfo retrieves file info from a host. If the file is missing, will return FileOwner{},nil,nil
func (*Host) GetHostAndPort ¶
GetHostAndPort returns the host and port to connect
func (*Host) GetNetwork ¶
GetNetwork returns the network to connect to this host
type HostBackend ¶
type HostBackend interface {
NewSession(Session, *Host) (HostSession, error)
}
HostBackend opens a new session to run commands on the host
type HostCommandResponse ¶
HostCommandResponse contains the response of the command
type HostSession ¶
type HostSession interface { WriteFile(name string, perms os.FileMode, content []byte) (CmdErr, error) ReadFile(name string) (os.FileInfo, []byte, CmdErr, error) Run(cmd string, env map[string]string) (HostCommandResponse, error) GetFileInfo(file string) (FileOwner, os.FileInfo, CmdErr, error) MkDir(string) (CmdErr, error) Chmod(string, int) (CmdErr, error) Chown(string, string, string) (CmdErr, error) Close() }
HostSession declares the operations that can run on the host
type InternalInventory ¶
InternalInentory adds additional functions to the basic inventory interface for server use only.
type Inventory ¶
type Inventory interface { // Select returns a new inventory containing only the hosts // selected by the given selectors from the given inventory Select(string, ...*pb.Selector) (string, error) // Union combines inventories to build a new host set containing // all the hosts in the sources Union([]string) (string, error) // Make creates a new inventory from the given host IDs Make([]string) (string, error) // Add adds new hosts to the given inventory, and returns the new // inventory ID Add(string, []string) (string, error) // GetHostIDs returns the host IDs included in the inventory GetHostIDs(string) ([]string, error) // GetHostInfo returns the host information for the given hosts GetHostInfo([]string) ([]*pb.HostInfo, error) // Release notifies the server that the inventory is no longer // needed, and can be freed Release(string) }
Inventory server interface. Inventory keeps all known servers
type InventoryConfiguration ¶
type InventoryConfiguration struct {
PrivateKey *sshdial.RawPrivateKey
}
InventoryConfiguration contains the configuration loaded from the inventory
type Logger ¶
type Logger interface { Print(...interface{}) Printf(string, ...interface{}) }
Logger provides the printing functions. A logger is associated with a single host
type Logging ¶
type Logging interface { // New returns the logger for the host. If logToStdout is true, then // prints logs also to stdout New(h *Host, logToStdout bool) Logger }
Logging provides access to loggers
type Module ¶
type Module interface { // Func calls a module function Func(Session, string, []byte) (Response, error) // Short help about the module Describe() string // Long help about the module Help() string }
Module interface is to be implemented by all modules
type ModuleMgr ¶
type ModuleMgr interface { // SendRequest to a module function SendRequest(session, module, funcName string, data []byte) (Response, error) Close() }
ModuleMgr deals with calling modules
type Response ¶
type Response struct { Success bool // This should be set to true if the work caused any changes Modified bool FuncName string ErrorMsg string Data []byte }
Response is the response returned by a module call
func CallLocalModule ¶
CallLocalModule calls a local module if there is one registered
type Session ¶
type Session interface { GetID() string // Close a session Close() // GetLogger returns a logger for the host GetLogger(host *Host) Logger // GetHost returns a host from the session GetHost(hostID string) (*Host, error) // GetCfg returns a path from cfg, either seen by host, or global config GetCfg(hostId, path string) interface{} // GetInv returns inventory GetInv() InternalInventory SetInv(InternalInventory) GetModules() ModuleMgr SetModules(ModuleMgr) SetLogStdout(bool) SetLog(Logging) GetConfig() interface{} SetConfig(interface{}) SetArgs([]string) GetArgs() []string }
Session interface
func GetSession ¶
GetSession returns a session by ID. Returns nil if not found