com.amazonaws.PredefinedClientConfigurations Java Examples

The following examples show how to use com.amazonaws.PredefinedClientConfigurations. 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: AmazonS3Factory.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public AmazonS3 create(final BlobStoreConfiguration blobStoreConfiguration) {
  NexusS3ClientBuilder builder = NexusS3ClientBuilder.standard();

  String accessKeyId = blobStoreConfiguration.attributes(CONFIG_KEY).get(ACCESS_KEY_ID_KEY, String.class);
  String secretAccessKey = blobStoreConfiguration.attributes(CONFIG_KEY).get(SECRET_ACCESS_KEY_KEY, String.class);
  String region = blobStoreConfiguration.attributes(CONFIG_KEY).get(REGION_KEY, String.class);
  String signerType = blobStoreConfiguration.attributes(CONFIG_KEY).get(SIGNERTYPE_KEY, String.class);
  String forcePathStyle = blobStoreConfiguration.attributes(CONFIG_KEY).get(FORCE_PATH_STYLE_KEY, String.class);

  if (!isNullOrEmpty(accessKeyId) && !isNullOrEmpty(secretAccessKey)) {
    String sessionToken = blobStoreConfiguration.attributes(CONFIG_KEY).get(SESSION_TOKEN_KEY, String.class);
    AWSCredentials credentials = buildCredentials(accessKeyId, secretAccessKey, sessionToken);

    String assumeRole = blobStoreConfiguration.attributes(CONFIG_KEY).get(ASSUME_ROLE_KEY, String.class);
    AWSCredentialsProvider credentialsProvider = buildCredentialsProvider(credentials, region, assumeRole);

    builder = builder.withCredentials(credentialsProvider);
  }

  if (!isNullOrEmptyOrDefault(region)) {
    String endpoint = blobStoreConfiguration.attributes(CONFIG_KEY).get(ENDPOINT_KEY, String.class);
    if (!isNullOrEmpty(endpoint)) {
      builder = builder.withEndpointConfiguration(new AmazonS3ClientBuilder.EndpointConfiguration(endpoint, region));
    } else {
      builder = builder.withRegion(region);
    }
  }

  ClientConfiguration clientConfiguration = PredefinedClientConfigurations.defaultConfig();
  if (connectionPoolSize > 0) {
    clientConfiguration.setMaxConnections(connectionPoolSize);
  }
  if (!isNullOrEmptyOrDefault(signerType)) {
    clientConfiguration.setSignerOverride(signerType);
  }
  builder = builder.withClientConfiguration(clientConfiguration);

  builder = builder.withPathStyleAccessEnabled(Boolean.parseBoolean(forcePathStyle));

  builder.withBlobStoreConfig(blobStoreConfiguration);

  return builder.build();
}