List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:io.jeffrey.web.Wake.java
public static void main(String[] args) throws Exception { String configFilename = ".wake"; for (int k = 0; k < args.length - 1; k++) { if ("--config".equals(args[k]) || "-c".equals(args[k])) { configFilename = args[k + 1]; }// ww w. jav a 2 s.co m } File configFile = new File(configFilename); Config config; if (configFile.exists()) { FileReader reader = new FileReader(configFile); try { config = new Config(reader); } finally { reader.close(); ; } } else { // roll with the defaults (thus, no deployment config = new Config(); } ArrayList<String> errors = new ArrayList<>(); File input = config.getFile(Config.ConfigFile.Input, errors); File merge = config.getFile(Config.ConfigFile.Merge, errors); File output = null; String bucket = config.get(Config.ConfigKey.Bucket, false, errors); String redirectBucket = config.get(Config.ConfigKey.RedirectBucket, false, errors); AmazonS3 s3 = null; if (bucket != null) { String accessKey = config.get(Config.ConfigKey.AccessKey, true, errors); String secret = config.get(Config.ConfigKey.SecretKey, true, errors); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secret); s3 = new AmazonS3Client(credentials); } else { output = config.getFile(Config.ConfigFile.Output, errors); } if (errors.size() > 0) { System.err.println("There were too many errors:"); errors.forEach((error) -> System.err.println(error)); return; } // load them from disk DiskLoaderStage raw = new DiskLoaderStage(input); // sort them for giggles SortByOrderStage sorted = new SortByOrderStage(raw); // inject the topology (connect the pages together according to the one true tree) InjectTopologyStage withTopology = new InjectTopologyStage(sorted); // inject snippets SnippetInjectorStage withSnippets = new SnippetInjectorStage(withTopology); // put templates into place TemplateCrossStage withTemplates = new TemplateCrossStage(withSnippets); // assemble the manifest InMemoryAssembler assembly = new InMemoryAssembler(merge, withTemplates); // build the spelling page // TODO: clean this up final StringBuilder spelling = new StringBuilder(); spelling.append("<pre>"); assembly.validate((url, html) -> { try { spelling.append("<h1>" + url + "</h1>\n"); JLanguageTool langTool = new JLanguageTool(new AmericanEnglish()); langTool.activateDefaultPatternRules(); Document doc = Jsoup.parse(html); Elements elements = doc.select("p"); elements.forEach((element) -> { String plain = new HtmlToPlainText().getPlainText(element); plain = plain.replaceAll(" \\s*", " "); plain = plain.replaceAll("\\s* ", " "); try { List<RuleMatch> matches = langTool.check(plain); if (matches.size() > 0) { spelling.append(plain); spelling.append("\n"); for (RuleMatch match : matches) { spelling.append("Potential error at line " + match.getLine() + ", column " + match.getColumn() + ": " + match.getMessage()); spelling.append("\n"); spelling.append("Suggested correction: " + match.getSuggestedReplacements()); spelling.append("\n"); } } } catch (IOException ioe) { throw new RuntimeException(ioe); } }); } catch (Exception err) { System.err.println("Exception checking:" + url); err.printStackTrace(); } }); spelling.append("</pre>"); // let's simply write it to disk PutTarget target; if (s3 == null) { System.out.println("writing to disk"); target = new DiskPutTarget(output); } else { System.out.println("writing to s3"); target = new S3PutObjectTarget(bucket, s3); } assembly.put("__spelling.html", spelling.toString()); // engage! assembly.assemble(target); }
From source file:io.konig.camel.aws.s3.DeleteObjectComponentVerifierExtension.java
License:Apache License
@Override protected Result verifyConnectivity(Map<String, Object> parameters) { ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY); try {/* w ww .j a va 2s .co m*/ S3Configuration configuration = setProperties(new S3Configuration(), parameters); AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider) .withRegion(Regions.valueOf(configuration.getRegion())).build(); client.listBuckets(); } catch (SdkClientException e) { ResultErrorBuilder errorBuilder = ResultErrorBuilder .withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) .detail("aws_s3_exception_message", e.getMessage()) .detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()) .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e); builder.error(errorBuilder.build()); } catch (Exception e) { builder.error(ResultErrorBuilder.withException(e).build()); } return builder.build(); }
From source file:io.konig.camel.component.aws.s3.client.impl.S3ClientStandardImpl.java
License:Apache License
/** * Getting the s3 aws client that is used. * @return Amazon S3 Client.//from w w w . jav a 2 s. com */ public AmazonS3 getS3Client() { AmazonS3 client = null; AmazonS3ClientBuilder clientBuilder = null; AmazonS3EncryptionClientBuilder encClientBuilder = null; ClientConfiguration clientConfiguration = null; if (configuration.hasProxyConfiguration()) { clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(configuration.getProxyHost()); clientConfiguration.setProxyPort(configuration.getProxyPort()); clientConfiguration.setMaxConnections(maxConnections); } else { clientConfiguration = new ClientConfiguration(); clientConfiguration.setMaxConnections(maxConnections); } if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); if (!configuration.isUseEncryption()) { clientBuilder = AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfiguration) .withCredentials(credentialsProvider); } else if (configuration.isUseEncryption()) { StaticEncryptionMaterialsProvider encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider( configuration.getEncryptionMaterials()); encClientBuilder = AmazonS3EncryptionClientBuilder.standard() .withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider) .withEncryptionMaterials(encryptionMaterialsProvider); } else { clientBuilder = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider); } if (!configuration.isUseEncryption()) { if (ObjectHelper.isNotEmpty(configuration.getRegion())) { clientBuilder = clientBuilder.withRegion(Regions.valueOf(configuration.getRegion())); } clientBuilder = clientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess()); client = clientBuilder.build(); } else { if (ObjectHelper.isNotEmpty(configuration.getRegion())) { encClientBuilder = encClientBuilder.withRegion(Regions.valueOf(configuration.getRegion())); } encClientBuilder = encClientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess()); client = encClientBuilder.build(); } } else { if (!configuration.isUseEncryption()) { clientBuilder = AmazonS3ClientBuilder.standard(); } else if (configuration.isUseEncryption()) { StaticEncryptionMaterialsProvider encryptionMaterialsProvider = new StaticEncryptionMaterialsProvider( configuration.getEncryptionMaterials()); encClientBuilder = AmazonS3EncryptionClientBuilder.standard() .withClientConfiguration(clientConfiguration) .withEncryptionMaterials(encryptionMaterialsProvider); } else { clientBuilder = AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfiguration); } if (!configuration.isUseEncryption()) { if (ObjectHelper.isNotEmpty(configuration.getRegion())) { clientBuilder = clientBuilder.withRegion(Regions.valueOf(configuration.getRegion())); } clientBuilder = clientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess()); client = clientBuilder.build(); } else { if (ObjectHelper.isNotEmpty(configuration.getRegion())) { encClientBuilder = encClientBuilder.withRegion(Regions.valueOf(configuration.getRegion())); } encClientBuilder = encClientBuilder.withPathStyleAccessEnabled(configuration.isPathStyleAccess()); client = encClientBuilder.build(); } } return client; }
From source file:io.konig.etl.aws.CamelEtlRouteController.java
License:Apache License
@Bean AmazonSQSClient sqsClient() { AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY); return new AmazonSQSClient(credentials); }
From source file:io.konig.etl.aws.CamelEtlRouteController.java
License:Apache License
@Bean AmazonS3Client s3Client() { AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY); return new AmazonS3Client(credentials); }
From source file:io.konig.maven.AwsDeployment.java
License:Apache License
AWSStaticCredentialsProvider getCredential() throws InvalidAWSCredentialsException { verifyAWSCredentials();//from ww w . j a v a2s. c om return new AWSStaticCredentialsProvider(new BasicAWSCredentials(System.getProperty("aws.accessKeyId"), System.getProperty("aws.secretKey"))); }
From source file:io.konig.schemagen.aws.AWSCloudFormationUtil.java
License:Apache License
public static AWSStaticCredentialsProvider getCredential() throws InvalidAWSCredentialsException { verifyAWSCredentials();/*from w w w .java 2 s . c o m*/ return new AWSStaticCredentialsProvider(new BasicAWSCredentials(System.getProperty("aws.accessKeyId"), System.getProperty("aws.secretKey"))); }
From source file:io.macgyver.plugin.cloud.aws.AWSServiceFactory.java
License:Apache License
private AWSCredentialsProvider getCredentialsProvider(ServiceDefinition def) { String accessKey = def.getProperty("accessKey"); String secretKey = def.getProperty("secretKey"); if (!StringUtils.isNullOrEmpty(accessKey) && !StringUtils.isNullOrEmpty(secretKey)) { logger.info("using static credentials " + accessKey + " for AWS service " + def.getName()); return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); }/* w ww . j a v a2s . c o m*/ String sourceService = def.getProperty("sourceService"); String assumeRoleName = def.getProperty("assumeRoleName"); if (!StringUtils.isNullOrEmpty(sourceService) && !StringUtils.isNullOrEmpty(assumeRoleName)) { String roleArn = "arn:aws:iam::" + def.getProperty("accountId") + ":role/" + assumeRoleName; logger.info("using assume-role credentials for " + roleArn + " from " + sourceService + " for AWS service " + def.getName()); return new AWSServiceClientAssumeRoleCredentialsProvider(registry, sourceService, roleArn); } logger.info("using default credentials provider for AWS service " + def.getName()); return new DefaultAWSCredentialsProviderChain(); }
From source file:io.pivotal.strepsirrhini.chaoslemur.infrastructure.InfrastructureConfiguration.java
License:Apache License
@Bean @ConditionalOnProperty("aws.accessKeyId") AmazonEC2Client amazonEC2(@Value("${aws.accessKeyId}") String accessKeyId, @Value("${aws.secretAccessKey}") String secretAccessKey, @Value("${aws.region:us-east-1}") String regionName) { AmazonEC2Client amazonEC2Client = new AmazonEC2Client( new BasicAWSCredentials(accessKeyId, secretAccessKey)); Region region = Region.getRegion(Regions.fromName(regionName)); amazonEC2Client.setEndpoint(region.getServiceEndpoint("ec2")); return amazonEC2Client; }
From source file:io.pivotal.xd.chaoslemur.infrastructure.InfrastructureConfiguration.java
License:Apache License
@Bean @ConditionalOnProperty("aws.accessKeyId") AmazonEC2 amazonEC2(@Value("${aws.accessKeyId}") String accessKeyId, @Value("${aws.secretAccessKey}") String secretAccessKey) { return new AmazonEC2Client(new BasicAWSCredentials(accessKeyId, secretAccessKey)); }