List of usage examples for com.amazonaws.auth DefaultAWSCredentialsProviderChain getCredentials
@Override
public AWSCredentials getCredentials()
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 w w w . ja va 2 s . 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;// ww w . java 2s . com 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); }
From source file:com.epam.dlab.auth.modules.AwsSecurityServiceModule.java
License:Apache License
@Provides @Singleton/*w w w .j av a 2 s .c o m*/ private AWSCredentials awsCredentials(DefaultAWSCredentialsProviderChain providerChain) { if (conf.isDevMode()) { return devAwsCredentials(); } else { return providerChain.getCredentials(); } }
From source file:com.mweagle.tereus.aws.CloudFormation.java
License:Open Source License
public Optional<DescribeStacksResult> createStack(final CreateStackRequest request, final Region awsRegion, Logger logger) {// w ww. jav a 2 s . co m DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient( credentialProviderChain.getCredentials()); awsClient.setRegion(awsRegion); logger.info("Creating stack: {}", request.getStackName()); Optional<DescribeStacksResult> completionResult = Optional.empty(); try { // There are no prior events for a creation request Future<CreateStackResult> createStackRequest = awsClient.createStackAsync(request); final CreateStackResult stackResult = createStackRequest.get(); logger.info("Stack ({}) creation in progress.", stackResult.getStackId()); completionResult = waitForStackComplete(awsClient, stackResult.getStackId(), Collections.emptyList(), logger); } catch (Exception ex) { logger.error(ex); } return completionResult; }
From source file:com.mweagle.tereus.aws.CloudFormation.java
License:Open Source License
public Optional<DescribeStacksResult> updateStack(final UpdateStackRequest request, final Region awsRegion, Logger logger) {/* w ww . java2s.co m*/ DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient( credentialProviderChain.getCredentials()); awsClient.setRegion(awsRegion); logger.info("Updating stack: {}", request.getStackName()); Optional<DescribeStacksResult> completionResult = Optional.empty(); try { final List<StackEvent> priorEvents = getStackEvents(awsClient, request.getStackName(), logger); logger.info("Total number of pre-existing stack events: {}", priorEvents.size()); Future<UpdateStackResult> updateStackResult = awsClient.updateStackAsync(request); final UpdateStackResult stackResult = updateStackResult.get(); logger.info("Stack ({}) creation in progress.", stackResult.getStackId()); completionResult = waitForStackComplete(awsClient, request.getStackName(), priorEvents, logger); } catch (Exception ex) { logger.error(ex); } return completionResult; }
From source file:com.mweagle.tereus.aws.S3Resource.java
License:Open Source License
public Optional<String> upload() { try {//from www . j a va 2 s . c om DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); final TransferManager transferManager = new TransferManager(credentialProviderChain.getCredentials()); final ObjectMetadata metadata = new ObjectMetadata(); if (this.inputStreamLength.isPresent()) { metadata.setContentLength(this.inputStreamLength.get()); } final PutObjectRequest uploadRequest = new PutObjectRequest(bucketName, keyName, this.inputStream, metadata); final Upload templateUpload = transferManager.upload(uploadRequest); templateUpload.waitForUploadResult(); this.resourceURL = Optional.of(getS3Path()); } catch (Exception ex) { throw new RuntimeException(ex); } return this.resourceURL; }
From source file:com.mweagle.tereus.input.TereusAWSInput.java
License:Open Source License
public TereusAWSInput(final String awsRegion, final boolean dryRun, final String loggerName) { this.awsRegion = (null != awsRegion) ? Region.getRegion(Regions.fromName(awsRegion)) : Region.getRegion(Regions.US_EAST_1); this.dryRun = dryRun; DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); this.awsCredentials = credentialProviderChain.getCredentials(); this.logger = LogManager.getLogger(loggerName); }
From source file:io.hekate.cluster.seed.jclouds.aws.AwsCredentialsSupplier.java
License:Apache License
@Override public Credentials get() { String identity = getIdentity() != null ? getIdentity().trim() : null; String credential = getCredential() != null ? getCredential().trim() : null; if (identity == null || identity.isEmpty() || credential == null || credential.isEmpty()) { DefaultAWSCredentialsProviderChain chain = new DefaultAWSCredentialsProviderChain(); AWSCredentials cred = chain.getCredentials(); if (cred instanceof BasicSessionCredentials) { BasicSessionCredentials sesCred = (BasicSessionCredentials) cred; return new SessionCredentials.Builder().identity(sesCred.getAWSAccessKeyId()) .credential(sesCred.getAWSSecretKey()).sessionToken(sesCred.getSessionToken()).build(); } else {// ww w . java 2s. co m return new Credentials.Builder<>().identity(cred.getAWSAccessKeyId()) .credential(cred.getAWSSecretKey()).build(); } } return super.get(); }
From source file:io.kodokojo.config.module.AwsModule.java
License:Open Source License
@Provides @Singleton/*from w ww .java 2 s . c o m*/ DnsManager provideDnsManager(ApplicationConfig applicationConfig, AwsConfig awsConfig) { AWSCredentials credentials = null; try { DefaultAWSCredentialsProviderChain defaultAWSCredentialsProviderChain = new DefaultAWSCredentialsProviderChain(); credentials = defaultAWSCredentialsProviderChain.getCredentials(); } catch (RuntimeException e) { LOGGER.warn("Unable to retrieve AWS credentials."); } if (StringUtils.isNotBlank(System.getenv("NO_DNS")) || credentials == null) { LOGGER.info("Using NoOpDnsManager as DnsManger implementation"); return new NoOpDnsManager(); } else { LOGGER.info("Using Route53DnsManager as DnsManger implementation"); return new Route53DnsManager(applicationConfig.domain(), Region.getRegion(Regions.fromName(awsConfig.region()))); } }
From source file:io.kodokojo.config.module.AwsModule.java
License:Open Source License
@Provides @Singleton//from w ww. jav a 2s.c om EmailSender provideEmailSender(AwsConfig awsConfig, EmailConfig emailConfig) { if (StringUtils.isBlank(emailConfig.smtpHost())) { AWSCredentials credentials = null; try { DefaultAWSCredentialsProviderChain defaultAWSCredentialsProviderChain = new DefaultAWSCredentialsProviderChain(); credentials = defaultAWSCredentialsProviderChain.getCredentials(); } catch (RuntimeException e) { LOGGER.warn("Unable to retrieve AWS credentials."); } if (credentials == null) { return new NoopEmailSender(); } else { return new SesEmailSender(emailConfig.smtpFrom(), Region.getRegion(Regions.fromName(awsConfig.region()))); } } else { return new SmtpEmailSender(emailConfig.smtpHost(), emailConfig.smtpPort(), emailConfig.smtpUsername(), emailConfig.smtpPassword(), emailConfig.smtpFrom()); } }