From 0b2b4829df093c26c73bf8c4a9e8a5babdca704f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20G=C3=BCrkan=20YALAMAN?= Date: Fri, 25 Aug 2023 19:06:01 +0200 Subject: [PATCH] [Enterprise Search] Update config template for self managed connectors. (#164854) ## Summary https://github.com/elastic/kibana/assets/1410658/e9e1dfb3-1acd-4255-9abf-b9b58f1a060a (cherry picked from commit 7e4b67e2390ff0d2637b10153c049da73ee6ab34) --- .../generate_connector_api_key_api_logic.ts | 2 +- .../connector/connector_configuration.tsx | 22 +++++++------- .../search_index/connector/constants.ts | 29 +++++++++++++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/connector/generate_connector_api_key_api_logic.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/connector/generate_connector_api_key_api_logic.ts index 59145a7721f1a..ace963d9208be 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/connector/generate_connector_api_key_api_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/connector/generate_connector_api_key_api_logic.ts @@ -8,7 +8,7 @@ import { createApiLogic } from '../../../shared/api_logic/create_api_logic'; import { HttpLogic } from '../../../shared/http'; -interface ApiKey { +export interface ApiKey { api_key: string; encoded: string; id: string; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration.tsx index 6989f0571efd6..0667451d8e761 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/connector_configuration.tsx @@ -28,6 +28,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { ConnectorStatus } from '../../../../../../common/types/connectors'; import { BetaConnectorCallout } from '../../../../shared/beta/beta_connector_callout'; +import { useCloudDetails } from '../../../../shared/cloud_details/cloud_details'; import { docLinks } from '../../../../shared/doc_links'; import { generateEncodedPath } from '../../../../shared/encode_path_params'; import { EuiButtonTo, EuiLinkTo } from '../../../../shared/react_router_helpers'; @@ -45,7 +46,7 @@ import { SearchIndexTabId } from '../search_index'; import { ApiKeyConfig } from './api_key_configuration'; import { ConnectorConfigurationConfig } from './connector_configuration_config'; import { ConnectorNameAndDescription } from './connector_name_and_description/connector_name_and_description'; -import { BETA_CONNECTORS, CONNECTORS } from './constants'; +import { BETA_CONNECTORS, CONNECTORS, getConnectorTemplate } from './constants'; import { NativeConnectorConfiguration } from './native_connector_configuration/native_connector_configuration'; export const ConnectorConfiguration: React.FC = () => { @@ -53,6 +54,8 @@ export const ConnectorConfiguration: React.FC = () => { const { index, recheckIndexLoading } = useValues(IndexViewLogic); const { indexName } = useValues(IndexNameLogic); const { recheckIndex } = useActions(IndexViewLogic); + const cloudContext = useCloudDetails(); + if (!isConnectorIndex(index)) { return <>; } @@ -151,15 +154,14 @@ export const ConnectorConfiguration: React.FC = () => { - {`connectors: - - - connector_id: "${index.connector.id}" - service_type: "${index.connector.service_type || 'changeme'}"${ - apiKeyData?.encoded - ? ` - api_key: "${apiKeyData?.encoded}"` - : '' - }`} + {getConnectorTemplate({ + apiKeyData, + connectorData: { + id: index.connector.id, + service_type: index.connector.service_type, + }, + host: cloudContext.elasticsearchUrl, + })} diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/constants.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/constants.ts index b10069f12c3fe..b53628fa82a5a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/constants.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/connector/constants.ts @@ -5,10 +5,13 @@ * 2.0. */ +import dedent from 'dedent'; + import { CONNECTOR_DEFINITIONS } from '../../../../../../common/connectors/connectors'; import { docLinks } from '../../../../shared/doc_links'; import { CONNECTOR_ICONS } from '../../../../shared/icons/connector_icons'; +import { ApiKey } from '../../../api/connector/generate_connector_api_key_api_logic'; import { ConnectorClientSideDefinition } from './types'; @@ -163,3 +166,29 @@ export const CUSTOM_CONNECTORS = CONNECTORS.filter(({ isNative }) => !isNative); export const NATIVE_CONNECTORS = CONNECTORS.filter(({ isNative }) => isNative); export const BETA_CONNECTORS = CONNECTORS.filter(({ isBeta }) => isBeta); + +export const getConnectorTemplate = ({ + apiKeyData, + connectorData, + host, +}: { + apiKeyData: ApiKey | undefined; + connectorData: { + id: string; + service_type: string | null; + }; + host?: string; +}) => dedent`connectors: + - + connector_id: "${connectorData.id}" + service_type: "${connectorData.service_type || 'changeme'}"${ + apiKeyData?.encoded + ? ` + api_key: "${apiKeyData?.encoded}"` + : '' +} + + elasticsearch: + host: "${host || 'https://locahost:9200'}" + api_key: "${apiKeyData?.encoded || ''}" +`;