-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #498 from djesionek/JENKINS-56927-bugfix
- Loading branch information
Showing
6 changed files
with
71 additions
and
17 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
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
48 changes: 48 additions & 0 deletions
48
src/test/java/hudson/plugins/ec2/util/SSHCredentialHelper.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,48 @@ | ||
package hudson.plugins.ec2.util; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import jenkins.model.Jenkins; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey; | ||
import com.cloudbees.plugins.credentials.Credentials; | ||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.CredentialsScope; | ||
import com.cloudbees.plugins.credentials.CredentialsStore; | ||
import com.cloudbees.plugins.credentials.SystemCredentialsProvider; | ||
import com.cloudbees.plugins.credentials.domains.Domain; | ||
|
||
public class SSHCredentialHelper { | ||
|
||
public static void assureSshCredentialAvailableThroughCredentialProviders(String id){ | ||
BasicSSHUserPrivateKey sshKeyCredentials = new BasicSSHUserPrivateKey(CredentialsScope.SYSTEM, id, "key", | ||
new BasicSSHUserPrivateKey.PrivateKeySource() { | ||
@NonNull | ||
@Override | ||
public List<String> getPrivateKeys() { | ||
return Collections.singletonList(PrivateKeyHelper.generate()); | ||
} | ||
}, "", "EC2 Testing Cloud Private Key"); | ||
|
||
addNewGlobalCredential(sshKeyCredentials); | ||
} | ||
|
||
private static void addNewGlobalCredential(Credentials credentials){ | ||
for (CredentialsStore credentialsStore: CredentialsProvider.lookupStores(Jenkins.get())) { | ||
|
||
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) { | ||
|
||
try { | ||
credentialsStore.addCredentials(Domain.global(), credentials); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Failed to add testing credential"); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
} |