@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; }
/** * <p> * If you used <a>CreateKeyPair</a> to create the key pair, this is the SHA-1 digest of the DER encoded private key. * If you used <a>ImportKeyPair</a> to provide AWS the public key, this is the MD5 public key fingerprint as * specified in section 4 of RFC4716. * </p> * * @param keyFingerprint * If you used <a>CreateKeyPair</a> to create the key pair, this is the SHA-1 digest of the DER encoded * private key. If you used <a>ImportKeyPair</a> to provide AWS the public key, this is the MD5 public key * fingerprint as specified in section 4 of RFC4716. * @return Returns a reference to this object so that method calls can be chained together. */ public KeyPairInfo withKeyFingerprint(String keyFingerprint) { setKeyFingerprint(keyFingerprint); return this; }
/** * <p> * The name of the key pair. * </p> * * @param keyName * The name of the key pair. * @return Returns a reference to this object so that method calls can be chained together. */ public KeyPairInfo withKeyName(String keyName) { setKeyName(keyName); return this; }
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; }
public KeyPairInfo unmarshall(StaxUnmarshallerContext context) throws Exception { KeyPairInfo keyPairInfo = new KeyPairInfo(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return keyPairInfo; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("keyFingerprint", targetDepth)) { keyPairInfo.setKeyFingerprint(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("keyName", targetDepth)) { keyPairInfo.setKeyName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return keyPairInfo; } } } }
/** * 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 KeyPairInfo unmarshall(StaxUnmarshallerContext context) throws Exception { KeyPairInfo keyPairInfo = new KeyPairInfo(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) return keyPairInfo; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("keyName", targetDepth)) { keyPairInfo.setKeyName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("keyFingerprint", targetDepth)) { keyPairInfo.setKeyFingerprint(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { return keyPairInfo; } } } }
@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; }
/** * 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 KeyPairInfo unmarshall(StaxUnmarshallerContext context) throws Exception { KeyPairInfo keyPairInfo = new KeyPairInfo(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return keyPairInfo; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("keyFingerprint", targetDepth)) { keyPairInfo.setKeyFingerprint(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("keyName", targetDepth)) { keyPairInfo.setKeyName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return keyPairInfo; } } } }
/** * <p> * The name of the key pair. * </p> * * @param keyName * The name of the key pair. * @return Returns a reference to this object so that method calls can be chained together. */ public KeyPairInfo withKeyName(String keyName) { setKeyName(keyName); return this; }
/** * <p> * If you used <a>CreateKeyPair</a> to create the key pair, this is the SHA-1 digest of the DER encoded private key. * If you used <a>ImportKeyPair</a> to provide AWS the public key, this is the MD5 public key fingerprint as * specified in section 4 of RFC4716. * </p> * * @param keyFingerprint * If you used <a>CreateKeyPair</a> to create the key pair, this is the SHA-1 digest of the DER encoded * private key. If you used <a>ImportKeyPair</a> to provide AWS the public key, this is the MD5 public key * fingerprint as specified in section 4 of RFC4716. * @return Returns a reference to this object so that method calls can be chained together. */ public KeyPairInfo withKeyFingerprint(String keyFingerprint) { setKeyFingerprint(keyFingerprint); return this; }
/** * 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 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 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()); } } }
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()); } }
@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; }
@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; }
/** * 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(); }
@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; }