Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Untangle the DB_TYPE env var logic #40

Open
wants to merge 1 commit into
base: feature/surf
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/agent/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ DB_CONNECTION_NAME=default
# You can find instructions on how to self-host a Supabase deployment here: https://supabase.com/docs/guides/self-hosting
# You must inform below the DB connection specs. Either use the URL (more flexible), or use DB_HOST and DB_PORT.
# You can also include username and password: postgresql://user:password:5432/vc-issuer-db
DB_TYPE="sqlite"
DB_URL="postgresql://postgres:your-super-secret-and-long-postgres-password@127.0.0.1:5432/postgres"
#
# NOTE: DB_TYPE Must be 'postgres' and not 'postgresql'. It cannot be anything else.
DB_TYPE="postgres"
DB_URL="postgres://postgres:your-super-secret-and-long-postgres-password@127.0.0.1:5432/postgres"
#DB_DATABASE_NAME=postgres
#DB_USERNAME=postgres
#DB_PASSWORD=your-super-secret-and-long-postgres-password
Expand Down Expand Up @@ -82,4 +84,4 @@ OID4VCI_ISSUER_OPTIONS_PATH=
VC_API_BASE_PATH=/agent/vc

# The URL of the universal resolver.
UNIVERSAL_RESOLVER_RESOLVE_URL="https://dev.uniresolver.io/1.0/identifiers"
UNIVERSAL_RESOLVER_RESOLVE_URL="https://dev.uniresolver.io/1.0/identifiers"
23 changes: 1 addition & 22 deletions packages/agent/src/environment-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const toBoolean = (value: string | undefined, defaultValue?: boolean): boolean =
* so the rest of the code doesn't have to know the exact environment values
*/
export const ENV_VAR_PREFIX = process.env.ENV_VAR_PREFIX ?? ''
export const DB_TYPE = process.env.DB_TYPE ?? (() => { throw new Error('DB_TYPE is required') })();
export const DB_URL = env('DB_URL', ENV_VAR_PREFIX) // Using DB_URL is optional
export const DB_HOST = env('DB_HOST', ENV_VAR_PREFIX)
export const DB_PORT = env('DB_PORT', ENV_VAR_PREFIX)
Expand All @@ -42,28 +43,6 @@ export const DB_DATABASE_NAME = env('DB_DATABASE_NAME', ENV_VAR_PREFIX) ?? 'web-
export const DB_CACHE_ENABLED = env('DB_CACHE_ENABLED', ENV_VAR_PREFIX) ?? 'true'
export const DB_ENCRYPTION_KEY = env('DB_ENCRYPTION_KEY', ENV_VAR_PREFIX) ?? '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c'

let dbType = env('DB_TYPE', ENV_VAR_PREFIX)
if (!dbType) {
if (DB_URL) {
if (DB_URL.includes('sqlite')) {
dbType = 'sqlite'
} else if (DB_URL.startsWith('http') || DB_URL.startsWith('postgres')) {
dbType = 'postgres'
} else {
dbType = 'postgres'
}
}
}
if (!dbType) {
if (DB_HOST || DB_PORT) {
dbType = 'postgres'
}
} else if (dbType.toLowerCase().includes('postgres')) {
dbType = 'postgres'
}
export const DB_TYPE = dbType ?? 'postgres'
process.env[`${ENV_VAR_PREFIX}${DB_TYPE}`] = DB_TYPE // make sure we sync back in case we did not have it above

export const INTERNAL_HOSTNAME_OR_IP = env('INTERNAL_HOSTNAME_OR_IP', ENV_VAR_PREFIX) ?? env('HOSTNAME', ENV_VAR_PREFIX) ?? '0.0.0.0'
export const INTERNAL_PORT = env('PORT', ENV_VAR_PREFIX) ? Number.parseInt(env('PORT', ENV_VAR_PREFIX)!) : 5000
export const EXTERNAL_HOSTNAME = env('EXTERNAL_HOSTNAME', ENV_VAR_PREFIX) ?? 'localhost'
Expand Down