srvconn

package
v0.0.0-...-b64c738 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: GPL-3.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolSSH    = "ssh"
	ProtocolTELNET = "telnet"
	ProtocolK8s    = "k8s"

	ProtocolMySQL      = "mysql"
	ProtocolMariadb    = "mariadb"
	ProtocolSQLServer  = "sqlserver"
	ProtocolRedis      = "redis"
	ProtocolMongoDB    = "mongodb"
	ProtocolPostgreSQL = "postgresql"
)
View Source
const (
	LinuxSuCommand = "su - %s; exit"
)
View Source
const (
	PostgreSQLPrompt = "Password for user %s:"
)
View Source
const (
	SFTPPathSeparator = "/"
)
View Source
const (
	SearchFolderName = "_Search"
)

Variables

View Source
var (
	ErrUnSupportedProtocol = errors.New("unsupported protocol")

	ErrKubectlClient = errors.New("not found Kubectl client")

	ErrMySQLClient     = errors.New("not found MySQL client")
	ErrSQLServerClient = errors.New("not found SQLServer client")

	ErrRedisClient      = errors.New("not found Redis client")
	ErrMongoDBClient    = errors.New("not found MongoDB client")
	ErrPostgreSQLClient = errors.New("not found PostgreSQL client")
)
View Source
var (
	ErrNotFoundCommand = errors.New("not found command")

	ErrNotFoundShell = errors.New("not found any shell")
)
View Source
var (
	ErrNoAvailable = errors.New("no available gateway")
	ErrGatewayDial = errors.New("gateway dial addr failed")
	ErrSSHClient   = errors.New("new ssh client failed")
)
View Source
var ErrorTimeout = errors.New("time out")
View Source
var (
	InValidToken = errors.New("invalid token")
)

Functions

func AddClientCache

func AddClientCache(key string, client *SSHClient)

func BuildMongoDBURI

func BuildMongoDBURI(opts ...MongoOpt) string

func ClearTempFileDelay

func ClearTempFileDelay(sleepTime time.Duration, filepath ...string)

func DoLogin

func DoLogin(opt *sqlOption, lcmd *localcommand.LocalCommand, dbType string) (*localcommand.LocalCommand, error)

func FindAvailableShell

func FindAvailableShell(opt *ContainerOptions) (shell string, err error)

func HasShellInContainer

func HasShellInContainer(opt *ContainerOptions, shell string) error

func IsSupportedProtocol

func IsSupportedProtocol(p string) error

func LoginToSu

func LoginToSu(sc *SSHConnection) error

func MakeReuseSSHClientKey

func MakeReuseSSHClientKey(userId, assetId, systemUserId,
	ip, username string) string

func MatchLoginPrefix

func MatchLoginPrefix(prefix string, dbType string, lcmd *localcommand.LocalCommand) (*localcommand.LocalCommand, error)

func NewSftpConn

func NewSftpConn(sess *gossh.Session) (*sftp.Client, error)

func StoreCAFileToLocal

func StoreCAFileToLocal(caCert string) (caFilepath string, err error)

Types

type AssetDir

type AssetDir struct {
	ID string

	ShowHidden bool
	// contains filtered or unexported fields
}

func NewAssetDir

func NewAssetDir(jmsService *service.JMService, user *model.User, logChan chan<- *model.FTPLog,
	opts ...FolderBuilderOption) AssetDir

func (*AssetDir) Create

func (ad *AssetDir) Create(path string) (*sftp.File, error)

func (*AssetDir) CreateFTPLog

func (ad *AssetDir) CreateFTPLog(su *model.SystemUser, operate, filename string, isSuccess bool)

func (*AssetDir) GetSFTPAndRealPath

func (ad *AssetDir) GetSFTPAndRealPath(su *model.SystemUser, path string) (conn *SftpConn, realPath string)

func (*AssetDir) GetSftpClient

func (ad *AssetDir) GetSftpClient(su *model.SystemUser) (conn *SftpConn, err error)

func (*AssetDir) IsDir

func (ad *AssetDir) IsDir() bool

