core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSSHPort = 22
	DefaultGroup   = "default"
	ConfigEnvKey   = "SSHC_CONFIG"
)

Variables

This section is empty.

Functions

func AppendRunLog

func AppendRunLog(host Host, rec RunLogRecord) error

func BuildRemoteCommand

func BuildRemoteCommand(command string, env map[string]string) (string, error)

func BuildRemoteCommandWithCWD

func BuildRemoteCommandWithCWD(command string, env map[string]string, cwd string) (string, error)

func ErrorString

func ErrorString(err error) string

func ExecuteRemote

func ExecuteRemote(host Host, command string, opts RunOptions) ([]byte, error)

func HostGroupName

func HostGroupName(host Host) string

func HostLogName

func HostLogName(host Host) string

func JoinRemotePath

func JoinRemotePath(base, elem string) string

func LoadRunEnv

func LoadRunEnv(file string, inline []string) (map[string]string, error)

func LocalDirPath

func LocalDirPath(remotePath, localPath string) string

func LocalFilePath

func LocalFilePath(remotePath, localPath string) string

func LoginRemote

func LoginRemote(host Host) error

func LoginRemoteWithOptions

func LoginRemoteWithOptions(host Host, opts LoginOptions) error

func NewRemoteScriptPath

func NewRemoteScriptPath(value time.Time) string

func NewRemoteScriptPathInDir

func NewRemoteScriptPathInDir(value time.Time, dir string) string

func Now

func Now() time.Time

func ParseTimeout

func ParseTimeout(value string) (time.Duration, error)

func ReadRunLogs

func ReadRunLogs(target, match string, tail int) ([]string, error)

func RemoteFilePath

func RemoteFilePath(localPath, remotePath string) string

func RemoteRelPath

func RemoteRelPath(root, current string) string

func RunStatus

func RunStatus(err error) string

func SaveStore

func SaveStore(store *Store) error

func SetNowForTest

func SetNowForTest(fn func() time.Time) func()

func SetUserHomeDirForTest

func SetUserHomeDirForTest(fn func() (string, error)) func()

func SinceMS

func SinceMS(start time.Time) int64

func StorePath

func StorePath() (string, error)

func ValidateSudoUser

func ValidateSudoUser(user string) error

Types

type Host

type Host struct {
	Name     string `json:"name"`
	IP       string `json:"ip"`
	User     string `json:"user"`
	Password string `json:"password"`
	KeyPath  string `json:"key_path,omitempty"`
	Remark   string `json:"remark,omitempty"`
	Group    string `json:"group,omitempty"`
	Port     int    `json:"port"`
}

func LoadSSHConfigHosts

func LoadSSHConfigHosts() ([]Host, error)

func ParseSSHConfig

func ParseSSHConfig(reader io.Reader) ([]Host, error)

type LoginOptions

type LoginOptions struct {
	Stdin  *os.File
	Stdout io.Writer
	Stderr io.Writer
	Term   string
}

type RunLogRecord

type RunLogRecord struct {
	Target           string
	Command          string
	Status           string
	StartedAt        time.Time
	DurationMS       int64
	Output           string
	Error            string
	CWD              string
	Script           string
	RemoteScript     string
	KeepRemoteScript bool
}

type RunOptions

type RunOptions struct {
	Timeout          time.Duration
	KillAfter        time.Duration
	Env              map[string]string
	CWD              string
	Sudo             bool
	SudoUser         string
	ScriptPath       string
	RemoteScriptDir  string
	RemoteScriptPath string
	KeepRemoteScript bool
}

type Store

type Store struct {
	Hosts []Host `json:"hosts"`
}

func LoadStore

func LoadStore() (*Store, error)

func LoadStoreWithSSHConfig

func LoadStoreWithSSHConfig() (*Store, error)

func (Store) Find

func (s Store) Find(target string) (Host, bool)

func (Store) MatchHosts

func (s Store) MatchHosts(target string) []Host

func (Store) ResolveHost

func (s Store) ResolveHost(target string) (Host, bool, error)

func (*Store) Upsert

func (s *Store) Upsert(host Host) error

type TransferJob

type TransferJob struct {
	LocalPath  string
	RemotePath string
	RemoteDir  bool
}

type TransferOptions

type TransferOptions struct {
	SHA256    bool
	RemoveDir bool
}

type TransferResult

type TransferResult struct {
	Bytes        int64
	Files        int
	Directories  int
	Elapsed      time.Duration
	LocalSHA256  string
	RemoteSHA256 string
	SHA256OK     bool
}

func FetchRemote

func FetchRemote(host Host, remotePath, localPath string, opts TransferOptions) (result TransferResult, err error)

func UploadRemote

func UploadRemote(host Host, localPath, remotePath string, opts TransferOptions) (result TransferResult, err error)

func UploadRemoteBatch

func UploadRemoteBatch(host Host, jobs []TransferJob, opts TransferOptions) (result TransferResult, err error)

Jump to

Keyboard shortcuts

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