Example usage for com.amazonaws.services.s3 AmazonS3ClientBuilder standard

List of usage examples for com.amazonaws.services.s3 AmazonS3ClientBuilder standard

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3ClientBuilder standard.

Prototype

public static AmazonS3ClientBuilder standard() 

Source Link

Usage

From source file:ch.myniva.gradle.caching.s3.internal.AwsS3BuildCacheServiceFactory.java

License:Apache License

private AmazonS3 createS3Client(AwsS3BuildCache config) {
    AmazonS3 s3;// w w w .  j av  a  2  s . c  o  m
    try {
        AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard();
        if (!isNullOrEmpty(config.getAwsAccessKeyId()) && !isNullOrEmpty(config.getAwsSecretKey())) {
            s3Builder.withCredentials(new AWSStaticCredentialsProvider(
                    new BasicAWSCredentials(config.getAwsAccessKeyId(), config.getAwsSecretKey())));
        }
        if (isNullOrEmpty(config.getEndpoint())) {
            s3Builder.withRegion(config.getRegion());
        } else {
            s3Builder.withEndpointConfiguration(
                    new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion()));
        }
        s3 = s3Builder.build();
    } catch (SdkClientException e) {
        logger.debug("Error while building AWS S3 client: {}", e.getMessage());
        throw new GradleException("Creation of S3 build cache failed; cannot create S3 client", e);
    }
    return s3;
}

From source file:com.att.aro.core.cloud.aws.AwsRepository.java

License:Apache License

private void constructRepo(String accessId, String secretKey, String region, String bucketName,
        ClientConfiguration config) {//from   ww w .j  a v a 2 s  .  co  m
    System.setProperty("java.net.useSystemProxies", "true");
    if (isNotBlank(accessId) && isNotBlank(secretKey) && isNotBlank(region) && isNotBlank(bucketName)) {
        try {
            AWSCredentials creds = new BasicAWSCredentials(accessId, secretKey);
            Regions regions = Regions.fromName(region);
            this.bucketName = bucketName;
            s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
                    .withRegion(regions).withClientConfiguration(config).build();
            transferMgr = TransferManagerBuilder.standard().withS3Client(s3Client).build();
        } catch (IllegalArgumentException ille) {
            LOGGER.error(ille.getMessage(), ille);
        } catch (Exception exp) {
            LOGGER.error(exp.getMessage(), exp);
        }
    }
}

From source file:com.dragovorn.dragonbot.DragonBot.java

License:Open Source License

@Override
public void start() {
    setState(BotState.STARTING);/*w w w.  ja va  2  s.co m*/

    AmazonS3 client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
    this.transferManager = TransferManagerBuilder.standard().withS3Client(client).build();

    UpdatePanel update = new UpdatePanel();

    new MainWindow(update);

    if (Bot.getInstance().getConfiguration().getCheckForUpdates()) {
        getLogger().info("Checking for newer version of the updater...");

        try {
            if (client
                    .getObjectMetadata(
                            new GetObjectMetadataRequest("dl.dragovorn.com", "DragonBot/updater.jar"))
                    .getLastModified().getTime() > FileManager.getUpdater().lastModified()) {
                getLogger().info("Found a newer version of the updater, downloading it now...");

                FileManager.getUpdater().delete();

                GetObjectRequest request = new GetObjectRequest("dl.dragovorn.com", "DragonBot/updater.jar");

                try {
                    this.transferManager.download(request, FileManager.getUpdater()).waitForCompletion();
                } catch (InterruptedException exception) {
                    /* Shouldn't happen */ }
            }
        } catch (Throwable throwable) {
            getLogger().info("Unable to connect to the internet!");
        }

        getLogger().info("Checking for updates...");
        update.update();

        if (update.shouldStop()) {
            stop();
            return;
        }
    }

    getLogger().info("Initializing Dragon Bot v" + getVersion() + "!");

    this.name = this.config.getName();
    this.auth = this.config.getAuth();

    this.commandManager.registerCommand(new Github());
    this.commandManager.registerCommand(new VersionCmd());

    this.pluginManager.enablePlugins();

    if (!this.name.equals("") && !this.config.getAuth().equals("")) {
        getLogger().info("Connecting to twitch!");

        try {
            connect();
        } catch (ConnectionException | IOException exception) {
            getLogger().info("Unable to connect!");
        }

        if (this.config.getAutoConnect() && !this.config.getChannel().equals("")) {
            getLogger().info("Automatically connected to " + this.config.getChannel());

            connectTo("#" + this.config.getChannel());
        }
    } else {
        String buttons[] = { "Ok" };

        JOptionPane.showOptionDialog(null,
                "You don't have a twitch account configured! Please set the bot's twitch account in the options menu!",
                "Twitch Account", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, buttons,
                buttons[0]);

        getLogger().info("No twitch account detected.");
    }

    if (!this.isConnected()) {
        MainWindow.getInstance().getChannelButton().setEnabled(false);
        MainWindow.getInstance().getChannelButton()
                .setToolTipText("The current account was unable to connect!");
    }

    setState(BotState.RUNNING);

    MainWindow.getInstance().setContentPane(MainWindow.getInstance().getPanel());
    MainWindow.getInstance().pack();
    MainWindow.getInstance().center();

    getLogger().info("Dragon Bot v" + getVersion() + " initialized!");
}