func (*AssetDir) IsUniqueSu

func (ad *AssetDir) IsUniqueSu() (folderName string, ok bool)

func (*AssetDir) MkdirAll

func (ad *AssetDir) MkdirAll(path string) (err error)

func (*AssetDir) ModTime

func (ad *AssetDir) ModTime() time.Time

func (*AssetDir) Mode

func (ad *AssetDir) Mode() os.FileMode

func (*AssetDir) Name

func (ad *AssetDir) Name() string

func (*AssetDir) Open

func (ad *AssetDir) Open(path string) (*sftp.File, error)

func (*AssetDir) ReadDir

func (ad *AssetDir) ReadDir(path string) (res []os.FileInfo, err error)
func (ad *AssetDir) ReadLink(path string) (res string, err error)

func (*AssetDir) Remove

func (ad *AssetDir) Remove(path string) (err error)

func (*AssetDir) RemoveDirectory

func (ad *AssetDir) RemoveDirectory(path string) (err error)

func (*AssetDir) Rename

func (ad *AssetDir) Rename(oldNamePath, newNamePath string) (err error)

func (*AssetDir) Size

func (ad *AssetDir) Size() int64

func (*AssetDir) Stat

func (ad *AssetDir) Stat(path string) (res os.FileInfo, err error)
func (ad *AssetDir) Symlink(oldNamePath, newNamePath string) (err error)

func (*AssetDir) Sys

func (ad *AssetDir) Sys() interface{}

type ContainerConnection

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

func NewContainerConnection

func NewContainerConnection(opts ...ContainerOption) (*ContainerConnection, error)

func (*ContainerConnection) Close

func (c *ContainerConnection) Close() error

func (*ContainerConnection) KeepAlive

func (c *ContainerConnection) KeepAlive() error

func (*ContainerConnection) Read

func (c *ContainerConnection) Read(p []byte) (int, error)

func (*ContainerConnection) SetWinSize

func (c *ContainerConnection) SetWinSize(w, h int) error

func (*ContainerConnection) Write

func (c *ContainerConnection) Write(p []byte) (int, error)

type ContainerOption

type ContainerOption func(*ContainerOptions)

func ContainerHost

func ContainerHost(host string) ContainerOption

func ContainerName

func ContainerName(container string) ContainerOption

func ContainerNamespace

func ContainerNamespace(namespace string) ContainerOption

func ContainerPodName

func ContainerPodName(name string) ContainerOption

func ContainerPtyWin

func ContainerPtyWin(win Windows) ContainerOption

func ContainerSkipTls

func ContainerSkipTls(isSkipTls bool) ContainerOption

func ContainerToken

func ContainerToken(token string) ContainerOption

type ContainerOptions

type ContainerOptions struct {
	Host          string
	Token         string
	PodName       string
	Namespace     string
	ContainerName string
	IsSkipTls     bool
	// contains filtered or unexported fields
}

func (ContainerOptions) K8sCfg

func (o ContainerOptions) K8sCfg() *rest.Config

func (ContainerOptions) String

func (o ContainerOptions) String() string

type ExecuteResult

type ExecuteResult struct {
	Finished bool
	Err      error
}

type FakeFileInfo

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

func NewFakeFile

func NewFakeFile(name string, isDir bool) *FakeFileInfo

func NewFakeSymFile

func NewFakeSymFile(name string) *FakeFileInfo

func (*FakeFileInfo) IsDir

func (f *FakeFileInfo) IsDir() bool

func (*FakeFileInfo) ModTime

func (f *FakeFileInfo) ModTime() time.Time

func (*FakeFileInfo) Mode

func (f *FakeFileInfo) Mode() os.FileMode

func (*FakeFileInfo) Name

func (f *FakeFileInfo) Name() string

func (*FakeFileInfo) Size

func (f *FakeFileInfo) Size() int64

func (*FakeFileInfo) Sys

func (f *FakeFileInfo) Sys() interface{}

type FileInfoList

type FileInfoList []os.FileInfo

func (FileInfoList) Len

