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

chore(websocket): Adding support for redis username in websocket server #25826

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 superset-websocket/spec/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ describe('server', () => {
server.redisUrlFromConfig({
port: 6380,
host: 'redis.local',
username: 'cool-user',
password: 'foo',
db: 1,
ssl: false,
}),
).toEqual('redis://:foo@redis.local:6380/1');
).toEqual('redis://cool-user:foo@redis.local:6380/1');
});
test('it builds a valid Redis URL with SSL', () => {
expect(
Expand Down
3 changes: 3 additions & 0 deletions superset-websocket/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ConfigType = {
port: number;
host: string;
password: string;
username: string;
db: number;
ssl: boolean;
};
Expand Down Expand Up @@ -70,6 +71,7 @@ function defaultConfig(): ConfigType {
host: '127.0.0.1',
port: 6379,
password: '',
username: 'default',
db: 0,
ssl: false,
},
Expand Down Expand Up @@ -114,6 +116,7 @@ function applyEnvOverrides(config: ConfigType): ConfigType {
REDIS_HOST: val => (config.redis.host = val),
REDIS_PORT: val => (config.redis.port = toNumber(val)),
REDIS_PASSWORD: val => (config.redis.password = val),
REDIS_USERNAME: val => (config.redis.username = val),
REDIS_DB: val => (config.redis.db = toNumber(val)),
REDIS_SSL: val => (config.redis.ssl = toBoolean(val)),
STATSD_HOST: val => (config.statsd.host = val),
Expand Down
4 changes: 3 additions & 1 deletion superset-websocket/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface SocketInstance {
interface RedisConfig {
port: number;
host: string;
username?: string | null;
password?: string | null;
db: number;
ssl: boolean;
Expand Down Expand Up @@ -105,7 +106,8 @@ if (startServer && opts.jwtSecret.length < 32)

export const redisUrlFromConfig = (redisConfig: RedisConfig): string => {
let url = redisConfig.ssl ? 'rediss://' : 'redis://';
if (redisConfig.password) url += `:${redisConfig.password}@`;
if (redisConfig.password)
url += `${redisConfig.username}:${redisConfig.password}@`;
url += `${redisConfig.host}:${redisConfig.port}/${redisConfig.db}`;
return url;
};
Expand Down
Loading