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(backend)!: update env variables #2732

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ services:
EXCHANGE_RATES_URL: http://cloud-nine-wallet/rates
REDIS_URL: redis://shared-redis:6379/0
WALLET_ADDRESS_URL: ${CLOUD_NINE_WALLET_ADDRESS_URL:-https://cloud-nine-wallet-backend/.well-known/pay}
ILP_CONNECTOR_ADDRESS: ${CLOUD_NINE_CONNECTOR_URL}
ILP_CONNECTOR_ADDRESS: http://127.0.0.1:3002
ENABLE_TELEMETRY: false
KEY_ID: rafiki
depends_on:
- shared-database
- shared-redis
Expand Down
3 changes: 3 additions & 0 deletions localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
ports:
- "4000:80"
- "4001:3001"
- "4002:3002"
- '9231:9229'
networks:
- rafiki
Expand All @@ -55,6 +56,7 @@ services:
AUTH_SERVER_GRANT_URL: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-http://happy-life-bank-auth:3006}
AUTH_SERVER_INTROSPECTION_URL: http://happy-life-bank-auth:3007
ILP_ADDRESS: test.happy-life-bank
ILP_CONNECTOR_ADDRESS: http://127.0.0.1:4002
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
API_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
WEBHOOK_URL: http://happy-life-bank/webhooks
Expand All @@ -63,6 +65,7 @@ services:
REDIS_URL: redis://shared-redis:6379/2
WALLET_ADDRESS_URL: ${HAPPY_LIFE_BANK_WALLET_ADDRESS_URL:-https://happy-life-bank-backend/.well-known/pay}
ENABLE_TELEMETRY: false
KEY_ID: rafiki
depends_on:
- cloud-nine-backend
happy-life-auth:
Expand Down
1 change: 1 addition & 0 deletions packages/backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
`<rootDir>/packages/${packageName}/src/`,
`<rootDir>/node_modules`
],
setupFiles: [`<rootDir>/packages/${packageName}/jest.env.js`],
id: packageName,
displayName: packageName,
rootDir: '../..'
Expand Down
9 changes: 9 additions & 0 deletions packages/backend/jest.env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
process.env.INSTANCE_NAME = 'Rafiki'
process.env.KEY_ID = 'myKey'
process.env.OPEN_PAYMENTS_URL = 'http://127.0.0.1:3000'
process.env.ILP_CONNECTOR_ADDRESS = 'http://127.0.0.1:3002'
process.env.ILP_ADDRESS = 'test.rafiki'
process.env.AUTH_SERVER_GRANT_URL = 'http://127.0.0.1:3006'
process.env.AUTH_SERVER_INTROSPECTION_URL = 'http://127.0.0.1:3007/'
process.env.WEBHOOK_URL = 'http://127.0.0.1:4001/webhook'
process.env.STREAM_SECRET = '2/PxuRFV9PAp0yJlnAifJ+1OxujjjI16lN+DBnLNRLA='
72 changes: 36 additions & 36 deletions packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { loadOrGenerateKey } from '@interledger/http-signature-utils'
import * as crypto from 'crypto'
import dotenv from 'dotenv'
import * as fs from 'fs'
import { ConnectionOptions } from 'tls'

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

if (envValue) return envValue
if (defaultValue) return defaultValue

throw new Error(`Environment variable ${name} must be set.`)
}

