Search in sources :

Example 11 with BasicAWSCredentials

use of com.amazonaws.auth.BasicAWSCredentials in project android-simpl3r by jgilfelt.

the class UploadService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    s3Client = new AmazonS3Client(new BasicAWSCredentials(getString(R.string.s3_access_key), getString(R.string.s3_secret)));
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    IntentFilter f = new IntentFilter();
    f.addAction(UPLOAD_CANCELLED_ACTION);
    registerReceiver(uploadCancelReceiver, f);
}
Also used : IntentFilter(android.content.IntentFilter) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 12 with BasicAWSCredentials

use of com.amazonaws.auth.BasicAWSCredentials 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 13 with BasicAWSCredentials

use of com.amazonaws.auth.BasicAWSCredentials in project exhibitor by soabase.

the class S3ClientImpl method changeCredentials.

@Override
public void changeCredentials(S3Credential credential) {
    RefCountedClient newRefCountedClient = (credential != null) ? new RefCountedClient(createClient(null, new BasicAWSCredentials(credential.getAccessKeyId(), credential.getSecretAccessKey()), null)) : new RefCountedClient(createClient(null, null, null));
    RefCountedClient oldRefCountedClient = client.getAndSet(newRefCountedClient);
    if (oldRefCountedClient != null) {
        oldRefCountedClient.markForDelete();
    }
}
Also used : BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 14 with BasicAWSCredentials

use of com.amazonaws.auth.BasicAWSCredentials in project siena by mandubian.

the class SdbPersistenceManager method init.

public void init(Properties p) {
    String awsAccessKeyId = p.getProperty("awsAccessKeyId");
    String awsSecretAccessKey = p.getProperty("awsSecretAccessKey");
    if (awsAccessKeyId == null || awsSecretAccessKey == null)
        throw new SienaException("Both awsAccessKeyId and awsSecretAccessKey properties must be set");
    prefix = p.getProperty("prefix");
    if (prefix == null)
        prefix = "";
    sdb = new AmazonSimpleDBClient(new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey));
}
Also used : AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) SienaException(siena.SienaException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 15 with BasicAWSCredentials

use of com.amazonaws.auth.BasicAWSCredentials in project ORCID-Source by ORCID.

the class S3Utils method createBuckets.

//Create S3 buckets for a given prefix
public static void createBuckets(String bucketPrefix, String accessKey, String secretKey) {
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonS3 s3 = new AmazonS3Client(credentials);
    String api12JsonPrefix = bucketPrefix + "-api-1-2-json-";
    String api12XMLPrefix = bucketPrefix + "-api-1-2-xml-";
    String api20JsonPrefix = bucketPrefix + "-api-2-0-json-";
    String api20XMLPrefix = bucketPrefix + "-api-2-0-xml-";
    for (int i = 0; i <= 10; i++) {
        char lastCharacter = (i == 10 ? 'x' : Character.forDigit(i, 10));
        if (!s3.doesBucketExist(api12JsonPrefix + lastCharacter)) {
            s3.createBucket((api12JsonPrefix + lastCharacter), Region.EU_Ireland);
        }
        if (!s3.doesBucketExist(api12XMLPrefix + lastCharacter)) {
            s3.createBucket((api12XMLPrefix + lastCharacter), Region.EU_Ireland);
        }
        if (!s3.doesBucketExist(api20JsonPrefix + lastCharacter)) {
            s3.createBucket((api20JsonPrefix + lastCharacter), Region.EU_Ireland);
        }
        if (!s3.doesBucketExist(api20XMLPrefix + lastCharacter)) {
            s3.createBucket((api20XMLPrefix + lastCharacter), Region.EU_Ireland);
        }
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)42 AWSCredentials (com.amazonaws.auth.AWSCredentials)25 ClientConfiguration (com.amazonaws.ClientConfiguration)16 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)10 AmazonClientException (com.amazonaws.AmazonClientException)5 InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)4 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)3 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)3 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)3 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)2 StaticCredentialsProvider (com.amazonaws.internal.StaticCredentialsProvider)2 Region (com.amazonaws.regions.Region)2 AmazonCloudWatchClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchClient)2 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 AmazonGlacierClient (com.amazonaws.services.glacier.AmazonGlacierClient)2 AmazonKinesisClient (com.amazonaws.services.kinesis.AmazonKinesisClient)2