package au.gov.dva;


import au.gov.dva.sopref.exceptions.ConfigurationError;

public class AppSettings {

    private static final String envVarName = "DEP_ENV";

    public static Environment getEnvironment() {

        String envVarValue = System.getenv(envVarName);
        if (envVarValue == null)
        {
            throw new ConfigurationError(String.format("Environment variable %smust have value.", envVarName));
        }
        switch (envVarValue)
        {
            case "devtest" : return Environment.devtest;
            case "devtestlocal" : return Environment.devtestlocal;
            case "prod" : return Environment.prod;
            default: throw new ConfigurationError(String.format("Value for environment variable %smust be 'devtest','devtestlocal' or 'prod'", envVarValue));

        }

    }

    public static class AzureStorage {

        // todo: get production values from environment variables



        public static class DevTest {
            // For use with Azure storage emulator.
            public final static String accountName = "devstoreaccount1";
            public final static String accountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
            public final static String storageConnectionString =  "UseDevelopmentStorage=true";
        }
    }

    public enum Environment {
        prod,
        devtest,
        devtestlocal
    }
}






@@ -72,16 +72,75 @@
 Error;%0A%0A
+import static au.gov.dva.AppSettings.Environment.devtest;%0A%0A
 public c
@@ -216,16 +216,17 @@
 _ENV%22;%0A%0A
+%0A
     publ
@@ -559,36 +559,24 @@
 t%22 : return 
-Environment.
 devtest;%0A   
@@ -863,139 +863,1026 @@
   %7D%0A
-%0A    %7D%0A%0A    public static class AzureStorage %7B%0A%0A        // todo: get production values from environment variables%0A%0A%0A%0A        public
+    %7D%0A%0A    private static String getEnvVarValue(String envVarName)%0A    %7B%0A        String value = System.getenv(envVarName);%0A        if (value == null)%0A        %7B%0A            throw new ConfigurationError(String.format(%22Expecting value for environment variable: %25s%22, envVarName));%0A        %7D%0A        return value;%0A    %7D%0A%0A    public static class AzureStorage %7B%0A%0A        // todo: get production values from environment variables%0A%0A        private static final String AZURE_STORAGE_CONNECTION_STRING = %22AZURE_STORAGE_CONNECTION_STRING%22;%0A%0A        public static String getConnectionString() %7B%0A            switch (getEnvironment())%0A            %7B%0A                case devtestlocal: return DevTestLocal.storageConnectionString;%0A                case devtest: return getEnvVarValue(AZURE_STORAGE_CONNECTION_STRING);%0A                case prod: return getEnvVarValue(AZURE_STORAGE_CONNECTION_STRING);%0A                default: throw new ConfigurationError(%22Cannot get Azure connection string%22);%0A            %7D%0A        %7D%0A%0A%0A%0A        private
  sta
@@ -1898,16 +1898,21 @@
  DevTest
+Local
  %7B%0A     

Set up AppSettings to provide appropriate Azure Storage Connection string depending on environment.