common

package
v0.0.0-...-45ed272 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2018 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TransferGet get file from remote servers
	TransferGet = "GET"
	// TransferPut put file to remote servers
	TransferPut = "PUT"
	// TransferDefaultMaxSize default max size to transfer
	TransferDefaultMaxSize = 1099511627776 // 100MB
)

Variables

View Source
var ConfigFileList = []string{
	"./optool.yml",
	homeDir() + "/optool.yml",
	"/etc/optool.yml",
	"/tmp/optool.yml",
}

ConfigFileList read config file one by one if not exists

View Source
var UUIDPath = homeDir() + "/.optool-id"

UUIDPath default path for saving machine ID

Functions

func Decrypt

func Decrypt(s string) []byte

Decrypt decrypt string with uuid

func Encrypt

func Encrypt(s string) string

Encrypt encrypt string with uuid

func GetAuth

func GetAuth() (auth []ssh.AuthMethod, err error)

GetAuth get auth method list from configs

func ParseConfig

func ParseConfig(f string) error

ParseConfig parse configure file

func TagList

func TagList()

TagList list all configured tags

func TagPrint

func TagPrint(t string)

TagPrint print specified tag configure

Types

type AuthConfig

type AuthConfig struct {
	User              string `yaml:"user"`
	Password          string `yaml:"password"`
	PrivateKey        string `yaml:"private_key"`
	PrivateKeyContent string `yaml:"private_key_content"`
	PrivateKeyPhrase  string `yaml:"private_key_phrase"`
	PlainPassword     bool   `yaml:"plain_password"` // 是否是明文的密码(通用password和phrase)
}

AuthConfig configures for host authorization

type Configure

type Configure struct {
	Server Server `yaml:"server"`
	//Hosts        map[string][]string `yaml:"hosts"` // structure: group => host list
	Auth AuthConfig        `yaml:"auth"`
	Tags map[string]string `yaml:"tags"` // shortcut for frequently used commands
	Gzip bool              `yaml:"-"`    // enable gzip transfer
	//DefaultGroup string              `yaml:"default_group"` // set default host group
	TransferMaxSize int64 `yaml:"transfer_max_size"`
}

Configure global configure

var C *Configure

C exported parsed configure

type FileTransfer

type FileTransfer struct {
	Source string
	Target string
	Size   int64
	Elapse time.Duration
}

FileTransfer transfer file info

type RemoteCommand

type RemoteCommand struct {
	Hosts    []string
	Cmd      string
	PipeMode bool

	PipeChan  chan bool
	PipeIn    map[string]io.WriteCloser
	PipeOut   map[string]io.Reader
	PipeError map[string]io.Reader

	Output  map[string]string
	Error   map[string]string
	Running map[string]*ssh.Session
	// contains filtered or unexported fields
}

RemoteCommand remote command structure

func NewRemoteCommand

func NewRemoteCommand(hosts []string, cmd string) *RemoteCommand

NewRemoteCommand prepare a remote execution

func (*RemoteCommand) ClosePipe

func (rc *RemoteCommand) ClosePipe()

ClosePipe close ssh sessions

func (*RemoteCommand) PrettyPrint

func (rc *RemoteCommand) PrettyPrint(wo io.Writer, we io.Writer, noHeader bool, noHost bool)

PrettyPrint print output and errors

func (*RemoteCommand) Start

func (rc *RemoteCommand) Start() (err error)

Start run remote command

type Server

type Server struct {
	DefaultGroup string              `yaml:"default_group"`
	DefaultPort  int                 `yaml:"default_port"`
	Hosts        map[string][]string `yaml:"hosts"`
}

Server server groups and default port/group config

type Transfer

type Transfer struct {
	Inited         bool
	Method         string // GET,PUT
	LocalPath      string
	RemotePath     string
	Recursive      bool
	Hosts          []string
	Clients        map[string]*ssh.Client
	SftpClient     map[string]*sftp.Client
	Override       bool                    // override remote existed file?
	TransferResult map[string]FileTransfer // result of transfering
	Lock           sync.Mutex
}

Transfer transfer files via ssh

func NewTransfer

func NewTransfer(method, localPath, remotePath string, hosts []string) *Transfer

NewTransfer get file transfer instance

func (*Transfer) PrettyPrint

func (t *Transfer) PrettyPrint()

PrettyPrint print transfer result

func (*Transfer) Start

func (t *Transfer) Start() (err error)

Start start file transfer

Jump to

Keyboard shortcuts

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