Documentation ¶
Overview ¶
Copyright © 2020 Marvin
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2020 Marvin ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
const ( // DefaultExecuteTimeout default SSH command execution timeout, unit: seconds DefaultExecuteTimeout = 60 // DefaultConnectTimeout default SSH connection timeout, unit: seconds DefaultConnectTimeout = 10 )
Variables ¶
var ( ErrPropSSHCommand = errorx.RegisterPrintableProperty("ssh_command") ErrPropSSHStdout = errorx.RegisterPrintableProperty("ssh_stdout") ErrPropSSHStderr = errorx.RegisterPrintableProperty("ssh_stderr") ErrSSHExecuteFailed = errNSSSH.NewType("execute_failed") ErrSSHExecuteTimedout = errNSSSH.NewType("execute_timeout") )
Functions ¶
func FindSSHAuthorizedKeysFile ¶
FindSSHAuthorizedKeysFile Find the correct path to the SSH authorization key file
Types ¶
type EasySSHExecutor ¶
type EasySSHExecutor struct { Config *easyssh.MakeConfig Locale string // The locale to use when executing the command Sudo bool // Whether all commands run using this executor use sudo }
EasySSHExecutor implements EasySSH Executor as the SSH transport protocol layer
func (*EasySSHExecutor) Execute ¶
func (e *EasySSHExecutor) Execute(ctx context.Context, cmd string, sudo bool, execTimeout ...time.Duration) ([]byte, []byte, error)
Execute the run command over SSH, which does not invoke any specific shell by default
func (*EasySSHExecutor) Transfer ¶
func (e *EasySSHExecutor) Transfer(ctx context.Context, src, dst string, download bool, limit int) error
Transfer the copy file via SCP This function depends on `scp` (tools from OpenSSH or other SSH implementations) This function is based on easyssh.MakeConfig.Scp() but supports copying to remote files
type Executor ¶
type Executor interface { // Execute the run command and return stdout and stderr // If cmd times out and cannot exit, an error will be returned. The default timeout is 60 seconds. Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) (stdout []byte, stderr []byte, err error) // Transfer copy files from or to target Transfer(ctx context.Context, src, dst string, download bool, limit int) error }
Executor is the SSH executor interface, all tasks will be executed through the SSH executor
type Local ¶
type Local struct { Config *SSHConfig Sudo bool // all commands run with this executor will be using sudo Locale string // the locale used when executing the command }
Local execute the command at local host.
type SSHConfig ¶
type SSHConfig struct { Host string // SSH Host Port int // SSH Host Port User string // SSH Host Username Password string // SSH Host Username Password KeyFile string // SSH Private Key File Passphrase string // SSH Private Key Password ConnectTimeout time.Duration // TCP Connect timeout ExecuteTimeout time.Duration // Command execute timeout Proxy *SSHConfig // ssh proxy config }
SSHConfig is the configuration required to establish an SSH connection