saultcommon

package
v0.0.0-...-504a021 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2017 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTOML toml.Config

DefaultTOML is the default toml config

View Source
var MaxLengthHostID = 64

MaxLengthHostID is the maximum length of host id

View Source
var MaxLengthUserID = 32

MaxLengthUserID is the maximum length of user id

Functions

func BaseJoin

func BaseJoin(base string, paths ...string) string

BaseJoin joins the path

func CheckAccountName

func CheckAccountName(s string) bool

CheckAccountName checkes whether user name is valid or not

func CheckHostID

func CheckHostID(s string) bool

CheckHostID checkes whether HostRegistry.ID is valid or not

func CheckSSHAgent

func CheckSSHAgent()

CheckSSHAgent checkes ssh agent is running

func CheckUserID

func CheckUserID(s string) bool

CheckUserID checkes whether UserRegistry.ID is valid or not

func ColorFunc

func ColorFunc(attr ...color.Attribute) func(string) string

ColorFunc is the wrapper for colorizing string

func CreateRSAPrivateKey

func CreateRSAPrivateKey(bits int) (privateKey *rsa.PrivateKey, err error)

CreateRSAPrivateKey makes RSA private key

func EncodePrivateKey

func EncodePrivateKey(privateKey *rsa.PrivateKey) ([]byte, error)

EncodePrivateKey encode private key as pem format

func EncodePublicKey

func EncodePublicKey(publicKey interface{}) (b []byte, err error)

EncodePublicKey generates public key string

func FindSignerInSSHAgentFromFile

func FindSignerInSSHAgentFromFile(file string) (signer saultssh.Signer, err error)

FindSignerInSSHAgentFromFile will find signer from ssh agent with public key file

func FindSignerInSSHAgentFromPublicKey

func FindSignerInSSHAgentFromPublicKey(publicKey saultssh.PublicKey) (
	signer saultssh.Signer, err error,
)

FindSignerInSSHAgentFromPublicKey will find signer from ssh agent with public key

func FingerprintMD5PublicKey

func FingerprintMD5PublicKey(key saultssh.PublicKey) string

FingerprintMD5PublicKey makes md5 finterprint string of ssh public key; from https://github.com/golang/go/issues/12292#issuecomment-255588529 //

func FingerprintSHA256PublicKey

func FingerprintSHA256PublicKey(key saultssh.PublicKey) string

FingerprintSHA256PublicKey makes the sha256 fingerprint string of ssh public key; from https://github.com/golang/go/issues/12292#issuecomment-255588529

func GetAuthorizedKey

func GetAuthorizedKey(publicKey saultssh.PublicKey) string

GetAuthorizedKey strips the public key string

func GetDefaultLogrusFormatter

func GetDefaultLogrusFormatter() logrus.Formatter

GetDefaultLogrusFormatter return the default logrus formatter

func GetSSHAgent

func GetSSHAgent() (saultsshAgent.Agent, error)

GetSSHAgent returns ssh agent

func GetServerLogrusFormatter

func GetServerLogrusFormatter() logrus.Formatter

GetServerLogrusFormatter return the server logrus formatter

func GetSignerFromPrivateKey

func GetSignerFromPrivateKey(s []byte) (saultssh.Signer, error)

GetSignerFromPrivateKey loads private key signer from string

func LoadPrivateKeySignerWithPasspharaseTrial

func LoadPrivateKeySignerWithPasspharaseTrial(privateKeyFile string) (signer saultssh.Signer, err error)

LoadPrivateKeySignerWithPasspharaseTrial load private key with passphrase

func LoadPublicKeyFromPrivateKeyFile

func LoadPublicKeyFromPrivateKeyFile(f string) (publicKey saultssh.PublicKey, err error)

LoadPublicKeyFromPrivateKeyFile loads public key from private key with passpharase

func MakeFirstLowerCase

func MakeFirstLowerCase(s string) string

MakeFirstLowerCase replace the first char to lower case

func MakeFirstUpperCase

func MakeFirstUpperCase(s string) string

MakeFirstUpperCase replace the first char to upper case

func MakeOutputString

func MakeOutputString(log *logrus.Logger, s string, level logrus.Level) string

MakeOutputString makes output string for sault client

func MakePascalCase

func MakePascalCase(s string) string

MakePascalCase make the underscore connected string, 'pascal_case' to 'PascalCase'

func MakeRandomString

func MakeRandomString() string

MakeRandomString makes random string, based on md5 and uuid

func MakeUUID

func MakeUUID() string

MakeUUID generates the uuid version5 string

func ParseBooleanString

func ParseBooleanString(s string) (v bool, err error)

ParseBooleanString parse the boolean string to bool

func ParseHostAccount

func ParseHostAccount(s string) (userName, hostName string, err error)

