@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getKeyFingerprint() == null) ? 0 : getKeyFingerprint().hashCode()); hashCode = prime * hashCode + ((getKeyName() == null) ? 0 : getKeyName().hashCode()); return hashCode; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getKeyFingerprint() != null) sb.append("KeyFingerprint: ").append(getKeyFingerprint()).append(","); if (getKeyName() != null) sb.append("KeyName: ").append(getKeyName()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof KeyPairInfo == false) return false; KeyPairInfo other = (KeyPairInfo) obj; if (other.getKeyFingerprint() == null ^ this.getKeyFingerprint() == null) return false; if (other.getKeyFingerprint() != null && other.getKeyFingerprint().equals(this.getKeyFingerprint()) == false) return false; if (other.getKeyName() == null ^ this.getKeyName() == null) return false; if (other.getKeyName() != null && other.getKeyName().equals(this.getKeyName()) == false) return false; return true; }
public static void main(String[] args) { final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DescribeKeyPairsResult response = ec2.describeKeyPairs(); for(KeyPairInfo key_pair : response.getKeyPairs()) { System.out.printf( "Found key pair with name %s " + "and fingerprint %s", key_pair.getKeyName(), key_pair.getKeyFingerprint()); } } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getKeyName() == null) ? 0 : getKeyName().hashCode()); hashCode = prime * hashCode + ((getKeyFingerprint() == null) ? 0 : getKeyFingerprint().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof KeyPairInfo == false) return false; KeyPairInfo other = (KeyPairInfo)obj; if (other.getKeyName() == null ^ this.getKeyName() == null) return false; if (other.getKeyName() != null && other.getKeyName().equals(this.getKeyName()) == false) return false; if (other.getKeyFingerprint() == null ^ this.getKeyFingerprint() == null) return false; if (other.getKeyFingerprint() != null && other.getKeyFingerprint().equals(this.getKeyFingerprint()) == false) return false; return true; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getKeyName() != null) sb.append("KeyName: " + getKeyName() + ","); if (getKeyFingerprint() != null) sb.append("KeyFingerprint: " + getKeyFingerprint() ); sb.append("}"); return sb.toString(); }
protected Optional<KeyPairInfo> getKeyPairInfo(String name, List<KeyPairInfo> list) { for (KeyPairInfo element : list) { logger.debug("fingerprint - {}, name - {}", element.getKeyFingerprint(), element.getKeyName()); if (name.equals(element.getKeyName())) { return Optional.of(element); } } return Optional.<KeyPairInfo> absent(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getKeyFingerprint() == null) ? 0 : getKeyFingerprint().hashCode()); hashCode = prime * hashCode + ((getKeyName() == null) ? 0 : getKeyName().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof KeyPairInfo == false) return false; KeyPairInfo other = (KeyPairInfo) obj; if (other.getKeyFingerprint() == null ^ this.getKeyFingerprint() == null) return false; if (other.getKeyFingerprint() != null && other.getKeyFingerprint().equals(this.getKeyFingerprint()) == false) return false; if (other.getKeyName() == null ^ this.getKeyName() == null) return false; if (other.getKeyName() != null && other.getKeyName().equals(this.getKeyName()) == false) return false; return true; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getKeyFingerprint() != null) sb.append("KeyFingerprint: ").append(getKeyFingerprint()).append(","); if (getKeyName() != null) sb.append("KeyName: ").append(getKeyName()); sb.append("}"); return sb.toString(); }
public static List<String> getKeyName() { DescribeKeyPairsRequest dkpr = new DescribeKeyPairsRequest(); DescribeKeyPairsResult dkpresult = amazonEC2Client.describeKeyPairs(dkpr); List<KeyPairInfo> keyPairs = dkpresult.getKeyPairs(); List<String> keyPairNameList = new ArrayList<String>(); for (KeyPairInfo keyPairInfo : keyPairs) { keyPairNameList.add(keyPairInfo.getKeyName()); } for (int i = 0; i < keyPairs.size(); i++) { System.out.println(keyPairNameList.get(i)); } return keyPairNameList; }
/** * Load keypairs * * @return list of keypairs */ public static List<String> loadKeypairs() { List<String> resultList = new ArrayList<String>(); DescribeKeyPairsResult results = getEC2Client().describeKeyPairs(); for (KeyPairInfo key : results.getKeyPairs()) { resultList.add(key.getKeyName()); } return resultList; }
/** * Load keypairs * * @return list of keypairs */ public static List<String> loadKeypairs() { List<String> resultList = new ArrayList<String>(); DescribeKeyPairsResult results = getEC2Client().describeKeyPairs(); for (KeyPairInfo key : results.getKeyPairs()) { resultList.add(key.getKeyName()); } return resultList; }
public FormValidation doGenerateKey(StaplerResponse rsp, URL ec2EndpointUrl, boolean useInstanceProfileForCredentials, String accessId, String secretKey) throws IOException, ServletException { try { AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey); AmazonEC2 ec2 = connect(credentialsProvider, ec2EndpointUrl); List<KeyPairInfo> existingKeys = ec2.describeKeyPairs().getKeyPairs(); int n = 0; while(true) { boolean found = false; for (KeyPairInfo k : existingKeys) { if(k.getKeyName().equals("hudson-"+n)) found=true; } if(!found) break; n++; } CreateKeyPairRequest request = new CreateKeyPairRequest("hudson-" + n); KeyPair key = ec2.createKeyPair(request).getKeyPair(); rsp.addHeader("script","findPreviousFormItem(button,'privateKey').value='"+key.getKeyMaterial().replace("\n","\\n")+"'"); return FormValidation.ok(Messages.EC2Cloud_Success()); } catch (AmazonClientException e) { LOGGER.log(Level.WARNING, "Failed to check EC2 credential",e); return FormValidation.error(e.getMessage()); } } }
public FormValidation doGenerateKey(StaplerResponse rsp, URL ec2EndpointUrl, boolean useInstanceProfileForCredentials, String credentialsId, String roleArn, String roleSessionName, String region) throws IOException, ServletException { try { AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, credentialsId, roleArn, roleSessionName, region); AmazonEC2 ec2 = connect(credentialsProvider, ec2EndpointUrl); List<KeyPairInfo> existingKeys = ec2.describeKeyPairs().getKeyPairs(); int n = 0; while (true) { boolean found = false; for (KeyPairInfo k : existingKeys) { if (k.getKeyName().equals("hudson-" + n)) found = true; } if (!found) break; n++; } CreateKeyPairRequest request = new CreateKeyPairRequest("hudson-" + n); KeyPair key = ec2.createKeyPair(request).getKeyPair(); rsp.addHeader("script", "findPreviousFormItem(button,'privateKey').value='" + key.getKeyMaterial().replace("\n", "\\n") + "'"); return FormValidation.ok(Messages.EC2Cloud_Success()); } catch (AmazonClientException e) { LOGGER.log(Level.WARNING, "Failed to check EC2 credential", e); return FormValidation.error(e.getMessage()); } }
/** * Finds the {@link KeyPairInfo} that corresponds to this key in EC2. */ public com.amazonaws.services.ec2.model.KeyPair find(AmazonEC2 ec2) throws IOException, AmazonClientException { String fp = getFingerprint(); String pfp = getPublicFingerprint(); for (KeyPairInfo kp : ec2.describeKeyPairs().getKeyPairs()) { if (kp.getKeyFingerprint().equalsIgnoreCase(fp)) { com.amazonaws.services.ec2.model.KeyPair keyPair = new com.amazonaws.services.ec2.model.KeyPair(); keyPair.setKeyName(kp.getKeyName()); keyPair.setKeyFingerprint(fp); keyPair.setKeyMaterial(Secret.toString(privateKey)); return keyPair; } if (kp.getKeyFingerprint().equalsIgnoreCase(pfp)) { com.amazonaws.services.ec2.model.KeyPair keyPair = new com.amazonaws.services.ec2.model.KeyPair(); keyPair.setKeyName(kp.getKeyName()); keyPair.setKeyFingerprint(pfp); keyPair.setKeyMaterial(Secret.toString(privateKey)); return keyPair; } } return null; }
/** * Finds the {@link KeyPairInfo} that corresponds to this key in EC2. */ public com.amazonaws.services.ec2.model.KeyPair find(AmazonEC2 ec2) throws IOException, AmazonClientException { String fp = getFingerprint(); String pfp = getPublicFingerprint(); for(KeyPairInfo kp : ec2.describeKeyPairs().getKeyPairs()) { if(kp.getKeyFingerprint().equalsIgnoreCase(fp)) { com.amazonaws.services.ec2.model.KeyPair keyPair = new com.amazonaws.services.ec2.model.KeyPair(); keyPair.setKeyName(kp.getKeyName()); keyPair.setKeyFingerprint(fp); keyPair.setKeyMaterial(Secret.toString(privateKey)); return keyPair; } if(kp.getKeyFingerprint().equalsIgnoreCase(pfp)) { com.amazonaws.services.ec2.model.KeyPair keyPair = new com.amazonaws.services.ec2.model.KeyPair(); keyPair.setKeyName(kp.getKeyName()); keyPair.setKeyFingerprint(pfp); keyPair.setKeyMaterial(Secret.toString(privateKey)); return keyPair; } } return null; }