func (fl FileInfoList) Len() int

func (FileInfoList) Less

func (fl FileInfoList) Less(i, j int) bool

func (FileInfoList) Swap

func (fl FileInfoList) Swap(i, j int)

type FolderBuilderOption

type FolderBuilderOption func(info *folderOptions)

func WitRemoteAddr

func WitRemoteAddr(addr string) FolderBuilderOption

func WithAsset

func WithAsset(asset model.Asset) FolderBuilderOption

func WithDomain

func WithDomain(domain model.Domain) FolderBuilderOption

func WithFolderID

func WithFolderID(id string) FolderBuilderOption

func WithFolderName

func WithFolderName(name string) FolderBuilderOption

func WithSubFoldersLoadFunc

func WithSubFoldersLoadFunc(loadFunc SubFoldersLoadFunc) FolderBuilderOption

func WithSystemUsers

func WithSystemUsers(systemUsers []model.SystemUser) FolderBuilderOption

type K8sCon

type K8sCon struct {
	*localcommand.LocalCommand
	// contains filtered or unexported fields
}

func NewK8sConnection

func NewK8sConnection(ops ...K8sOption) (*K8sCon, error)

func (*K8sCon) KeepAlive

func (k *K8sCon) KeepAlive() error

type K8sOption

type K8sOption func(*k8sOptions)

func K8sClusterServer

func K8sClusterServer(clusterServer string) K8sOption

func K8sExtraEnvs

func K8sExtraEnvs(envs map[string]string) K8sOption

func K8sPtyWin

func K8sPtyWin(win Windows) K8sOption

func K8sSkipTls

func K8sSkipTls(isSkipTls bool) K8sOption

func K8sToken

func K8sToken(token string) K8sOption

func K8sUsername

func K8sUsername(username string) K8sOption

type MongoDBConn

type MongoDBConn struct {
	*localcommand.LocalCommand
	// contains filtered or unexported fields
}

func NewMongoDBConnection

func NewMongoDBConnection(ops ...SqlOption) (*MongoDBConn, error)

func (*MongoDBConn) Close

func (conn *MongoDBConn) Close() error

func (*MongoDBConn) KeepAlive

func (conn *MongoDBConn) KeepAlive() error

type MongoOpt

type MongoOpt func(*url.URL)

func MongoAuth

func MongoAuth(user, password string) MongoOpt

func MongoDBName

func MongoDBName(dbName string) MongoOpt

func MongoHost

func MongoHost(host string) MongoOpt

func MongoParams

func MongoParams(params ...map[string]string) MongoOpt

type MySQLConn

type MySQLConn struct {
	*localcommand.LocalCommand
	// contains filtered or unexported fields
}

func NewMySQLConnection

func NewMySQLConnection(ops ...SqlOption) (*MySQLConn, error)

func (*MySQLConn) Close

func (conn *MySQLConn) Close() error

func (*MySQLConn) KeepAlive

func (conn *MySQLConn) KeepAlive() error

type NodeDir

type NodeDir struct {
	ID string
	// contains filtered or unexported fields
}

func NewNodeDir

func NewNodeDir(builders ...FolderBuilderOption) NodeDir

func (*NodeDir) IsDir

func (nd *NodeDir) IsDir() bool

func (*NodeDir) List

func (nd *NodeDir) List() (res []os.FileInfo, err error)

func (*NodeDir) ModTime

func (nd *NodeDir) ModTime() time.Time

func (*NodeDir) Mode

func (nd *NodeDir) Mode() os.FileMode

func (*NodeDir) Name

func (nd *NodeDir) Name() string

func (*NodeDir) Size

func (nd *NodeDir) Size() int64

func (*NodeDir) Sys

func (nd *NodeDir) Sys() interface{}

type PostgreSQLConn

type PostgreSQLConn struct {
	*localcommand.LocalCommand
	// contains filtered or unexported fields
}

func NewPostgreSQLConnection

func NewPostgreSQLConnection(ops ...SqlOption) (*PostgreSQLConn, error)

