Documentation ¶
Index ¶
- Constants
- Variables
- func AbsPath(input string) string
- func AgentPostInitClientConfig(ctx *EventContext, clientConfig *ssh.ClientConfig)
- func AgentPostNewSession(ctx *EventContext, session *ssh.Session) error
- func AgentPostSSHDial(ctx *EventContext, client *ssh.Client) error
- func AuthPemPostInitClientConfig(ctx *EventContext, clientConfig *ssh.ClientConfig)
- func AuthPwdPostInitClientConfig(ctx *EventContext, clientConfig *ssh.ClientConfig)
- func AutoSSHAgent() error
- func CallbackOnStdout(ctx *EventContext, line []byte) error
- func CallbackPostShell(ctx *EventContext, stdin io.WriteCloser) error
- func ExtractBinary(name string, needClose bool) (*os.File, error)
- func FieldEmpty(t reflect.Type, v reflect.Value) bool
- func FieldsNotEmpty(v interface{}, ignoreKeys []string) ([]string, error)
- func IOOnStderr(ctx *EventContext, bytes []byte) error
- func IOOnStdout(ctx *EventContext, bytes []byte) error
- func InitConfig(config interface{}) error
- func InitNodes(nodes []*Node) error
- func InitNodesBaseOnGlobal(nodes []*Node, matchFunc MatchFunc)
- func InitSshNodes(nodes []*Node) error
- func IsBookmark(n *Node) bool
- func IsEAGAIN(err error) bool
- func MatchCommonConfig(node *Node, globalNode *Node) bool
- func MatchSshConfig(node *Node, globalNode *Node) bool
- func MergeNodes(dstPtr *[]*Node, src []*Node)
- func MergeSshConfig(nodes []*Node, sshNodes []*Node) error
- func ReadConfigBytes(filename string) (string, []byte, error)
- func ReadDefaultConfigBytes(names ...string) (string, []byte, error)
- func Shell() string
- func UserIdRsaIsNotExist() bool
- func WalkInterface(v reflect.Value, walked bool, solver ValueSolver) error
- type CallbackInfo
- type Client
- type ConfigLoader
- type CustomTemplate
- type EventContext
- type GithubRepository
- type KeyboardInteractive
- type MatchFunc
- type Node
- type NodeCallbackShell
- type NodeCp
- type NodeExec
- type NonblockReader
- type ReaderFunc
- type Repository
- type RuntimeSystem
- type SshConfigLoader
- type TemplateNode
- type ValueSolver
- type VersionMeta
- type WriteCounter
- type WriterFunc
- type YamlConfigLoader
Constants ¶
const ( PostInitClientConfig = "PostInitClientConfig" PostSSHDial = "PostSSHDial" PostNewSession = "PostNewSession" OnStdout = "OnStdout" OnStderr = "OnStderr" PostShell = "PostShell" )
const ( WalkIndexFlag = "$index" WalkOtherFlag = "$other" )
const ( TypeStr = "str" TypeParam = "param" )
const (
ApplicationName = "sshw"
)
const (
KeyAgent = "agent"
)
const (
KeyCallback = "callback"
)
Variables ¶
var ( SshPath = path.Join(homeDir, ".ssh/config") SshwDir = path.Join(homeDir, ".config/sshw") SshwGlobalConfigPath = path.Join(SshwDir, "config.yaml") )
var (
DefaultCiphers = []string{
"aes128-ctr",
"aes192-ctr",
"aes256-ctr",
"aes128-gcm@openssh.com",
"chacha20-poly1305@openssh.com",
"arcfour256",
"arcfour128",
"arcfour",
"aes128-cbc",
"3des-cbc",
"blowfish-cbc",
"cast128-cbc",
"aes192-cbc",
"aes256-cbc",
}
)
Functions ¶
func AbsPath ¶
AbsPath returns absolute path and match wild path if match multiple path, return first
func AgentPostInitClientConfig ¶ added in v1.8.2
func AgentPostInitClientConfig(ctx *EventContext, clientConfig *ssh.ClientConfig)
func AgentPostNewSession ¶ added in v1.8.2
func AgentPostNewSession(ctx *EventContext, session *ssh.Session) error
func AgentPostSSHDial ¶ added in v1.8.2
func AgentPostSSHDial(ctx *EventContext, client *ssh.Client) error
func AuthPemPostInitClientConfig ¶ added in v1.8.2
func AuthPemPostInitClientConfig(ctx *EventContext, clientConfig *ssh.ClientConfig)
func AuthPwdPostInitClientConfig ¶ added in v1.8.2
func AuthPwdPostInitClientConfig(ctx *EventContext, clientConfig *ssh.ClientConfig)
if set password, auto auth password if set KeyboardInteractions, match question and then auto auth interaction
func CallbackOnStdout ¶ added in v1.8.2
func CallbackOnStdout(ctx *EventContext, line []byte) error
func CallbackPostShell ¶ added in v1.8.2
func CallbackPostShell(ctx *EventContext, stdin io.WriteCloser) error
func FieldsNotEmpty ¶
search not empty field in v if key in ignoreKeys, skip validation
func IOOnStderr ¶ added in v1.8.2
func IOOnStderr(ctx *EventContext, bytes []byte) error
func IOOnStdout ¶ added in v1.8.2
func IOOnStdout(ctx *EventContext, bytes []byte) error
func InitConfig ¶ added in v1.10.0
func InitConfig(config interface{}) error
render template into nodes 1. Parse template ${Env_Variable} 2. solve path.convert '*' to absPath
func InitNodesBaseOnGlobal ¶ added in v1.10.0
update nodes based on global config if host is equal, update node only iterate first level
func InitSshNodes ¶ added in v1.10.0
1. load global yaml 2. render template
func MatchCommonConfig ¶ added in v1.10.0
func MatchSshConfig ¶ added in v1.10.0
func MergeNodes ¶
merge srcNode to dstNode only compare name and override, otherwise it is complex.
func MergeSshConfig ¶ added in v1.10.0
match .ssh/config Pattern if Node.Host == config.Host set config.HostName to Node.Host same set config.User and config.Port
func ReadConfigBytes ¶ added in v1.9.1
return filepath and bytes of config
func ReadDefaultConfigBytes ¶ added in v1.9.1
func UserIdRsaIsNotExist ¶ added in v1.8.1
func UserIdRsaIsNotExist() bool
func WalkInterface ¶
func WalkInterface(v reflect.Value, walked bool, solver ValueSolver) error
Types ¶
type CallbackInfo ¶ added in v1.8.2
func NewCallbackInfo ¶ added in v1.8.2
func NewCallbackInfo() *CallbackInfo
type Client ¶
type Client interface { // -----local // run pre commands ExecsPre() error CanConnect() bool // terminal makeRaw and store width height InitTerminal() error RecoverTerminal() // run post commands ExecsPost() error WatchWindowChange(windowChange func(ch, cw int) error) // -----local or remote Connect() error Scp(ctx context.Context) error Shell() error Close() error // -----remote GetClient() *ssh.Client SetClient(client *ssh.Client) // send keepalive to ssh server Ping() error }
type ConfigLoader ¶ added in v1.10.0
func NewSshConfigLoader ¶ added in v1.10.0
func NewSshConfigLoader(r io.Reader) ConfigLoader
func NewYamlConfigLoader ¶ added in v1.10.0
func NewYamlConfigLoader(bs []byte) ConfigLoader
type CustomTemplate ¶
type CustomTemplate struct {
Templates []*TemplateNode
}
func ParseSshwTemplate ¶
func ParseSshwTemplate(src string) *CustomTemplate
Read string to Template For example: INPUT: ParseSshwTemplate("Foo${foo:a}bar") OUTPUT: []{{Type: TypeStr, Value: "Foo"}, {Type: TypeParam}, Value: "${foo:a}"}, {Type: TypeStr, Value: "bar"}}
func (*CustomTemplate) Execute ¶
func (c *CustomTemplate) Execute() string
type EventContext ¶ added in v1.8.2
func NewEventContext ¶ added in v1.8.2
func NewEventContext(node *Node) *EventContext
func (*EventContext) Get ¶ added in v1.8.2
func (e *EventContext) Get(key string) (interface{}, bool)
func (*EventContext) Put ¶ added in v1.8.2
func (e *EventContext) Put(key string, value interface{})
type GithubRepository ¶
func (*GithubRepository) Download ¶
func (g *GithubRepository) Download(versionMeta *VersionMeta) (*os.File, error)
Using version and filename to generate a remote url that is used to download file. Download it to file tmp. Then backup original file and replace it with Downloaded file.
func (*GithubRepository) LatestVersion ¶
func (g *GithubRepository) LatestVersion() (*VersionMeta, error)
type KeyboardInteractive ¶
type KeyboardInteractive struct { Question string Answer string GoogleAuth bool `yaml:"google-auth"` }
when it have KeyboardInteractive sshw will answer question if question contains content that we set. if AnswerAll is true, it will don't match question
type Node ¶
type Node struct { // Node Name or .ssh/config Host Name string `yaml:"name"` Alias string `yaml:"alias,omitempty"` ExecsPre []*NodeExec `yaml:"execs-pre,omitempty"` ExecsStop []*NodeExec `yaml:"execs-stop,omitempty"` Host string `yaml:"host,omitempty"` User string `yaml:"user,omitempty"` Port int `yaml:"port,omitempty"` KeyPath string `yaml:"keypath,omitempty"` Passphrase string `yaml:"passphrase,omitempty"` Password string `yaml:"password,omitempty"` CallbackShells []*NodeCallbackShell `yaml:"callback-shells,omitempty"` Scps []*NodeCp `yaml:"scps"` Children []*Node `yaml:"children,omitempty"` Jump []*Node `yaml:"jump,omitempty"` MergeIgnore bool `yaml:"merge-ignore,omitempty"` KeyboardInteractions []KeyboardInteractive `yaml:"keyboard-interactions"` ControlMaster *bool `yaml:"control-master"` Stdin io.ReadCloser `yaml:"-"` Stdout io.Writer `yaml:"-"` Stderr io.Writer `yaml:"-"` Width int `yaml:"-"` Height int `yaml:"-"` State *terminal.State `yaml:"-"` Session *ssh.Session `yaml:"-"` }
func LoadYamlConfig ¶
return filepath and nodes, load config in filename
func LoadYamlConfig0 ¶ added in v1.10.0
return yaml config
type NodeCallbackShell ¶
type NonblockReader ¶ added in v1.9.3
func NewNonblockReader ¶ added in v1.9.3
func NewNonblockReader(r *os.File) (*NonblockReader, error)
func (*NonblockReader) Close ¶ added in v1.9.3
func (n2 *NonblockReader) Close() error
type ReaderFunc ¶ added in v1.9.3
type Repository ¶
type Repository interface { // get remote version LatestVersion() (*VersionMeta, error) // download remote file to specified path Download(versionMeta *VersionMeta) (*os.File, error) }
type RuntimeSystem ¶
type SshConfigLoader ¶ added in v1.10.0
type SshConfigLoader struct {
// contains filtered or unexported fields
}
func (*SshConfigLoader) Decode ¶ added in v1.10.0
func (s *SshConfigLoader) Decode(nodes *[]*Node) error
type TemplateNode ¶
func NewParamNode ¶
func NewParamNode(v string) *TemplateNode
func NewStrNode ¶
func NewStrNode(v string) *TemplateNode
type ValueSolver ¶
type ValueSolver func(k string, t reflect.Type, v reflect.Value, structField *reflect.StructField) (skipSearch bool)
if t.kind() in array or slice, name is $index return true, if would skip deepSearching type like slice or array or map
type VersionMeta ¶
type WriteCounter ¶
WriteCounter counts the number of bytes written to it. It implements to the io.Writer interface and we can pass this into io.TeeReader() which will report progress on each write cycle.
func NewWriteCounter ¶
func NewWriteCounter() *WriteCounter
func (*WriteCounter) PrintProgress ¶
func (wc *WriteCounter) PrintProgress()
type WriterFunc ¶ added in v1.9.3
type YamlConfigLoader ¶ added in v1.10.0
type YamlConfigLoader struct {
// contains filtered or unexported fields
}
func (*YamlConfigLoader) Decode ¶ added in v1.10.0
func (y *YamlConfigLoader) Decode(nodes *[]*Node) error