Skip to content

Commit

Permalink
Few more simplifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed May 9, 2022
1 parent c4a79f5 commit 9ecedd2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const request = async <T = unknown>({
method = 'get',
data,
configurationUtilities,
headers,
...rest
}: {
axios: AxiosInstance;
Expand All @@ -37,7 +38,8 @@ export const request = async <T = unknown>({
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,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/telemetry/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/osquery/server/lib/telemetry/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } : {}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } : {}),
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/synthetics/server/lib/telemetry/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'] },
Expand Down

0 comments on commit 9ecedd2

Please sign in to comment.