Documentation
¶
Index ¶
- Constants
- func AppendRunLog(host Host, rec RunLogRecord) error
- func ApplyHostImport(config *Config, plan HostImportPlan) error
- func AuthLabel(host Host) string
- func BackupConfigFile(now time.Time) (string, error)
- func BuildRemoteCommand(command string, env map[string]string) (string, error)
- func BuildRemoteCommandWithCWD(command string, env map[string]string, cwd string) (string, error)
- func DecryptPassword(value string) (string, error)
- func EncryptConfigExport(config Config, key string, now time.Time) ([]byte, error)
- func EncryptPassword(password string) (string, error)
- func ErrorString(err error) string
- func ExecuteRemote(host Host, command string, opts RunOptions) ([]byte, error)
- func GenerateExportKey() (string, error)
- func HasDoctorErrors(issues []DoctorIssue) bool
- func HostGroupName(host Host) string
- func HostLogName(host Host) string
- func JoinRemotePath(base, elem string) string
- func LegacyStorePath() (string, error)
- func LoadRunEnv(file string, inline []string) (map[string]string, error)
- func LocalDirPath(remotePath, localPath string) string
- func LocalFilePath(remotePath, localPath string) string
- func LoginRemote(host Host) error
- func LoginRemoteWithOptions(host Host, opts LoginOptions) error
- func MergeImportedConfig(current, imported Config, strategy ImportStrategy) (Config, ImportResult, error)
- func NewRemoteScriptPath(value time.Time) string
- func NewRemoteScriptPathInDir(value time.Time, dir string) string
- func NewRunTaskID(startedAt time.Time, host Host, rec RunLogRecord) string
- func Now() time.Time
- func ParseHostImport(reader io.Reader, format HostImportFormat, defaults HostImportDefaults) ([]Host, []HostImportError)
- func ParseHostImportCSV(reader io.Reader, defaults HostImportDefaults) ([]Host, []HostImportError)
- func ParseHostImportIPs(reader io.Reader, defaults HostImportDefaults) ([]Host, []HostImportError)
- func ParseHostImportPlain(reader io.Reader, defaults HostImportDefaults) ([]Host, []HostImportError)
- func ParseLogLineRange(spec string) (start int, end int, ok bool, err error)
- func ParseTimeout(value string) (time.Duration, error)
- func PasswordKeyPath() (string, error)
- func ReadConfigFile() (string, []byte, error)
- func ReadHostsFile(path string) ([]string, error)
- func ReadRunLogOutputByID(target, taskID string) ([]byte, error)
- func ReadRunLogs(target, match string, tail int) ([]string, error)
- func ReadRunLogsSelected(target, match string, tail int, rangeSpec string) ([]string, error)
- func RemoteFilePath(localPath, remotePath string) string
- func RemoteRelPath(root, current string) string
- func RunOutputPath(taskID string, startedAt time.Time) (string, string, error)
- func RunStatus(err error) string
- func SaveConfig(config *Config) error
- func SaveStore(store *Store) error
- func SelectLogLines(lines []string, rangeSpec string, tail int) ([]string, error)
- func SetNowForTest(fn func() time.Time) func()
- func SetUserHomeDirForTest(fn func() (string, error)) func()
- func SinceMS(start time.Time) int64
- func StorePath() (string, error)
- func ValidateSudoUser(user string) error
- type AuthProfile
- type BatchHostSource
- type Config
- func (c Config) EffectiveHost(host Host, overrides HostOverrides) (EffectiveHost, bool, error)
- func (c Config) FindAuthProfile(name string) (AuthProfile, bool)
- func (c Config) ResolveConnection(host Host) (ResolvedConnection, error)
- func (c Config) ResolveEffectiveHost(target string, overrides HostOverrides) (EffectiveHost, bool, error)
- type ConfigExportFile
- type ConfigExportPayload
- type Defaults
- type DoctorIssue
- type EffectiveHost
- type Host
- type HostImportAction
- type HostImportChange
- type HostImportConflict
- type HostImportDefaults
- type HostImportError
- type HostImportFormat
- type HostImportOptions
- type HostImportPlan
- type HostOverrides
- type ImportResult
- type ImportStrategy
- type LoginOptions
- type RemoteClient
- type ResolveConnectionOptions
- type ResolvedConnection
- type RunLogRecord
- type RunOptions
- type Store
- type TransferJob
- type TransferOptions
- type TransferResult
- func FetchRemote(host Host, remotePath, localPath string, opts TransferOptions) (result TransferResult, err error)
- func UploadRemote(host Host, localPath, remotePath string, opts TransferOptions) (result TransferResult, err error)
- func UploadRemoteBatch(host Host, jobs []TransferJob, opts TransferOptions) (result TransferResult, err error)
Constants ¶
View Source
const ( DoctorOK = "ok" DoctorWarn = "warn" DoctorError = "error" )
View Source
const ( ConfigExportVersion = 1 ConfigExportApp = "sshc" )
View Source
const ( HostKeyCheckKnownHosts = "known_hosts" HostKeyCheckInsecure = "insecure" DefaultConnectTimeout = "20s" DefaultRemoteScriptDir = "/tmp" DefaultKnownHostsPath = "~/.ssh/known_hosts" )
View Source
const ( DefaultSSHPort = 22 DefaultGroup = "default" ConfigVersion = 1 ConfigEnvKey = "SSHC_CONFIG" ConfigFileName = "sshc.config.json" LegacyConfigFileName = "hosts.json" )
View Source
const MaskedSecret = "***"
Variables ¶
This section is empty.
Functions ¶
func AppendRunLog ¶
func AppendRunLog(host Host, rec RunLogRecord) error
func ApplyHostImport ¶ added in v0.7.0
func ApplyHostImport(config *Config, plan HostImportPlan) error
func BuildRemoteCommand ¶
func DecryptPassword ¶ added in v0.5.0
func EncryptConfigExport ¶ added in v0.7.0
func EncryptPassword ¶ added in v0.5.0
func ErrorString ¶
func ExecuteRemote ¶
func ExecuteRemote(host Host, command string, opts RunOptions) ([]byte, error)
func GenerateExportKey ¶ added in v0.7.0
func HasDoctorErrors ¶ added in v0.6.0
func HasDoctorErrors(issues []DoctorIssue) bool
func HostGroupName ¶
func HostLogName ¶
func JoinRemotePath ¶
func LegacyStorePath ¶ added in v0.5.0
func LocalDirPath ¶
func LocalFilePath ¶
func LoginRemote ¶
func LoginRemoteWithOptions ¶
func LoginRemoteWithOptions(host Host, opts LoginOptions) error
func MergeImportedConfig ¶ added in v0.7.0
func MergeImportedConfig(current, imported Config, strategy ImportStrategy) (Config, ImportResult, error)
func NewRemoteScriptPath ¶
func NewRunTaskID ¶ added in v0.6.0
func NewRunTaskID(startedAt time.Time, host Host, rec RunLogRecord) string
func ParseHostImport ¶ added in v0.7.0
func ParseHostImport(reader io.Reader, format HostImportFormat, defaults HostImportDefaults) ([]Host, []HostImportError)
func ParseHostImportCSV ¶ added in v0.7.0
func ParseHostImportCSV(reader io.Reader, defaults HostImportDefaults) ([]Host, []HostImportError)
func ParseHostImportIPs ¶ added in v0.7.0
func ParseHostImportIPs(reader io.Reader, defaults HostImportDefaults) ([]Host, []HostImportError)
func ParseHostImportPlain ¶ added in v0.7.0
func ParseHostImportPlain(reader io.Reader, defaults HostImportDefaults) ([]Host, []HostImportError)
func ParseLogLineRange ¶ added in v0.6.0
func PasswordKeyPath ¶ added in v0.5.0
func ReadConfigFile ¶ added in v0.6.0
func ReadHostsFile ¶ added in v0.6.0
func ReadRunLogOutputByID ¶ added in v0.6.0
func ReadRunLogsSelected ¶ added in v0.6.0
func RemoteFilePath ¶
func RemoteRelPath ¶
func RunOutputPath ¶ added in v0.6.0
func SaveConfig ¶ added in v0.6.0
func SelectLogLines ¶ added in v0.6.0
func SetNowForTest ¶
func SetUserHomeDirForTest ¶
func ValidateSudoUser ¶
Types ¶
type AuthProfile ¶ added in v0.6.0
type AuthProfile struct {
Name string `json:"name"`
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
PasswordEnc string `json:"password_enc,omitempty"`
KeyPath string `json:"key_path,omitempty"`
Remark string `json:"remark,omitempty"`
}
func MaskAuthProfile ¶ added in v0.6.0
func MaskAuthProfile(profile AuthProfile) AuthProfile
type BatchHostSource ¶ added in v0.6.0
type Config ¶ added in v0.6.0
type Config struct {
Version int `json:"version"`
LogsPath string `json:"logs_path,omitempty"`
Defaults Defaults `json:"defaults,omitempty"`
AuthProfiles []AuthProfile `json:"auth_profiles"`
Hosts []Host `json:"hosts"`
}
func DecryptConfigExport ¶ added in v0.7.0
func LoadConfig ¶ added in v0.6.0
func LoadConfigWithSSHConfig ¶ added in v0.6.0
func MaskConfig ¶ added in v0.6.0
func (Config) EffectiveHost ¶ added in v0.6.0
func (c Config) EffectiveHost(host Host, overrides HostOverrides) (EffectiveHost, bool, error)
func (Config) FindAuthProfile ¶ added in v0.6.0
func (c Config) FindAuthProfile(name string) (AuthProfile, bool)
func (Config) ResolveConnection ¶ added in v0.6.0
func (c Config) ResolveConnection(host Host) (ResolvedConnection, error)
func (Config) ResolveEffectiveHost ¶ added in v0.6.0
func (c Config) ResolveEffectiveHost(target string, overrides HostOverrides) (EffectiveHost, bool, error)
type ConfigExportFile ¶ added in v0.7.0
type ConfigExportPayload ¶ added in v0.7.0
type Defaults ¶ added in v0.6.0
type Defaults struct {
User string `json:"user,omitempty"`
Port int `json:"port,omitempty"`
ConnectTimeout string `json:"connect_timeout,omitempty"`
RunTimeout string `json:"run_timeout,omitempty"`
RemoteScriptDir string `json:"remote_script_dir,omitempty"`
HostKeyCheck string `json:"host_key_check,omitempty"`
KnownHostsPath string `json:"known_hosts_path,omitempty"`
}
type DoctorIssue ¶ added in v0.6.0
type DoctorIssue struct {
Level string `json:"level"`
Item string `json:"item"`
Message string `json:"message"`
}
func CheckConfig ¶ added in v0.6.0
func CheckConfig(config Config) []DoctorIssue
type EffectiveHost ¶ added in v0.6.0
type EffectiveHost struct {
Host
ConnectTimeout string
RunTimeout string
RemoteScriptDir string
HostKeyCheck string
KnownHostsPath string
}
func (EffectiveHost) ToHost ¶ added in v0.6.0
func (h EffectiveHost) ToHost() Host
type Host ¶
type Host struct {
Name string `json:"name"`
IP string `json:"ip"`
AuthRef string `json:"auth_ref,omitempty"`
User string `json:"user"`
Password string `json:"password,omitempty"`
PasswordEnc string `json:"password_enc,omitempty"`
KeyPath string `json:"key_path,omitempty"`
Remark string `json:"remark,omitempty"`
Group string `json:"group,omitempty"`
Port int `json:"port,omitempty"`
Jump string `json:"jump,omitempty"`
ConnectTimeout string `json:"connect_timeout,omitempty"`
RunTimeout string `json:"run_timeout,omitempty"`
RemoteScriptDir string `json:"remote_script_dir,omitempty"`
HostKeyCheck string `json:"host_key_check,omitempty"`
KnownHostsPath string `json:"known_hosts_path,omitempty"`
}
func LoadSSHConfigHosts ¶
func ResolveBatchHosts ¶ added in v0.6.0
func ResolveBatchHosts(source BatchHostSource) ([]Host, error)
func ResolveHostWithSSHConfig ¶ added in v0.6.0
func ResolveHostWithSSHConfig(target string, overrides HostOverrides) (Host, bool, error)
type HostImportAction ¶ added in v0.7.0
type HostImportAction string
const ( HostImportActionAdd HostImportAction = "add" HostImportActionUpdate HostImportAction = "update" HostImportActionSkip HostImportAction = "skip" )
type HostImportChange ¶ added in v0.7.0
type HostImportChange struct {
Action HostImportAction
Host Host
ExistingIndex int
Reason string
}
type HostImportConflict ¶ added in v0.7.0
type HostImportDefaults ¶ added in v0.7.0
type HostImportError ¶ added in v0.7.0
func (HostImportError) Error ¶ added in v0.7.0
func (e HostImportError) Error() string
type HostImportFormat ¶ added in v0.7.0
type HostImportFormat string
const ( HostImportIPs HostImportFormat = "ips" HostImportPlain HostImportFormat = "plain" HostImportCSV HostImportFormat = "csv" )
type HostImportOptions ¶ added in v0.7.0
type HostImportOptions struct {
Format HostImportFormat
Defaults HostImportDefaults
Overwrite bool
SkipExisting bool
}
type HostImportPlan ¶ added in v0.7.0
type HostImportPlan struct {
Hosts []Host
Changes []HostImportChange
Added int
Updated int
Skipped int
Conflicts []HostImportConflict
Invalid []HostImportError
}
func PlanHostImport ¶ added in v0.7.0
func PlanHostImport(config Config, hosts []Host, opts HostImportOptions) (HostImportPlan, error)
type HostOverrides ¶ added in v0.6.0
type ImportResult ¶ added in v0.7.0
type ImportStrategy ¶ added in v0.7.0
type ImportStrategy string
const ( ImportMerge ImportStrategy = "merge" ImportOverwrite ImportStrategy = "overwrite" ImportReplace ImportStrategy = "replace" )
type LoginOptions ¶
type RemoteClient ¶ added in v0.6.0
type ResolveConnectionOptions ¶ added in v0.6.0
type ResolveConnectionOptions struct {
Jump string
}
type ResolvedConnection ¶ added in v0.6.0
func ResolveConnectionForHost ¶ added in v0.6.0
func ResolveConnectionForHost(host Host) (ResolvedConnection, error)
func ResolveConnectionWithSSHConfig ¶ added in v0.6.0
func ResolveConnectionWithSSHConfig(target string, opts ResolveConnectionOptions) (ResolvedConnection, bool, error)
type RunLogRecord ¶
type RunLogRecord struct {
Target string
TaskID string
Command string
Status string
StartedAt time.Time
DurationMS int64
Output string
OutputFile string
OutputBytes int64
OutputSHA256 string
OutputInline bool
OutputPreview string
Error string
CWD string
Script string
RemoteScript string
KeepRemoteScript bool
}
type RunOptions ¶
type Store ¶
func LoadConfigSettings ¶ added in v0.5.0
func LoadStoreWithSSHConfig ¶
func (Store) MatchHosts ¶
type TransferJob ¶
type TransferOptions ¶
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)
Click to show internal directories.
Click to hide internal directories.