List of usage examples for com.amazonaws.auth ClasspathPropertiesFileCredentialsProvider ClasspathPropertiesFileCredentialsProvider
public ClasspathPropertiesFileCredentialsProvider(String credentialsFilePath)
From source file:arcade.database.S3Connections.java
License:Open Source License
/** * Constructor that connects to S3Instance *///from w w w . j a va2 s . com public S3Connections() { myS3Instance = new AmazonS3Client( new ClasspathPropertiesFileCredentialsProvider("AwsCredentials.properties")); Region usWest2 = Region.getRegion(Regions.US_WEST_2); myS3Instance.setRegion(usWest2); }
From source file:com.chimpler.example.hazelcast.AccountClient.java
License:Apache License
public static HazelcastInstance initHazelcastClient() throws Exception { ClientConfig hazelCastClientConfig = new ClientConfig(); hazelCastClientConfig.getGroupConfig().setName("dev").setPassword("dev-pass"); AWSCredentialsProvider awsCredentialProvider = new ClasspathPropertiesFileCredentialsProvider( "aws.properties"); AmazonEC2Client ec2 = new AmazonEC2Client(awsCredentialProvider); DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones(); System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones."); DescribeInstancesResult describeInstancesRequest = ec2.describeInstances(); for (Reservation reservation : describeInstancesRequest.getReservations()) { for (Instance instance : reservation.getInstances()) { for (GroupIdentifier group : instance.getSecurityGroups()) { if (group.getGroupName().equals("jclouds#hazelcast")) { System.out.println("EC2 instance " + instance.getPublicIpAddress()); hazelCastClientConfig.addAddress(instance.getPublicIpAddress(), instance.getPublicIpAddress() + ":5701"); }/*w ww . j a v a2s. co m*/ } } } HazelcastInstance hazelCastClient = HazelcastClient.newHazelcastClient(hazelCastClientConfig); return hazelCastClient; }
From source file:com.cloud.Assignment.QueueSender.java
License:Open Source License
public boolean sendToQueue(String queue, String message) throws Exception { Properties props = new Properties(); AWSCredentials credentials = null;/* w w w . j a v a2 s . c om*/ String myQueueUrl = null; System.out.println("Queue :" + queue + " Message :" + message); try { credentials = new ClasspathPropertiesFileCredentialsProvider("AwsCredentials.properties") .getCredentials(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); props.load(loader.getResourceAsStream("/QueueURL.properties")); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/prabhus/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usWest2); try { myQueueUrl = props.getProperty(queue); System.out.println("URL :" + myQueueUrl); System.out.println("Sending " + message); sqs.sendMessage(new SendMessageRequest(myQueueUrl, message)); isMessagePosted = true; } catch (AmazonServiceException ase) { throw new AmazonServiceException("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); } catch (AmazonClientException ace) { System.out.println("Error Message: " + ace.getMessage()); throw new AmazonClientException("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); } return isMessagePosted; }
From source file:com.enitalk.configs.AwsConfig.java
@Bean public AWSCredentials awsCredentials() { ClasspathPropertiesFileCredentialsProvider credentials = new ClasspathPropertiesFileCredentialsProvider( "AwsS3Credentials.properties"); return credentials.getCredentials(); }
From source file:com.intuit.s3encrypt.S3Encrypt.java
License:Open Source License
public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { // create Options object Options options = new Options(); options.addOption(create_bucket);/*from w ww .j a v a 2 s . co m*/ options.addOption(create_key); options.addOption(delete_bucket); options.addOption(get); options.addOption(help); options.addOption(inspect); options.addOption(keyfile); options.addOption(list_buckets); options.addOption(list_objects); options.addOption(put); options.addOption(remove); options.addOption(rotate); options.addOption(rotateall); options.addOption(rotateKey); // CommandLineParser parser = new GnuParser(); // Changed from above GnuParser to below PosixParser because I found code which allows for multiple arguments PosixParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); Logger.getRootLogger().setLevel(Level.OFF); if (cmd.hasOption("help")) { HelpFormatter help = new HelpFormatter(); System.out.println(); help.printHelp("S3Encrypt", options); System.out.println(); System.exit(1); } else if (cmd.hasOption("create_key")) { keyname = cmd.getOptionValue("keyfile"); createKeyFile(keyname); key = new File(keyname); } else { if (cmd.hasOption("keyfile")) { keyname = cmd.getOptionValue("keyfile"); } key = new File(keyname); } if (!(key.exists())) { System.out.println("Key does not exist or not provided"); System.exit(1); } // AmazonS3 s3 = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider()); ClasspathPropertiesFileCredentialsProvider credentials = new ClasspathPropertiesFileCredentialsProvider( ".s3encrypt"); EncryptionMaterials encryptionMaterials = new EncryptionMaterials(getKeyFile(keyname)); AmazonS3EncryptionClient s3 = new AmazonS3EncryptionClient(credentials.getCredentials(), encryptionMaterials); // Region usWest2 = Region.getRegion(Regions.US_WEST_2); // s3.setRegion(usWest2); if (cmd.hasOption("create_bucket")) { String bucket = cmd.getOptionValue("create_bucket"); System.out.println("Creating bucket " + bucket + "\n"); s3.createBucket(bucket); } else if (cmd.hasOption("delete_bucket")) { String bucket = cmd.getOptionValue("delete_bucket"); System.out.println("Deleting bucket " + bucket + "\n"); s3.deleteBucket(bucket); } else if (cmd.hasOption("get")) { String[] searchArgs = cmd.getOptionValues("get"); String bucket = searchArgs[0]; String filename = searchArgs[1]; getS3Object(cmd, s3, bucket, filename); } else if (cmd.hasOption("inspect")) { String[] searchArgs = cmd.getOptionValues("inspect"); String bucket = searchArgs[0]; String filename = searchArgs[1]; String keyname = "encryption_key"; String metadata = inspectS3Object(cmd, s3, bucket, filename, keyname); System.out.println(metadata); } else if (cmd.hasOption("list_buckets")) { System.out.println("Listing buckets"); for (Bucket bucket : s3.listBuckets()) { System.out.println(bucket.getName()); } System.out.println(); } else if (cmd.hasOption("list_objects")) { String bucket = cmd.getOptionValue("list_objects"); System.out.println("Listing objects"); ObjectListing objectListing = s3.listObjects(new ListObjectsRequest().withBucketName(bucket)); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println(objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); } else if (cmd.hasOption("put")) { String[] searchArgs = cmd.getOptionValues("put"); String bucket = searchArgs[0]; String filename = searchArgs[1]; String metadataKeyname = "encryption_key"; String key = keyname; putS3Object(cmd, s3, bucket, filename, metadataKeyname, key); } else if (cmd.hasOption("remove")) { String[] searchArgs = cmd.getOptionValues("remove"); String bucket = searchArgs[0]; String filename = searchArgs[1]; System.out.println("Removing object in S3 from BUCKET = " + bucket + " FILENAME = " + filename); s3.deleteObject(new DeleteObjectRequest(bucket, filename)); System.out.println(); } else if (cmd.hasOption("rotate")) { String[] searchArgs = cmd.getOptionValues("rotate"); String bucket = searchArgs[0]; String filename = searchArgs[1]; String key1 = cmd.getOptionValue("keyfile"); String key2 = cmd.getOptionValue("rotateKey"); String metadataKeyname = "encryption_key"; System.out.println("Supposed to get object from here OPTION VALUE = " + bucket + " FILENAME = " + filename + " KEY1 = " + key1 + " KEY2 = " + key2); EncryptionMaterials rotateEncryptionMaterials = new EncryptionMaterials(getKeyFile(key2)); AmazonS3EncryptionClient rotateS3 = new AmazonS3EncryptionClient(credentials.getCredentials(), rotateEncryptionMaterials); getS3Object(cmd, s3, bucket, filename); putS3Object(cmd, rotateS3, bucket, filename, metadataKeyname, key2); } else if (cmd.hasOption("rotateall")) { String[] searchArgs = cmd.getOptionValues("rotateall"); String bucket = searchArgs[0]; String key1 = searchArgs[1]; String key2 = searchArgs[2]; System.out.println("Supposed to rotateall here for BUCKET NAME = " + bucket + " KEY1 = " + key1 + " KEY2 = " + key2); } else { System.out.println("Something went wrong... "); System.exit(1); } } catch (ParseException e) { e.printStackTrace(); } 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 " + "an internal error 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:com.netflix.genie.web.configs.aws.AwsS3Config.java
License:Apache License
/** * Create the credentials needed for the application to be able to connect to Aws. Only triggered if the * property cloud.aws.credentials.provided is set to true in the config. * * @param credentialsFilePath The path of the file containing aws credentials * @return AWS credentials object to use to connect to AWS *//* w w w. jav a2s . co m*/ @Bean @ConditionalOnProperty(value = "genie.aws.credentials.file") public ClasspathPropertiesFileCredentialsProvider awsCredentialsFromFile( @Value("${genie.aws.credentials.file}") final String credentialsFilePath) { log.info("Creating file credentials provider bean"); return new ClasspathPropertiesFileCredentialsProvider(credentialsFilePath); }
From source file:cz.rkr.template.tts.SampleIvonaSpeechCloudCreateSpeech.java
License:Open Source License
private static void init() { speechCloud = new IvonaSpeechCloudClient( new ClasspathPropertiesFileCredentialsProvider("IvonaCredentials2.properties")); speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); }
From source file:cz.rkr.template.tts.SampleIvonaSpeechCloudGetCreateSpeechURL.java
License:Open Source License
private static void init() { speechCloud = new IvonaSpeechCloudClient( new ClasspathPropertiesFileCredentialsProvider("IvonaCredentials.properties")); speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); }
From source file:IvonaSpeechCloudCreateSpeech.SampleIvonaSpeechCloudCreateSpeech.java
License:Open Source License
private static void init() { speechCloud = new IvonaSpeechCloudClient( new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties")); speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); }
From source file:xyz.zaddrot.api.Speaker.java
private static void init(String path) { speechCloud = new IvonaSpeechCloudClient(new ClasspathPropertiesFileCredentialsProvider(path)); speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com"); }