forked from jenkinsci/ssh-agents-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.java
More file actions
134 lines (117 loc) · 3.9 KB
/
Connection.java
File metadata and controls
134 lines (117 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright The Original Author or Authors
* SPDX-License-Identifier: MIT
*/
package io.jenkins.plugins.sshbuildagents.ssh;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.sshd.client.session.ClientSession;
/**
* Interface to manage an SSH connection.
*
*/
public interface Connection extends AutoCloseable {
/**
* Execute a command and return the exit code returned when it finish.
*
* @param command Command to execute.
* @return The exit code of the command (if the command ran).
* @throws IOException in case of an error launching the command.
*/
int execCommand(String command) throws IOException;
/**
* Create a {@link ShellChannel} to execute non-interactive commands.
*
* @return Return a {@link ShellChannel}
* @throws IOException
*/
ShellChannel shellChannel() throws IOException;
/**
* @return Return the host configured to connect by SSH.
*/
String getHostname();
/**
* @return Return the port configured to connect by SSH.
*/
int getPort();
/**
* Copy a file to the host by SCP. It does not create folders, so the folders of the path must
* exist prior to calling this.
* FIXME The remote file should be relative to the working directory.
* FIXME use SHA instead of MD5 to check the content of the file, it is no longer in the JDK.
* @param remoteFile Full path to the remote file.
* @param data Array of bytes with the data to write.
* @param overwrite @{code true} to overwrite the file if it already exists. If @{false} and the file exists an @{code IOException} will be thrown.
* @param checkSameContent if true will calculate and compare the checksum of the remote file and data and if identical will skip writing the file.
* @throws IOException
*/
void copyFile(String remoteFile, byte[] data, boolean overwrite, boolean checkSameContent) throws IOException;
/**
* Set the TCP_NODELAY flag on connections.
*
* @param tcpNoDelay True to set TCP_NODELAY.
*/
void setTCPNoDelay(boolean tcpNoDelay);
/**
* Establishes an SSH connection with the configuration set in the class.
*
* @return Return a {@link ClientSession} to interact with the SSH connection.
* @throws IOException
*/
ClientSession connect() throws IOException;
/**
* Set Server host verifier.
*
* @param verifier The Server host verifier to use.
*/
void setServerHostKeyVerifier(ServerHostKeyVerifier verifier);
/**
* Set the connection timeout.
*
* @param timeout Timeout in milliseconds.
*/
void setTimeout(long timeout);
/**
* Set the credential to use to authenticate in the SSH service.
*
* @param credentials Credentials used to authenticate.
*/
void setCredentials(StandardUsernameCredentials credentials);
/**
* Set the time to wait between retries.
*
* @param time Time to wait in seconds.
*/
void setRetryWaitTime(int time);
/**
* Set the number of times we will retry the SSH connection.
*
* @param retries Number of retries.
*/
void setRetries(int retries);
/**
* Set the absolute path to the working directory.
*
* @param path absolute path to the working directory.
*/
void setWorkingDirectory(String path);
/**
* Set the standard error output.
*
* @param stderr Value of the new standard error output.
*/
void setStdErr(OutputStream stderr);
/**
* Set the standard output.
*
* @param stdout Value of the new standard output.
*/
void setStdOut(OutputStream stdout);
/**
* Check if the connection is open.
*
* @return True if the connection is open, false otherwise.
*/
boolean isOpen();
}