ParseHostAccount splits the `@` connected account and host name

func ParseMinusName

func ParseMinusName(s string) (name string, minus bool)

ParseMinusName parse the minus string to bool

func ParsePublicKey

func ParsePublicKey(b []byte) (saultssh.PublicKey, error)

ParsePublicKey parses string and makes PublicKey

func ParseSaultAccountName

func ParseSaultAccountName(s string) (account, hostID string, err error)

ParseSaultAccountName splits the `+` connected account and host name

func PrintInstance

func PrintInstance(data interface{})

PrintInstance prints instance

func PrintfInstance

func PrintfInstance(format string, data ...interface{})

PrintfInstance will format and print instance

func ReadPassword

func ReadPassword(maxTries int) (password string, err error)

ReadPassword read password from terminal

func SetupLog

func SetupLog(level logrus.Level, out io.Writer, formatter logrus.Formatter)

SetupLog will set up the logging

func SimpleTemplating

func SimpleTemplating(t string, values interface{}) (string, error)

SimpleTemplating help to apply string to template

func SplitHostPort

func SplitHostPort(s string, defaultPort uint64) (host string, port uint64, err error)

SplitHostPort is similar to net.SplitHostPort, but it can parse without ":port"

func SprintInstance

func SprintInstance(data interface{}) string

SprintInstance will make instance to string

func SprintfInstance

func SprintfInstance(format string, data ...interface{}) string

SprintfInstance will format instance

func StringFilter

func StringFilter(vs []string, f func(string) bool) []string

StringFilter was from https://gobyexample.com/collection-functions

func Templating

func Templating(t, name string, values interface{}) (string, error)

Templating help to apply string to template

Types

type CommandError

type CommandError struct {
	Type    CommandErrorType
	Message string
}

CommandError is err

func NewCommandError

func NewCommandError(errType CommandErrorType, message string) *CommandError

NewCommandError create CommandError

func (*CommandError) Error

func (e *CommandError) Error() string

type CommandErrorType

type CommandErrorType uint

CommandErrorType is err type

const (
	// CommandErrorNone is none error
	CommandErrorNone CommandErrorType = iota + 1
	// CommandErrorCommon is common error
	CommandErrorCommon
	// CommandErrorDialError is connection error
	CommandErrorDialError
	// CommandErrorAuthFailed is authentication error
	CommandErrorAuthFailed
	// CommandErrorInjectClientKey is injecting error
	CommandErrorInjectClientKey
	// CommandErrorPermissionDenied is permission error
	CommandErrorPermissionDenied
)

type CommandMsg

type CommandMsg struct {
	Name          string
	Data          []byte
	IsSaultClient bool
}

CommandMsg is command message

func NewCommandMsg

func NewCommandMsg(name string, data interface{}) (msg *CommandMsg, err error)

NewCommandMsg create CommandMsg

func (*CommandMsg) GetData

func (msg *CommandMsg) GetData(out interface{}) (err error)

GetData decode data to out

type DefaultLogrusFormatter

type DefaultLogrusFormatter struct {
	logrus.Formatter
}

DefaultLogrusFormatter is the default logrus formatter

func (DefaultLogrusFormatter) Format

func (d DefaultLogrusFormatter) Format(e *logrus.Entry) ([]byte, error)

Format is the method for logrus formatter

type FlagPrivateKey

type FlagPrivateKey struct {
	Path   string
	Signer saultssh.Signer
}

FlagPrivateKey is for public key

func (*FlagPrivateKey) Set

func (f *FlagPrivateKey) Set(file string) (err error)

Set is method for flagSet flag

func (*FlagPrivateKey) String

func (f *FlagPrivateKey) String() string

type FlagSaultServer

type FlagSaultServer struct {
	SaultServerName string
	Address         string
}

FlagSaultServer is for sault server address

func (*FlagSaultServer) Set

func (f *FlagSaultServer) Set(v string) error

Set is method for flagSet flag

func (*FlagSaultServer) String

func (f *FlagSaultServer) String() string

type HostAndUserNotLinked

type HostAndUserNotLinked struct {
	UserID string
	HostID string
}

HostAndUserNotLinked means host and user is not linked

func (*HostAndUserNotLinked) Error

func (e *HostAndUserNotLinked) Error() string

type HostDoesNotExistError

type HostDoesNotExistError struct {
	ID      string
	Message string
}

HostDoesNotExistError means host does not exist

func (*HostDoesNotExistError) Error

func (e *HostDoesNotExistError) Error() string

type HostExistError

type HostExistError struct {
	ID string
}

HostExistError means host exist

func (*HostExistError) Error

func (e *HostExistError) Error() string

type HostNothingToUpdate

type HostNothingToUpdate struct {
	ID string
}

