AmazonConfigurationLoader { public Set<Credentials> getConfiguredCredentials() { List<Object> keypairList = configuration.getList(KEYPAIRS, Collections.EMPTY_LIST); Map<String, Map<String, String>> keypairSpecifications = ConfigurationUtil.reduceObjectList(keypairList, "Keypairs must be specified as a list of objects."); Set<Credentials> credentials = Sets.newHashSetWithExpectedSize(keypairSpecifications.size()); for (Map.Entry<String, Map<String, String>> entry : keypairSpecifications.entrySet()) { String keyPairName = entry.getKey(); Map<String, String> keyPairValues = entry.getValue(); String user = ConfigurationUtil.getCheckedConfigValue( USER, keyPairValues, "keypair", keyPairName); String privateKeyPath = ConfigurationUtil.getCheckedConfigValue( PRIVATE_KEY, keyPairValues, "keypair", keyPairName); File privateKey = ConfigurationUtil.getCheckedFile( privateKeyPath, PRIVATE_KEY, "keypair", keyPairName); String publicKeyPath = keyPairValues.get(PUBLIC_KEY); if(publicKeyPath != null) { File publicKey = ConfigurationUtil.getCheckedFile( publicKeyPath, PUBLIC_KEY, "keypair", keyPairName); credentials.add(new KeyPairCredentials( keyPairName, user, privateKey, publicKey)); } else { credentials.add(new AmazonConfiguredKeyPairCredentials( keyPairName, user, privateKey)); } } return credentials; } AmazonConfigurationLoader(Configuration configuration); String getAccessKeyId(); String getSecretKey(); String getNodeJvmOptions(); LogLevel getNodeLogLevel(); Boolean getNodeRemoteLogging(); Integer getNodeRemoteLoggingPort(); Set<Credentials> getConfiguredCredentials(); Map<String, AWSInstanceProfile> getConfiguredProfiles(); static final String ACCESS_KEY_ID; static final String SECRET_KEY; static final String KEYPAIRS; static final String PROFILES; static final String PRIVATE_KEY; static final String PUBLIC_KEY; static final String USER; static final String AMI_ID; static final String REGION; static final String ZONE; static final String TYPE; static final String KEYPAIR; static final String SHUTDOWN_STATE; static final String GROUP; static final String SPOT_PRICE; static final String SPOT_REQUEST_TYPE; static final String SPOT_REQUEST_VALID_FROM; static final String SPOT_REQUEST_VALID_TO; static final String PLACEMENT_GROUP; static final String NODE_JVM_OPTIONS; static final String NODE_LOG_LEVEL; static final String NODE_LOG_REMOTE; static final String NODE_LOG_REMOTE_PORT; }
@Test public void testGetConfiguredCredentials() throws ConfigurationException { goodConfigSetup(); Set<Credentials> result = configLoader.getConfiguredCredentials(); Credentials c1 = new AmazonConfiguredKeyPairCredentials(KEYPAIR1, USER1, new File(privateKeyPath)); Credentials c2 = new KeyPairCredentials(KEYPAIR2, USER2, new File(privateKeyPath), new File(publicKeyPath)); assertThat(result, allOf( hasItem(c1), hasItem(c2) )); }
@Test(expected=IllegalArgumentException.class) public void testGetBadConfiguredCredentials() throws ConfigurationException { badConfigSetup(); configLoader.getConfiguredCredentials(); }