From 9ecedd20f8f5d1c257896eccdb8c9e232018bfda Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Mon, 9 May 2022 15:37:08 +0200 Subject: [PATCH] Few more simplifications. --- .../actions/server/builtin_action_types/lib/axios_utils.ts | 4 +++- x-pack/plugins/fleet/server/telemetry/sender.ts | 2 +- x-pack/plugins/osquery/server/lib/telemetry/sender.ts | 4 ++-- .../security_solution/server/lib/telemetry/sender.ts | 4 ++-- x-pack/plugins/synthetics/server/lib/telemetry/sender.ts | 4 ++-- .../test/ui_capabilities/common/services/ui_capabilities.ts | 6 +++--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/actions/server/builtin_action_types/lib/axios_utils.ts b/x-pack/plugins/actions/server/builtin_action_types/lib/axios_utils.ts index 6430172d4c4a5..c367c9ea44919 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/lib/axios_utils.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/lib/axios_utils.ts @@ -18,6 +18,7 @@ export const request = async ({ method = 'get', data, configurationUtilities, + headers, ...rest }: { axios: AxiosInstance; @@ -37,7 +38,8 @@ export const request = async ({ return await axios(url, { ...rest, method, - headers: rest.headers ? rest.headers : undefined, + // Axios doesn't support `null` value for `headers` property. + headers: headers ?? undefined, data: data ?? {}, // use httpAgent and httpsAgent and set axios proxy: false, to be able to handle fail on invalid certs httpAgent, diff --git a/x-pack/plugins/fleet/server/telemetry/sender.ts b/x-pack/plugins/fleet/server/telemetry/sender.ts index 206dde5b1adf9..8c53fc850741f 100644 --- a/x-pack/plugins/fleet/server/telemetry/sender.ts +++ b/x-pack/plugins/fleet/server/telemetry/sender.ts @@ -168,7 +168,7 @@ export class TelemetryEventsSender { const resp = await axios.post(telemetryUrl, ndjson, { headers: { 'Content-Type': 'application/x-ndjson', - ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : {}), + ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : undefined), 'X-Elastic-Stack-Version': clusterVersionNumber ? clusterVersionNumber : '7.16.0', }, }); diff --git a/x-pack/plugins/osquery/server/lib/telemetry/sender.ts b/x-pack/plugins/osquery/server/lib/telemetry/sender.ts index 2f447adec3aff..a2acc2fe8ec6f 100644 --- a/x-pack/plugins/osquery/server/lib/telemetry/sender.ts +++ b/x-pack/plugins/osquery/server/lib/telemetry/sender.ts @@ -267,8 +267,8 @@ export class TelemetryEventsSender { const resp = await axios.post(telemetryUrl, ndjson, { headers: { 'Content-Type': 'application/x-ndjson', - ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : {}), - ...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : {}), + ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : undefined), + ...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : undefined), 'X-Elastic-Stack-Version': clusterVersionNumber ? clusterVersionNumber : '8.0.0', ...(licenseId ? { 'X-Elastic-License-ID': licenseId } : {}), }, diff --git a/x-pack/plugins/security_solution/server/lib/telemetry/sender.ts b/x-pack/plugins/security_solution/server/lib/telemetry/sender.ts index bafeddf0800d1..7490038abddd0 100644 --- a/x-pack/plugins/security_solution/server/lib/telemetry/sender.ts +++ b/x-pack/plugins/security_solution/server/lib/telemetry/sender.ts @@ -299,8 +299,8 @@ export class TelemetryEventsSender implements ITelemetryEventsSender { const resp = await axiosInstance.post(telemetryUrl, ndjson, { headers: { 'Content-Type': 'application/x-ndjson', - ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : {}), - ...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : {}), + ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : undefined), + ...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : undefined), 'X-Elastic-Stack-Version': clusterVersionNumber ? clusterVersionNumber : '8.0.0', ...(licenseId ? { 'X-Elastic-License-ID': licenseId } : {}), }, diff --git a/x-pack/plugins/synthetics/server/lib/telemetry/sender.ts b/x-pack/plugins/synthetics/server/lib/telemetry/sender.ts index 2627add01888b..5130ea034f94d 100644 --- a/x-pack/plugins/synthetics/server/lib/telemetry/sender.ts +++ b/x-pack/plugins/synthetics/server/lib/telemetry/sender.ts @@ -174,8 +174,8 @@ export class TelemetryEventsSender { const resp = await axios.post(telemetryUrl, ndjson, { headers: { 'Content-Type': 'application/x-ndjson', - ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : {}), - ...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : {}), + ...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : undefined), + ...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : undefined), 'X-Elastic-Stack-Version': clusterVersionNumber ? clusterVersionNumber : '8.2.0', }, }); diff --git a/x-pack/test/ui_capabilities/common/services/ui_capabilities.ts b/x-pack/test/ui_capabilities/common/services/ui_capabilities.ts index 2bf8959aebeb4..9cb3da7e8fd5c 100644 --- a/x-pack/test/ui_capabilities/common/services/ui_capabilities.ts +++ b/x-pack/test/ui_capabilities/common/services/ui_capabilities.ts @@ -5,7 +5,7 @@ * 2.0. */ -import axios, { AxiosInstance } from 'axios'; +import axios, { AxiosInstance, AxiosRequestHeaders } from 'axios'; import type { Capabilities as UICapabilities } from '@kbn/core/types'; import { format as formatUrl } from 'url'; import util from 'util'; @@ -61,13 +61,13 @@ export class UICapabilitiesService { this.log.debug( `requesting ${spaceUrlPrefix}/api/core/capabilities to parse the uiCapabilities` ); - const requestHeaders = credentials + const requestHeaders: AxiosRequestHeaders = credentials ? { Authorization: `Basic ${Buffer.from( `${credentials.username}:${credentials.password}` ).toString('base64')}`, } - : undefined; + : {}; const response = await this.axios.post( `${spaceUrlPrefix}/api/core/capabilities`, { applications: [...applications, 'kibana:stack_management'] },