Skip to content

Commit

Permalink
Adding dual connection options
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrichlake committed Dec 15, 2023
1 parent 2396521 commit 298a6ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public Map<HttpEndpoint, Function<DomainRequest, DomainResponse>> domainRegistra
ApplicationContext.register(OrderSender.class, LocalFileOrderSender.getInstance());

if (ApplicationContext.getProperty("DB_URL") != null) {
// logger.logInfo("Registering the database implementation for partner metadata");
ApplicationContext.register(
PartnerMetadataStorage.class, DatabasePartnerMetadataStorage.getInstance());
ApplicationContext.register(
Expand All @@ -87,7 +86,6 @@ public Map<HttpEndpoint, Function<DomainRequest, DomainResponse>> domainRegistra

} else {
ApplicationContext.register(OrderSender.class, ReportStreamOrderSender.getInstance());
// logger.logInfo("Registering the database implementation for partner metadata");
ApplicationContext.register(
PartnerMetadataStorage.class, DatabasePartnerMetadataStorage.getInstance());
ApplicationContext.register(SqlDriverManager.class, EtorSqlDriverManager.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,40 @@ protected Connection connect() throws SQLException {

// Ternaries prevent NullPointerException during testing since we decided not to mock env
// vars.
var user =
String user =
ApplicationContext.getProperty("DB_USER") == null
? ""
: ApplicationContext.getProperty("DB_USER");
// var pass =
// ApplicationContext.getProperty("DB_PASS") == null
// ? ""
// : ApplicationContext.getProperty("DB_PASS");
var ssl =
String pass =
ApplicationContext.getProperty("DB_PASS") == null
? ""
: ApplicationContext.getProperty("DB_PASS");
String ssl =
ApplicationContext.getProperty("DB_SSL") == null
? ""
: ApplicationContext.getProperty("DB_SSL");

Properties props = new Properties();
props.setProperty("user", user);
logger.logInfo("About to get the db password");

String token =
new DefaultAzureCredentialBuilder()
.build()
.getTokenSync(
new TokenRequestContext()
.addScopes(
"https://ossrdbms-aad.database.windows.net/.default")) // TODO: This string could need to be "https://ossrdbms-aad.database.windows.net/.default"
.getToken();
pass.isBlank()
? new DefaultAzureCredentialBuilder()
.build()
.getTokenSync(
new TokenRequestContext()
.addScopes(
"https://ossrdbms-aad.database.windows.net/.default"))
.getToken()
: pass;

logger.logInfo("got the db password");

props.setProperty("password", token);

// If the below prop isn't set to require and we just set ssl=true it will expect a CA cert
// in azure which breaks it
props.setProperty("sslmode", ssl);
conn = driverManager.getConnection(url, props);
logger.logInfo("DB Connected Successfully");
Expand Down
2 changes: 1 addition & 1 deletion generate_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
env_content="ENV=local\nKEY_VAULT_NAME=ti-key-vault-name
\nREPORT_STREAM_URL_PREFIX=http://localhost:7071\nDB_URL=localhost
\nDB_PORT=5433\nDB_NAME=intermediary\nDB_USER=intermediary
\nDB_PASS=changeIT!\nDB_SSL=false"
\nDB_PASS=changeIT!\nDB_SSL=require"

# Get directory of script file
script_dir="$(dirname "$0")"
Expand Down

0 comments on commit 298a6ec

Please sign in to comment.