func (*PostgreSQLConn) Close

func (conn *PostgreSQLConn) Close() error

func (*PostgreSQLConn) KeepAlive

func (conn *PostgreSQLConn) KeepAlive() error

type RedisConn

type RedisConn struct {
	*localcommand.LocalCommand
	// contains filtered or unexported fields
}

func NewRedisConnection

func NewRedisConnection(ops ...SqlOption) (*RedisConn, error)

func (*RedisConn) Close

func (conn *RedisConn) Close() error

func (*RedisConn) KeepAlive

func (conn *RedisConn) KeepAlive() error

type SQLServerConn

type SQLServerConn struct {
	*localcommand.LocalCommand
	// contains filtered or unexported fields
}

func NewSQLServerConnection

func NewSQLServerConnection(ops ...SqlOption) (*SQLServerConn, error)

func (*SQLServerConn) Close

func (conn *SQLServerConn) Close() error

func (*SQLServerConn) KeepAlive

func (conn *SQLServerConn) KeepAlive() error

type SSHClient

type SSHClient struct {
	*gossh.Client
	Cfg         *SSHClientOptions
	ProxyClient *SSHClient

	sync.Mutex
	// contains filtered or unexported fields
}

func GetClientFromCache

func GetClientFromCache(key string) (client *SSHClient, ok bool)

func NewSSHClient

func NewSSHClient(opts ...SSHClientOption) (*SSHClient, error)

func NewSSHClientWithCfg

func NewSSHClientWithCfg(cfg *SSHClientOptions) (*SSHClient, error)

func (*SSHClient) AcquireSession

func (s *SSHClient) AcquireSession() (*gossh.Session, error)

func (*SSHClient) Close

func (s *SSHClient) Close() error

func (*SSHClient) RefCount

func (s *SSHClient) RefCount() int32

func (*SSHClient) ReleaseSession

func (s *SSHClient) ReleaseSession(sess *gossh.Session)

func (*SSHClient) String

func (s *SSHClient) String() string

type SSHClientOption

type SSHClientOption func(conf *SSHClientOptions)

func SSHClientHost

func SSHClientHost(host string) SSHClientOption

func SSHClientKeyboardAuth

func SSHClientKeyboardAuth(keyboardAuth gossh.KeyboardInteractiveChallenge) SSHClientOption

func SSHClientPassphrase

func SSHClientPassphrase(passphrase string) SSHClientOption

func SSHClientPassword

func SSHClientPassword(password string) SSHClientOption

func SSHClientPort

func SSHClientPort(port int) SSHClientOption

func SSHClientPrivateAuth

func SSHClientPrivateAuth(privateAuth gossh.Signer) SSHClientOption

func SSHClientPrivateKey

func SSHClientPrivateKey(privateKey string) SSHClientOption

func SSHClientProxyClient

func SSHClientProxyClient(proxyArgs ...SSHClientOptions) SSHClientOption

func SSHClientTimeout

func SSHClientTimeout(timeout int) SSHClientOption

func SSHClientUsername

func SSHClientUsername(username string) SSHClientOption

type SSHClientOptions

type SSHClientOptions struct {
	Host       string
	Port       string
	Username   string
	Password   string
	PrivateKey string
	Passphrase string
	Timeout    int

	PrivateAuth gossh.Signer
	// contains filtered or unexported fields
}

func (*SSHClientOptions) AuthMethods

func (cfg *SSHClientOptions) AuthMethods() []gossh.AuthMethod

type SSHConnection

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

func NewSSHConnection

func NewSSHConnection(sess *gossh.Session, opts ...SSHOption) (*SSHConnection, error)

func (*SSHConnection) Close

func (sc *SSHConnection) Close() (err error)

func (*SSHConnection) KeepAlive

func (sc *SSHConnection) KeepAlive() error

func (*SSHConnection) Read

func (sc *SSHConnection) Read(p []byte) (n int, err error)

func (*SSHConnection) SetWinSize

func (sc *SSHConnection) SetWinSize(w, h int) error

func (*SSHConnection) Write

