Example usage for com.amazonaws.services.ec2 AmazonEC2 describeKeyPairs

List of usage examples for com.amazonaws.services.ec2 AmazonEC2 describeKeyPairs

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2 AmazonEC2 describeKeyPairs.

Prototype

DescribeKeyPairsResult describeKeyPairs();

Source Link

Document

Simplified method form for invoking the DescribeKeyPairs operation.

Usage

From source file:aws.example.ec2.DescribeKeyPairs.java

License:Open Source License

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());
    }/*from  ww  w  .  j a  va  2  s .c  o  m*/
}

From source file:com.ec2box.manage.action.AWSCredAction.java

License:Apache License

/**
 * Validates fields for credential submit
 *///from w w  w. j a v  a2  s.  c  o m
public void validateSaveAWSCred() {
    if (awsCred.getAccessKey() == null || awsCred.getAccessKey().trim().equals("")) {
        addFieldError("awsCred.accessKey", "Required");
    }
    if (awsCred.getSecretKey() == null || awsCred.getSecretKey().trim().equals("")) {
        addFieldError("awsCred.secretKey", "Required");
    }
    if (!this.hasErrors()) {
        try {
            //check if credential are valid
            BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(),
                    awsCred.getSecretKey());
            AmazonEC2 service = new AmazonEC2Client(awsCredentials, AWSClientConfig.getClientConfig());

            service.describeKeyPairs();
        } catch (Exception ex) {
            addActionError("Invalid Credentials");
        }
    }
    if (this.hasActionErrors() || this.hasErrors()) {
        sortedSet = AWSCredDB.getAWSCredSet(sortedSet);
    }
}

From source file:com.keybox.manage.model.AWSCred.java

License:Apache License

/**
 * Test if AWS Credentials are valid//from  ww  w .ja  v a2s  .co m
 * @return AWS Credentials valid
 */
public boolean isValid() {
    boolean valid = true;

    try {
        //check if credential are valid
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(getAccessKey(), getSecretKey());
        AmazonEC2 service = new AmazonEC2Client(awsCredentials, AWSClientConfig.getClientConfig());
        service.describeKeyPairs();
    } catch (Exception ex) {
        valid = false;
    }
    return valid;
}

From source file:ec2.DescribeKeyPairs.java

License:Open Source License

public static void main(String[] args) {

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DescribeKeyPairsResult response = ec2.describeKeyPairs();

    for (KeyPairInfo keyPair : response.getKeyPairs()) {
        System.out.printf("Found key pair with name %s and fingerprint %s", keyPair.getKeyName(),
                keyPair.getKeyFingerprint());
    }//  w w  w  .  ja  va  2 s  .c o m
}

From source file:edu.umass.cs.aws.support.AWSEC2.java

License:Apache License

/**
 * Describe Key Pairs/*  ww w  .ja va2 s. com*/
 *
 * @param ec2
 */
public static void describeKeyPairs(AmazonEC2 ec2) {
    StringBuilder output = new StringBuilder();
    String prefix = currentTab + "Key Pairs: ";
    DescribeKeyPairsResult dkr = ec2.describeKeyPairs();
    for (KeyPairInfo keyPairInfo : dkr.getKeyPairs()) {
        output.append(prefix);
        prefix = ", ";
        output.append(keyPairInfo.getKeyName());
    }
    System.out.println(output);
}

From source file:edu.umass.cs.aws.support.AWSEC2.java

License:Apache License

/**
 * Returns the name of an existing key pair of the given name or null if it does not exist.
 *
 * @param ec2/*from w ww  .  j  a va  2 s  . c om*/
 * @param name
 * @return the name of the keypair or null
 */
public static String findKeyPairInfo(AmazonEC2 ec2, String name) {
    DescribeKeyPairsResult dkr = ec2.describeKeyPairs();
    for (KeyPairInfo keyPairInfo : dkr.getKeyPairs()) {
        if (name.equals(keyPairInfo.getKeyName())) {
            System.out.println("Found key pair " + name);
            return name;
        }
    }
    return null;
}

From source file:hudson.plugins.ec2.EC2AxisPrivateKey.java

License:Open Source License

/**
 * Finds the {@link KeyPairInfo} that corresponds to this key in EC2.
 *//*  ww w.j  a  va2s  . com*/
public com.amazonaws.services.ec2.model.KeyPair find(AmazonEC2 ec2) throws IOException, AmazonClientException {
    String fp = getFingerprint();
    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;
        }
    }
    return null;
}

From source file:hudson.plugins.ec2.EC2PrivateKey.java

License:Open Source License

/**
 * Finds the {@link KeyPairInfo} that corresponds to this key in EC2.
 *//* w ww .  j  a  v  a 2  s  . c  o  m*/
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;
}