Skip to content

Commit de51b4c

Browse files
committed
Fixed using KeyMaterial2
1 parent 5b1d2a9 commit de51b4c

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<scope>import</scope>
5858
<type>pom</type>
5959
</dependency>
60+
<!-- TODO until in BOM: -->
61+
<dependency>
62+
<groupId>org.jenkins-ci.plugins</groupId>
63+
<artifactId>docker-commons</artifactId>
64+
<version>454.v2171c32a_8cdd</version> <!-- TODO https://github.com/jenkinsci/docker-commons-plugin/pull/166 -->
65+
</dependency>
6066
</dependencies>
6167
</dependencyManagement>
6268
<dependencies>

src/main/java/org/jenkinsci/plugins/docker/workflow/AbstractEndpointStepExecution2.java

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
*/
2424
package org.jenkinsci.plugins.docker.workflow;
2525

26+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2627
import hudson.EnvVars;
28+
import hudson.FilePath;
2729
import java.io.IOException;
2830
import java.util.logging.Level;
2931
import java.util.logging.Logger;
3032
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterial;
33+
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterial2;
3134
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterialFactory;
3235
import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander;
3336
import org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution;
@@ -50,19 +53,19 @@ protected AbstractEndpointStepExecution2(StepContext context) {
5053

5154
private void doStart() throws Exception {
5255
KeyMaterialFactory keyMaterialFactory = newKeyMaterialFactory();
53-
KeyMaterial material = keyMaterialFactory.materialize();
56+
KeyMaterial2 material = keyMaterialFactory.materialize2();
5457
getContext().newBodyInvoker().
55-
withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new Expander(material))).
56-
withCallback(new Callback(material)).
58+
withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new Expander2(material))).
59+
withCallback(new Callback2(material)).
5760
start();
5861
}
5962

60-
private static class Expander extends EnvironmentExpander {
63+
private static class Expander2 extends EnvironmentExpander {
6164

6265
private static final long serialVersionUID = 1;
63-
private final KeyMaterial material;
66+
private final KeyMaterial2 material;
6467

65-
Expander(KeyMaterial material) {
68+
Expander2(KeyMaterial2 material) {
6669
this.material = material;
6770
}
6871

@@ -72,15 +75,53 @@ private static class Expander extends EnvironmentExpander {
7275

7376
}
7477

75-
private class Callback extends TailCall {
78+
private class Callback2 extends TailCall {
7679

7780
private static final long serialVersionUID = 1;
78-
private final KeyMaterial material;
81+
private final KeyMaterial2 material;
7982

80-
Callback(KeyMaterial material) {
83+
Callback2(KeyMaterial2 material) {
8184
this.material = material;
8285
}
8386

87+
@Override protected void finished(StepContext context) throws Exception {
88+
try {
89+
material.close(context.get(FilePath.class).getChannel());
90+
} catch (IOException | InterruptedException x) {
91+
Logger.getLogger(AbstractEndpointStepExecution2.class.getName()).log(Level.WARNING, null, x);
92+
}
93+
}
94+
95+
}
96+
97+
@SuppressFBWarnings(value = {"NP_UNWRITTEN_FIELD", "UWF_NULL_FIELD"})
98+
@Deprecated
99+
private static class Expander extends EnvironmentExpander {
100+
101+
private static final long serialVersionUID = 1;
102+
private final KeyMaterial material = null;
103+
104+
private Expander() {
105+
assert false : "only deserialized";
106+
}
107+
108+
@Override public void expand(EnvVars env) throws IOException, InterruptedException {
109+
env.putAll(material.env());
110+
}
111+
112+
}
113+
114+
@SuppressFBWarnings(value = {"NP_UNWRITTEN_FIELD", "UWF_NULL_FIELD"})
115+
@Deprecated
116+
private class Callback extends TailCall {
117+
118+
private static final long serialVersionUID = 1;
119+
private final KeyMaterial material = null;
120+
121+
private Callback() {
122+
assert false : "only deserialized";
123+
}
124+
84125
@Override protected void finished(StepContext context) throws Exception {
85126
try {
86127
material.close();

0 commit comments

Comments
 (0)