S3FileInputPlugin extends AbstractS3FileInputPlugin { @Override protected AmazonS3 newS3Client(PluginTask task) { S3PluginTask t = (S3PluginTask) task; Optional<String> endpoint = t.getEndpoint(); Optional<String> region = t.getRegion(); AmazonS3ClientBuilder builder = super.defaultS3ClientBuilder(t); if (endpoint.isPresent()) { if (region.isPresent()) { log.warn("Either configure endpoint or region, " + "if both is specified only the endpoint will be in effect."); } builder.setEndpointConfiguration(new EndpointConfiguration(endpoint.get(), null)); } else if (region.isPresent()) { builder.setRegion(region.get()); } else { builder.setEndpointConfiguration(new EndpointConfiguration("s3.amazonaws.com", null)); } return builder.build(); }    }
@Test public void configuredEndpoint() { final ConfigMapper configMapper = CONFIG_MAPPER_FACTORY.createConfigMapper(); final ConfigSource configSource = config.deepCopy() .set("endpoint", "s3-ap-southeast-1.amazonaws.com") .set("region", "ap-southeast-2"); final S3PluginTask task = configMapper.map(configSource, S3PluginTask.class); S3FileInputPlugin plugin = runtime.getInstance(S3FileInputPlugin.class); AmazonS3 s3Client = plugin.newS3Client(task); assertEquals(s3Client.getRegion(), Region.AP_Singapore); }
@Test public void configuredRegion() { final ConfigMapper configMapper = CONFIG_MAPPER_FACTORY.createConfigMapper(); final ConfigSource configSource = config.deepCopy() .set("region", "ap-southeast-2") .remove("endpoint"); final S3PluginTask task = configMapper.map(configSource, S3PluginTask.class); S3FileInputPlugin plugin = runtime.getInstance(S3FileInputPlugin.class); AmazonS3 s3Client = plugin.newS3Client(task); assertEquals(s3Client.getRegion(), Region.AP_Sydney); }
@Test public void unconfiguredEndpointAndRegion() { final ConfigMapper configMapper = CONFIG_MAPPER_FACTORY.createConfigMapper(); final ConfigSource configSource = config.deepCopy() .remove("endpoint") .remove("region"); final S3PluginTask task = configMapper.map(configSource, S3PluginTask.class); S3FileInputPlugin plugin = runtime.getInstance(S3FileInputPlugin.class); AmazonS3 s3Client = plugin.newS3Client(task); assertEquals(s3Client.getRegion(), Region.US_Standard); }