Search in sources :

Example 1 with AWSCredentials

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));
}
Also used : AWSCredentials(com.amazonaws.auth.AWSCredentials)

Example 2 with AWSCredentials

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);
}
Also used : AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AWSCredentialsConfig(io.druid.common.aws.AWSCredentialsConfig) File(java.io.File) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with AWSCredentials

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);
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 4 with AWSCredentials

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;
    }
}
Also used : Region(com.amazonaws.regions.Region) ProfilesConfigFile(com.amazonaws.auth.profile.ProfilesConfigFile) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 5 with AWSCredentials

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();
}
Also used : PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonRoute53Client(com.amazonaws.services.route53.AmazonRoute53Client)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)75 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)41 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)15 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)14 ClientConfiguration (com.amazonaws.ClientConfiguration)13 AmazonClientException (com.amazonaws.AmazonClientException)12 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)11 Test (org.junit.Test)11 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)10 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)9 File (java.io.File)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)7 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)6 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)4 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)4 IOException (java.io.IOException)4 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)3 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)3 Instance (com.amazonaws.services.ec2.model.Instance)3 AWSServiceDiscovery (com.amazonaws.services.servicediscovery.AWSServiceDiscovery)3