From source file:com.emc.vipr.s3.sample.AWSS3Factory.java

License:Open Source License

public static AmazonS3 getS3Client() {
    BasicAWSCredentials creds = new BasicAWSCredentials(S3_ACCESS_KEY_ID, S3_SECRET_KEY);

    ClientConfiguration cc = new ClientConfiguration();
    //cc.setProxyHost("localhost");
    //cc.setProxyPort(8888);

    // Force use of v2 Signer.
    cc.setSignerOverride("S3SignerType");

    AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds))
            .withClientConfiguration(cc).withPathStyleAccessEnabled(true) // Path-style bucket naming is highly recommended
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(S3_ENDPOINT, null)).build();

    return client;
}

From source file:com.formkiq.core.service.AssetServiceS3Default.java

License:Apache License

/**
 * @return {@link AmazonS3}/* w  w  w  .j a  v a  2s  .co m*/
 */
private AmazonS3 getS3Connection() {

    if (this.s3client == null) {
        AWSCredentials credentials = new BasicAWSCredentials(this.s3AccessKey, this.s3AccessSecret);
        this.s3client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_WEST_2) // TODO create aws.properties
                .build();
    }

    return this.s3client;
}

From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java

License:MIT License

/**
 * ?/*  w ww .  j a v  a 2s  . c  om*/
 *
 * @param bucketName
 * @return s3client
 * @throws StoreException
 * @throws Exception
 */
private AmazonS3 getS3Client(String bucketName) throws StoreException {
    logger.debug("get S3 Client start.");
    // ?
    AWSCredentialsProvider provider = new EnvironmentVariableCredentialsProvider();

    // 
    ClientConfiguration clientConfig = new ClientConfiguration()

            // .withProtocol(Protocol.HTTPS) // Proxy
            // .withProxyHost("proxyHost")
            // .withProxyPort(80)
            // .withProxyUsername("proxyUsername")
            // .withProxyPassword("proxyPassword")

            .withConnectionTimeout(10000);

    // ?
    AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(provider)
            .withClientConfiguration(clientConfig).withRegion(DEFAULT_REGION)
            .withForceGlobalBucketAccessEnabled(true).build();

    logger.debug("Region={}", s3client.getRegion());

    try {
        // ??
        if (!CommonUtils.isNullOrEmpty(bucketName) && !(s3client.doesBucketExistV2(bucketName))) {
            s3client.createBucket(new CreateBucketRequest(bucketName, DEFAULT_REGION.getName()));
        }
        // Get location.
        String bucketLocation = s3client.getBucketLocation(new GetBucketLocationRequest(bucketName));
        logger.info("bucket location={}", bucketLocation);
    } catch (AmazonClientException ace) {
        throw new StoreException(HttpStatus.SC_CONFLICT, ErrorClassification.BS0003, ace, "?");
    }

    logger.info("get S3 Client end.");
    return s3client;
}

From source file:com.netflix.genie.common.internal.aws.s3.S3ClientFactory.java

License:Apache License

