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

feat(env)!: rename few of them and specify default values #2720

Closed
wants to merge 4 commits into from
Closed
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
25 changes: 12 additions & 13 deletions packages/auth/src/config/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as crypto from 'crypto'
import dotenv from 'dotenv'

function envString(name: string, value: string): string {
function envString(name: string, value?: string): string {
const envValue = process.env[name]
return envValue == null ? value : envValue
if (envValue) return envValue

if (typeof value === 'undefined') {
throw new Error(`Missing required key value (${name})`)
}

return value
}

function envInt(name: string, value: number): number {
Expand Down Expand Up @@ -36,17 +41,11 @@ export const Config = {
'AUTH_DATABASE_URL',
'postgresql://postgres:password@localhost:5432/auth_development'
),
identityServerDomain: envString(
'IDENTITY_SERVER_DOMAIN',
'http://localhost:3030/mock-idp/'
),
identityServerSecret: envString('IDENTITY_SERVER_SECRET', 'replace-me'),
authServerDomain: envString(
'AUTH_SERVER_DOMAIN',
`http://localhost:${envInt('AUTH_PORT', 3006)}`
),
identityServerDomain: envString('IDENTITY_SERVER_URL'),
identityServerSecret: envString('IDENTITY_SERVER_SECRET'),
authServerDomain: envString('AUTH_SERVER_URL'),
waitTimeSeconds: envInt('WAIT_SECONDS', 5),
cookieKey: envString('COOKIE_KEY', crypto.randomBytes(32).toString('hex')),
cookieKey: envString('COOKIE_KEY'),
interactionExpirySeconds: envInt('INTERACTION_EXPIRY_SECONDS', 10 * 60), // Default 10 minutes
accessTokenExpirySeconds: envInt('ACCESS_TOKEN_EXPIRY_SECONDS', 10 * 60), // Default 10 minutes
databaseCleanupWorkers: envInt('DATABASE_CLEANUP_WORKERS', 1),
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/accounting/psql/balance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('Balances', (): void => {
let asset: Asset

beforeAll(async (): Promise<void> => {
const deps = initIocContainer({ ...Config, useTigerbeetle: false })
Config.useTigerbeetle = false
const deps = initIocContainer()
appContainer = await createTestApp(deps)
serviceDeps = {
logger: await deps.use('logger'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('Ledger Account', (): void => {
let asset: Asset

beforeAll(async (): Promise<void> => {
const deps = initIocContainer({ ...Config, useTigerbeetle: false })
Config.useTigerbeetle = false
const deps = initIocContainer()
appContainer = await createTestApp(deps)
serviceDeps = {
logger: await deps.use('logger'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ describe('Ledger Transfer', (): void => {
let asset: Asset

beforeAll(async (): Promise<void> => {
const deps = initIocContainer({ ...Config, useTigerbeetle: false })
Config.useTigerbeetle = false
const deps = initIocContainer()
appContainer = await createTestApp(deps)
serviceDeps = {
logger: await deps.use('logger'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('Ledger Transfer Model', (): void => {
let asset: Asset

beforeAll(async (): Promise<void> => {
const deps = initIocContainer({ ...Config, useTigerbeetle: false })
Config.useTigerbeetle = false
const deps = initIocContainer()
appContainer = await createTestApp(deps)
knex = appContainer.knex
})
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/accounting/psql/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ describe('Psql Accounting Service', (): void => {
let asset: Asset

beforeAll(async (): Promise<void> => {
deps = initIocContainer({ ...Config, useTigerbeetle: false })
Config.useTigerbeetle = false
const deps = initIocContainer()
appContainer = await createTestApp(deps)
knex = appContainer.knex
accountingService = await deps.use('accountingService')
Expand Down
8 changes: 3 additions & 5 deletions packages/backend/src/accounting/tigerbeetle/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ describe('Tigerbeetle Accounting Service', (): void => {
const tigerbeetlePort = (global as unknown as { tigerbeetlePort: number })
.tigerbeetlePort

deps = initIocContainer({
...Config,
tigerbeetleReplicaAddresses: [tigerbeetlePort.toString()],
useTigerbeetle: true
})
Config.useTigerbeetle = true
Config.tigerbeetleReplicaAddresses = [tigerbeetlePort.toString()]
deps = initIocContainer()
appContainer = await createTestApp(deps)
accountingService = await deps.use('accountingService')
accountFactory = new AccountFactory(accountingService, newLedger)
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/asset/model.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Knex } from 'knex'

import { AssetService } from './service'
import { Config } from '../config/app'
import { createTestApp, TestContainer } from '../tests/app'
import { IocContract } from '@adonisjs/fold'
import { initIocContainer } from '../'
Expand All @@ -18,7 +17,7 @@ describe('Models', (): void => {
let knex: Knex

beforeAll(async (): Promise<void> => {
deps = initIocContainer(Config)
deps = initIocContainer()
appContainer = await createTestApp(deps)
assetService = await deps.use('assetService')
knex = await deps.use('knex')
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/asset/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getPageTests } from '../shared/baseModel.test'
import { createTestApp, TestContainer } from '../tests/app'
import { createAsset, randomAsset } from '../tests/asset'
import { truncateTables } from '../tests/tableManager'
import { Config } from '../config/app'
import { IocContract } from '@adonisjs/fold'
import { initIocContainer } from '../'
import { AppServices } from '../app'
Expand All @@ -22,7 +21,7 @@ describe('Asset Service', (): void => {
let assetService: AssetService

beforeAll(async (): Promise<void> => {
deps = initIocContainer(Config)
deps = initIocContainer()
appContainer = await createTestApp(deps)
assetService = await deps.use('assetService')
})
Expand Down
Loading
Loading