package com.amazonaws.service.apigateway.importer.config;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class AwsConfig {
    private String region = "us-east-1";
    private String profile = "default";

    public String getRegion() {
        return region;
    }

    public String getProfile() {
        return profile;
    }

    public void load() {

        String home = System.getProperty("user.home");
//        ProfilesConfigFile file = new ProfilesConfigFile(home + "/.aws/config");

        Properties awsConfigProperties = new Properties();

        // todo: use profile
        try {
            awsConfigProperties.load(new FileInputStream(home + "/.aws/config"));
        } catch (IOException e) {
            throw new RuntimeException("Could not load configuration. Please run 'aws configure'");
        }

        region = awsConfigProperties.getProperty("region");
    }

}

@@ -52,16 +52,102 @@
 onfig;%0A%0A
+import org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A%0A
 import j
@@ -253,16 +253,88 @@
 onfig %7B%0A
+    private static final Log LOG = LogFactory.getLog(AwsConfig.class);%0A%0A
     priv
@@ -558,17 +558,16 @@
 oad() %7B%0A
-%0A
         
@@ -616,91 +616,8 @@
 e%22);
-%0A//        ProfilesConfigFile file = new ProfilesConfigFile(home + %22/.aws/config%22);
 %0A%0A  
@@ -686,42 +686,54 @@
     
-// todo: use profile%0A        try %7B
+try %7B%0A            // todo: use default profile
 %0A   
@@ -964,16 +964,23 @@
         
+String 
 region =
@@ -1019,21 +1019,275 @@
 (%22region%22);%0A
+%0A        if (region != null) %7B%0A            this.region = region;%0A        %7D else %7B%0A            LOG.warn(%22Could not load region configuration. Please ensure AWS CLI is configured via 'aws configure'. Will use default region of %22 + this.region);%0A        %7D%0A%0A
     %7D%0A%0A%7D%0A

Use default region if region settings not configured