Java Code Examples for com.amazonaws.services.s3.AmazonS3Client#setS3ClientOptions()

The following examples show how to use com.amazonaws.services.s3.AmazonS3Client#setS3ClientOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3StorageDriver.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
private AmazonS3Client getAmazonS3Client(BackupRestoreContext ctx) throws URISyntaxException {
    final String accessKey = ctx.getAccountId();
    final String secretKey = ctx.getSecretKey();
    String endpoint = getEndpoint(ctx);
    LOGGER.info("endpoint: {}", endpoint);

    final BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
    final AmazonS3Client amazonS3Client = new AmazonS3Client(basicAWSCredentials);
    amazonS3Client.setEndpoint(endpoint);

    if (ctx.usesEmc()) {
        final S3ClientOptions options = new S3ClientOptions();
        options.setPathStyleAccess(true);
        amazonS3Client.setS3ClientOptions(options);
    }

    return amazonS3Client;
}
 
Example 2
Source File: S3StorageFactory.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Override
public Storage newStorage(Config config)
{
    AmazonS3Client client = new AmazonS3Client(
            buildCredentialsProvider(config),
            buildClientConfiguration(config));
    if (config.has("endpoint")) {
        client.setEndpoint(config.get("endpoint", String.class));
    }

    if (config.has("path-style-access")) {
        client.setS3ClientOptions(
          S3ClientOptions.builder().setPathStyleAccess(
            config.get("path-style-access", Boolean.class, false)
          ).build());
    }

    String bucket = config.get("bucket", String.class);

    return new S3Storage(config, client, bucket);
}
 
Example 3
Source File: AbstractS3Processor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void initalizeEndpointOverride(final ProcessContext context, final AmazonS3Client s3) {
    // if ENDPOINT_OVERRIDE is set, use PathStyleAccess
    if(StringUtils.trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).getValue()).isEmpty() == false){
        final S3ClientOptions s3Options = new S3ClientOptions();
        s3Options.setPathStyleAccess(true);
        s3.setS3ClientOptions(s3Options);
    }
}
 
Example 4
Source File: S3ClientFactory.java    From front50 with Apache License 2.0 5 votes vote down vote up
public static AmazonS3 create(
    AWSCredentialsProvider awsCredentialsProvider, S3Properties s3Properties) {
  ClientConfiguration clientConfiguration = new ClientConfiguration();
  if (s3Properties.getProxyProtocol() != null) {
    if (s3Properties.getProxyProtocol().equalsIgnoreCase("HTTPS")) {
      clientConfiguration.setProtocol(Protocol.HTTPS);
    } else {
      clientConfiguration.setProtocol(Protocol.HTTP);
    }
    Optional.ofNullable(s3Properties.getProxyHost()).ifPresent(clientConfiguration::setProxyHost);
    Optional.ofNullable(s3Properties.getProxyPort())
        .map(Integer::parseInt)
        .ifPresent(clientConfiguration::setProxyPort);
  }

  AmazonS3Client client = new AmazonS3Client(awsCredentialsProvider, clientConfiguration);

  if (!StringUtils.isEmpty(s3Properties.getEndpoint())) {
    client.setEndpoint(s3Properties.getEndpoint());

    if (!StringUtils.isEmpty(s3Properties.getRegionOverride())) {
      client.setSignerRegionOverride(s3Properties.getRegionOverride());
    }

    client.setS3ClientOptions(
        S3ClientOptions.builder().setPathStyleAccess(s3Properties.getPathStyleAccess()).build());
  } else {
    Optional.ofNullable(s3Properties.getRegion())
        .map(Regions::fromName)
        .map(Region::getRegion)
        .ifPresent(client::setRegion);
  }

  return client;
}
 
Example 5
Source File: AbstractS3Processor.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void initalizeEndpointOverride(final ProcessContext context, final AmazonS3Client s3) {
    // if ENDPOINT_OVERRIDE is set, use PathStyleAccess
    if(StringUtils.trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).evaluateAttributeExpressions().getValue()).isEmpty() == false){
        final S3ClientOptions s3Options = new S3ClientOptions();
        s3Options.setPathStyleAccess(true);
        s3.setS3ClientOptions(s3Options);
    }
}