From 340755a09f828a474c3b1e632f4750533ca678ac Mon Sep 17 00:00:00 2001 From: maksadbek Date: Tue, 26 Nov 2024 15:00:55 +0100 Subject: [PATCH] feat(repeater): add PROXY and NO_PROXY env variables (#620) PROXY is an alias to --proxy flag NO_PROXY is an alias to --proxy-domains-bypass flag Co-authored-by: Or Rubin --- src/Commands/RunRepeater.ts | 32 ++++++++++++++++++++++++++++++-- src/Config/CliBuilder.ts | 2 ++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Commands/RunRepeater.ts b/src/Commands/RunRepeater.ts index cda1f8e9..c929eddb 100644 --- a/src/Commands/RunRepeater.ts +++ b/src/Commands/RunRepeater.ts @@ -5,6 +5,7 @@ import { DefaultRepeaterServerOptions, RepeaterLauncher } from '../Repeater'; import { Arguments, Argv, CommandModule } from 'yargs'; import { captureException } from '@sentry/node'; import { normalize } from 'node:path'; +import process from 'node:process'; export class RunRepeater implements CommandModule { public readonly command = 'repeater [options]'; @@ -135,13 +136,40 @@ export class RunRepeater implements CommandModule { requiresArg: true, array: true, describe: - 'Space-separated list of domains that should be routed through the proxy. This option is only applicable when using the --proxy option' + 'Space-separated list of domains that should be routed through the proxy. This option is only applicable when using the --proxy option', + coerce(arg: string[]): string[] { + // if values are passed from env variable, they are passed as a single string + if (arg.length === 1) { + if (arg[0].includes(' ')) { + return arg[0].trim().split(' '); + } + + return arg; + } + + return arg; + } }) .option('proxy-domains-bypass', { requiresArg: true, array: true, + default: process.env.NO_PROXY?.trim() + .split(',') + .map((domain) => domain.trim()), describe: - 'Space-separated list of domains that should not be routed through the proxy. This option is only applicable when using the --proxy option' + 'Space-separated list of domains that should not be routed through the proxy. This option is only applicable when using the --proxy option', + coerce(arg: string[]): string[] { + // if values are passed from env variable, they are passed as a single string + if (arg.length === 1) { + if (arg[0].includes(' ')) { + return arg[0].trim().split(' '); + } + + return arg; + } + + return arg; + } }) .conflicts({ daemon: 'remove-daemon', diff --git a/src/Config/CliBuilder.ts b/src/Config/CliBuilder.ts index d64223e1..22284684 100644 --- a/src/Config/CliBuilder.ts +++ b/src/Config/CliBuilder.ts @@ -5,6 +5,7 @@ import { CliInfo } from './CliInfo'; import { Arguments, Argv, CommandModule } from 'yargs'; import { init, runWithAsyncContext, setContext } from '@sentry/node'; import ms from 'ms'; +import process from 'node:process'; export interface CliBuilderOptions { info: CliInfo; @@ -62,6 +63,7 @@ export class CliBuilder { }) .option('proxy', { requiresArg: true, + default: process.env.PROXY, describe: 'Specify a proxy URL to route all traffic through. This should be an HTTP(S), SOCKS4, or SOCKS5 URL. By default, if you specify SOCKS://, then SOCKS5h is applied.' })