-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Use Jenkins proxy settings for Secrets Manager communication (
#306) Co-authored-by: Preslav Petkov <[email protected]> Co-authored-by: Chris Kilding <[email protected]>
- Loading branch information
1 parent
ca3f373
commit a0ad826
Showing
16 changed files
with
361 additions
and
6 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
117 changes: 117 additions & 0 deletions
117
src/main/java/io/jenkins/plugins/credentials/secretsmanager/config/ClientConfiguration.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,117 @@ | ||
package io.jenkins.plugins.credentials.secretsmanager.config; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AbstractDescribableImpl; | ||
import hudson.model.Descriptor; | ||
import hudson.util.Secret; | ||
import io.jenkins.plugins.credentials.secretsmanager.Messages; | ||
import org.jenkinsci.Symbol; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
public class ClientConfiguration extends AbstractDescribableImpl<ClientConfiguration> implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String nonProxyHosts; | ||
private String proxyHost; | ||
private Integer proxyPort; | ||
private String proxyUsername; | ||
private Secret proxyPassword; | ||
|
||
@DataBoundConstructor | ||
public ClientConfiguration(String nonProxyHosts, String proxyHost, Integer proxyPort, String proxyUsername, Secret proxyPassword) { | ||
this.nonProxyHosts = nonProxyHosts; | ||
this.proxyHost = proxyHost; | ||
this.proxyPort = proxyPort; | ||
this.proxyUsername = proxyUsername; | ||
this.proxyPassword = proxyPassword; | ||
} | ||
|
||
public String getNonProxyHosts() { | ||
return nonProxyHosts; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setNonProxyHosts(String nonProxyHosts) { | ||
this.nonProxyHosts = nonProxyHosts; | ||
} | ||
|
||
public String getProxyHost() { | ||
return proxyHost; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setProxyHost(String proxyHost) { | ||
this.proxyHost = proxyHost; | ||
} | ||
|
||
public Integer getProxyPort() { | ||
return proxyPort; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setProxyPort(Integer proxyPort) { | ||
this.proxyPort = proxyPort; | ||
} | ||
|
||
public String getProxyUsername() { | ||
return proxyUsername; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setProxyUsername(String proxyUsername) { | ||
this.proxyUsername = proxyUsername; | ||
} | ||
|
||
public Secret getProxyPassword() { | ||
return proxyPassword; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setProxyPassword(Secret proxyPassword) { | ||
this.proxyPassword = proxyPassword; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ClientConfiguration that = (ClientConfiguration) o; | ||
return Objects.equals(proxyPort, that.proxyPort) && Objects.equals(nonProxyHosts, that.nonProxyHosts) && Objects.equals(proxyHost, that.proxyHost) && Objects.equals(proxyUsername, that.proxyUsername) && Objects.equals(proxyPassword, that.proxyPassword); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(nonProxyHosts, proxyHost, proxyPort, proxyUsername, proxyPassword); | ||
} | ||
|
||
public com.amazonaws.ClientConfiguration build() { | ||
final var configuration = new com.amazonaws.ClientConfiguration(); | ||
|
||
configuration.setNonProxyHosts(nonProxyHosts); | ||
configuration.setProxyHost(proxyHost); | ||
if (proxyPort != null) { | ||
configuration.setProxyPort(proxyPort); | ||
} | ||
configuration.setProxyUsername(proxyUsername); | ||
configuration.setProxyPassword(Secret.toString(proxyPassword)); | ||
|
||
return configuration; | ||
} | ||
|
||
@Extension | ||
@Symbol("clientConfiguration") | ||
@SuppressWarnings("unused") | ||
public static class DescriptorImpl extends Descriptor<ClientConfiguration> { | ||
@Override | ||
@Nonnull | ||
public String getDisplayName() { | ||
return Messages.clientConfiguration(); | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
src/main/resources/io/jenkins/plugins/credentials/secretsmanager/config/Client/config.jelly
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
1 change: 1 addition & 0 deletions
1
...esources/io/jenkins/plugins/credentials/secretsmanager/config/Client/config_en.properties
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
2 changes: 2 additions & 0 deletions
2
...io/jenkins/plugins/credentials/secretsmanager/config/Client/help-clientConfiguration.html
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,2 @@ | ||
<p>Override the AWS client configuration.</p> | ||
<p>When this is in default mode, the plugin will automatically use the Jenkins HTTP proxy settings if you have configured them.</p> |
18 changes: 18 additions & 0 deletions
18
...ces/io/jenkins/plugins/credentials/secretsmanager/config/ClientConfiguration/config.jelly
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,18 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry title="${%nonProxyHosts}"> | ||
<f:textbox field="nonProxyHosts" /> | ||
</f:entry> | ||
<f:entry title="${%proxyHost}"> | ||
<f:textbox field="proxyHost" /> | ||
</f:entry> | ||
<f:entry title="${%proxyPort}"> | ||
<f:number field="proxyPort" min="0" max="65535" /> | ||
</f:entry> | ||
<f:entry title="${%proxyUsername}"> | ||
<f:textbox field="proxyUsername" /> | ||
</f:entry> | ||
<f:entry title="${%proxyPassword}"> | ||
<f:password field="proxyPassword" /> | ||
</f:entry> | ||
</j:jelly> |
5 changes: 5 additions & 0 deletions
5
...enkins/plugins/credentials/secretsmanager/config/ClientConfiguration/config_en.properties
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,5 @@ | ||
nonProxyHosts = Non-Proxy Hosts | ||
proxyHost = Proxy Host | ||
proxyPort = Proxy Port | ||
proxyUsername = Proxy Username | ||
proxyPassword = Proxy Password |
32 changes: 32 additions & 0 deletions
32
src/test/java/io/jenkins/plugins/credentials/secretsmanager/config/ClientTest.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,32 @@ | ||
package io.jenkins.plugins.credentials.secretsmanager.config; | ||
|
||
import hudson.ProxyConfiguration; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.SoftAssertions.assertSoftly; | ||
|
||
public class ClientTest { | ||
|
||
@Test | ||
public void shouldConvertProxyConfigurationToClientConfiguration() { | ||
// Given | ||
final var host = "localhost"; | ||
final var port = 8000; | ||
final var noProxyHost = "example.com"; | ||
final var username = "foo"; | ||
final var password = "fake"; | ||
final var proxyConfiguration = new ProxyConfiguration(host, port, username, password, noProxyHost); | ||
|
||
// When | ||
final var clientConfiguration = Client.toClientConfiguration(proxyConfiguration); | ||
|
||
// Then | ||
assertSoftly(s -> { | ||
s.assertThat(clientConfiguration.getProxyHost()).as("Host").isEqualTo(host); | ||
s.assertThat(clientConfiguration.getProxyPort()).as("Port").isEqualTo(port); | ||
s.assertThat(clientConfiguration.getProxyUsername()).as("Username").isEqualTo(username); | ||
s.assertThat(clientConfiguration.getProxyPassword()).as("Password").isEqualTo(password); | ||
s.assertThat(clientConfiguration.getNonProxyHosts()).as("Non-Proxy Hosts").isEqualTo(noProxyHost); | ||
}); | ||
} | ||
} |
Oops, something went wrong.