Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-34437] Factory to use Jenkins Proxy configuration with a Ama…
…zonECRClient. (#10) * Factory to use Jenkins Proxy configuration with a AmazonECRClient. * minimise class
- Loading branch information
1 parent
8ec69b4
commit 76824ef
Showing
1 changed file
with
29 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.amazonaws; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.services.ecr.AmazonECRClient; | ||
import jenkins.model.Jenkins; | ||
|
||
/** | ||
* Factory to use Jenkins Proxy configuration with a AmazonECRClient. | ||
* | ||
* @author Marcus Wallin, kuisathaverat | ||
*/ | ||
public class AmazonECRClientFactory { | ||
|
||
/** | ||
* @param credentials {@link AWSCredentials} to use. | ||
* @return {@link AmazonECRClient} configured to use the proxy configured on Jenkins. | ||
*/ | ||
public AmazonECRClient getAmazonECRClientWithProxy(AWSCredentials credentials) { | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
Jenkins j = Jenkins.getInstance(); | ||
if (j != null && j.proxy != null) { | ||
conf.setProxyHost(j.proxy.name); | ||
conf.setProxyPort(j.proxy.port); | ||
conf.setProxyUsername(j.proxy.getUserName()); | ||
conf.setProxyPassword(j.proxy.getPassword()); | ||
} | ||
return new AmazonECRClient(credentials, conf); | ||
} | ||
} |