Rename getProxyAgents to getCustomAgents (#89813)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Mike Côté 2021-02-02 11:13:55 -05:00 committed by GitHub
parent 3f97a04c63
commit 33bf590386
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 21 deletions

View file

@ -10,7 +10,7 @@ import { Logger } from '../../../../../../src/core/server';
import { addTimeZoneToDate, request, patch, getErrorMessage } from './axios_utils';
import { loggingSystemMock } from '../../../../../../src/core/server/mocks';
import { actionsConfigMock } from '../../actions_config.mock';
import { getProxyAgents } from './get_proxy_agents';
import { getCustomAgents } from './get_custom_agents';
const logger = loggingSystemMock.create().get() as jest.Mocked<Logger>;
const configurationUtilities = actionsConfigMock.create();
@ -66,7 +66,7 @@ describe('request', () => {
proxyRejectUnauthorizedCertificates: true,
proxyUrl: 'https://localhost:1212',
});
const { httpAgent, httpsAgent } = getProxyAgents(configurationUtilities, logger);
const { httpAgent, httpsAgent } = getCustomAgents(configurationUtilities, logger);
const res = await request({
axios,

View file

@ -6,7 +6,7 @@
import { AxiosInstance, Method, AxiosResponse, AxiosBasicCredentials } from 'axios';
import { Logger } from '../../../../../../src/core/server';
import { getProxyAgents } from './get_proxy_agents';
import { getCustomAgents } from './get_custom_agents';
import { ActionsConfigurationUtilities } from '../../actions_config';
export const request = async <T = unknown>({
@ -29,7 +29,7 @@ export const request = async <T = unknown>({
validateStatus?: (status: number) => boolean;
auth?: AxiosBasicCredentials;
}): Promise<AxiosResponse> => {
const { httpAgent, httpsAgent } = getProxyAgents(configurationUtilities, logger);
const { httpAgent, httpsAgent } = getCustomAgents(configurationUtilities, logger);
return await axios(url, {
...rest,

View file

@ -8,12 +8,12 @@ import { Agent as HttpsAgent } from 'https';
import HttpProxyAgent from 'http-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { Logger } from '../../../../../../src/core/server';
import { getProxyAgents } from './get_proxy_agents';
import { getCustomAgents } from './get_custom_agents';
import { loggingSystemMock } from '../../../../../../src/core/server/mocks';
import { actionsConfigMock } from '../../actions_config.mock';
const logger = loggingSystemMock.create().get() as jest.Mocked<Logger>;
describe('getProxyAgents', () => {
describe('getCustomAgents', () => {
const configurationUtilities = actionsConfigMock.create();
test('get agents for valid proxy URL', () => {
@ -21,7 +21,7 @@ describe('getProxyAgents', () => {
proxyUrl: 'https://someproxyhost',
proxyRejectUnauthorizedCertificates: false,
});
const { httpAgent, httpsAgent } = getProxyAgents(configurationUtilities, logger);
const { httpAgent, httpsAgent } = getCustomAgents(configurationUtilities, logger);
expect(httpAgent instanceof HttpProxyAgent).toBeTruthy();
expect(httpsAgent instanceof HttpsProxyAgent).toBeTruthy();
});
@ -31,13 +31,13 @@ describe('getProxyAgents', () => {
proxyUrl: ':nope: not a valid URL',
proxyRejectUnauthorizedCertificates: false,
});
const { httpAgent, httpsAgent } = getProxyAgents(configurationUtilities, logger);
const { httpAgent, httpsAgent } = getCustomAgents(configurationUtilities, logger);
expect(httpAgent).toBe(undefined);
expect(httpsAgent instanceof HttpsAgent).toBeTruthy();
});
test('return default agents for undefined proxy options', () => {
const { httpAgent, httpsAgent } = getProxyAgents(configurationUtilities, logger);
const { httpAgent, httpsAgent } = getCustomAgents(configurationUtilities, logger);
expect(httpAgent).toBe(undefined);
expect(httpsAgent instanceof HttpsAgent).toBeTruthy();
});

View file

@ -11,17 +11,17 @@ import { HttpsProxyAgent } from 'https-proxy-agent';
import { Logger } from '../../../../../../src/core/server';
import { ActionsConfigurationUtilities } from '../../actions_config';
interface GetProxyAgentsResponse {
interface GetCustomAgentsResponse {
httpAgent: HttpAgent | undefined;
httpsAgent: HttpsAgent | undefined;
}
export function getProxyAgents(
export function getCustomAgents(
configurationUtilities: ActionsConfigurationUtilities,
logger: Logger
): GetProxyAgentsResponse {
): GetCustomAgentsResponse {
const proxySettings = configurationUtilities.getProxySettings();
const defaultResponse = {
const defaultAgents = {
httpAgent: undefined,
httpsAgent: new HttpsAgent({
rejectUnauthorized: configurationUtilities.isRejectUnauthorizedCertificatesEnabled(),
@ -29,7 +29,7 @@ export function getProxyAgents(
};
if (!proxySettings) {
return defaultResponse;
return defaultAgents;
}
logger.debug(`Creating proxy agents for proxy: ${proxySettings.proxyUrl}`);
@ -38,7 +38,7 @@ export function getProxyAgents(
proxyUrl = new URL(proxySettings.proxyUrl);
} catch (err) {
logger.warn(`invalid proxy URL "${proxySettings.proxyUrl}" ignored`);
return defaultResponse;
return defaultAgents;
}
const httpAgent = new HttpProxyAgent(proxySettings.proxyUrl);

View file

@ -22,7 +22,7 @@ import {
ExecutorType,
} from '../types';
import { ActionsConfigurationUtilities } from '../actions_config';
import { getProxyAgents } from './lib/get_proxy_agents';
import { getCustomAgents } from './lib/get_custom_agents';
export type SlackActionType = ActionType<{}, ActionTypeSecretsType, ActionParamsType, unknown>;
export type SlackActionTypeExecutorOptions = ActionTypeExecutorOptions<
@ -130,10 +130,10 @@ async function slackExecutor(
const { message } = params;
const proxySettings = configurationUtilities.getProxySettings();
const proxyAgents = getProxyAgents(configurationUtilities, logger);
const httpProxyAgent = webhookUrl.toLowerCase().startsWith('https')
? proxyAgents.httpsAgent
: proxyAgents.httpAgent;
const customAgents = getCustomAgents(configurationUtilities, logger);
const agent = webhookUrl.toLowerCase().startsWith('https')
? customAgents.httpsAgent
: customAgents.httpAgent;
if (proxySettings) {
logger.debug(`IncomingWebhook was called with proxyUrl ${proxySettings.proxyUrl}`);
@ -143,7 +143,7 @@ async function slackExecutor(
// https://slack.dev/node-slack-sdk/webhook
// node-slack-sdk use Axios inside :)
const webhook = new IncomingWebhook(webhookUrl, {
agent: httpProxyAgent,
agent,
});
result = await webhook.send(message);
} catch (err) {