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 and rename env variables #2749

Merged
merged 15 commits into from
Jun 25, 2024
Merged
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
5 changes: 3 additions & 2 deletions localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,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}
golobitch marked this conversation as resolved.
Show resolved Hide resolved
ENABLE_TELEMETRY: false
ILP_CONNECTOR_URL: ${CLOUD_NINE_CONNECTOR_URL}
ENABLE_TELEMETRY: true
KEY_ID: 7097F83B-CB84-469E-96C6-2141C72E22C0
depends_on:
- shared-database
- shared-redis
Expand Down
5 changes: 4 additions & 1 deletion localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:
ports:
- "4000:80"
- "4001:3001"
- "4002:3002"
- '9231:9229'
networks:
- rafiki
Expand All @@ -58,14 +59,16 @@ 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_URL: http://127.0.0.1:4002
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
API_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
WEBHOOK_URL: http://happy-life-bank/webhooks
OPEN_PAYMENTS_URL: ${HAPPY_LIFE_BANK_OPEN_PAYMENTS_URL:-http://happy-life-bank-backend}
EXCHANGE_RATES_URL: http://happy-life-bank/rates
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
ENABLE_TELEMETRY: true
KEY_ID: 53f2d913-e98a-40b9-b270-372d0547f23d
depends_on:
- cloud-nine-backend
happy-life-auth:
Expand Down
11 changes: 11 additions & 0 deletions packages/backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ const baseConfig = require('../../jest.config.base.js')
const packageName = require('./package.json').name

process.env.LOG_LEVEL = 'silent'
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_URL = '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='
process.env.USE_TIGERBEETLE = false
process.env.ENABLE_TELEMETRY = false

module.exports = {
...baseConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ export class App {
router.get(
WALLET_ADDRESS_PATH,
getWalletAddressUrlFromPath,
createSpspMiddleware(this.config.spspEnabled),
createSpspMiddleware(this.config.enableSpspPaymentPointers),
createValidatorMiddleware(
walletAddressServerSpec,
{
Expand Down
74 changes: 37 additions & 37 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'),
ilpConnectorUrl: envString('ILP_CONNECTOR_URL'),
instanceName: envString('INSTANCE_NAME'),
streamSecret: Buffer.from(process.env.STREAM_SECRET || '', 'base64'),
useTigerbeetle: envBool('USE_TIGERBEETLE', true),
golobitch marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -142,8 +142,8 @@ export const Config = {
adminApiSignatureVersion: envInt('API_SIGNATURE_VERSION', 1),
adminApiSignatureTtl: envInt('ADMIN_API_SIGNATURE_TTL_SECONDS', 30),

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 @@ -166,27 +166,27 @@ export const Config = {
'INCOMING_PAYMENT_EXPIRY_MAX_MS',
2592000000
), // 30 days
spspEnabled: envBool('ENABLE_SPSP', true)
enableSpspPaymentPointers: envBool('ENABLE_SPSP_PAYMENT_POINTERS', true)
}

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
10 changes: 5 additions & 5 deletions packages/backend/src/graphql/resolvers/auto-peering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('Auto Peering Resolvers', (): void => {

const peerDetails = {
staticIlpAddress: 'test.peer2',
ilpConnectorAddress: 'http://peer-two.com',
ilpConnectorUrl: 'http://peer-two.com',
name: 'Test Peer',
httpToken: 'httpToken'
}
Expand All @@ -137,7 +137,7 @@ describe('Auto Peering Resolvers', (): void => {
outgoing: {
__typename: 'HttpOutgoing',
authToken: expect.any(String),
endpoint: peerDetails.ilpConnectorAddress
endpoint: peerDetails.ilpConnectorUrl
}
},
maxPacketAmount: input.maxPacketAmount?.toString(),
Expand All @@ -153,7 +153,7 @@ describe('Auto Peering Resolvers', (): void => {

const peerDetails = {
staticIlpAddress: 'test.peer2',
ilpConnectorAddress: 'http://peer-two.com',
ilpConnectorUrl: 'http://peer-two.com',
name: 'Test Peer',
httpToken: 'httpToken'
}
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('Auto Peering Resolvers', (): void => {
outgoing: {
__typename: 'HttpOutgoing',
authToken: expect.any(String),
endpoint: peerDetails.ilpConnectorAddress
endpoint: peerDetails.ilpConnectorUrl
}
},
maxPacketAmount: input.maxPacketAmount?.toString(),
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('Auto Peering Resolvers', (): void => {
outgoing: {
__typename: 'HttpOutgoing',
authToken: expect.any(String),
endpoint: peerDetails.ilpConnectorAddress
endpoint: peerDetails.ilpConnectorUrl
}
},
maxPacketAmount: secondInput.maxPacketAmount?.toString(),
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ export const gracefulShutdown = async (
await redis.quit()
redis.disconnect()

const telemetry = await container.use('telemetry')
if (telemetry) {
await telemetry.shutdown()
if (config.enableTelemetry) {
const telemetry = await container.use('telemetry')
telemetry?.shutdown()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Auto Peering Routes', (): void => {
url: `/`,
body: {
staticIlpAddress: 'test.rafiki-money',
ilpConnectorAddress: 'http://peer.rafiki.money',
ilpConnectorUrl: 'http://peer.rafiki.money',
asset: { code: asset.code, scale: asset.scale },
httpToken: 'someHttpToken',
maxPacketAmount: 1000,
Expand All @@ -53,7 +53,7 @@ describe('Auto Peering Routes', (): void => {
expect(ctx.status).toBe(200)
expect(ctx.body).toEqual({
staticIlpAddress: config.ilpAddress,
ilpConnectorAddress: config.ilpConnectorAddress,
ilpConnectorUrl: config.ilpConnectorUrl,
httpToken: expect.any(String),
name: config.instanceName
})
Expand All @@ -65,7 +65,7 @@ describe('Auto Peering Routes', (): void => {
url: `/`,
body: {
staticIlpAddress: 'test.rafiki-money',
ilpConnectorAddress: 'http://peer.rafiki.money',
ilpConnectorUrl: 'http://peer.rafiki.money',
asset: { code: 'ABC', scale: 2 },
httpToken: 'someHttpToken'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AutoPeeringService } from './service'

interface PeeringRequestArgs {
staticIlpAddress: string
ilpConnectorAddress: string
ilpConnectorUrl: string
asset: { code: string; scale: number }
httpToken: string
maxPacketAmount?: number
Expand Down
Loading
Loading