PRDONE-94: updated to look for dotenv properties and fall back to environment vars

This commit is contained in:
Tim Chamberlain
2022-08-30 13:33:13 -05:00
parent dcea96579c
commit 4bf1fe8638
2 changed files with 47 additions and 41 deletions

View File

@ -103,17 +103,21 @@ class ConnectionManagerTest
private RDBMSBackendMetaData getAuroraBacked() private RDBMSBackendMetaData getAuroraBacked()
{ {
Dotenv dotenv = Dotenv.configure() Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
.systemProperties() String vendor = (dotenv.get("RDBMS_VENDOR") != null) ? dotenv.get("RDBMS_VENDOR") : System.getenv("RDBMS_VENDOR");
.ignoreIfMissing() String hostname = (dotenv.get("RDBMS_HOSTNAME") != null) ? dotenv.get("RDBMS_HOSTNAME") : System.getenv("RDBMS_HOSTNAME");
.load(); Integer port = (dotenv.get("RDBMS_PORT") != null) ? Integer.valueOf(Objects.requireNonNull(dotenv.get("RDBMS_PORT"))) : Integer.valueOf(System.getenv("RDBMS_PORT"));
String databaseName = (dotenv.get("RDBMS_DATABASE_NAME") != null) ? dotenv.get("RDBMS_DATABASE_NAME") : System.getenv("RDBMS_DATABASE_NAME");
String userName = (dotenv.get("RDBMS_USERNAME") != null) ? dotenv.get("RDBMS_USERNAME") : System.getenv("RDBMS_USERNAME");
String password = (dotenv.get("RDBMS_PASSWORD") != null) ? dotenv.get("RDBMS_PASSWORD") : System.getenv("RDBMS_PASSWORD");
return new RDBMSBackendMetaData() return new RDBMSBackendMetaData()
.withName("aurora-test") .withName("aurora-test")
.withVendor(System.getProperty("RDBMS_VENDOR")) .withVendor(vendor)
.withHostName(System.getProperty("RDBMS_HOSTNAME")) .withHostName(hostname)
.withPort(Integer.valueOf(Objects.requireNonNull(System.getProperty("RDBMS_PORT")))) .withPort(port)
.withDatabaseName(System.getProperty("RDBMS_DATABASE_NAME")) .withDatabaseName(databaseName)
.withUsername(System.getProperty("RDBMS_USERNAME")) .withUsername(userName)
.withPassword(System.getProperty("RDBMS_PASSWORD")); .withPassword(password);
} }
} }

View File

