<commit_before>package core.aws.client;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.regions.Region;
import core.aws.env.Environment;
import core.aws.util.Asserts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * due to nature of cloud manager, to use plain design to achieve maximum simplicity and flexibility
 *
 * @author neo
 */
public class AWS {
    public static final Logger LOGGER = LoggerFactory.getLogger(AWS.class);
    public static EC2 ec2;
    public static S3 s3;
    public static EC2VPC vpc;
    public static ElasticLoadBalancing elb;
    public static IAM iam;
    public static AutoScaling as;
    public static CloudWatch cloudWatch;

    public static void initialize(Environment env) throws IOException {
        Asserts.isNull(ec2, "initialize should only be called once");

        LOGGER.info("initialize aws clients");
        AWSCredentialsProvider provider = loadAWSCredentials(env.envDir);
        Region region = Region.getRegion(env.region);
        ec2 = new EC2(provider, region);
        vpc = new EC2VPC(provider, region);
        elb = new ElasticLoadBalancing(provider, region);
        s3 = new S3(provider, region);
        iam = new IAM(provider, region);
        as = new AutoScaling(provider, region);
        cloudWatch = new CloudWatch(provider, region);
    }

    private static AWSCredentialsProvider loadAWSCredentials(Path envDir) throws IOException {
        AWSCredentialsProvider provider;
        Path awsCredential = envDir.resolve("aws.properties");
        if (Files.exists(awsCredential)) {
            LOGGER.info("found aws.properties, use it as aws credentials, file={}", awsCredential);
            PropertiesCredentials credentials = new PropertiesCredentials(awsCredential.toFile());
            provider = new StaticCredentialsProvider(credentials);
        } else {
            LOGGER.info("not found aws.properties, use default credentials (env or instanceProfile)");
            provider = new DefaultAWSCredentialsProviderChain();
        }
        return provider;
    }
}<commit_msg>update aws sdk deprecated api<commit_after>package core.aws.client;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.regions.Region;
import core.aws.env.Environment;
import core.aws.util.Asserts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * due to nature of cloud manager, to use plain design to achieve maximum simplicity and flexibility
 *
 * @author neo
 */
public class AWS {
    public static final Logger LOGGER = LoggerFactory.getLogger(AWS.class);
    public static EC2 ec2;
    public static S3 s3;
    public static EC2VPC vpc;
    public static ElasticLoadBalancing elb;
    public static IAM iam;
    public static AutoScaling as;
    public static CloudWatch cloudWatch;

    public static void initialize(Environment env) throws IOException {
        Asserts.isNull(ec2, "initialize should only be called once");

        LOGGER.info("initialize aws clients");
        AWSCredentialsProvider provider = loadAWSCredentials(env.envDir);
        Region region = Region.getRegion(env.region);
        ec2 = new EC2(provider, region);
        vpc = new EC2VPC(provider, region);
        elb = new ElasticLoadBalancing(provider, region);
        s3 = new S3(provider, region);
        iam = new IAM(provider, region);
        as = new AutoScaling(provider, region);
        cloudWatch = new CloudWatch(provider, region);
    }

    private static AWSCredentialsProvider loadAWSCredentials(Path envDir) throws IOException {
        AWSCredentialsProvider provider;
        Path awsCredential = envDir.resolve("aws.properties");
        if (Files.exists(awsCredential)) {
            LOGGER.info("found aws.properties, use it as aws credentials, file={}", awsCredential);
            PropertiesCredentials credentials = new PropertiesCredentials(awsCredential.toFile());
            provider = new AWSStaticCredentialsProvider(credentials);
        } else {
            LOGGER.info("not found aws.properties, use default credentials (env or instanceProfile)");
            provider = new DefaultAWSCredentialsProviderChain();
        }
        return provider;
    }
}
{'fraction_non_alphanumeric': 0.0847816871555744, 'fraction_numerical': 0.005510809665112336, 'mean_word_length': 3.5949367088607596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1203073', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1286, 'n_words': 358}