From c55173f9a38f7f4c83b7d811acca3ef62d44536f Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 23 Mar 2020 18:40:25 -0400 Subject: [PATCH] [Fleet] add Agent config details yaml view (#60943) (#60989) --- .../ingest_manager/common/services/routes.ts | 4 + .../enrollment_instructions/index.tsx | 0 .../enrollment_instructions/manual/index.tsx | 0 .../enrollment_instructions/shell/index.tsx | 14 ++-- .../hooks/use_request/agent_config.ts | 7 ++ .../details_page/components/yaml/index.tsx | 78 +++++++++++++++++++ .../agent_config/details_page/index.tsx | 4 +- .../agent_enrollment_flyout/instructions.tsx | 5 +- 8 files changed, 103 insertions(+), 9 deletions(-) rename x-pack/plugins/ingest_manager/public/applications/ingest_manager/{sections/fleet/agent_list_page => }/components/enrollment_instructions/index.tsx (100%) rename x-pack/plugins/ingest_manager/public/applications/ingest_manager/{sections/fleet/agent_list_page => }/components/enrollment_instructions/manual/index.tsx (100%) rename x-pack/plugins/ingest_manager/public/applications/ingest_manager/{sections/fleet/agent_list_page => }/components/enrollment_instructions/shell/index.tsx (86%) create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx diff --git a/x-pack/plugins/ingest_manager/common/services/routes.ts b/x-pack/plugins/ingest_manager/common/services/routes.ts index 01b3b1983486c..7cc6fc3c66afb 100644 --- a/x-pack/plugins/ingest_manager/common/services/routes.ts +++ b/x-pack/plugins/ingest_manager/common/services/routes.ts @@ -82,6 +82,10 @@ export const agentConfigRouteService = { getDeletePath: () => { return AGENT_CONFIG_API_ROUTES.DELETE_PATTERN; }, + + getInfoFullPath: (agentConfigId: string) => { + return AGENT_CONFIG_API_ROUTES.FULL_INFO_PATTERN.replace('{agentConfigId}', agentConfigId); + }, }; export const fleetSetupRouteService = { diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_list_page/components/enrollment_instructions/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/components/enrollment_instructions/index.tsx similarity index 100% rename from x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_list_page/components/enrollment_instructions/index.tsx rename to x-pack/plugins/ingest_manager/public/applications/ingest_manager/components/enrollment_instructions/index.tsx diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_list_page/components/enrollment_instructions/manual/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/components/enrollment_instructions/manual/index.tsx similarity index 100% rename from x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_list_page/components/enrollment_instructions/manual/index.tsx rename to x-pack/plugins/ingest_manager/public/applications/ingest_manager/components/enrollment_instructions/manual/index.tsx diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_list_page/components/enrollment_instructions/shell/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/components/enrollment_instructions/shell/index.tsx similarity index 86% rename from x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_list_page/components/enrollment_instructions/shell/index.tsx rename to x-pack/plugins/ingest_manager/public/applications/ingest_manager/components/enrollment_instructions/shell/index.tsx index 04e84902bc9d4..e6990927b926e 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_list_page/components/enrollment_instructions/shell/index.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/components/enrollment_instructions/shell/index.tsx @@ -12,7 +12,7 @@ import { EuiFieldText, EuiPopover, } from '@elastic/eui'; -import { EnrollmentAPIKey } from '../../../../../../types'; +import { EnrollmentAPIKey } from '../../../types'; // No need for i18n as these are platform names const PLATFORMS = { @@ -37,11 +37,13 @@ export const ShellEnrollmentInstructions: React.FunctionComponent = ({ const [isPlatformOptionsOpen, setIsPlatformOptionsOpen] = useState(false); // Build quick installation command - const quickInstallInstructions = `${ - kibanaCASha256 ? `CA_SHA256=${kibanaCASha256} ` : '' - }API_KEY=${ - apiKey.api_key - } sh -c "$(curl ${kibanaUrl}/api/ingest_manager/fleet/install/${currentPlatform})"`; + // const quickInstallInstructions = `${ + // kibanaCASha256 ? `CA_SHA256=${kibanaCASha256} ` : '' + // }API_KEY=${ + // apiKey.api_key + // } sh -c "$(curl ${kibanaUrl}/api/ingest_manager/fleet/install/${currentPlatform})"`; + + const quickInstallInstructions = `./agent enroll ${kibanaUrl} ${apiKey.api_key}`; return ( <> diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts index d44cc67e2dc4c..d16d835f8c701 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts @@ -32,6 +32,13 @@ export const useGetOneAgentConfig = (agentConfigId: string) => { }); }; +export const useGetOneAgentConfigFull = (agentConfigId: string) => { + return useRequest({ + path: agentConfigRouteService.getInfoFullPath(agentConfigId), + method: 'get', + }); +}; + export const sendGetOneAgentConfig = (agentConfigId: string) => { return sendRequest({ path: agentConfigRouteService.getInfoPath(agentConfigId), diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx new file mode 100644 index 0000000000000..57031a3d72abe --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx @@ -0,0 +1,78 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { memo } from 'react'; +import { dump } from 'js-yaml'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { + EuiTitle, + EuiSpacer, + EuiText, + EuiCodeBlock, + EuiFlexGroup, + EuiFlexItem, +} from '@elastic/eui'; +import { AgentConfig } from '../../../../../../../../common/types/models'; +import { + useGetOneAgentConfigFull, + useGetEnrollmentAPIKeys, + useGetOneEnrollmentAPIKey, + useCore, +} from '../../../../../hooks'; +import { ShellEnrollmentInstructions } from '../../../../../components/enrollment_instructions'; +import { Loading } from '../../../../../components'; + +const CONFIG_KEYS_ORDER = ['id', 'revision', 'outputs', 'datasources']; + +export const ConfigYamlView = memo<{ config: AgentConfig }>(({ config }) => { + const core = useCore(); + + const fullConfigRequest = useGetOneAgentConfigFull(config.id); + const apiKeysRequest = useGetEnrollmentAPIKeys(); + const apiKeyRequest = useGetOneEnrollmentAPIKey(apiKeysRequest.data?.list?.[0].id as string); + + if (fullConfigRequest.isLoading && !fullConfigRequest.data) { + return ; + } + + return ( + + + + {dump(fullConfigRequest.data.item, { + sortKeys: (keyA: string, keyB: string) => { + return CONFIG_KEYS_ORDER.indexOf(keyA) - CONFIG_KEYS_ORDER.indexOf(keyB); + }, + })} + + + + +

+ +

+
+ + + + + + {apiKeyRequest.data && ( + + )} +
+
+ ); +}); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/index.tsx index efb96f6459254..450f86df5c03a 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/index.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/index.tsx @@ -31,6 +31,7 @@ import { LinkedAgentCount } from '../components'; import { useAgentConfigLink } from './hooks/use_details_uri'; import { DETAILS_ROUTER_PATH, DETAILS_ROUTER_SUB_PATH } from './constants'; import { ConfigDatasourcesView } from './components/datasources'; +import { ConfigYamlView } from './components/yaml'; const Divider = styled.div` width: 0; @@ -282,8 +283,7 @@ export const AgentConfigDetailsLayout: React.FunctionComponent = () => { { - // TODO: YAML implementation tracked via https://github.com/elastic/kibana/issues/57958 - return
YAML placeholder
; + return ; }} />