@Override public String importKeyPair(final KeyPair keyPair) { synchronized (lock_) { String fingerprint; checkState(!isNullOrEmpty(keyPair.getKeyName())); checkState(!isNullOrEmpty(keyPair.getKeyMaterial())); KeyPair keyPair2 = getKeyPair(keyPair.getKeyName()); if (keyPair2 == null) { fingerprint = new AmazonEC2Client(awsCredentials_).importKeyPair(new ImportKeyPairRequest(keyPair.getKeyName(), keyPair.getKeyMaterial())).getKeyFingerprint(); } else { fingerprint = keyPair2.getKeyFingerprint(); } return fingerprint; } }
@Override public void importKeyPair(String keyName, String publicKey) throws AutoException { // キーペアがすでに登録されていたら何もしない DescribeKeyPairsRequest request = new DescribeKeyPairsRequest(); DescribeKeyPairsResult result = ec2Client.describeKeyPairs(request); List<KeyPairInfo> keyPairs = result.getKeyPairs(); for (KeyPairInfo keyPair : keyPairs) { if (keyPair.getKeyName().equals(keyName)) { log.info(platform.getPlatformName() + " の " + keyName + " はすでに登録されている為、キーのインポートをスキップします"); System.out.println("IMPORT_SKIPPED"); return; } } // インポート ImportKeyPairRequest request2 = new ImportKeyPairRequest(); request2.withKeyName(keyName); request2.withPublicKeyMaterial(publicKey); ec2Client.importKeyPair(request2); log.info(keyName + "のキーをインポートしました。"); }
@Test public void testImportKey() { String keyName = "key-name"; String publicKeyMaterial = "public-key-material"; String keyNameResult = "key-name-result"; when(ec2Client.importKeyPair(new ImportKeyPairRequest(keyName, publicKeyMaterial))) .thenReturn(new ImportKeyPairResult().withKeyName(keyNameResult)); // invoke method under test String result = ec2Service.importKey(keyName, publicKeyMaterial); assertEquals(keyNameResult, result); }
@Override public KeyPair importKeyPair(ImportKeyPairRequest request, ResultCapture<ImportKeyPairResult> extractor) { ActionResult result = service.performAction("ImportKeyPair", request, extractor); if (result == null) return null; return new KeyPairImpl(result.getResource()); }
@Override public KeyPair importKeyPair(String publicKeyMaterial, String keyName, ResultCapture<ImportKeyPairResult> extractor) { ImportKeyPairRequest request = new ImportKeyPairRequest() .withPublicKeyMaterial(publicKeyMaterial) .withKeyName(keyName); return importKeyPair(request, extractor); }
@Override public void setUp() throws Exception { super.setUp(); client.importKeyPair(new ImportKeyPairRequest().withKeyName(KEYPAIR_NAME) .withPublicKeyMaterial(getResourceAsString("/org/apache/provisionr/test/id_rsa_test.pub"))); }
@Override public ImportKeyPairResult importKeyPair(ImportKeyPairRequest importKeyPairRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
@Override public KeyPair importKeyPair(ImportKeyPairRequest request) { return importKeyPair(request, null); }
private void importPoolPublicKeyPair(AmazonEC2 client, String keyName, String publicKey) { ImportKeyPairResult result = client.importKeyPair(new ImportKeyPairRequest() .withKeyName(keyName).withPublicKeyMaterial(publicKey)); LOG.info("<< Created remote key with fingerprint {}", result.getKeyFingerprint()); }
/** * Import a key pair to AWS EC2. * * @param keyName Friendly name for the key * @param publicKeyMaterial Public key * @return Key name */ public String importKey(final String keyName, final String publicKeyMaterial) { final ImportKeyPairRequest request = new ImportKeyPairRequest(keyName, publicKeyMaterial); final ImportKeyPairResult result = ec2Client.importKeyPair(request); return result.getKeyName(); }
/** * Performs the <code>ImportKeyPair</code> action. * * <p> * * @return The <code>KeyPair</code> resource object associated with the * result of this action. * @see ImportKeyPairRequest */ com.amazonaws.resources.ec2.KeyPair importKeyPair(ImportKeyPairRequest request);
/** * Performs the <code>ImportKeyPair</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * * @return The <code>KeyPair</code> resource object associated with the * result of this action. * @see ImportKeyPairRequest */ com.amazonaws.resources.ec2.KeyPair importKeyPair(ImportKeyPairRequest request, ResultCapture<ImportKeyPairResult> extractor);