Example usage for com.amazonaws ClientConfiguration ClientConfiguration

List of usage examples for com.amazonaws ClientConfiguration ClientConfiguration

Introduction

In this page you can find the example usage for com.amazonaws ClientConfiguration ClientConfiguration.

Prototype

public ClientConfiguration() 

Source Link

Usage

From source file:org.geowebcache.s3.S3BlobStoreConfig.java

License:Open Source License

/**
 * @return {@link AmazonS3Client} constructed from this {@link S3BlobStoreConfig}.
 *///from  w w w .  jav a  2s  . c  o  m
public AmazonS3Client buildClient() {
    AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    ClientConfiguration clientConfig = new ClientConfiguration();
    if (null != useHTTPS) {
        clientConfig.setProtocol(useHTTPS ? Protocol.HTTPS : Protocol.HTTP);
    }
    if (null != maxConnections && maxConnections > 0) {
        clientConfig.setMaxConnections(maxConnections);
    }
    clientConfig.setProxyDomain(proxyDomain);
    clientConfig.setProxyWorkstation(proxyWorkstation);
    clientConfig.setProxyHost(proxyHost);
    if (null != proxyPort) {
        clientConfig.setProxyPort(proxyPort);
    }
    clientConfig.setProxyUsername(proxyUsername);
    clientConfig.setProxyPassword(proxyPassword);
    if (null != useGzip) {
        clientConfig.setUseGzip(useGzip);
    }
    log.debug("Initializing AWS S3 connection");
    return new AmazonS3Client(awsCredentials, clientConfig);
}

From source file:org.geowebcache.s3.S3BlobStoreInfo.java

License:Open Source License

/** @return {@link AmazonS3Client} constructed from this {@link S3BlobStoreInfo}. */
public AmazonS3Client buildClient() {
    ClientConfiguration clientConfig = new ClientConfiguration();
    if (null != useHTTPS) {
        clientConfig.setProtocol(useHTTPS ? Protocol.HTTPS : Protocol.HTTP);
    }/*from   w  w w.j  a v  a  2s  . c  o m*/
    if (null != maxConnections && maxConnections > 0) {
        clientConfig.setMaxConnections(maxConnections);
    }
    clientConfig.setProxyDomain(proxyDomain);
    clientConfig.setProxyWorkstation(proxyWorkstation);
    clientConfig.setProxyHost(proxyHost);
    if (null != proxyPort) {
        clientConfig.setProxyPort(proxyPort);
    }
    clientConfig.setProxyUsername(proxyUsername);
    clientConfig.setProxyPassword(proxyPassword);
    if (null != useGzip) {
        clientConfig.setUseGzip(useGzip);
    }
    log.debug("Initializing AWS S3 connection");
    AmazonS3Client client = new AmazonS3Client(getCredentialsProvider(), clientConfig);
    if (endpoint != null && !"".equals(endpoint)) {
        S3ClientOptions s3ClientOptions = new S3ClientOptions();
        s3ClientOptions.setPathStyleAccess(true);
        client.setS3ClientOptions(s3ClientOptions);
        client.setEndpoint(endpoint);
    }
    if (!client.doesBucketExist(bucket)) {
        client.createBucket(bucket);
    }
    return client;
}

From source file:org.gradle.internal.resource.transport.aws.s3.S3Client.java

License:Apache License

private ClientConfiguration createConnectionProperties() {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    Optional<HttpProxySettings.HttpProxy> proxyOptional = s3ConnectionProperties.getProxy();
    if (proxyOptional.isPresent()) {
        HttpProxySettings.HttpProxy proxy = s3ConnectionProperties.getProxy().get();
        clientConfiguration.setProxyHost(proxy.host);
        clientConfiguration.setProxyPort(proxy.port);
        PasswordCredentials credentials = proxy.credentials;
        if (credentials != null) {
            clientConfiguration.setProxyUsername(credentials.getUsername());
            clientConfiguration.setProxyPassword(credentials.getPassword());
        }//from  w  w w  .  jav a  2  s  .  c om
    }
    Optional<Integer> maxErrorRetryCount = s3ConnectionProperties.getMaxErrorRetryCount();
    if (maxErrorRetryCount.isPresent()) {
        clientConfiguration.setMaxErrorRetry(maxErrorRetryCount.get());
    }
    return clientConfiguration;
}

From source file:org.gridgain.grid.spi.cloud.ec2lite.GridEc2LiteCloudSpi.java

License:GNU General Public License