private AmazonS3 buildS3Client(final S3ClientKey s3ClientKey) {
    // TODO: Do something about allowing ClientConfiguration to be passed in
    return AmazonS3ClientBuilder.standard().withRegion(s3ClientKey.getRegion())
            .withForceGlobalBucketAccessEnabled(true).withCredentials(s3ClientKey.getRoleARN().map(roleARN -> {
                // TODO: Perhaps rename with more detailed info?
                final String roleSession = "Genie-Agent-" + UUID.randomUUID().toString();

                return (AWSCredentialsProvider) new STSAssumeRoleSessionCredentialsProvider.Builder(roleARN,
                        roleSession).withStsClient(this.stsClient).build();
            }).orElse(this.awsCredentialsProvider)).build();
}

From source file:com.netflix.genie.web.util.S3ClientFactory.java

License:Apache License

/**
 * Constructor./*ww w .jav  a 2  s.  c om*/
 *
 * @param awsCredentialsProvider The default credentials provider for this instance
 * @param awsClientConfiguration The AWS client configuration for Genie
 * @param awsRegion              The AWS region the app is running in
 * @param roleArn                The role to assume before accessing S3 resources if necessary
 */
public S3ClientFactory(@NotNull final AWSCredentialsProvider awsCredentialsProvider,
        @NotNull final ClientConfiguration awsClientConfiguration, @NotNull final String awsRegion,
        @Nullable final String roleArn) {
    this.awsCredentialsProvider = awsCredentialsProvider;
    this.awsClientConfiguration = awsClientConfiguration;
    this.awsRegion = awsRegion;

    this.roleArn = roleArn;
    this.assumeRole = StringUtils.isNotBlank(this.roleArn);

    // Create the default S3 client given the credentials provider and the client configuration
    this.defaultS3Client = AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider)
            .withClientConfiguration(awsClientConfiguration).withRegion(this.awsRegion).build();
}

From source file:com.netflix.genie.web.util.S3ClientFactory.java

License:Apache License

/**
 * Get an S3 client given the configuration of the system.
 *
 * @return an S3 client//from  w  ww  . j  av  a 2  s  . c  o  m
 */
public AmazonS3 getS3Client() {
    if (this.assumeRole) {
        // TODO: It's possible this could be optimized to reuse a client that a role has already been assumed for
        //       it would take more logic in this class and likely isn't worth it right now before we decide how
        //       4.x may work best. As it is now create a new client every time one is requested to assume a role

        // See: https://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingTempSessionTokenJava.html
        final AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
                .withCredentials(this.awsCredentialsProvider)
                .withClientConfiguration(this.awsClientConfiguration).withRegion(this.awsRegion).build();

        final AssumeRoleRequest roleRequest = new AssumeRoleRequest().withRoleArn(this.roleArn)
                .withRoleSessionName("Genie-" + UUID.randomUUID().toString());

        final AssumeRoleResult roleResult = stsClient.assumeRole(roleRequest);
        final Credentials sessionCredentials = roleResult.getCredentials();

        final BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(
                sessionCredentials.getAccessKeyId(), sessionCredentials.getSecretAccessKey(),
                sessionCredentials.getSessionToken());

        return AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(basicSessionCredentials))
                .withClientConfiguration(this.awsClientConfiguration).withRegion(this.awsRegion).build();
    } else {
        return this.defaultS3Client;
    }
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.s3.S3ArtifactCredentials.java

License:Apache License

private AmazonS3 getS3Client() {
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();

    if (!StringUtils.isEmpty(apiEndpoint)) {
        AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(
                apiEndpoint, apiRegion);
        builder.setEndpointConfiguration(endpoint);
        builder.setPathStyleAccessEnabled(true);
    } else if (!StringUtils.isEmpty(region)) {
        builder.setRegion(region);/*from  w  ww  .  j  a va 2 s  .c o  m*/
    }

    if (!StringUtils.isEmpty(awsAccessKeyId) && !StringUtils.isEmpty(awsSecretAccessKey)) {
        BasicAWSCredentials awsStaticCreds = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey);
        builder.withCredentials(new AWSStaticCredentialsProvider(awsStaticCreds));
    }

    return builder.build();
}