use of com.amazonaws.auth.AWSCredentials in project elasticsearch by elastic.
the class AwsS3ServiceImplTests method launchAWSCredentialsWithElasticsearchSettingsTest.
protected void launchAWSCredentialsWithElasticsearchSettingsTest(Settings singleRepositorySettings, Settings settings, String expectedKey, String expectedSecret) {
String configName = InternalAwsS3Service.CLIENT_NAME.get(singleRepositorySettings);
AWSCredentials credentials = InternalAwsS3Service.buildCredentials(logger, deprecationLogger, settings, singleRepositorySettings, configName).getCredentials();
assertThat(credentials.getAWSAccessKeyId(), is(expectedKey));
assertThat(credentials.getAWSSecretKey(), is(expectedSecret));
}
use of com.amazonaws.auth.AWSCredentials in project druid by druid-io.
the class TestAWSCredentialsProvider method testWithFileSessionCredentials.
@Test
public void testWithFileSessionCredentials() throws IOException {
AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
EasyMock.expect(config.getAccessKey()).andReturn("");
EasyMock.expect(config.getSecretKey()).andReturn("");
File file = folder.newFile();
PrintWriter out = new PrintWriter(file.getAbsolutePath());
out.println("sessionToken=sessionTokenSample\nsecretKey=secretKeySample\naccessKey=accessKeySample");
out.close();
EasyMock.expect(config.getFileSessionCredentials()).andReturn(file.getAbsolutePath()).atLeastOnce();
EasyMock.replay(config);
AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
AWSCredentials credentials = provider.getCredentials();
assertTrue(credentials instanceof AWSSessionCredentials);
AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) credentials;
assertEquals(sessionCredentials.getAWSAccessKeyId(), "accessKeySample");
assertEquals(sessionCredentials.getAWSSecretKey(), "secretKeySample");
assertEquals(sessionCredentials.getSessionToken(), "sessionTokenSample");
// try to create
s3Module.getRestS3Service(provider);
}
use of com.amazonaws.auth.AWSCredentials in project hadoop by apache.
the class AWSCredentialProviderList method getCredentials.
/**
* Iterate through the list of providers, to find one with credentials.
* If {@link #reuseLastProvider} is true, then it is re-used.
* @return a set of credentials (possibly anonymous), for authenticating.
*/
@Override
public AWSCredentials getCredentials() {
checkNotEmpty();
if (reuseLastProvider && lastProvider != null) {
return lastProvider.getCredentials();
}
AmazonClientException lastException = null;
for (AWSCredentialsProvider provider : providers) {
try {
AWSCredentials credentials = provider.getCredentials();
if ((credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) || (credentials instanceof AnonymousAWSCredentials)) {
lastProvider = provider;
LOG.debug("Using credentials from {}", provider);
return credentials;
}
} catch (AmazonClientException e) {
lastException = e;
LOG.debug("No credentials provided by {}: {}", provider, e.toString(), e);
}
}
// no providers had any credentials. Rethrow the last exception
// or create a new one.
String message = "No AWS Credentials provided by " + listProviderNames();
if (lastException != null) {
message += ": " + lastException;
}
throw new AmazonClientException(message, lastException);
}
use of com.amazonaws.auth.AWSCredentials in project openhab1-addons by openhab.
the class DynamoDBConfig method fromConfig.
/**
*
* @param config persistence service configuration
* @return DynamoDB configuration. Returns null in case of configuration errors
*/
public static DynamoDBConfig fromConfig(Map<String, Object> config) {
if (config == null || config.isEmpty()) {
logger.error("Configuration not provided! At least AWS region and credentials must be provided.");
return null;
}
try {
String regionName = (String) config.get("region");
if (isBlank(regionName)) {
invalidRegionLogHelp(regionName);
return null;
}
final Region region;
try {
region = Region.getRegion(Regions.fromName(regionName));
} catch (IllegalArgumentException e) {
invalidRegionLogHelp(regionName);
return null;
}
AWSCredentials credentials;
String accessKey = (String) config.get("accessKey");
String secretKey = (String) config.get("secretKey");
if (!isBlank(accessKey) && !isBlank(secretKey)) {
logger.debug("accessKey and secretKey specified. Using those.");
credentials = new BasicAWSCredentials(accessKey, secretKey);
} else {
logger.debug("accessKey and/or secretKey blank. Checking profilesConfigFile and profile.");
String profilesConfigFile = (String) config.get("profilesConfigFile");
String profile = (String) config.get("profile");
if (isBlank(profilesConfigFile) || isBlank(profile)) {
logger.error("Specify either 1) accessKey and secretKey; or 2) profilesConfigFile and " + "profile for providing AWS credentials");
return null;
}
credentials = new ProfilesConfigFile(profilesConfigFile).getCredentials(profile);
}
String table = (String) config.get("tablePrefix");
if (isBlank(table)) {
logger.debug("Using default table name {}", DEFAULT_TABLE_PREFIX);
table = DEFAULT_TABLE_PREFIX;
}
final boolean createTable;
String createTableParam = (String) config.get("createTable");
if (isBlank(createTableParam)) {
logger.debug("Creating table on demand: {}", DEFAULT_CREATE_TABLE_ON_DEMAND);
createTable = DEFAULT_CREATE_TABLE_ON_DEMAND;
} else {
createTable = Boolean.parseBoolean(createTableParam);
}
final long readCapacityUnits;
String readCapacityUnitsParam = (String) config.get("readCapacityUnits");
if (isBlank(readCapacityUnitsParam)) {
logger.debug("Read capacity units: {}", DEFAULT_READ_CAPACITY_UNITS);
readCapacityUnits = DEFAULT_READ_CAPACITY_UNITS;
} else {
readCapacityUnits = Long.parseLong(readCapacityUnitsParam);
}
final long writeCapacityUnits;
String writeCapacityUnitsParam = (String) config.get("writeCapacityUnits");
if (isBlank(writeCapacityUnitsParam)) {
logger.debug("Write capacity units: {}", DEFAULT_WRITE_CAPACITY_UNITS);
writeCapacityUnits = DEFAULT_WRITE_CAPACITY_UNITS;
} else {
writeCapacityUnits = Long.parseLong(writeCapacityUnitsParam);
}
return new DynamoDBConfig(region, credentials, table, createTable, readCapacityUnits, writeCapacityUnits);
} catch (Exception e) {
logger.error("Error with configuration", e);
return null;
}
}
use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class Route53 method main.
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
AWSCredentials credentials = new PropertiesCredentials(AWSEC2.class.getResourceAsStream("resources/AwsCredentials.properties"));
//Create Amazon Client object
route53 = new AmazonRoute53Client(credentials);
listRecordSetsForHostedZone();
}
Aggregations