From 5077c2834f7b24ff6b0683db239b22a3a1441664 Mon Sep 17 00:00:00 2001 From: Manuelraa Date: Sun, 14 Jul 2024 10:56:33 +0200 Subject: [PATCH] chore: reduce code duplication for agent configuration Signed-off-by: Manuelraa --- server/auth/types/openid/openid_auth.ts | 34 +++++++++++-------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/server/auth/types/openid/openid_auth.ts b/server/auth/types/openid/openid_auth.ts index a857213e..b1f69bd6 100644 --- a/server/auth/types/openid/openid_auth.ts +++ b/server/auth/types/openid/openid_auth.ts @@ -174,27 +174,23 @@ export class OpenIdAuthentication extends AuthenticationType { }; } this.logger.info(getObjectProperties(this.wreckHttpsOption, 'WreckHttpsOptions')); + + // Use proxy agent to allow usage of e.g. http_proxy environment variable + const httpAgent = new ProxyAgent(); + const httpsAllowUnauthorizedAgent = new ProxyAgent({ + rejectUnauthorized: false, + }); + let httpsAgent = new ProxyAgent(); if (Object.keys(this.wreckHttpsOption).length > 0) { - return wreck.defaults({ - agents: { - http: new ProxyAgent(), - https: new ProxyAgent(this.wreckHttpsOption), - httpsAllowUnauthorized: new ProxyAgent({ - rejectUnauthorized: false, - }), - }, - }); - } else { - return wreck.defaults({ - agents: { - http: new ProxyAgent(), - https: new ProxyAgent(), - httpsAllowUnauthorized: new ProxyAgent({ - rejectUnauthorized: false, - }), - }, - }); + httpsAgent = new ProxyAgent(this.wreckHttpsOption); } + return wreck.defaults({ + agents: { + http: httpAgent, + https: httpsAgent, + httpsAllowUnauthorized: httpsAllowUnauthorizedAgent, + }, + }); } getWreckHttpsOptions(): WreckHttpsOptions {