From e4f014628b6e35b20e0322e2d4d3a4b490adccd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20G=C3=BCrkan=20YALAMAN?= Date: Fri, 25 Aug 2023 16:57:36 +0200 Subject: [PATCH 1/2] Update config template for self managed connectors. --- .../generate_connector_api_key_api_logic.ts | 2 +- .../connector/connector_configuration.tsx | 18 ++++++------- .../search_index/connector/constants.ts | 27 +++++++++++++++++++ 3 files changed, 36 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..bfed22c06a504 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 @@ -45,7 +45,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 = () => { @@ -151,15 +151,13 @@ 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, + }, + })} 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..6f3008de1fab6 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,27 @@ 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, +}: { + apiKeyData: ApiKey | undefined; + connectorData: { + id: string; + service_type: string | null; + }; +}) => dedent`connectors: + - + connector_id: "${connectorData.id}" + service_type: "${connectorData.service_type || 'changeme'}"${ + apiKeyData?.encoded + ? ` + api_key: "${apiKeyData?.encoded}"` + : '' +} + + elasticsearch: + host: "https://locahost:9200", + api_key: "${apiKeyData?.encoded || ''}" +`; From efd0ef692cc14b1045c91afb5d415c22e2de517c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20G=C3=BCrkan=20YALAMAN?= Date: Fri, 25 Aug 2023 17:06:55 +0200 Subject: [PATCH 2/2] Add cloud context --- .../search_index/connector/connector_configuration.tsx | 4 ++++ .../components/search_index/connector/constants.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) 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 bfed22c06a504..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'; @@ -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 <>; } @@ -157,6 +160,7 @@ export const ConnectorConfiguration: React.FC = () => { 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 6f3008de1fab6..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 @@ -170,12 +170,14 @@ 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}" @@ -187,6 +189,6 @@ export const getConnectorTemplate = ({ } elasticsearch: - host: "https://locahost:9200", + host: "${host || 'https://locahost:9200'}" api_key: "${apiKeyData?.encoded || ''}" `;