Skip to content

Commit

Permalink
Applied recipes UpgradeNextMajorParentVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesbusy authored and Valentin Delaye committed Oct 4, 2024
1 parent a8dfc7b commit d940ca3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.0</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -28,7 +28,7 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/ansible-plugin</gitHubRepo>
<jenkins.version>2.462.1</jenkins.version>
<jenkins.version>2.479</jenkins.version>
<spotless.check.skip>false</spotless.check.skip>

<!-- Test dependencies version -->
Expand All @@ -39,7 +39,7 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.440.x</artifactId>
<artifactId>bom-weekly</artifactId>
<version>3413.v0d896b_76a_30d</version>
<type>pom</type>
<scope>import</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,15 @@ public T setVaultTmpPath(FilePath vaultTmpPath) {
}

protected ArgumentListBuilder prependPasswordCredentials(ArgumentListBuilder args) {
if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials passwordCredentials = (UsernamePasswordCredentials) credentials;
if (credentials instanceof UsernamePasswordCredentials passwordCredentials) {
args.add("sshpass").addMasked("-p" + Secret.toString(passwordCredentials.getPassword()));
}
return args;
}

protected ArgumentListBuilder appendCredentials(ArgumentListBuilder args) throws IOException, InterruptedException {
if (credentials instanceof SSHUserPrivateKey) {
if (credentials instanceof SSHUserPrivateKey privateKeyCredentials) {
FilePath tmpPath = vaultTmpPath != null ? vaultTmpPath : ws;
SSHUserPrivateKey privateKeyCredentials = (SSHUserPrivateKey) credentials;
key = Utils.createSshKeyFile(key, tmpPath, privateKeyCredentials, copyCredentialsInWorkspace);
args.add("--private-key").add(key.getRemote().replace("%", "%%"));
args.add("-u").add(privateKeyCredentials.getUsername());
Expand All @@ -269,12 +267,10 @@ protected ArgumentListBuilder appendVaultPasswordFile(ArgumentListBuilder args)
throws IOException, InterruptedException {
if (vaultCredentials != null) {
FilePath tmpPath = vaultTmpPath != null ? vaultTmpPath : ws;
if (vaultCredentials instanceof FileCredentials) {
FileCredentials secretFile = (FileCredentials) vaultCredentials;
if (vaultCredentials instanceof FileCredentials secretFile) {
vaultPassword = Utils.createVaultPasswordFile(vaultPassword, tmpPath, secretFile);
args.add("--vault-password-file").add(vaultPassword.getRemote().replace("%", "%%"));
} else if (vaultCredentials instanceof StringCredentials) {
StringCredentials secretText = (StringCredentials) vaultCredentials;
} else if (vaultCredentials instanceof StringCredentials secretText) {
vaultPassword = Utils.createVaultPasswordFile(vaultPassword, tmpPath, secretText);
args.add("--vault-password-file").add(vaultPassword.getRemote().replace("%", "%%"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.tools.ToolInstallation;
import hudson.tools.ToolProperty;
import java.io.IOException;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import jenkins.model.Jenkins;
Expand All @@ -41,6 +42,9 @@
public class AnsibleInstallation extends ToolInstallation
implements EnvironmentSpecific<AnsibleInstallation>, NodeSpecific<AnsibleInstallation>, Serializable {

@Serial
private static final long serialVersionUID = 1;

@DataBoundConstructor
public AnsibleInstallation(String name, String home, List<? extends ToolProperty<?>> properties) {
super(name, home, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ protected ArgumentListBuilder appendNewVaultPasswordFile(ArgumentListBuilder arg
throws IOException, InterruptedException {
if (newVaultCredentials != null) {
FilePath tmpPath = vaultTmpPath != null ? vaultTmpPath : ws;
if (newVaultCredentials instanceof FileCredentials) {
FileCredentials secretFile = (FileCredentials) newVaultCredentials;
if (newVaultCredentials instanceof FileCredentials secretFile) {
newVaultPassword = Utils.createVaultPasswordFile(newVaultPassword, tmpPath, secretFile);
args.add("--new-vault-password-file")
.add(newVaultPassword.getRemote().replace("%", "%%"));
} else if (newVaultCredentials instanceof StringCredentials) {
StringCredentials secretText = (StringCredentials) newVaultCredentials;
} else if (newVaultCredentials instanceof StringCredentials secretText) {
newVaultPassword = Utils.createVaultPasswordFile(newVaultPassword, tmpPath, secretText);
args.add("--new-vault-password-file")
.add(newVaultPassword.getRemote().replace("%", "%%"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ private static List<ExtraVar> convertExtraVars(Map<String, Object> extraVars) {
ExtraVar var = new ExtraVar();
var.setKey(entry.getKey());
Object o = entry.getValue();
if (o instanceof Map) {
var.setSecretValue(getSecretFromScalarValue(((Map<?, ?>) o).get("value")));
Object hidden = ((Map<?, ?>) o).get("hidden");
if (o instanceof Map<?,?> map) {
var.setSecretValue(getSecretFromScalarValue(map.get("value")));
Object hidden = map.get("hidden");
// If we are given a Boolean value for hidden, respect that.
// Otherwise if omitted or explictly null or any other type adopt the safe default of hidden=true.
if (hidden instanceof Boolean) {
var.setHidden((Boolean) hidden);
if (hidden instanceof Boolean boolean1) {
var.setHidden(boolean1);
} else {
var.setHidden(true);
}
Expand All @@ -418,14 +418,14 @@ private static List<ExtraVar> convertExtraVars(Map<String, Object> extraVars) {
}

private static Secret getSecretFromScalarValue(Object o) {
if (o instanceof String) {
return Secret.fromString((String) o);
if (o instanceof String string) {
return Secret.fromString(string);
} else if (o instanceof Boolean) {
return Secret.fromString(o.toString());
} else if (o instanceof Number) {
return Secret.fromString(o.toString());
} else if (o instanceof Secret) {
return (Secret) o;
} else if (o instanceof Secret secret) {
return secret;
} else {
return null;
}
Expand Down

0 comments on commit d940ca3

Please sign in to comment.