/**
 * Creates EC2 client based on current SPI parameters.
 *//*from   ww  w  .jav  a2s .com*/
private void initEC2Client() {
    ClientConfiguration ec2config = new ClientConfiguration();

    if (prxHost != null) {
        ec2config.setProxyHost(prxHost);

        if (prxPort != -1)
            ec2config.setProxyPort(prxPort);

        if (prxUser != null) {
            ec2config.setProxyUsername(prxUser);

            if (prxPwd != null)
                ec2config.setProxyPassword(prxPwd);
        }
    }

    // In test mode, the test should inject client itself.
    ec2 = testMode ? null
            : new AmazonEC2Client(new BasicAWSCredentials(accessKeyId, secretAccessKey), ec2config);
}

From source file:org.gridgain.grid.util.ec2.GridEc2Helper.java

License:GNU General Public License

/**
 * @return EC2 client./*from  w w  w  . java  2s. c o m*/
 * @throws GridException Thrown in case of any exception.
 */
private AmazonEC2 initEc2Client() throws GridException {
    if (ec2keys == null || ec2keys.getAccessKeyId() == null || ec2keys.getSecretAccessKey() == null) {
        throw new GridException("Some EC2 keys not specified.");
    }

    return new AmazonEC2Client(new BasicAWSCredentials(ec2keys.getAccessKeyId(), ec2keys.getSecretAccessKey()),
            new ClientConfiguration());
}

From source file:org.icgc.dcc.storage.server.service.download.ObjectDownloadServiceStubFactory.java

License:Open Source License

public static AmazonS3 createS3ClientForRadosGW(String endpoint) {
    // Configs copied from S3Config
    // RadosGW doesn't support latest AWS API version: AWSS3V4SignerType
    val clientConfiguration = new ClientConfiguration();
    SignerFactory.registerSigner("S3Signer", S3Signer.class);
    clientConfiguration.setSignerOverride("S3SignerType");
    clientConfiguration.setProtocol(Protocol.HTTPS);
    val s3Client = new AmazonS3Client(new BasicAWSCredentials("accesskey", "secret"), clientConfiguration);
    s3Client.setEndpoint(endpoint);//from www .  j  a v a2  s.  co  m
    s3Client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
    return s3Client;
}

From source file:org.jenkinsci.plugins.awsdevicefarm.AWSDeviceFarm.java

License:Open Source License

/**
 * Private AWSDeviceFarm constructor. Uses the roleArn to generate STS creds if the roleArn isn't null; otherwise
 * just uses the AWSCredentials creds.//  w w  w .jav a 2  s  . c  om
 *
 * @param creds   AWSCredentials creds to use for authentication.
 * @param roleArn Role ARN to use for authentication.
 */
private AWSDeviceFarm(AWSCredentials creds, String roleArn) {
    if (roleArn != null) {
        STSAssumeRoleSessionCredentialsProvider sts = new STSAssumeRoleSessionCredentialsProvider.Builder(
                roleArn, RandomStringUtils.randomAlphanumeric(8)).build();
        creds = sts.getCredentials();
    }

    ClientConfiguration clientConfiguration = new ClientConfiguration()
            .withUserAgent("AWS Device Farm - Jenkins v1.0");
    api = new AWSDeviceFarmClient(creds, clientConfiguration);
    api.setServiceNameIntern("devicefarm");
}

From source file:org.mule.module.s3.S3Connector.java

License:Open Source License

/**
 * Creates an {@link AmazonS3} client. If accessKey and secretKey are not set,
 * the resulting client is anonymous//from  w w  w  .jav  a 2s . c  om
 * 
 * @return a new {@link AmazonS3}
 */
private AmazonS3 createAmazonS3(String accessKey, String secretKey) {
    ClientConfiguration clientConfig = new ClientConfiguration();
    if (proxyUsername != null) {
        clientConfig.setProxyUsername(proxyUsername);
    }
    if (proxyPort != null) {
        clientConfig.setProxyPort(proxyPort);
    }
    if (proxyPassword != null) {
        clientConfig.setProxyPassword(proxyPassword);
    }
    if (proxyHost != null) {
        clientConfig.setProxyHost(proxyHost);
    }
    if (connectionTimeout != null) {
        clientConfig.setConnectionTimeout(connectionTimeout);
    }
    if (socketTimeout != null) {
        clientConfig.setSocketTimeout(socketTimeout);
    }

    return new AmazonS3Client(createCredentials(accessKey, secretKey), clientConfig);
}

