List of usage examples for com.amazonaws.auth PropertiesCredentials PropertiesCredentials
public PropertiesCredentials(InputStream inputStream) throws IOException
From source file:org.apache.nifi.processors.aws.s3.AbstractS3IT.java
License:Apache License
@BeforeClass public static void oneTimeSetup() { // Creates a client and bucket for this test final FileInputStream fis; try {/*w w w . j a va2 s .co m*/ fis = new FileInputStream(CREDENTIALS_FILE); } catch (FileNotFoundException e1) { fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e1.getLocalizedMessage()); return; } try { final PropertiesCredentials credentials = new PropertiesCredentials(fis); client = new AmazonS3Client(credentials); if (client.doesBucketExist(BUCKET_NAME)) { fail("Bucket " + BUCKET_NAME + " exists. Choose a different bucket name to continue test"); } CreateBucketRequest request = REGION.contains("east") ? new CreateBucketRequest(BUCKET_NAME) // See https://github.com/boto/boto3/issues/125 : new CreateBucketRequest(BUCKET_NAME, REGION); client.createBucket(request); } catch (final AmazonS3Exception e) { fail("Can't create the key " + BUCKET_NAME + ": " + e.getLocalizedMessage()); } catch (final IOException e) { fail("Caught IOException preparing tests: " + e.getLocalizedMessage()); } finally { FileUtils.closeQuietly(fis); } if (!client.doesBucketExist(BUCKET_NAME)) { fail("Setup incomplete, tests will fail"); } }
From source file:org.applicationMigrator.migrationclient.User.java
License:Apache License
private AWSCredentials readCredentialsFromPropertiesFile(String credentialsFilePath) throws FileNotFoundException, IOException { AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFilePath)); return credentials; }
From source file:org.applicationMigrator.userManagement.UserManagementWorker.java
License:Apache License
private void createUser(String ANDROID_ID) throws FileNotFoundException, IllegalArgumentException, IOException { Random randomizer = new Random(System.currentTimeMillis()); String userName = "User" + randomizer.nextDouble(); CreateUserRequest user = new CreateUserRequest(); user.setUserName(userName);/*www . j a v a 2s . c om*/ AWSCredentials credentials = new PropertiesCredentials( new File("C:\\AndroidMigration\\Credentials\\AwsCredentials.properties")); AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(credentials); CreateUserResult result = null; AccessKey accessKey = null; try { boolean userCreatedSuccessfully = false; while (!userCreatedSuccessfully) { try { result = client.createUser(user); userCreatedSuccessfully = true; } catch (EntityAlreadyExistsException exception) { user.setUserName(userName + randomizer.nextDouble()); userCreatedSuccessfully = false; } } CreateAccessKeyRequest accessKeyRequest = new CreateAccessKeyRequest(); accessKeyRequest.setUserName(result.getUser().getUserName()); CreateAccessKeyResult accessKeyResult = client.createAccessKey(accessKeyRequest); accessKey = accessKeyResult.getAccessKey(); grantPermissions(user, client); File userList = new File(USER_LIST_FILEPATH); BufferedWriter userListFileWriter = new BufferedWriter(new FileWriter(userList)); // Concurrency ? userListFileWriter.write(ANDROID_ID + " "); userListFileWriter.write(accessKey.getAccessKeyId() + " "); userListFileWriter.write(accessKey.getSecretAccessKey() + " "); userListFileWriter.write(user.getUserName() + " "); userListFileWriter.close(); } catch (Exception e) { if (accessKey != null) { DeleteAccessKeyRequest deleteAccessKeyRequest = new DeleteAccessKeyRequest( accessKey.getAccessKeyId()); deleteAccessKeyRequest.setUserName(user.getUserName()); client.deleteAccessKey(deleteAccessKeyRequest); DeleteUserRequest deleteUserRequest = new DeleteUserRequest(user.getUserName()); client.deleteUser(deleteUserRequest); } throw e; } }
From source file:org.boriken.s3fileuploader.S3SampleRefactored.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*from w w w .j av a2 s . c o m*/ * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ AmazonS3 s3 = new AmazonS3Client(new PropertiesCredentials( S3SampleRefactored.class.getResourceAsStream("../conf/AwsCredentials.properties"))); // String bucketName = "chamakits-my-first-s3-bucket-" + UUID.randomUUID(); String bucketName = "chamakits-HelloS3"; String key = "somekey"; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); try { // createBucket(s3,bucketName); // listBuckets(s3); // createFile(s3,bucketName,key); // downloadFile(s3,bucketName,key); // listFiles(s3, bucketName,""); // deleteFile(s3, bucketName, key); // deleteBucket(s3, bucketName); listFiles(s3, bucketName, ""); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon S3, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:org.chombo.util.ConfigurationLoader.java
License:Apache License
/** * @param confFilePath/* w ww .j a v a 2s . co m*/ * @return * @throws IOException */ private boolean loadConfigS3(String confFilePath) throws IOException { Matcher matcher = s3pattern.matcher(confFilePath); matcher.matches(); String bucket = matcher.group(1); String key = matcher.group(2); AmazonS3 s3 = new AmazonS3Client( new PropertiesCredentials(Utility.class.getResourceAsStream("AwsCredentials.properties"))); S3Object object = s3.getObject(new GetObjectRequest(bucket, key)); InputStream fis = object.getObjectContent(); List<String> lines = getConfigLines(fis); setFilteredConfiguration(lines); return true; }
From source file:org.chombo.util.Utility.java
License:Apache License
private static boolean loadConfigS3(Configuration conf, String confFilePath) throws IOException { Matcher matcher = s3pattern.matcher(confFilePath); matcher.matches();//w w w .j a va2s .c o m String bucket = matcher.group(1); String key = matcher.group(2); AmazonS3 s3 = new AmazonS3Client( new PropertiesCredentials(Utility.class.getResourceAsStream("AwsCredentials.properties"))); S3Object object = s3.getObject(new GetObjectRequest(bucket, key)); InputStream is = object.getObjectContent(); Properties configProps = new Properties(); configProps.load(is); for (Object keyObj : configProps.keySet()) { String keySt = keyObj.toString(); conf.set(keySt, configProps.getProperty(keySt)); } return true; }
From source file:org.deeplearning4j.aws.s3.BaseS3.java
License:Apache License
public BaseS3(File file) throws Exception { if (accessKey != null && secretKey != null) creds = new BasicAWSCredentials(accessKey, secretKey); else/* w ww .j a va 2s.c om*/ creds = new PropertiesCredentials(file); }
From source file:org.deeplearning4j.aws.s3.BaseS3.java
License:Apache License
public BaseS3(InputStream is) throws Exception { if (accessKey != null && secretKey != null) creds = new BasicAWSCredentials(accessKey, secretKey); else//from ww w. j av a2s . c o m creds = new PropertiesCredentials(is); }
From source file:org.exem.flamingo.web.filesystem.s3.AwsS3Factory.java
License:Apache License
/** * Properties? Input Stream? ? ./*from www. j a va 2 s .c o m*/ * Properties? <tt>accessKey</tt> <tt>secretKey</tt>? ?? . * * @return {@link AmazonS3} * @throws IOException Properties ?? Input Stream? */ private static AmazonS3 createS3Client(InputStream is) throws IOException { AWSCredentials credentials = new PropertiesCredentials(is); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTP); return new AmazonS3Client(credentials, clientConfig); }
From source file:org.geppetto.persistence.s3.S3Manager.java
License:Open Source License
private AmazonS3 getS3Connection() { if (_s3Connection == null) { File credentialsFile = new File(PersistenceHelper.SETTINGS_DIR + "/aws.credentials"); try {/*from w ww.ja v a2s. c om*/ _s3Connection = new AmazonS3Client(new PropertiesCredentials(credentialsFile)); } catch (Exception e) { _logger.warn("Could not initialize S3 connection", e); } } return _s3Connection; }