Skip to content

Commit

Permalink
Merge branch 'main' into upgrade/superagent-supertest
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Aug 16, 2023
2 parents d0f5fca + 431e505 commit 833a843
Show file tree
Hide file tree
Showing 27 changed files with 447 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ function ConfigurationValueColumn({
</EuiText>
{value && (
<EuiButtonIcon
aria-label="Copy to clipboard"
aria-label={i18n.translate(
'xpack.apm.onboarding.column.value.copyIconText',
{
defaultMessage: 'Copy to clipboard',
}
)}
color="text"
iconType="copy"
onClick={() => copyToClipboard(value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import { i18n } from '@kbn/i18n';
import {
copyToClipboard,
EuiBasicTable,
EuiBasicTableColumn,
EuiButton,
EuiButtonIcon,
EuiLink,
EuiMarkdownFormat,
EuiSpacer,
Expand Down Expand Up @@ -144,9 +146,24 @@ function ConfigurationValueColumn({
}

return (
<EuiText size="s" color="accent">
{value}
</EuiText>
<>
<EuiText size="s" color="accent">
{value}
</EuiText>
{value && (
<EuiButtonIcon
aria-label={i18n.translate(
'xpack.apm.onboarding.otel.column.value.copyIconText',
{
defaultMessage: 'Copy to clipboard',
}
)}
color="text"
iconType="copy"
onClick={() => copyToClipboard(value)}
/>
)}
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
EuiSpacer,
} from '@elastic/eui';
import React, { useState } from 'react';
import { useEuiTheme } from '@elastic/eui';
import {
INSTRUCTION_VARIANT,
getDisplayText,
Expand Down Expand Up @@ -44,10 +45,11 @@ export function InstructionsSet({
const onSelectedTabChange = (tab: string) => {
setSelectedTab(tab);
};
const { euiTheme } = useEuiTheme();

function InstructionTabs({ agentTabs }: { agentTabs: AgentTab[] }) {
return (
<EuiTabs>
<EuiTabs style={{ padding: `0 ${euiTheme.size.l}` }}>
{agentTabs.map((tab) => (
<EuiTab
key={tab.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function serverlessInstructions(
const displayApiKeyErrorCallout = error && Boolean(errorMessage);
const commonOptions: AgentInstructions = {
baseUrl,
apmServerUrl: config.managedServiceUrl,
apmServerUrl: `${config.managedServiceUrl}:443`,
checkAgentStatus,
agentStatus,
agentStatusLoading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
EuiSpacer,
EuiText,
EuiBasicTableColumn,
EuiButtonIcon,
copyToClipboard,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { ValuesType } from 'utility-types';
Expand Down Expand Up @@ -75,9 +77,24 @@ export function OpenTelemetryInstructions({
}
),
render: (_, { value }) => (
<EuiText size="s" color="accent">
{value}
</EuiText>
<>
<EuiText size="s" color="accent">
{value}
</EuiText>
{value && (
<EuiButtonIcon
aria-label={i18n.translate(
'xpack.apm.tutorial.config_otel.column.value.copyIconText',
{
defaultMessage: 'Copy to clipboard',
}
)}
color="text"
iconType="copy"
onClick={() => copyToClipboard(value)}
/>
)}
</>
),
},
{
Expand Down
41 changes: 35 additions & 6 deletions x-pack/plugins/apm/scripts/diagnostics_bundle/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,34 @@
/* eslint-disable no-console */

import datemath from '@elastic/datemath';
import { errors } from '@elastic/elasticsearch';
import { AxiosError } from 'axios';
import yargs from 'yargs';
import { initDiagnosticsBundle } from './diagnostics_bundle';

const { argv } = yargs(process.argv.slice(2))
.option('esHost', {
demandOption: true,
type: 'string',
description: 'Elasticsearch host name',
})
.option('kbHost', {
demandOption: true,
type: 'string',
description: 'Kibana host name',
})
.option('username', {
demandOption: true,
type: 'string',
description: 'Kibana host name',
})
.option('password', {
demandOption: true,
type: 'string',
description: 'Kibana host name',
})
.option('cloudId', {
type: 'string',
})
.option('apiKey', {
type: 'string',
})
.option('rangeFrom', {
type: 'string',
description: 'Time-range start',
Expand All @@ -48,10 +52,20 @@ const { argv } = yargs(process.argv.slice(2))
})
.help();

const { esHost, kbHost, password, username, kuery } = argv;
const { esHost, kbHost, password, username, kuery, apiKey, cloudId } = argv;
const rangeFrom = argv.rangeFrom as unknown as number;
const rangeTo = argv.rangeTo as unknown as number;

if ((!esHost || !kbHost) && !cloudId) {
console.error('Either esHost and kbHost or cloudId must be provided');
process.exit(1);
}

if ((!username || !password) && !apiKey) {
console.error('Either username and password or apiKey must be provided');
process.exit(1);
}

if (rangeFrom) {
console.log(`rangeFrom = ${new Date(rangeFrom).toISOString()}`);
}
Expand All @@ -64,6 +78,8 @@ initDiagnosticsBundle({
esHost,
kbHost,
password,
apiKey,
cloudId,
username,
start: rangeFrom,
end: rangeTo,
Expand All @@ -73,7 +89,20 @@ initDiagnosticsBundle({
console.log(res);
})
.catch((err) => {
console.log(err);
process.exitCode = 1;
if (err instanceof AxiosError && err.response?.data) {
console.error(err.response.data);
return;
}

// @ts-expect-error
if (err instanceof errors.ResponseError && err.meta.body.error.reason) {
// @ts-expect-error
console.error(err.meta.body.error.reason);
return;
}

console.error(err);
});

function convertDate(dateString: string): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,43 @@ type DiagnosticsBundle = APIReturnType<'GET /internal/apm/diagnostics'>;
export async function initDiagnosticsBundle({
esHost,
kbHost,
cloudId,
username,
password,
apiKey,
start,
end,
kuery,
}: {
esHost: string;
kbHost: string;
username: string;
password: string;
esHost?: string;
kbHost?: string;
cloudId?: string;
start: number | undefined;
end: number | undefined;
kuery: string | undefined;
username?: string;
password?: string;
apiKey?: string;
}) {
const esClient = new Client({ node: esHost, auth: { username, password } });
const auth = username && password ? { username, password } : undefined;
const apiKeyHeader = apiKey ? { Authorization: `ApiKey ${apiKey}` } : {};
const { kibanaHost } = parseCloudId(cloudId);

const esClient = new Client({
...(esHost ? { node: esHost } : {}),
...(cloudId ? { cloud: { id: cloudId } } : {}),
auth,
headers: { ...apiKeyHeader },
});

const kibanaClient = axios.create({
baseURL: kbHost,
auth: { username, password },
baseURL: kbHost ?? kibanaHost,
auth,
// @ts-expect-error
headers: { 'kbn-xsrf': 'true', ...apiKeyHeader },
});
const apmIndices = await getApmIndices(kibanaClient);

const bundle = await getDiagnosticsBundle({
esClient,
apmIndices,
Expand Down Expand Up @@ -99,3 +115,19 @@ async function getKibanaVersion(kibanaClient: AxiosInstance) {
const res = await kibanaClient.get('/api/status');
return res.data.version.number;
}

function parseCloudId(cloudId?: string) {
if (!cloudId) {
return {};
}

const [instanceAlias, encodedString] = cloudId.split(':');
const decodedString = Buffer.from(encodedString, 'base64').toString('utf8');
const [hostname, esId, kbId] = decodedString.split('$');

return {
kibanaHost: `https://${kbId}.${hostname}`,
esHost: `https://${esId}.${hostname}`,
instanceAlias,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const getSafeVulnerabilitiesQueryFilter = (query?: QueryDslQueryContainer
{ exists: { field: 'vulnerability.score.base' } },
{ exists: { field: 'vulnerability.score.version' } },
{ exists: { field: 'resource.id' } },
{ exists: { field: 'resource.name' } },
],
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
EuiHorizontalRule,
} from '@elastic/eui';
import type { NewPackagePolicy } from '@kbn/fleet-plugin/public';
import { PackageInfo } from '@kbn/fleet-plugin/common';
import { NewPackagePolicyInput, PackageInfo } from '@kbn/fleet-plugin/common';
import { FormattedMessage } from '@kbn/i18n-react';
import { css } from '@emotion/react';
import { i18n } from '@kbn/i18n';
Expand All @@ -34,6 +34,7 @@ import {
NewPackagePolicyPostureInput,
} from '../utils';
import { SetupFormat, useAwsCredentialsForm } from './hooks';
import { AWS_ORGANIZATION_ACCOUNT } from '../policy_template_form';
import { AwsCredentialsType } from '../../../../common/types';

interface AWSSetupInfoContentProps {
Expand Down Expand Up @@ -106,8 +107,10 @@ interface Props {

const CloudFormationSetup = ({
hasCloudFormationTemplate,
input,
}: {
hasCloudFormationTemplate: boolean;
input: NewPackagePolicyInput;
}) => {
if (!hasCloudFormationTemplate) {
return (
Expand All @@ -119,6 +122,9 @@ const CloudFormationSetup = ({
</EuiCallOut>
);
}

const accountType = input.streams?.[0]?.vars?.['aws.account_type']?.value;

return (
<>
<EuiText color="subdued" size="s">
Expand All @@ -127,12 +133,21 @@ const CloudFormationSetup = ({
list-style: auto;
`}
>
<li>
<FormattedMessage
id="xpack.csp.awsIntegration.cloudFormationSetupStep.login"
defaultMessage="Log in as an admin to the AWS Account you want to onboard"
/>
</li>
{accountType === AWS_ORGANIZATION_ACCOUNT ? (
<li>
<FormattedMessage
id="xpack.csp.awsIntegration.cloudFormationSetupStep.organizationLogin"
defaultMessage="Log in as an admin in your organization's AWS management account"
/>
</li>
) : (
<li>
<FormattedMessage
id="xpack.csp.awsIntegration.cloudFormationSetupStep.login"
defaultMessage="Log in as an admin to the AWS Account you want to onboard"
/>
</li>
)}
<li>
<FormattedMessage
id="xpack.csp.awsIntegration.cloudFormationSetupStep.save"
Expand Down Expand Up @@ -224,7 +239,7 @@ export const AwsCredentialsForm = ({
/>
<EuiSpacer size="l" />
{setupFormat === 'cloud_formation' && (
<CloudFormationSetup hasCloudFormationTemplate={hasCloudFormationTemplate} />
<CloudFormationSetup hasCloudFormationTemplate={hasCloudFormationTemplate} input={input} />
)}
{setupFormat === 'manual' && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export const getVulnerabilitiesGridCellActions = <
if (columnId === columns.cvss) {
return vulnerabilityRow.vulnerability?.score.base;
}
if (columnId === columns.resource) {
if (columnId === columns.resourceId) {
return vulnerabilityRow.resource?.id;
}
if (columnId === columns.resourceName) {
return vulnerabilityRow.resource?.name;
}
if (columnId === columns.severity) {
Expand All @@ -52,15 +55,9 @@ export const getVulnerabilitiesGridCellActions = <
if (columnId === columns.version) {
return vulnerabilityRow.vulnerability?.package?.version;
}
if (columnId === columns.fix_version) {
if (columnId === columns.fixedVersion) {
return vulnerabilityRow.vulnerability?.package?.fixed_version;
}
if (columnId === columns.resource_id) {
return vulnerabilityRow.resource?.id;
}
if (columnId === columns.resource_name) {
return vulnerabilityRow.resource?.name;
}
if (columnId === columns.region) {
return vulnerabilityRow.cloud?.region;
}
Expand Down
Loading

0 comments on commit 833a843

Please sign in to comment.