|
36 | 36 | import java.io.File; |
37 | 37 | import java.io.IOException; |
38 | 38 | import java.io.Serializable; |
39 | | -import java.io.StringReader; |
40 | 39 | import java.util.ArrayList; |
41 | 40 | import java.util.Arrays; |
42 | 41 | import java.util.Collections; |
43 | 42 | import java.util.List; |
44 | 43 | import java.util.concurrent.TimeUnit; |
45 | 44 | import java.util.logging.Level; |
46 | 45 | import java.util.logging.Logger; |
| 46 | +import java.util.stream.Collectors; |
47 | 47 |
|
48 | 48 | import jenkins.model.Jenkins; |
49 | 49 | import net.jcip.annotations.GuardedBy; |
50 | 50 | import org.apache.commons.io.FileUtils; |
51 | 51 | import org.apache.commons.lang.StringUtils; |
52 | | -import org.jenkins.ui.icon.Icon; |
53 | | -import org.jenkins.ui.icon.IconSet; |
54 | | -import org.jenkins.ui.icon.IconType; |
55 | | -import org.kohsuke.putty.PuTTYKey; |
56 | 52 | import org.kohsuke.stapler.DataBoundConstructor; |
57 | 53 |
|
58 | 54 | /** |
@@ -154,24 +150,9 @@ public synchronized List<String> getPrivateKeys() { |
154 | 150 | } |
155 | 151 | long lastModified = privateKeySource.getPrivateKeysLastModified(); |
156 | 152 | if (privateKeys == null || privateKeys.isEmpty() || lastModified > privateKeysLastModified) { |
157 | | - List<String> privateKeys = new ArrayList<>(); |
158 | | - for (String privateKey : privateKeySource.getPrivateKeys()) { |
159 | | - try { |
160 | | - if (PuTTYKey.isPuTTYKeyFile(new StringReader(privateKey))) { |
161 | | - // strictly we should be encrypting the openssh version with the passphrase, but |
162 | | - // if the key we pass back does not have a passphrase, then the passphrase will not be |
163 | | - // checked, so not an issue. |
164 | | - privateKeys.add(new PuTTYKey(new StringReader(privateKey), |
165 | | - passphrase == null ? "" : passphrase.getPlainText()) |
166 | | - .toOpenSSH()); |
167 | | - } else { |
168 | | - privateKeys.add(privateKey.endsWith("\n") ? privateKey : privateKey + "\n"); |
169 | | - } |
170 | | - } catch (IOException e) { |
171 | | - // ignore |
172 | | - } |
173 | | - } |
174 | | - this.privateKeys = privateKeys; |
| 153 | + this.privateKeys = privateKeySource.getPrivateKeys().stream() |
| 154 | + .map(privateKey -> privateKey.endsWith("\n") ? privateKey : privateKey + "\n") |
| 155 | + .collect(Collectors.toList()); |
175 | 156 | this.privateKeysLastModified = lastModified; |
176 | 157 | } |
177 | 158 | return privateKeys; |
|
0 commit comments