forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CLIConnectionFactory.java
40 lines (33 loc) · 1.17 KB
/
CLIConnectionFactory.java
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
package hudson.cli;
import org.apache.commons.codec.binary.Base64;
/**
* Fluent-API to instantiate {@link CLI}.
*
* @author Kohsuke Kawaguchi
*/
public class CLIConnectionFactory {
String authorization;
/**
* For CLI connection that goes through HTTP, sometimes you need
* to pass in the custom authentication header (before Jenkins even get to authenticate
* the CLI channel.) This method lets you specify the value of this header.
*/
public CLIConnectionFactory authorization(String value) {
this.authorization = value;
return this;
}
/**
* Convenience method to call {@link #authorization} with the HTTP basic authentication.
* Currently unused.
*/
public CLIConnectionFactory basicAuth(String username, String password) {
return basicAuth(username+':'+password);
}
/**
* Convenience method to call {@link #authorization} with the HTTP basic authentication.
* Cf. {@code BasicHeaderApiTokenAuthenticator}.
*/
public CLIConnectionFactory basicAuth(String userInfo) {
return authorization("Basic " + new String(Base64.encodeBase64((userInfo).getBytes())));
}
}