List of usage examples for com.amazonaws.auth DefaultAWSCredentialsProviderChain DefaultAWSCredentialsProviderChain
public DefaultAWSCredentialsProviderChain()
From source file:KinesisStreamDataProducer.java
License:Open Source License
private static void init() throws Exception { kinesisClient = new AmazonKinesisClient(new DefaultAWSCredentialsProviderChain()); }
From source file:alluxio.underfs.s3a.S3AUnderFileSystem.java
License:Apache License
/** * Constructs a new instance of {@link S3AUnderFileSystem}. * * @param uri the {@link AlluxioURI} for this UFS *//*from ww w. jav a 2 s .com*/ public S3AUnderFileSystem(AlluxioURI uri) { super(uri); mBucketName = uri.getHost(); mBucketPrefix = PathUtils.normalizePath(Constants.HEADER_S3A + mBucketName, PATH_SEPARATOR); // Set the aws credential system properties based on Alluxio properties, if they are set if (Configuration.containsKey(PropertyKey.S3A_ACCESS_KEY)) { System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_SYSTEM_PROPERTY, Configuration.get(PropertyKey.S3A_ACCESS_KEY)); } if (Configuration.containsKey(PropertyKey.S3A_SECRET_KEY)) { System.setProperty(SDKGlobalConfiguration.SECRET_KEY_SYSTEM_PROPERTY, Configuration.get(PropertyKey.S3A_SECRET_KEY)); } // Checks, in order, env variables, system properties, profile file, and instance profile AWSCredentialsProvider credentials = new AWSCredentialsProviderChain( new DefaultAWSCredentialsProviderChain()); // Set the client configuration based on Alluxio configuration values ClientConfiguration clientConf = new ClientConfiguration(); // Socket timeout clientConf.setSocketTimeout(Configuration.getInt(PropertyKey.UNDERFS_S3A_SOCKET_TIMEOUT_MS)); // HTTP protocol if (Configuration.getBoolean(PropertyKey.UNDERFS_S3A_SECURE_HTTP_ENABLED)) { clientConf.setProtocol(Protocol.HTTPS); } else { clientConf.setProtocol(Protocol.HTTP); } // Proxy host if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_HOST)) { clientConf.setProxyHost(Configuration.get(PropertyKey.UNDERFS_S3_PROXY_HOST)); } // Proxy port if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_PORT)) { clientConf.setProxyPort(Configuration.getInt(PropertyKey.UNDERFS_S3_PROXY_PORT)); } mClient = new AmazonS3Client(credentials, clientConf); if (Configuration.containsKey(PropertyKey.UNDERFS_S3_ENDPOINT)) { mClient.setEndpoint(Configuration.get(PropertyKey.UNDERFS_S3_ENDPOINT)); } mManager = new TransferManager(mClient); TransferManagerConfiguration transferConf = new TransferManagerConfiguration(); transferConf.setMultipartCopyThreshold(MULTIPART_COPY_THRESHOLD); mManager.setConfiguration(transferConf); mAccountOwnerId = mClient.getS3AccountOwner().getId(); // Gets the owner from user-defined static mapping from S3 canonical user id to Alluxio // user name. String owner = CommonUtils.getValueFromStaticMapping( Configuration.get(PropertyKey.UNDERFS_S3_OWNER_ID_TO_USERNAME_MAPPING), mAccountOwnerId); // If there is no user-defined mapping, use the display name. if (owner == null) { owner = mClient.getS3AccountOwner().getDisplayName(); } mAccountOwner = owner == null ? mAccountOwnerId : owner; AccessControlList acl = mClient.getBucketAcl(mBucketName); mBucketMode = S3AUtils.translateBucketAcl(acl, mAccountOwnerId); }
From source file:awsm.AwsmCredentialsPlugin.java
License:Open Source License
private AwsCredentials getAwsCredentials() { if (gradleAwsCredentials != null) { return gradleAwsCredentials; }//from w w w . j a v a2s . co m final AWSCredentials awsCredentials = new DefaultAWSCredentialsProviderChain().getCredentials(); logger.info("Got AWS credentials {} with access key {}", awsCredentials, awsCredentials.getAWSAccessKeyId()); gradleAwsCredentials = createGradleAwsCredentials(awsCredentials); return gradleAwsCredentials; }
From source file:backup.store.s3.S3BackupStoreUtil.java
License:Apache License
public static void removeBucket(String bucketName) throws Exception { removeAllObjects(bucketName);/* www. j a va2s. c om*/ AmazonS3Client client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); client.deleteBucket(bucketName); }
From source file:backup.store.s3.S3BackupStoreUtil.java
License:Apache License
public static void removeAllObjects(String bucketName) throws Exception { AmazonS3Client client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); ObjectListing listObjects = client.listObjects(bucketName); List<S3ObjectSummary> objectSummaries = listObjects.getObjectSummaries(); for (S3ObjectSummary objectSummary : objectSummaries) { String key = objectSummary.getKey(); client.deleteObject(bucketName, key); }/* w w w . ja v a 2 s . c o m*/ }
From source file:backup.store.s3.S3BackupStoreUtil.java
License:Apache License
public static void removeAllObjects(String bucketName, String prefix) throws Exception { AmazonS3Client client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); ObjectListing listObjects = client.listObjects(bucketName); List<S3ObjectSummary> objectSummaries = listObjects.getObjectSummaries(); for (S3ObjectSummary objectSummary : objectSummaries) { String key = objectSummary.getKey(); if (key.startsWith(prefix)) { client.deleteObject(bucketName, key); }/* ww w .j av a 2s .c om*/ } }
From source file:backup.store.s3.S3BackupStoreUtil.java
License:Apache License
public static boolean exists(String bucketName) throws Exception { AmazonS3Client client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); return client.doesBucketExist(bucketName); }
From source file:backup.store.s3.S3BackupStoreUtil.java
License:Apache License
public static void createBucket(String bucketName) throws Exception { AmazonS3Client client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); client.createBucket(bucketName);//from w w w . j a va 2 s . c om }
From source file:be.ugent.intec.halvade.uploader.AWSUploader.java
License:Open Source License
public AWSUploader(String existingBucketName, boolean sse, String profile) throws IOException { SSE = sse;/*from ww w.j a v a 2s. c o m*/ this.profile = profile; this.existingBucketName = existingBucketName; AWSCredentials c; try { DefaultAWSCredentialsProviderChain prov = new DefaultAWSCredentialsProviderChain(); c = prov.getCredentials(); } catch (AmazonClientException ex) { // read from ~/.aws/credentials String access = null; String secret = null; try (BufferedReader br = new BufferedReader( new FileReader(System.getProperty("user.home") + "/.aws/credentials"))) { String line; while ((line = br.readLine()) != null && !line.contains("[" + this.profile + "]")) { } line = br.readLine(); if (line != null) access = line.split(" = ")[1]; line = br.readLine(); if (line != null) secret = line.split(" = ")[1]; } c = new BasicAWSCredentials(access, secret); } this.tm = new TransferManager(c); }
From source file:be.ugent.intec.halvade.uploader.CopyOfAWSUploader.java
License:Open Source License
public CopyOfAWSUploader(String existingBucketName) throws IOException { this.existingBucketName = existingBucketName; AWSCredentials c;//w ww. java 2s. c o m try { DefaultAWSCredentialsProviderChain prov = new DefaultAWSCredentialsProviderChain(); c = prov.getCredentials(); } catch (AmazonClientException ex) { // read from ~/.aws/credentials String access = null; String secret = null; try (BufferedReader br = new BufferedReader( new FileReader(System.getProperty("user.home") + "/.aws/credentials"))) { String line; while ((line = br.readLine()) != null && !line.contains("[default]")) { } line = br.readLine(); if (line != null) access = line.split(" = ")[1]; line = br.readLine(); if (line != null) secret = line.split(" = ")[1]; } c = new BasicAWSCredentials(access, secret); } this.tm = new TransferManager(c); }