mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
fix: use ACL username and decode credentials in Redis URL parsing (#2434)
* fix: use ACL username and decode credentials in Redis URL parsing * fix: pass family and TLS options to the collab app module
This commit is contained in:
@@ -63,6 +63,7 @@ export class CollaborationGateway {
|
|||||||
redis: new RedisClient({
|
redis: new RedisClient({
|
||||||
host: this.redisConfig.host,
|
host: this.redisConfig.host,
|
||||||
port: this.redisConfig.port,
|
port: this.redisConfig.port,
|
||||||
|
username: this.redisConfig.username,
|
||||||
password: this.redisConfig.password,
|
password: this.redisConfig.password,
|
||||||
db: this.redisConfig.db,
|
db: this.redisConfig.db,
|
||||||
family: this.redisConfig.family,
|
family: this.redisConfig.family,
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import { RedisModule } from '@nestjs-labs/nestjs-ioredis';
|
|||||||
import { RedisConfigService } from '../../integrations/redis/redis-config.service';
|
import { RedisConfigService } from '../../integrations/redis/redis-config.service';
|
||||||
import { CaslModule } from '../../core/casl/casl.module';
|
import { CaslModule } from '../../core/casl/casl.module';
|
||||||
import { CacheModule } from '@nestjs/cache-manager';
|
import { CacheModule } from '@nestjs/cache-manager';
|
||||||
import KeyvRedis from '@keyv/redis';
|
import KeyvRedis, { defaultReconnectStrategy } from '@keyv/redis';
|
||||||
|
import { parseRedisUrl } from '../../common/helpers';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -33,10 +34,20 @@ import KeyvRedis from '@keyv/redis';
|
|||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
useFactory: async (environmentService: EnvironmentService) => {
|
useFactory: async (environmentService: EnvironmentService) => {
|
||||||
const redisUrl = environmentService.getRedisUrl();
|
const redisUrl = environmentService.getRedisUrl();
|
||||||
|
const { family, tls } = parseRedisUrl(redisUrl);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ttl: 5 * 1000,
|
ttl: 5 * 1000,
|
||||||
stores: [new KeyvRedis(redisUrl)],
|
stores: [
|
||||||
|
new KeyvRedis({
|
||||||
|
url: redisUrl,
|
||||||
|
socket: {
|
||||||
|
family,
|
||||||
|
reconnectStrategy: defaultReconnectStrategy,
|
||||||
|
...tls,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
inject: [EnvironmentService],
|
inject: [EnvironmentService],
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export type RedisConfig = {
|
|||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
db: number;
|
db: number;
|
||||||
|
username?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
family?: number;
|
family?: number;
|
||||||
tls?: { rejectUnauthorized?: boolean };
|
tls?: { rejectUnauthorized?: boolean };
|
||||||
@@ -36,7 +37,15 @@ export type RedisConfig = {
|
|||||||
export function parseRedisUrl(redisUrl: string): RedisConfig {
|
export function parseRedisUrl(redisUrl: string): RedisConfig {
|
||||||
// format - redis[s]://[[username][:password]@][host][:port][/db-number][?family=4|6][&rejectUnauthorized=false]
|
// format - redis[s]://[[username][:password]@][host][:port][/db-number][?family=4|6][&rejectUnauthorized=false]
|
||||||
const url = new URL(redisUrl);
|
const url = new URL(redisUrl);
|
||||||
const { hostname, port, password, pathname, protocol, searchParams } = url;
|
const {
|
||||||
|
hostname,
|
||||||
|
port,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
pathname,
|
||||||
|
protocol,
|
||||||
|
searchParams,
|
||||||
|
} = url;
|
||||||
const portInt = port ? parseInt(port, 10) : 6379;
|
const portInt = port ? parseInt(port, 10) : 6379;
|
||||||
|
|
||||||
let db: number = 0;
|
let db: number = 0;
|
||||||
@@ -62,7 +71,15 @@ export function parseRedisUrl(redisUrl: string): RedisConfig {
|
|||||||
: {}
|
: {}
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return { host: hostname, port: portInt, password: password || undefined, db, family, tls };
|
return {
|
||||||
|
host: hostname,
|
||||||
|
port: portInt,
|
||||||
|
username: username ? decodeURIComponent(username) : undefined,
|
||||||
|
password: password ? decodeURIComponent(password) : undefined,
|
||||||
|
db,
|
||||||
|
family,
|
||||||
|
tls,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createRetryStrategy() {
|
export function createRetryStrategy() {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { GeneralQueueProcessor } from './processors/general-queue.processor';
|
|||||||
connection: {
|
connection: {
|
||||||
host: redisConfig.host,
|
host: redisConfig.host,
|
||||||
port: redisConfig.port,
|
port: redisConfig.port,
|
||||||
|
username: redisConfig.username,
|
||||||
password: redisConfig.password,
|
password: redisConfig.password,
|
||||||
db: redisConfig.db,
|
db: redisConfig.db,
|
||||||
family: redisConfig.family,
|
family: redisConfig.family,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export class RedisConfigService implements RedisOptionsFactory {
|
|||||||
config: {
|
config: {
|
||||||
host: redisConfig.host,
|
host: redisConfig.host,
|
||||||
port: redisConfig.port,
|
port: redisConfig.port,
|
||||||
|
username: redisConfig.username,
|
||||||
password: redisConfig.password,
|
password: redisConfig.password,
|
||||||
db: redisConfig.db,
|
db: redisConfig.db,
|
||||||
family: redisConfig.family,
|
family: redisConfig.family,
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import Redis from 'ioredis';
|
|||||||
new Redis({
|
new Redis({
|
||||||
host: redisConfig.host,
|
host: redisConfig.host,
|
||||||
port: redisConfig.port,
|
port: redisConfig.port,
|
||||||
|
username: redisConfig.username,
|
||||||
password: redisConfig.password,
|
password: redisConfig.password,
|
||||||
db: redisConfig.db,
|
db: redisConfig.db,
|
||||||
family: redisConfig.family,
|
family: redisConfig.family,
|
||||||
|
|||||||
Reference in New Issue
Block a user