func (sc *SSHConnection) Write(p []byte) (n int, err error)

type SSHManager

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

func (*SSHManager) AddClientCache

func (s *SSHManager) AddClientCache(key string, client *SSHClient)

type SSHOption

type SSHOption func(*SSHOptions)

func SSHCharset

func SSHCharset(charset string) SSHOption

func SSHLoginToSudo

func SSHLoginToSudo(ok bool) SSHOption

func SSHPtyWin

func SSHPtyWin(win Windows) SSHOption

func SSHSudoCommand

func SSHSudoCommand(cmd string) SSHOption

func SSHSudoPassword

func SSHSudoPassword(password string) SSHOption

func SSHSudoUsername

func SSHSudoUsername(username string) SSHOption

func SSHTerm

func SSHTerm(termType string) SSHOption

type SSHOptions

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

type SearchResultDir

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

func (*SearchResultDir) IsDir

func (sd *SearchResultDir) IsDir() bool

func (*SearchResultDir) List

func (sd *SearchResultDir) List() (res []os.FileInfo, err error)

func (*SearchResultDir) ModTime

func (sd *SearchResultDir) ModTime() time.Time

func (*SearchResultDir) Mode

func (sd *SearchResultDir) Mode() os.FileMode

func (*SearchResultDir) Name

func (sd *SearchResultDir) Name() string

func (*SearchResultDir) SetSubDirs

func (sd *SearchResultDir) SetSubDirs(subDirs map[string]os.FileInfo)

func (*SearchResultDir) Size

func (sd *SearchResultDir) Size() int64

func (*SearchResultDir) Sys

func (sd *SearchResultDir) Sys() interface{}

type ServerConnection

type ServerConnection interface {
	io.ReadWriteCloser
	SetWinSize(width, height int) error
	KeepAlive() error
}

type SftpConn

type SftpConn struct {
	HomeDirPath string
	// contains filtered or unexported fields
}

func (*SftpConn) Close

func (s *SftpConn) Close()

type SqlOption

type SqlOption func(*sqlOption)

func MySQLDisableAutoReHash

func MySQLDisableAutoReHash() SqlOption

func SqlAllowInvalidCert

func SqlAllowInvalidCert(allowInvalidCert bool) SqlOption

func SqlCaCert

func SqlCaCert(caCert string) SqlOption

func SqlCertKey

func SqlCertKey(certKey string) SqlOption

func SqlClientCert

func SqlClientCert(clientCert string) SqlOption

func SqlDBName

func SqlDBName(dbName string) SqlOption

func SqlHost

func SqlHost(host string) SqlOption

func SqlPassword

func SqlPassword(password string) SqlOption

func SqlPort

func SqlPort(port int) SqlOption

func SqlPtyWin

func SqlPtyWin(win Windows) SqlOption

func SqlUseSSL

func SqlUseSSL(useSSL bool) SqlOption

func SqlUsername

func SqlUsername(username string) SqlOption

type SubFoldersLoadFunc

type SubFoldersLoadFunc func() map[string]os.FileInfo

type TelnetConfig

type TelnetConfig struct {
	Host     string
	Port     string
	Username string
	Password string
	Term     string
	Charset  string

	Timeout time.Duration

	CustomSuccessPattern *regexp.Regexp
	// contains filtered or unexported fields
}

type TelnetConnection

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

func NewTelnetConnection

func NewTelnetConnection(opts ...TelnetOption) (*TelnetConnection, error)

func (*TelnetConnection) Close

func (tc *TelnetConnection) Close() (err error)

func (*TelnetConnection) KeepAlive

func (tc *TelnetConnection) KeepAlive() error

func (*TelnetConnection) Protocol

func (tc *TelnetConnection) Protocol() string

func (*TelnetConnection) Read

func (tc *TelnetConnection) Read(p []byte) (n int, err error)

func (*TelnetConnection) SetWinSize

func (tc *TelnetConnection) SetWinSize(w, h int) error

func (*TelnetConnection) Write

func (tc *TelnetConnection) Write(p []byte) (n int, err error)

