diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 07808df..ca9666d 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -3,7 +3,7 @@ This document provides detailed information about environment variables for the gateway. | Name | Description | Type | Default | -| --------------------------- | ---------------------------------------------------------------------------------------------------- | -------- | ---------------------------------------------- | +|-----------------------------|------------------------------------------------------------------------------------------------------| -------- |------------------------------------------------| | `ALLOWED_ROLES` | Allowed roles when authentication is enabled. | `array` | ["user", "viewer"] | | `ALLOWED_ROLES_NO_AUTH` | Allowed roles when authentication is disabled. | `array` | ["aerie_admin", "user", "viewer"] | | `AUTH_GROUP_ROLE_MAPPINGS` | JSON object that maps auth provider groups to Aerie roles. See [SSO authentication docs][SSO authn] | `JSON` | {} | @@ -21,7 +21,7 @@ This document provides detailed information about environment variables for the | `LOG_FILE` | Either an output filepath to log to, or 'console'. | `string` | console | | `LOG_LEVEL` | Logging level for filtering logs. | `string` | warn | | `PORT` | Port the Gateway server listens on. | `number` | 9000 | -| `POSTGRES_AERIE_MERLIN_DB` | Name of Merlin Postgres database. | `string` | aerie_merlin | +| `POSTGRES_AERIE_DB` | Name of Aerie Postgres database. | `string` | aerie | | `POSTGRES_HOST` | Hostname of Postgres instance. | `string` | localhost | | `POSTGRES_PASSWORD` | Password of Postgres instance. | `string` | | | `POSTGRES_PORT` | Port of Postgres instance. | `number` | 5432 | diff --git a/src/env.ts b/src/env.ts index b5b68f8..0f40cea 100644 --- a/src/env.ts +++ b/src/env.ts @@ -19,17 +19,18 @@ export type Env = { LOG_FILE: string; LOG_LEVEL: string; PORT: string; - POSTGRES_AERIE_MERLIN_DB: string; - POSTGRES_HOST: string; - POSTGRES_PASSWORD: string; - POSTGRES_PORT: string; - POSTGRES_USER: string; + AERIE_DB_HOST: string; + AERIE_DB_PORT: string; + GATEWAY_DB_USER: string; + GATEWAY_DB_PASSWORD: string; RATE_LIMITER_FILES_MAX: number; RATE_LIMITER_LOGIN_MAX: number; VERSION: string; }; export const defaultEnv: Env = { + AERIE_DB_HOST: 'localhost', + AERIE_DB_PORT: '5432', ALLOWED_ROLES: ['user', 'viewer'], ALLOWED_ROLES_NO_AUTH: ['aerie_admin', 'user', 'viewer'], AUTH_GROUP_ROLE_MAPPINGS: {}, @@ -39,6 +40,8 @@ export const defaultEnv: Env = { AUTH_URL: 'https://atb-ocio-12b.jpl.nasa.gov:8443/cam-api', DEFAULT_ROLE: ['user'], DEFAULT_ROLE_NO_AUTH: 'aerie_admin', + GATEWAY_DB_PASSWORD: '', + GATEWAY_DB_USER: '', GQL_API_URL: 'http://localhost:8080/v1/graphql', GQL_API_WS_URL: 'ws://localhost:8080/v1/graphql', HASURA_GRAPHQL_JWT_SECRET: '', @@ -47,11 +50,6 @@ export const defaultEnv: Env = { LOG_FILE: 'console', LOG_LEVEL: 'info', PORT: '9000', - POSTGRES_AERIE_MERLIN_DB: 'aerie_merlin', - POSTGRES_HOST: 'localhost', - POSTGRES_PASSWORD: '', - POSTGRES_PORT: '5432', - POSTGRES_USER: '', RATE_LIMITER_FILES_MAX: 1000, RATE_LIMITER_LOGIN_MAX: 1000, VERSION: '2.6.0', @@ -64,8 +62,7 @@ export const defaultEnv: Env = { function parseArray(value: string | undefined, defaultValue: T[]): T[] { if (typeof value === 'string') { try { - const parsedValue = JSON.parse(value); - return parsedValue; + return JSON.parse(value); } catch (e) { console.error(e); return defaultValue; @@ -124,16 +121,17 @@ export function getEnv(): Env { const LOG_FILE = env['LOG_FILE'] ?? defaultEnv.LOG_FILE; const LOG_LEVEL = env['LOG_LEVEL'] ?? defaultEnv.LOG_LEVEL; const PORT = env['PORT'] ?? defaultEnv.PORT; - const POSTGRES_AERIE_MERLIN_DB = env['POSTGRES_AERIE_MERLIN_DB'] ?? defaultEnv.POSTGRES_AERIE_MERLIN_DB; - const POSTGRES_HOST = env['POSTGRES_HOST'] ?? defaultEnv.POSTGRES_HOST; - const POSTGRES_PASSWORD = env['POSTGRES_PASSWORD'] ?? defaultEnv.POSTGRES_PASSWORD; - const POSTGRES_PORT = env['POSTGRES_PORT'] ?? defaultEnv.POSTGRES_PORT; - const POSTGRES_USER = env['POSTGRES_USER'] ?? defaultEnv.POSTGRES_USER; + const AERIE_DB_HOST = env['AERIE_DB_HOST'] ?? defaultEnv.AERIE_DB_HOST; + const AERIE_DB_PORT = env['AERIE_DB_PORT'] ?? defaultEnv.AERIE_DB_PORT; + const GATEWAY_DB_USER = env['GATEWAY_DB_USER'] ?? defaultEnv.GATEWAY_DB_USER; + const GATEWAY_DB_PASSWORD = env['GATEWAY_DB_PASSWORD'] ?? defaultEnv.GATEWAY_DB_PASSWORD; const RATE_LIMITER_FILES_MAX = parseNumber(env['RATE_LIMITER_FILES_MAX'], defaultEnv.RATE_LIMITER_FILES_MAX); const RATE_LIMITER_LOGIN_MAX = parseNumber(env['RATE_LIMITER_LOGIN_MAX'], defaultEnv.RATE_LIMITER_LOGIN_MAX); const VERSION = env['npm_package_version'] ?? defaultEnv.VERSION; return { + AERIE_DB_HOST, + AERIE_DB_PORT, ALLOWED_ROLES, ALLOWED_ROLES_NO_AUTH, AUTH_GROUP_ROLE_MAPPINGS, @@ -143,6 +141,8 @@ export function getEnv(): Env { AUTH_URL, DEFAULT_ROLE, DEFAULT_ROLE_NO_AUTH, + GATEWAY_DB_PASSWORD, + GATEWAY_DB_USER, GQL_API_URL, GQL_API_WS_URL, HASURA_GRAPHQL_JWT_SECRET, @@ -151,11 +151,6 @@ export function getEnv(): Env { LOG_FILE, LOG_LEVEL, PORT, - POSTGRES_AERIE_MERLIN_DB, - POSTGRES_HOST, - POSTGRES_PASSWORD, - POSTGRES_PORT, - POSTGRES_USER, RATE_LIMITER_FILES_MAX, RATE_LIMITER_LOGIN_MAX, VERSION, diff --git a/src/packages/db/db.ts b/src/packages/db/db.ts index ee1489a..c264c14 100644 --- a/src/packages/db/db.ts +++ b/src/packages/db/db.ts @@ -5,13 +5,7 @@ import getLogger from '../../logger.js'; const { Pool: DbPool } = pg; -const { - POSTGRES_AERIE_MERLIN_DB, - POSTGRES_HOST: host, - POSTGRES_PASSWORD: password, - POSTGRES_PORT: port, - POSTGRES_USER: user, -} = getEnv(); +const { AERIE_DB_HOST: host, AERIE_DB_PORT: port, GATEWAY_DB_USER: user, GATEWAY_DB_PASSWORD: password } = getEnv(); const logger = getLogger('packages/db/db'); @@ -25,7 +19,7 @@ export class DbMerlin { static async init(): Promise { try { const config: PoolConfig = { - database: POSTGRES_AERIE_MERLIN_DB, + database: 'aerie', host, password, port: parseInt(port, 10),