function envStringArray(name: string, value: string[]): string[] {
Expand Down Expand Up @@ -35,9 +38,18 @@ dotenv.config({
path: process.env.ENV_FILE || '.env'
})

let privateKeyFileEnv
try {
privateKeyFileEnv = envString('PRIVATE_KEY_FILE')
} catch (err) {
/* empty */
}

const privateKeyFileValue = loadOrGenerateKey(privateKeyFileEnv)

export const Config = {
logLevel: envString('LOG_LEVEL', 'info'),
enableTelemetry: envBool('ENABLE_TELEMETRY', true),
enableTelemetry: envBool('ENABLE_TELEMETRY', false),
livenet: envBool('LIVENET', false),
openTelemetryCollectors: envStringArray(
'OPEN_TELEMETRY_COLLECTOR_URLS',
Expand All @@ -59,7 +71,7 @@ export const Config = {
86_400_000
),
adminPort: envInt('ADMIN_PORT', 3001),
openPaymentsUrl: envString('OPEN_PAYMENTS_URL', 'http://127.0.0.1:3000'),
openPaymentsUrl: envString('OPEN_PAYMENTS_URL'),
openPaymentsPort: envInt('OPEN_PAYMENTS_PORT', 3003),
connectorPort: envInt('CONNECTOR_PORT', 3002),
autoPeeringServerPort: envInt('AUTO_PEERING_SERVER_PORT', 3005),
Expand All @@ -80,21 +92,15 @@ export const Config = {
trustProxy: envBool('TRUST_PROXY', false),
redisUrl: envString('REDIS_URL', 'redis://127.0.0.1:6379'),
redisTls: parseRedisTlsConfig(
envString('REDIS_TLS_CA_FILE_PATH', ''),
envString('REDIS_TLS_KEY_FILE_PATH', ''),
envString('REDIS_TLS_CERT_FILE_PATH', '')
process.env.REDIS_TLS_CA_FILE_PATH,
process.env.REDIS_TLS_KEY_FILE_PATH,
process.env.REDIS_TLS_CERT_FILE_PATH
),
ilpAddress: envString('ILP_ADDRESS', 'test.rafiki'),
ilpConnectorAddress: envString(
'ILP_CONNECTOR_ADDRESS',
'http://127.0.0.1:3002'
),
instanceName: envString('INSTANCE_NAME', 'Rafiki'),
streamSecret: process.env.STREAM_SECRET
? Buffer.from(process.env.STREAM_SECRET, 'base64')
: crypto.randomBytes(32),

useTigerbeetle: envBool('USE_TIGERBEETLE', false),
ilpAddress: envString('ILP_ADDRESS'),
ilpConnectorAddress: envString('ILP_CONNECTOR_ADDRESS'),
instanceName: envString('INSTANCE_NAME'),
streamSecret: Buffer.from(process.env.STREAM_SECRET || '', 'base64'),
useTigerbeetle: envBool('USE_TIGERBEETLE', true),
tigerbeetleClusterId: envInt('TIGERBEETLE_CLUSTER_ID', 0),
tigerbeetleReplicaAddresses: process.env.TIGERBEETLE_REPLICA_ADDRESSES
? process.env.TIGERBEETLE_REPLICA_ADDRESSES.split(',')
Expand All @@ -109,14 +115,8 @@ export const Config = {
walletAddressWorkers: envInt('WALLET_ADDRESS_WORKERS', 1),
walletAddressWorkerIdle: envInt('WALLET_ADDRESS_WORKER_IDLE', 200), // milliseconds

authServerGrantUrl: envString(
'AUTH_SERVER_GRANT_URL',
'http://127.0.0.1:3006'
),
authServerIntrospectionUrl: envString(
'AUTH_SERVER_INTROSPECTION_URL',
'http://127.0.0.1:3007/'
),
authServerGrantUrl: envString('AUTH_SERVER_GRANT_URL'),
authServerIntrospectionUrl: envString('AUTH_SERVER_INTROSPECTION_URL'),

outgoingPaymentWorkers: envInt('OUTGOING_PAYMENT_WORKERS', 4),
outgoingPaymentWorkerIdle: envInt('OUTGOING_PAYMENT_WORKER_IDLE', 200), // milliseconds
Expand All @@ -126,7 +126,7 @@ export const Config = {

webhookWorkers: envInt('WEBHOOK_WORKERS', 1),
webhookWorkerIdle: envInt('WEBHOOK_WORKER_IDLE', 200), // milliseconds
webhookUrl: envString('WEBHOOK_URL', 'http://127.0.0.1:4001/webhook'),
webhookUrl: envString('WEBHOOK_URL'),
webhookTimeout: envInt('WEBHOOK_TIMEOUT', 2000), // milliseconds
webhookMaxRetry: envInt('WEBHOOK_MAX_RETRY', 10),

Expand All @@ -141,8 +141,8 @@ export const Config = {
apiSecret: process.env.API_SECRET, // optional
apiSignatureVersion: envInt('API_SIGNATURE_VERSION', 1),

keyId: envString('KEY_ID', 'rafiki'),
privateKey: loadOrGenerateKey(envString('PRIVATE_KEY_FILE', '')),
keyId: envString('KEY_ID'),
privateKey: privateKeyFileValue,

graphQLIdempotencyKeyLockMs: envInt('GRAPHQL_IDEMPOTENCY_KEY_LOCK_MS', 2000),
graphQLIdempotencyKeyTtlMs: envInt(
Expand All @@ -169,23 +169,23 @@ export const Config = {
}

function parseRedisTlsConfig(
caFile: string,
keyFile: string,
certFile: string
caFile?: string,
keyFile?: string,
certFile?: string
): ConnectionOptions | undefined {
const options: ConnectionOptions = {}

// self-signed certs.
if (caFile !== '') {
if (caFile) {
options.ca = fs.readFileSync(caFile)
options.rejectUnauthorized = false
}

if (certFile !== '') {
if (certFile) {
options.cert = fs.readFileSync(certFile)
}

if (keyFile !== '') {
if (keyFile) {
options.key = fs.readFileSync(keyFile)
}

Expand Down
2 changes: 2 additions & 0 deletions test/integration/testenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
environment:
LOG_LEVEL: debug
NODE_ENV: development
INSTANCE_NAME: 'Rafiki'
CONNECTOR_PORT: 3102
ADMIN_PORT: 3101
OPEN_PAYMENTS_PORT: 3100
Expand All @@ -32,6 +33,7 @@ services:
AUTH_SERVER_INTROSPECTION_URL: http://cloud-nine-wallet-test-auth:3107
AUTH_SERVER_GRANT_URL: http://cloud-nine-wallet-test-auth:3106
ILP_ADDRESS: test.cloud-nine-wallet-test
ILP_CONNECTOR_ADDRESS: http://127.0.0.1:3102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be?

Suggested change
ILP_CONNECTOR_ADDRESS: http://127.0.0.1:3102
ILP_CONNECTOR_ADDRESS: http://host.docker.internal:3102

STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
WEBHOOK_URL: http://host.docker.internal:8888/webhooks
EXCHANGE_RATES_URL: http://host.docker.internal:8888/rates
Expand Down
2 changes: 2 additions & 0 deletions test/integration/testenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
environment:
NODE_ENV: development
LOG_LEVEL: debug
INSTANCE_NAME: 'Happy Life Test'
OPEN_PAYMENTS_URL: https://happy-life-bank-test-backend:4100
WALLET_ADDRESS_URL: https://happy-life-bank-test-backend:4100/.well-known/pay
ADMIN_PORT: 4101
Expand All @@ -29,6 +30,7 @@ services:
KEY_ID: keyid-97a3a431-8ee1-48fc-ac85-70e2f5eba8e5
PRIVATE_KEY_FILE: /workspace/private-key.pem
ILP_ADDRESS: test.happy-life-bank-test
ILP_CONNECTOR_ADDRESS: http://127.0.0.1:4102
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
WEBHOOK_URL: http://host.docker.internal:8889/webhooks
EXCHANGE_RATES_URL: http://host.docker.internal:8889/rates
Expand Down
Loading