HostNothingToUpdate means almost same with the target host

func (*HostNothingToUpdate) Error

func (e *HostNothingToUpdate) Error() string

type InvalidAccountNameError

type InvalidAccountNameError struct {
	Name string
}

InvalidAccountNameError means wrong accout name

func (*InvalidAccountNameError) Error

func (e *InvalidAccountNameError) Error() string

type InvalidHostAddressError

type InvalidHostAddressError struct {
	Address string
	Err     error
}

InvalidHostAddressError means wrong host address

func (*InvalidHostAddressError) Error

func (e *InvalidHostAddressError) Error() string

type InvalidHostIDError

type InvalidHostIDError struct {
	ID string
}

InvalidHostIDError means wrong host id

func (*InvalidHostIDError) Error

func (e *InvalidHostIDError) Error() string

type InvalidUserIDError

type InvalidUserIDError struct {
	ID string
}

InvalidUserIDError means wrong user id

func (*InvalidUserIDError) Error

func (e *InvalidUserIDError) Error() string

type LinkedAllError

type LinkedAllError struct {
}

LinkedAllError means failed to link

func (*LinkedAllError) Error

func (e *LinkedAllError) Error() string

type ResponseMsg

type ResponseMsg struct {
	Data interface{}
	Err  *ResponseMsgError
}

ResponseMsg is response message

func NewResponseMsg

func NewResponseMsg(result interface{}, errType CommandErrorType, e error) *ResponseMsg

NewResponseMsg create ResponseMsg

func (*ResponseMsg) ToJSON

func (r *ResponseMsg) ToJSON() ([]byte, error)

ToJSON produces json strings

type ResponseMsgError

type ResponseMsgError struct {
	ErrorType CommandErrorType
	Message   string
}

ResponseMsgError is response message error

func (*ResponseMsgError) Error

func (r *ResponseMsgError) Error() string

func (*ResponseMsgError) IsError

func (r *ResponseMsgError) IsError(errType CommandErrorType) bool

IsError checks error type

type SSHAgentNotRunning

type SSHAgentNotRunning struct {
	E error
}

SSHAgentNotRunning means ssh agent is not running

func (*SSHAgentNotRunning) Error

func (e *SSHAgentNotRunning) Error() string

func (*SSHAgentNotRunning) PrintWarning

func (e *SSHAgentNotRunning) PrintWarning()

PrintWarning prints warning message

type SSHClient

type SSHClient struct {
	Client *saultssh.Client
	// contains filtered or unexported fields
}

SSHClient is the wrapper of ssh.Cilent

func NewSSHClient

func NewSSHClient(account, address string) *SSHClient

NewSSHClient creates SSHClient

func (*SSHClient) AddAuthMethod

func (s *SSHClient) AddAuthMethod(auths ...saultssh.AuthMethod)

AddAuthMethod add AuthMethod

func (*SSHClient) Close

func (s *SSHClient) Close()

Close will close connection

func (*SSHClient) Connect

func (s *SSHClient) Connect() error

Connect will connect

func (*SSHClient) GetFile

func (s *SSHClient) GetFile(dest string) (content []byte, err error)

GetFile downloads file

func (*SSHClient) MakeDir

func (s *SSHClient) MakeDir(dest string, perm os.FileMode, recursive bool) error

MakeDir makes directory

func (*SSHClient) PutFile

func (s *SSHClient) PutFile(content string, dest string, perm os.FileMode) error

PutFile uploads file

func (*SSHClient) Remove

func (s *SSHClient) Remove(dest string) error

Remove removes file

func (*SSHClient) Run

func (s *SSHClient) Run(cmd string) (output []byte, err error)

Run runs command to the remote host

func (*SSHClient) SetTimeout

func (s *SSHClient) SetTimeout(t time.Duration)

SetTimeout set timeout

type TermSize

type TermSize struct {
	Row    uint16
	Col    uint16
	Xpixel uint16
	Ypixel uint16
}

TermSize contains the terminal dimension information

type UserDoesNotExistError

type UserDoesNotExistError struct {
	ID        string
	PublicKey saultssh.PublicKey
	Message   string
}

UserDoesNotExistError means user does not exists

func (*UserDoesNotExistError) Error

func (e *UserDoesNotExistError) Error() string

type UserExistsError

type UserExistsError struct {
	ID        string
	PublicKey []byte
}

UserExistsError means user exist

func (*UserExistsError) Error

func (e *UserExistsError) Error() string

type UserNothingToUpdate

type UserNothingToUpdate struct {
	ID string
}

UserNothingToUpdate means almost same with the target user

func (*UserNothingToUpdate) Error

func (e *UserNothingToUpdate) Error() string

Jump to

Keyboard shortcuts

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