From 27a457b53a88fc03ab7b68226d2567fcf6264084 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 4 Jan 2025 09:23:57 -0600 Subject: [PATCH] Add support for redis auth (#602) --- apps/platform/src/config/env.ts | 2 ++ apps/platform/src/config/redis.ts | 12 ++++++++---- docker-compose.yml | 6 ++++++ docs/docs/advanced/config.md | 14 +++++++++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/platform/src/config/env.ts b/apps/platform/src/config/env.ts index 3fb24f9a..84c3a690 100644 --- a/apps/platform/src/config/env.ts +++ b/apps/platform/src/config/env.ts @@ -73,6 +73,8 @@ export default (type?: EnvType): Env => { redis: { host: process.env.REDIS_HOST!, port: parseInt(process.env.REDIS_PORT!), + username: process.env.REDIS_USERNAME, + password: process.env.REDIS_PASSWORD, tls: process.env.REDIS_TLS === 'true', }, queue: driver(process.env.QUEUE_DRIVER, { diff --git a/apps/platform/src/config/redis.ts b/apps/platform/src/config/redis.ts index a3d00a32..8407239c 100644 --- a/apps/platform/src/config/redis.ts +++ b/apps/platform/src/config/redis.ts @@ -3,14 +3,18 @@ import IORedis, { Redis } from 'ioredis' export interface RedisConfig { host: string port: number + username?: string + password?: string tls: boolean } -export const DefaultRedis = (config: RedisConfig, extraOptions = {}): Redis => { +export const DefaultRedis = ({ port, host, username, password, tls }: RedisConfig, extraOptions = {}): Redis => { return new IORedis({ - port: config.port, - host: config.host, - tls: config.tls + port, + host, + ...username && { username }, + ...password && { password }, + tls: tls ? { rejectUnauthorized: false } : undefined, ...extraOptions, diff --git a/docker-compose.yml b/docker-compose.yml index 920ea3f8..3174968e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,6 +66,9 @@ services: REDIS_HOST: ${REDIS_HOST} REDIS_PORT: ${REDIS_PORT} REDIS_TLS: ${REDIS_TLS} + REDIS_CONCURRENCY: ${REDIS_CONCURRENCY} + REDIS_USERNAME: ${REDIS_USERNAME} + REDIS_PASSWORD: ${REDIS_PASSWORD} AWS_SQS_QUEUE_URL: ${AWS_SQS_QUEUE_URL} AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} @@ -135,6 +138,9 @@ services: REDIS_HOST: ${REDIS_HOST} REDIS_PORT: ${REDIS_PORT} REDIS_TLS: ${REDIS_TLS} + REDIS_CONCURRENCY: ${REDIS_CONCURRENCY} + REDIS_USERNAME: ${REDIS_USERNAME} + REDIS_PASSWORD: ${REDIS_PASSWORD} AWS_SQS_QUEUE_URL: ${AWS_SQS_QUEUE_URL} AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} diff --git a/docs/docs/advanced/config.md b/docs/docs/advanced/config.md index b2e75319..6ffba138 100644 --- a/docs/docs/advanced/config.md +++ b/docs/docs/advanced/config.md @@ -20,13 +20,25 @@ Find below a list of all environment variables that can be set at launch to conf ### Queue | key | type | required | |--|--|--| -| QUEUE_DRIVER | 'sqs' or 'memory' | true | +| QUEUE_DRIVER | 'sqs' or 'redis' or 'memory' | true | | AWS_SQS_QUEUE_URL | string | If driver is SQS | | AWS_REGION | string | If driver is SQS | | AWS_ACCESS_KEY_ID | string | If driver is SQS | | AWS_SECRET_ACCESS_KEY | string | If driver is SQS | +| REDIS_HOST | string | If driver is Redis | +| REDIS_PORT | string | If driver is Redis | +| REDIS_TLS | boolean | false | +### Redis +| key | type | required | +|--|--|--| +| REDIS_HOST | string | true | +| REDIS_PORT | string | true | +| REDIS_TLS | boolean | false | +| REDIS_USERNAME | string | false | +| REDIS_PASSWORD | string | false | + ### Storage | key | type | required | |--|--|--|