@ -73,22 +73,22 @@ public class SampleMetaDataProvider
{ {
public static boolean USE_MYSQL = true; public static boolean USE_MYSQL = true;
public static final String RDBMS_BACKEND_NAME = "rdbms"; public static final String RDBMS_BACKEND_NAME = "rdbms";
public static final String FILESYSTEM_BACKEND_NAME = "filesystem"; public static final String FILESYSTEM_BACKEND_NAME = "filesystem";
public static final String APP_NAME_GREETINGS = "greetingsApp"; public static final String APP_NAME_GREETINGS = "greetingsApp";
public static final String APP_NAME_PEOPLE = "peopleApp"; public static final String APP_NAME_PEOPLE = "peopleApp";
public static final String APP_NAME_MISCELLANEOUS = "miscellaneous"; public static final String APP_NAME_MISCELLANEOUS = "miscellaneous";
public static final String PROCESS_NAME_GREET = "greet"; public static final String PROCESS_NAME_GREET = "greet";
public static final String PROCESS_NAME_GREET_INTERACTIVE = "greetInteractive"; public static final String PROCESS_NAME_GREET_INTERACTIVE = "greetInteractive";
public static final String PROCESS_NAME_SIMPLE_SLEEP = "simpleSleep"; public static final String PROCESS_NAME_SIMPLE_SLEEP = "simpleSleep";
public static final String PROCESS_NAME_SIMPLE_THROW = "simpleThrow"; public static final String PROCESS_NAME_SIMPLE_THROW = "simpleThrow";
public static final String PROCESS_NAME_SLEEP_INTERACTIVE = "sleepInteractive"; public static final String PROCESS_NAME_SLEEP_INTERACTIVE = "sleepInteractive";
public static final String TABLE_NAME_PERSON = "person"; public static final String TABLE_NAME_PERSON = "person";
public static final String TABLE_NAME_CARRIER = "carrier"; public static final String TABLE_NAME_CARRIER = "carrier";
public static final String TABLE_NAME_CITY = "city"; public static final String TABLE_NAME_CITY = "city";
public static final String STEP_NAME_SLEEPER = "sleeper"; public static final String STEP_NAME_SLEEPER = "sleeper";
public static final String STEP_NAME_THROWER = "thrower"; public static final String STEP_NAME_THROWER = "thrower";
@ -135,15 +135,17 @@ public class SampleMetaDataProvider
.withName(PersonsByCreateDateBarChart.class.getSimpleName()) .withName(PersonsByCreateDateBarChart.class.getSimpleName())
.withCodeReference(new QCodeReference(PersonsByCreateDateBarChart.class, null))); .withCodeReference(new QCodeReference(PersonsByCreateDateBarChart.class, null)));
Dotenv dotenv = Dotenv.configure() Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
.ignoreIfMissing() String accountId = (dotenv.get("QUICKSIGHT_ACCOUNT_ID") != null) ? dotenv.get("QUICKSIGHT_ACCOUNT_ID") : System.getenv("QUICKSIGHT_ACCOUNT_ID");
.systemProperties() String accessKey = (dotenv.get("QUICKSIGHT_ACCESS_KEY") != null) ? dotenv.get("QUICKSIGHT_ACCESS_KEY") : System.getenv("QUICKSIGHT_ACCESS_KEY");
.load(); String secretKey = (dotenv.get("QUICKSIGHT_SECRET_KEY") != null) ? dotenv.get("QUICKSIGHT_SECRET_KEY") : System.getenv("QUICKSIGHT_SECRET_KEY");
String userArn = (dotenv.get("QUICKSIGHT_USER_ARN") != null) ? dotenv.get("QUICKSIGHT_USER_ARN") : System.getenv("QUICKSIGHT_USER_ARN");
QWidgetMetaDataInterface quickSightChartMetaData = new QuickSightChartMetaData() QWidgetMetaDataInterface quickSightChartMetaData = new QuickSightChartMetaData()
.withAccountId(System.getProperty("QUICKSIGHT_ACCCOUNT_ID")) .withAccountId(accountId)
.withAccessKey(System.getProperty("QUICKSIGHT_ACCESS_KEY")) .withAccessKey(accessKey)
.withSecretKey(System.getProperty("QUICKSIGHT_SECRET_KEY")) .withSecretKey(secretKey)
.withUserArn(System.getProperty("QUICKSIGHT_USER_ARN")) .withUserArn(userArn)
.withDashboardId("9e452e78-8509-4c81-bb7f-967abfc356da") .withDashboardId("9e452e78-8509-4c81-bb7f-967abfc356da")
.withRegion(Regions.US_EAST_2.getName()) .withRegion(Regions.US_EAST_2.getName())
.withName(QuickSightChartRenderer.class.getSimpleName()) .withName(QuickSightChartRenderer.class.getSimpleName())
@ -171,11 +173,7 @@ public class SampleMetaDataProvider
.withIcon(new QIcon().withName("location_city"))) .withIcon(new QIcon().withName("location_city")))
.withChild(qInstance.getProcess(PROCESS_NAME_GREET_INTERACTIVE)) .withChild(qInstance.getProcess(PROCESS_NAME_GREET_INTERACTIVE))
.withIcon(new QIcon().withName("waving_hand")) .withIcon(new QIcon().withName("waving_hand"))
.withWidgets(List.of .withWidgets(List.of(PersonsByCreateDateBarChart.class.getSimpleName(), QuickSightChartRenderer.class.getSimpleName()))
(
PersonsByCreateDateBarChart.class.getSimpleName(),
QuickSightChartRenderer.class.getSimpleName()
))
); );
qInstance.addApp(new QAppMetaData() qInstance.addApp(new QAppMetaData()
@ -213,18 +211,22 @@ public class SampleMetaDataProvider
{ {
if(USE_MYSQL) if(USE_MYSQL)
{ {
Dotenv dotenv = Dotenv.configure() Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
.ignoreIfMissing() String vendor = (dotenv.get("RDBMS_VENDOR") != null) ? dotenv.get("RDBMS_VENDOR") : System.getenv("RDBMS_VENDOR");
.systemProperties() String hostname = (dotenv.get("RDBMS_HOSTNAME") != null) ? dotenv.get("RDBMS_HOSTNAME") : System.getenv("RDBMS_HOSTNAME");
.load(); Integer port = (dotenv.get("RDBMS_PORT") != null) ? Integer.valueOf(Objects.requireNonNull(dotenv.get("RDBMS_PORT"))) : Integer.valueOf(System.getenv("RDBMS_PORT"));
String databaseName = (dotenv.get("RDBMS_DATABASE_NAME") != null) ? dotenv.get("RDBMS_DATABASE_NAME") : System.getenv("RDBMS_DATABASE_NAME");
String userName = (dotenv.get("RDBMS_USERNAME") != null) ? dotenv.get("RDBMS_USERNAME") : System.getenv("RDBMS_USERNAME");
String password = (dotenv.get("RDBMS_PASSWORD") != null) ? dotenv.get("RDBMS_PASSWORD") : System.getenv("RDBMS_PASSWORD");
return new RDBMSBackendMetaData() return new RDBMSBackendMetaData()
.withName(RDBMS_BACKEND_NAME) .withName(RDBMS_BACKEND_NAME)
.withVendor(System.getProperty("RDBMS_VENDOR")) .withVendor(vendor)
.withHostName(System.getProperty("RDBMS_HOSTNAME")) .withHostName(hostname)
.withPort(Integer.valueOf(Objects.requireNonNull(System.getProperty("RDBMS_PORT")))) .withPort(port)
.withDatabaseName(System.getProperty("RDBMS_DATABASE_NAME")) .withDatabaseName(databaseName)
.withUsername(System.getProperty("RDBMS_USERNAME")) .withUsername(userName)
.withPassword(System.getProperty("RDBMS_PASSWORD")); .withPassword(password);
} }
else else
{ {