From source file:org.nuxeo.ecm.core.storage.sql.S3BinaryManager.java

License:Apache License

@Override
protected void setupCloudClient() throws IOException {
    // Get settings from the configuration
    bucketName = getProperty(BUCKET_NAME_PROPERTY);
    bucketNamePrefix = MoreObjects.firstNonNull(getProperty(BUCKET_PREFIX_PROPERTY), StringUtils.EMPTY);
    String bucketRegion = getProperty(BUCKET_REGION_PROPERTY);
    if (isBlank(bucketRegion)) {
        bucketRegion = DEFAULT_BUCKET_REGION;
    }//from   w  ww.jav  a  2  s .  c  o m
    String awsID = getProperty(AWS_ID_PROPERTY);
    String awsSecret = getProperty(AWS_SECRET_PROPERTY);

    String proxyHost = Framework.getProperty(Environment.NUXEO_HTTP_PROXY_HOST);
    String proxyPort = Framework.getProperty(Environment.NUXEO_HTTP_PROXY_PORT);
    String proxyLogin = Framework.getProperty(Environment.NUXEO_HTTP_PROXY_LOGIN);
    String proxyPassword = Framework.getProperty(Environment.NUXEO_HTTP_PROXY_PASSWORD);

    int maxConnections = getIntProperty(CONNECTION_MAX_PROPERTY);
    int maxErrorRetry = getIntProperty(CONNECTION_RETRY_PROPERTY);
    int connectionTimeout = getIntProperty(CONNECTION_TIMEOUT_PROPERTY);
    int socketTimeout = getIntProperty(SOCKET_TIMEOUT_PROPERTY);

    String keystoreFile = getProperty(KEYSTORE_FILE_PROPERTY);
    String keystorePass = getProperty(KEYSTORE_PASS_PROPERTY);
    String privkeyAlias = getProperty(PRIVKEY_ALIAS_PROPERTY);
    String privkeyPass = getProperty(PRIVKEY_PASS_PROPERTY);
    String endpoint = getProperty(ENDPOINT_PROPERTY);
    String sseprop = getProperty(SERVERSIDE_ENCRYPTION_PROPERTY);
    if (isNotBlank(sseprop)) {
        userServerSideEncryption = Boolean.parseBoolean(sseprop);
    }

    // Fallback on default env keys for ID and secret
    if (isBlank(awsID)) {
        awsID = System.getenv(AWS_ID_ENV);
    }
    if (isBlank(awsSecret)) {
        awsSecret = System.getenv(AWS_SECRET_ENV);
    }

    if (isBlank(bucketName)) {
        throw new RuntimeException("Missing conf: " + BUCKET_NAME_PROPERTY);
    }

    if (!isBlank(bucketNamePrefix) && !bucketNamePrefix.endsWith("/")) {
        log.warn(String.format("%s %s S3 bucket prefix should end by '/' " + ": added automatically.",
                BUCKET_PREFIX_PROPERTY, bucketNamePrefix));
        bucketNamePrefix += "/";
    }
    // set up credentials
    if (isBlank(awsID) || isBlank(awsSecret)) {
        awsCredentialsProvider = new InstanceProfileCredentialsProvider();
        try {
            awsCredentialsProvider.getCredentials();
        } catch (AmazonClientException e) {
            throw new RuntimeException("Missing AWS credentials and no instance role found");
        }
    } else {
        awsCredentialsProvider = new BasicAWSCredentialsProvider(awsID, awsSecret);
    }

    // set up client configuration
    clientConfiguration = new ClientConfiguration();
    if (isNotBlank(proxyHost)) {
        clientConfiguration.setProxyHost(proxyHost);
    }
    if (isNotBlank(proxyPort)) {
        clientConfiguration.setProxyPort(Integer.parseInt(proxyPort));
    }
    if (isNotBlank(proxyLogin)) {
        clientConfiguration.setProxyUsername(proxyLogin);
    }
    if (proxyPassword != null) { // could be blank
        clientConfiguration.setProxyPassword(proxyPassword);
    }
    if (maxConnections > 0) {
        clientConfiguration.setMaxConnections(maxConnections);
    }
    if (maxErrorRetry >= 0) { // 0 is allowed
        clientConfiguration.setMaxErrorRetry(maxErrorRetry);
    }
    if (connectionTimeout >= 0) { // 0 is allowed
        clientConfiguration.setConnectionTimeout(connectionTimeout);
    }
    if (socketTimeout >= 0) { // 0 is allowed
        clientConfiguration.setSocketTimeout(socketTimeout);
    }

    // set up encryption
    encryptionMaterials = null;
    if (isNotBlank(keystoreFile)) {
        boolean confok = true;
        if (keystorePass == null) { // could be blank
            log.error("Keystore password missing");
            confok = false;
        }
        if (isBlank(privkeyAlias)) {
            log.error("Key alias missing");
            confok = false;
        }
        if (privkeyPass == null) { // could be blank
            log.error("Key password missing");
            confok = false;
        }
        if (!confok) {
            throw new RuntimeException("S3 Crypto configuration incomplete");
        }
        try {
            // Open keystore
            File ksFile = new File(keystoreFile);
            FileInputStream ksStream = new FileInputStream(ksFile);
            KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
            keystore.load(ksStream, keystorePass.toCharArray());
            ksStream.close();
            // Get keypair for alias
            if (!keystore.isKeyEntry(privkeyAlias)) {
                throw new RuntimeException("Alias " + privkeyAlias + " is missing or not a key alias");
            }
            PrivateKey privKey = (PrivateKey) keystore.getKey(privkeyAlias, privkeyPass.toCharArray());
            Certificate cert = keystore.getCertificate(privkeyAlias);
            PublicKey pubKey = cert.getPublicKey();
            KeyPair keypair = new KeyPair(pubKey, privKey);
            // Get encryptionMaterials from keypair
            encryptionMaterials = new EncryptionMaterials(keypair);
            cryptoConfiguration = new CryptoConfiguration();
        } catch (IOException | GeneralSecurityException e) {
            throw new RuntimeException("Could not read keystore: " + keystoreFile + ", alias: " + privkeyAlias,
                    e);
        }
    }
    isEncrypted = encryptionMaterials != null;

    // Try to create bucket if it doesn't exist
    if (!isEncrypted) {
        amazonS3 = new AmazonS3Client(awsCredentialsProvider, clientConfiguration);
    } else {
        amazonS3 = new AmazonS3EncryptionClient(awsCredentialsProvider,
                new StaticEncryptionMaterialsProvider(encryptionMaterials), clientConfiguration,
                cryptoConfiguration);
    }
    if (isNotBlank(endpoint)) {
        amazonS3.setEndpoint(endpoint);
    }

    // Set region explicitely for regions that reguire Version 4 signature
    ArrayList<String> V4_ONLY_REGIONS = new ArrayList<String>();
    V4_ONLY_REGIONS.add("eu-central-1");
    V4_ONLY_REGIONS.add("ap-northeast-2");
    if (V4_ONLY_REGIONS.contains(bucketRegion)) {
        amazonS3.setRegion(Region.getRegion(Regions.fromName(bucketRegion)));
    }

    try {
        if (!amazonS3.doesBucketExist(bucketName)) {
            amazonS3.createBucket(bucketName, bucketRegion);
            amazonS3.setBucketAcl(bucketName, CannedAccessControlList.Private);
        }
    } catch (AmazonClientException e) {
        throw new IOException(e);
    }

    // compat for NXP-17895, using "downloadfroms3", to be removed
    // these two fields have already been initialized by the base class initialize()
    // using standard property "directdownload"
    String dd = getProperty(DIRECTDOWNLOAD_PROPERTY_COMPAT);
    if (dd != null) {
        directDownload = Boolean.parseBoolean(dd);
    }
    int dde = getIntProperty(DIRECTDOWNLOAD_EXPIRE_PROPERTY_COMPAT);
    if (dde >= 0) {
        directDownloadExpire = dde;
    }

    transferManager = new TransferManager(amazonS3);
    abortOldUploads();
}

From source file:org.nuxeo.liveconnect.importer.aws.LiveconnectS3Blobprovider.java

License:Apache License

@Override
public void initialize(String blobProviderId, Map<String, String> properties) throws IOException {
    super.initialize(blobProviderId, properties);
    bucketName = properties.get(BUCKET_NAME_PROPERTY);
    String bucketRegion = properties.get(BUCKET_REGION_PROPERTY);
    String awsID = properties.get(AWS_ID_PROPERTY);
    String awsSecret = properties.get(AWS_SECRET_PROPERTY);
    amazonS3 = new AmazonS3Client(new BasicAWSCredentials(awsID, awsSecret), new ClientConfiguration());
    amazonS3.setRegion(Region.getRegion(Regions.fromName(bucketRegion)));
}