List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:com.netflix.exhibitor.core.s3.S3ClientFactoryImpl.java
License:Apache License
@Override public S3Client makeNewClient(final S3Credential credentials) throws Exception { return new S3Client() { private final AtomicReference<RefCountedClient> client = new AtomicReference<RefCountedClient>(null); {//from w w w . j a va 2 s . co m changeCredentials(credentials); } @Override public void changeCredentials(S3Credential credential) throws Exception { RefCountedClient newRefCountedClient = (credential != null) ? new RefCountedClient( new AmazonS3Client(new BasicAWSCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey()))) : null; RefCountedClient oldRefCountedClient = client.getAndSet(newRefCountedClient); if (oldRefCountedClient != null) { oldRefCountedClient.markForDelete(); } } @Override public void close() throws IOException { try { changeCredentials(null); } catch (Exception e) { throw new IOException(e); } } @Override public InitiateMultipartUploadResult initiateMultipartUpload(InitiateMultipartUploadRequest request) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { return amazonS3Client.initiateMultipartUpload(request); } finally { holder.release(); } } @Override public PutObjectResult putObject(PutObjectRequest request) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { return amazonS3Client.putObject(request); } finally { holder.release(); } } @Override public S3Object getObject(String bucket, String key) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { return amazonS3Client.getObject(bucket, key); } finally { holder.release(); } } @Override public ObjectListing listObjects(ListObjectsRequest request) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { return amazonS3Client.listObjects(request); } finally { holder.release(); } } @Override public ObjectListing listNextBatchOfObjects(ObjectListing previousObjectListing) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { return amazonS3Client.listNextBatchOfObjects(previousObjectListing); } finally { holder.release(); } } @Override public void deleteObject(String bucket, String key) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { amazonS3Client.deleteObject(bucket, key); } finally { holder.release(); } } @Override public UploadPartResult uploadPart(UploadPartRequest request) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { return amazonS3Client.uploadPart(request); } finally { holder.release(); } } @Override public void completeMultipartUpload(CompleteMultipartUploadRequest request) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { amazonS3Client.completeMultipartUpload(request); } finally { holder.release(); } } @Override public void abortMultipartUpload(AbortMultipartUploadRequest request) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { amazonS3Client.abortMultipartUpload(request); } finally { holder.release(); } } }; }
From source file:com.netflix.exhibitor.core.s3.S3ClientImpl.java
License:Apache License
@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(); }//from w w w . j ava 2 s. c om }
From source file:com.netflix.exhibitor.core.s3.S3ClientImpl.java
License:Apache License
@Override public void changeCredentials(S3Credential credential, S3ClientConfig clientConfig) { RefCountedClient newRefCountedClient = (credential != null) ? new RefCountedClient(createClient(null, new BasicAWSCredentials(credential.getAccessKeyId(), credential.getSecretAccessKey()), clientConfig)) : new RefCountedClient(createClient(null, null, clientConfig)); RefCountedClient oldRefCountedClient = client.getAndSet(newRefCountedClient); if (oldRefCountedClient != null) { oldRefCountedClient.markForDelete(); }//from ww w.jav a 2 s .c om }
From source file:com.netflix.priam.defaultimpl.ClearCredential.java
License:Apache License
public AWSCredentialsProvider getAwsCredentialProvider() { return new AWSCredentialsProvider() { public AWSCredentials getCredentials() { return new BasicAWSCredentials(AWS_ACCESS_ID, AWS_KEY); }// w ww. j av a 2s .c o m public void refresh() { // NOP } }; }
From source file:com.netflix.simianarmy.aws.AWSClient.java
License:Apache License
/** * Instantiates a new AWS client./*from w w w . j a v a2 s . co m*/ * * @param accessKey * the access key * @param secretKey * the secret key * @param region * the region */ public AWSClient(String accessKey, String secretKey, String region) { this.cred = new BasicAWSCredentials(accessKey, secretKey); this.region = region; }
From source file:com.netflix.spinnaker.clouddriver.artifacts.s3.S3ArtifactCredentials.java
License:Apache License
private AmazonS3 getS3Client() { AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); if (!StringUtils.isEmpty(apiEndpoint)) { AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration( apiEndpoint, apiRegion); builder.setEndpointConfiguration(endpoint); builder.setPathStyleAccessEnabled(true); } else if (!StringUtils.isEmpty(region)) { builder.setRegion(region);/*from ww w. j av a2 s . c o m*/ } if (!StringUtils.isEmpty(awsAccessKeyId) && !StringUtils.isEmpty(awsSecretAccessKey)) { BasicAWSCredentials awsStaticCreds = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey); builder.withCredentials(new AWSStaticCredentialsProvider(awsStaticCreds)); } return builder.build(); }
From source file:com.netflix.spinnaker.halyard.config.validate.v1.providers.aws.AwsAccountValidator.java
License:Apache License
public static AWSCredentialsProvider getAwsCredentialsProvider(String accessKeyId, String secretKey) { if (accessKeyId != null && secretKey != null) { return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, secretKey)); } else {/*from www .j a v a 2 s.c o m*/ return DefaultAWSCredentialsProviderChain.getInstance(); } }
From source file:com.neu.cloud.Controller.FifthUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase5-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {//from w w w .ja v a2 s. c om System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } 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.neu.cloud.Controller.FirstUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase1-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {//from w w w . j a v a 2 s.c om System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } 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.neu.cloud.Controller.FourthUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase4-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {/*from ww w . j av a 2s. co m*/ System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } 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()); } }