public static AWSCredentialsProvider getCredentialProviderC(Parameters config){ List<AWSCredentialsProvider> providers = new ArrayList<AWSCredentialsProvider>(); if ("YES".equals(config.get("aws.credentials.instaneProfile"))) providers.add(new InstanceProfileCredentialsProvider()); if ("YES".equals(config.get("aws.credentials.environmentVariable"))) providers.add(new EnvironmentVariableCredentialsProvider()); if ("YES".equals(config.get("aws.credentials.systemProperties"))) providers.add(new SystemPropertiesCredentialsProvider()); String accessKey = config.get("aws.credentials.accessKey").toString(); String secretKey = config.get("aws.credentials.secretKey").toString(); if (accessKey != null && accessKey.length() > 0){ providers.add(new AWSCredentialsConfigFileProvider(accessKey, secretKey)); } return new AWSCredentialsProviderChain(providers.toArray(new AWSCredentialsProvider[0])); }
public static AWSCredentialsProviderChain getAWSCredentialsProviderChain() { String cerberusRoleToAssume = System.getenv(CERBERUS_ASSUME_ROLE_ARN) != null ? System.getenv(CERBERUS_ASSUME_ROLE_ARN) : ""; String cerberusRoleToAssumeExternalId = System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) != null ? System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) : ""; STSAssumeRoleSessionCredentialsProvider sTSAssumeRoleSessionCredentialsProvider = new STSAssumeRoleSessionCredentialsProvider .Builder(cerberusRoleToAssume, UUID.randomUUID().toString()) .withExternalId(cerberusRoleToAssumeExternalId) .build(); AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain( new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(), sTSAssumeRoleSessionCredentialsProvider, new InstanceProfileCredentialsProvider()); return chain; }
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { String apiIntputStream = new Scanner(inputStream).useDelimiter("\\A").next(); JsonNode rootNode = (new ObjectMapper(new JsonFactory())).readTree(apiIntputStream); String myApiId = rootNode.path("requestContext").path("apiId").asText(); if (myApiId.isEmpty()) { myApiId = "TODO"; } // Not called from API Gateway final GenericApiGatewayClient client = new GenericApiGatewayClientBuilder() .withClientConfiguration(new ClientConfiguration()) .withCredentials(new EnvironmentVariableCredentialsProvider()) .withEndpoint("https://" + myApiId + ".execute-api.us-west-2.amazonaws.com") // your API ID .withRegion(Region.getRegion(Regions.fromName("us-west-2"))) .build(); GenericApiGatewayResponse apiResponse; ProxyResponse resp; try { apiResponse = client.execute( // throws exception for non-2xx response new GenericApiGatewayRequestBuilder() .withHttpMethod(HttpMethodName.GET) .withResourcePath("/Prod/hello").build()); System.out.println("Response: " + apiResponse.getBody()); System.out.println("Status: " + apiResponse.getHttpResponse().getStatusCode()); resp = new ProxyResponse("200", apiResponse.getBody()); } catch (GenericApiGatewayException e) { System.out.println("Client threw exception " + e); resp = new ProxyResponse("400", e.getMessage()); } String responseString = new ObjectMapper(new JsonFactory()).writeValueAsString(resp); OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8"); writer.write(responseString); writer.close(); }
@SuppressWarnings("deprecation") public ApiImporter(String profile, String accessKey, String secret) { if (accessKey != null && secret != null) { credentialsProvider=new AWSCredentialsProvider() { @Override public void refresh() { } @Override public AWSCredentials getCredentials() { return new AWSCredentials() { @Override public String getAWSSecretKey() { return secret; } @Override public String getAWSAccessKeyId() { return accessKey; } }; } }; } else { credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(profile), new InstanceProfileCredentialsProvider()); } amazonApiGatewayClient = new AmazonApiGatewayClient(credentialsProvider); }
MyCredentialsProvider() { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), // Removed due to ElasticBeanstalk environment not being setup with a profile dir // new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider(), new ClasspathPropertiesFileCredentialsProvider()); }
public byte[] getFromAWSS3Storage(String name) throws Exception { AmazonS3 s3Client = new AmazonS3Client(new EnvironmentVariableCredentialsProvider()); S3Object object = s3Client.getObject( new GetObjectRequest(containerName, name)); InputStream objectData = object.getObjectContent(); return IOUtils.toByteArray(objectData); }
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) { super( new InstanceProfileCredentialsProvider(), new ProfileCredentialsProvider(), new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); }
private AmazonS3Client getS3Client() { Optional<AWSCredentials> credentials = getCredentials(); if (credentials.isPresent()) { return new AmazonS3Client(credentials.get()); } else { return new AmazonS3Client(new EnvironmentVariableCredentialsProvider()); } }
private AmazonSNSClient getSNSClient() { Optional<AWSCredentials> credentials = getCredentials(); if (credentials.isPresent()) { return new AmazonSNSClient(credentials.get()); } else { return new AmazonSNSClient(new EnvironmentVariableCredentialsProvider()); } }
@Test @Ignore public void shouldPerformUploadToS3Bucket() throws Exception { File testFile = FileGenerator.generate(temporaryFolder.getRoot(), (1024 * 1024 * 1)); ByteRange byteRange = new ByteRange(0, testFile.length() - 1); ImmutableList<HashStrategy> hashStrategies = ImmutableList.of(Hashes.getHashStrategy(Hashes.SHA256, byteRange), Hashes.getHashStrategy(Hashes.MD5_BASE64, byteRange)); List<Hash> hashes; try (FileInputStream fileInputStream = new FileInputStream(testFile)) { hashes = ByteStreams.readBytes(fileInputStream, new HashByteProcessor(hashStrategies)); } Comparator<Hash> hashComparator = (o1, o2) -> o1.getOffset().compareTo(o2.getOffset()); List<Hash> signingHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.SHA256)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList()); List<Hash> partHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.MD5_BASE64)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList()); EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider(); AWSCredentials credentials = credentialsProvider.getCredentials(); S3Upload s3Upload = new S3Upload(credentials, HOST, "us-west-1", "/" + KEY, BUCKET, KEY, null); try (FileInputStream fileInputStream = new FileInputStream(testFile)) { s3Client.uploadObject(s3Upload, "testing", signingHashes.get(0).getValue(), partHashes.get(0).getValue(), testFile.length(), fileInputStream); } catch (Exception e) { LOGGER.error(e, e); } }
@Test @Ignore public void shouldPerformMultipartUploadToS3Bucket() throws Exception { File testFile = FileGenerator.generate(temporaryFolder.getRoot(), (1024 * 1024 * 10)); ImmutableList<HashStrategy> hashStrategies = Hashes.createByteRanges(PART_SIZE, testFile.length()).stream() .map(byteRange -> ImmutableList.of(Hashes.getHashStrategy(Hashes.SHA256, byteRange), Hashes.getHashStrategy(Hashes.MD5_BASE64, byteRange))).collect(ImmutableListsCollector.toImmutableList()); List<Hash> hashes; try (FileInputStream fileInputStream = new FileInputStream(testFile)) { hashes = ByteStreams.readBytes(fileInputStream, new HashByteProcessor(hashStrategies)); } Comparator<Hash> hashComparator = (o1, o2) -> o1.getOffset().compareTo(o2.getOffset()); List<Hash> signingHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.SHA256)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList()); List<Hash> partHashes = hashes.stream().filter(hash -> hash.getAlgorithm().equals(Hashes.MD5_BASE64)).sorted(hashComparator).collect(ImmutableListCollector.toImmutableList()); List<AWSUploadPart> uploadParts = IntStream.range(0, signingHashes.size()).mapToObj(index -> { Hash signingHash = signingHashes.get(index); Hash partHash = partHashes.get(index); return new AWSUploadPart(index, signingHash.getOffset(), signingHash.getLength().get(), signingHash.getValue(), partHash.getValue()); }).collect(ImmutableListCollector.toImmutableList()); EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider(); AWSCredentials credentials = credentialsProvider.getCredentials(); S3Upload initS3Upload = new S3Upload(credentials, HOST, "us-west-1", "/" + KEY, BUCKET, KEY, null); String uploadId = s3Client.initiateMultipartUpload(initS3Upload, testFile.getName()); S3Upload s3Upload = new S3Upload(credentials, HOST, "us-west-1", "/" + KEY, BUCKET, KEY, uploadId); try (FileInputStream fileInputStream = new FileInputStream(testFile)) { List<S3Part> s3Parts = uploadParts.stream().map(uploadPart -> s3Client.uploadMultipartPart(s3Upload, uploadPart, PART_SIZE, fileInputStream)).collect(Collectors.toList()); s3Client.completeMultipartUpload(s3Upload, s3Parts); } catch (Exception e) { LOGGER.error(e, e); s3Client.abortMultipartUpload(s3Upload); } }
@Test @Ignore public void shouldUploadToGlacierVault() throws Exception { File testFile = FileGenerator.generate(temporaryFolder.getRoot(), (1024 * 1024 * 10)); // create SHA-256 and MD5 hashes for each part EnvironmentVariableCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider(); AWSCredentials credentials = credentialsProvider.getCredentials(); String uploadId = glacierClient.initiateMultipartUpload(credentials, "us-west-1", "dev", "testing", 4194304); try (FileInputStream fileInputStream = new FileInputStream(testFile)) { URI destination = new URI("glacier://" + credentials.getAWSAccessKeyId() + ":" + credentials.getAWSSecretKey() + "@glacier.us-west-1.amazonaws.com/-/vaults/dev/multipart-uploads/" + uploadId); GlacierUpload glacierUpload = AWSClients.glacierUploadFromURI(destination); ImmutableList.Builder<AWSUploadPart> uploadPartBuilder = ImmutableList.builder(); uploadPartBuilder .add(new AWSUploadPart(0, 0, 4194304, "c72bed74619a0238b707f13fd6ee8bec14cc7779caca89248350ebc1ac9725ec", "ec9364f600b5e47c533056a548fda46affb964198244fe9d08540ad3884aa89f")); uploadPartBuilder.add(new AWSUploadPart(1, 4194304, 8388608, "dfc5f7fead60530c8f6155ef3405e7b1f21bdabf2dc2a7dc26573ad6dd44251e", "9deb0b59576f96e20efb79d09c274b6db16533314d37d1f1b74145283550031f")); uploadPartBuilder.add(new AWSUploadPart(2, 8388608, 10486525, "1da69b95fc1a32b26957c70b39fd3adf88c4726f77cf338fbeecf43bf50c0067", "1e7d14612ffb9cb4dae4dcedb8fd24dbd4d916fbf93677e782074dfc5986f54c")); uploadPartBuilder.build().forEach(uploadPart -> glacierClient.uploadMultipartPart(glacierUpload, uploadPart, 4194304, fileInputStream)); String archiveId = glacierClient.completeMultipartUpload(credentials, "us-west-1", "dev", uploadId, testFile.length(), "2b30a705e4dcfd60c89a5596c6d4d1ddf5c1a1576271fbada358a319175020cd"); } catch (Exception e) { LOGGER.error(e); glacierClient.abortMultipartUpload(credentials, "us-west-1", "dev", uploadId); } }
@TaskAction protected void deploy() { String versionLabel = getVersionLabel(); AWSCredentialsProviderChain credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(beanstalk.getProfile())); BeanstalkDeployer deployer = new BeanstalkDeployer(beanstalk.getS3Endpoint(), beanstalk.getBeanstalkEndpoint(), credentialsProvider); File warFile = getProject().files(war).getSingleFile(); deployer.deploy(warFile, deployment.getApplication(), deployment.getEnvironment(), deployment.getTemplate(), versionLabel); }
/** * * @return */ private AWSCredentialsProvider getCredentials() { return new AWSCredentialsProviderChain(new StaticCredentialsProvider( new AppenderCredentials()), new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider(), new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider()); }
private static AWSCredentialsProvider getEnvironmentVariableCredentialsProvider() { AWSCredentialsProvider provider = new EnvironmentVariableCredentialsProvider(); try { AWSCredentials credentials = provider.getCredentials(); if (credentials != null && credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) { return provider; } } catch (Throwable t) { //Ignore } return null; }
@Bean @Scope(WebApplicationContext.SCOPE_APPLICATION) public AWSCredentialsProvider credentials() { return new AWSCredentialsProviderChain( new InstanceProfileCredentialsProvider(), new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider() ); }
private AWSCredentialsProvider createCredentialsProvider(){ return new AWSCredentialsProviderChain( new InstanceProfileCredentialsProvider(), new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new AWSCredentialsConfigFileProvider() ); }
public static void main(String[] args) throws Exception { java.security.Security.setProperty("networkaddress.cache.ttl" , "60"); Server server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(80); server.addConnector(connector); ResourceHandler resource_handler = new ResourceHandler(); resource_handler.setResourceBase("."); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); ServletHolder holderEvents = new ServletHolder("ws-events", MessageProxyServlet.class); context.addServlet(holderEvents, "/kinesisapp/*"); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { resource_handler, context, new DefaultHandler() }); server.setHandler(handlers); server.start(); AWSCredentialsProvider credentialsProvider = new EnvironmentVariableCredentialsProvider(); KinesisClientLibConfiguration kinesisConfig = new KinesisClientLibConfiguration( System.getProperty("kinesisapp.name"), System.getProperty("kinesisapp.stream"), credentialsProvider, Long.toString(System.currentTimeMillis())) .withKinesisEndpoint(System.getProperty("kinesisapp.endpoint")); IRecordProcessorFactory factory = new Factory(); Worker worker = new Worker(factory, kinesisConfig); worker.run(); /* Processor p = new Processor(); p.test(); */ }
DefaultAWSCredentialsProviderChain(Config config) { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ConfigurationCredentialsProvider(config), new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider()); }
public AWSCredentialsProvider getCredentials(AWSCredentials credentials) { return new AWSCredentialsProviderChain( new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new StaticCredentialsProvider(credentials == null ? new NullCredentials() : credentials), new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider() ); }
public ServerAccessor(){ s3client = AmazonS3ClientBuilder.standard() .withCredentials(new EnvironmentVariableCredentialsProvider()) .withRegion(Regions.EU_CENTRAL_1).build(); }
public AWSEnviromentCredentialsConfigurator() { super(new EnvironmentVariableCredentialsProvider()); }
public CustomCredentialsProviderChain(ClientConfiguration clientConfiguration, ProfileIdentifier profile, Supplier<MFAToken> mfaTokenSupplier) { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialProvider(clientConfiguration, profile, mfaTokenSupplier), new EC2ContainerCredentialsProviderWrapper()); }
@Override public AWSCredentials getCredentials() { return new EnvironmentVariableCredentialsProvider().getCredentials(); }
public CustomCredentialsProviderChain() { super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider(), new ProfileCredentialsProvider()); }
public AWSCredentials getAwsCredentialsFromEnvironment() throws IOException { EnvironmentVariableCredentialsProvider credentials = new EnvironmentVariableCredentialsProvider(); return credentials.getCredentials(); }
public CustomCredentialsProviderChain() { super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider()); }
public CustomCredentialsProviderChain() { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider()); }