type TelnetOption

type TelnetOption func(*TelnetConfig)

func TelnetCharset

func TelnetCharset(charset string) TelnetOption

func TelnetCustomSuccessPattern

func TelnetCustomSuccessPattern(successPattern *regexp.Regexp) TelnetOption

func TelnetHost

func TelnetHost(host string) TelnetOption

func TelnetPort

func TelnetPort(port int) TelnetOption

func TelnetProxyOptions

func TelnetProxyOptions(proxyOpts []SSHClientOptions) TelnetOption

func TelnetPtyWin

func TelnetPtyWin(win Windows) TelnetOption

func TelnetUPassword

func TelnetUPassword(password string) TelnetOption

func TelnetUTimeout

func TelnetUTimeout(timeout int) TelnetOption

func TelnetUsername

func TelnetUsername(username string) TelnetOption

type UserSSHClient

type UserSSHClient struct {
	ID string // userID_assetID_systemUserID_systemUsername
	// contains filtered or unexported fields
}

func (*UserSSHClient) AddClient

func (u *UserSSHClient) AddClient(client *SSHClient)

func (*UserSSHClient) Count

func (u *UserSSHClient) Count() int

func (*UserSSHClient) GetClient

func (u *UserSSHClient) GetClient() *SSHClient

type UserSftpConn

type UserSftpConn struct {
	User *model.User
	Addr string
	Dirs map[string]os.FileInfo
	// contains filtered or unexported fields
}

func NewUserSftpConn

func NewUserSftpConn(jmsService *service.JMService, user *model.User, addr string,
	assets []model.Asset, systemUsers []model.SystemUser) *UserSftpConn

func (*UserSftpConn) Close

func (u *UserSftpConn) Close()

func (*UserSftpConn) Create

func (u *UserSftpConn) Create(path string) (*sftp.File, error)

func (*UserSftpConn) IsDir

func (u *UserSftpConn) IsDir() bool

func (*UserSftpConn) List

func (u *UserSftpConn) List() (res []os.FileInfo, err error)

func (*UserSftpConn) LoadNodeSubFoldersByKey

func (u *UserSftpConn) LoadNodeSubFoldersByKey(nodeKey string) SubFoldersLoadFunc

func (*UserSftpConn) MkdirAll

func (u *UserSftpConn) MkdirAll(path string) (err error)

func (*UserSftpConn) ModTime

func (u *UserSftpConn) ModTime() time.Time

func (*UserSftpConn) Mode

func (u *UserSftpConn) Mode() os.FileMode

func (*UserSftpConn) Name

func (u *UserSftpConn) Name() string

func (*UserSftpConn) Open

func (u *UserSftpConn) Open(path string) (*sftp.File, error)

func (*UserSftpConn) ParsePath

func (u *UserSftpConn) ParsePath(path string) (fi os.FileInfo, restPath string)

func (*UserSftpConn) ReadDir

func (u *UserSftpConn) ReadDir(path string) (res []os.FileInfo, err error)
func (u *UserSftpConn) ReadLink(path string) (name string, err error)

func (*UserSftpConn) Remove

func (u *UserSftpConn) Remove(path string) (err error)

func (*UserSftpConn) RemoveDirectory

func (u *UserSftpConn) RemoveDirectory(path string) (err error)

func (*UserSftpConn) Rename

func (u *UserSftpConn) Rename(oldNamePath, newNamePath string) (err error)

func (*UserSftpConn) Search

func (u *UserSftpConn) Search(key string) (res []os.FileInfo, err error)

func (*UserSftpConn) Size

func (u *UserSftpConn) Size() int64

func (*UserSftpConn) Stat

func (u *UserSftpConn) Stat(path string) (res os.FileInfo, err error)
func (u *UserSftpConn) Symlink(oldNamePath, newNamePath string) (err error)

func (*UserSftpConn) Sys

func (u *UserSftpConn) Sys() interface{}

type Windows

type Windows struct {
	Width  int
	Height int
}

Jump to

Keyboard shortcuts

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