Skip to content

Commit

Permalink
add logging around db secret fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed May 15, 2024
1 parent 3c5b506 commit 08d18de
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/api/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const client = new SecretsManagerClient({
});

const getSecretJson = async (name: string) => {
console.log("Fetching secret:", name);

try {
const response = await client.send(
new GetSecretValueCommand({
Expand All @@ -35,16 +37,19 @@ const getSecretJson = async (name: string) => {

const getDatabaseUrl = async () => {
if (process.env.DATABASE_URL) {
console.log("Using database connection string from environment");
return process.env.DATABASE_URL;
}

const secret = (await getSecretJson(DATABASE_SECRET_NAME)) as
| TdkDbSecret
| undefined;
if (!secret) {
console.error("No database connection string found");
return undefined;
}

console.log("Using database connection string from secret");
const { engine, username, password, host, port, dbname } = secret;
return `${engine}://${username}:${password}@${host}:${port}/${dbname}`;
};
Expand Down

0 comments on commit 08d18de

Please sign in to comment.