-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
535 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package jenkins.plugins.slack; | ||
|
||
import hudson.ProxyConfiguration; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.auth.AuthScope; | ||
import org.apache.http.auth.UsernamePasswordCredentials; | ||
import org.apache.http.client.CredentialsProvider; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.conn.routing.HttpRoutePlanner; | ||
import org.apache.http.impl.client.BasicCredentialsProvider; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.impl.conn.DefaultProxyRoutePlanner; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public class HttpClient { | ||
|
||
public static CloseableHttpClient getCloseableHttpClient(ProxyConfiguration proxy) { | ||
int timeoutInSeconds = 60; | ||
|
||
RequestConfig config = RequestConfig.custom() | ||
.setConnectTimeout(timeoutInSeconds * 1000) | ||
.setConnectionRequestTimeout(timeoutInSeconds * 1000) | ||
.setSocketTimeout(timeoutInSeconds * 1000).build(); | ||
|
||
final HttpClientBuilder clientBuilder = HttpClients.custom().setDefaultRequestConfig(config); | ||
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); | ||
clientBuilder.setDefaultCredentialsProvider(credentialsProvider); | ||
|
||
if (proxy != null) { | ||
final HttpHost proxyHost = new HttpHost(proxy.name, proxy.port); | ||
final HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost); | ||
clientBuilder.setRoutePlanner(routePlanner); | ||
|
||
String username = proxy.getUserName(); | ||
String password = proxy.getPassword(); | ||
// Consider it to be passed if username specified. Sufficient? | ||
if (username != null && !"".equals(username.trim())) { | ||
credentialsProvider.setCredentials(new AuthScope(proxyHost), | ||
new UsernamePasswordCredentials(username, password)); | ||
} | ||
} | ||
return clientBuilder.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/jenkins/plugins/slack/pipeline/SlackFileRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package jenkins.plugins.slack.pipeline; | ||
|
||
import hudson.FilePath; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public class SlackFileRequest { | ||
private final String fileToUploadPath; | ||
private final String token; | ||
private final String channels; | ||
|
||
private final String initialComment; | ||
private final FilePath filePath; | ||
|
||
public SlackFileRequest(FilePath filePath, String token, String channels, String initialComment, String fileToUploadPath) { | ||
this.token = token; | ||
this.channels = channels; | ||
this.initialComment = initialComment; | ||
this.filePath = filePath; | ||
this.fileToUploadPath = fileToUploadPath; | ||
} | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public String getChannels() { | ||
return channels; | ||
} | ||
|
||
public String getInitialComment() { | ||
return initialComment; | ||
} | ||
|
||
public FilePath getFilePath() { | ||
return filePath; | ||
} | ||
|
||
public String getFileToUploadPath() { | ||
return fileToUploadPath; | ||
} | ||
} |
Oops, something went wrong.