mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.16`: - [[Search][Connectors] Create connector via try in console (#197757)](https://github.com/elastic/kibana/pull/197757) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"José Luis González","email":"joseluisgj@gmail.com"},"sourceCommit":{"committedDate":"2024-10-29T22:18:49Z","message":"[Search][Connectors] Create connector via try in console (#197757)\n\n## Summary\r\n\r\nThis PR enables the possibility of creating a connector opening the\r\nembedded console in the start step.\r\n\r\n\r\n\r\n---------\r\n\r\nCo-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>\r\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"248119ec8c506311f8d24a35ccae318e066b3026","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","v9.0.0","Team:EnterpriseSearch","v8.16.0","backport:version","v8.17.0"],"title":"[Search][Connectors] Create connector via try in console","number":197757,"url":"https://github.com/elastic/kibana/pull/197757","mergeCommit":{"message":"[Search][Connectors] Create connector via try in console (#197757)\n\n## Summary\r\n\r\nThis PR enables the possibility of creating a connector opening the\r\nembedded console in the start step.\r\n\r\n\r\n\r\n---------\r\n\r\nCo-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>\r\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"248119ec8c506311f8d24a35ccae318e066b3026"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197757","number":197757,"mergeCommit":{"message":"[Search][Connectors] Create connector via try in console (#197757)\n\n## Summary\r\n\r\nThis PR enables the possibility of creating a connector opening the\r\nembedded console in the start step.\r\n\r\n\r\n\r\n---------\r\n\r\nCo-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>\r\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"248119ec8c506311f8d24a35ccae318e066b3026"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: José Luis González <joseluisgj@gmail.com>
This commit is contained in:
parent
87aa6d6eaf
commit
7578b6d280
2 changed files with 142 additions and 45 deletions
|
@ -218,50 +218,6 @@ export const CREATE_CONNECTOR_PLUGIN = {
|
|||
--index-language en
|
||||
--from-file config.yml
|
||||
`,
|
||||
CONSOLE_SNIPPET: dedent`# Create an index
|
||||
PUT /my-index-000001
|
||||
{
|
||||
"settings": {
|
||||
"index": {
|
||||
"number_of_shards": 3,
|
||||
"number_of_replicas": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Create an API key
|
||||
POST /_security/api_key
|
||||
{
|
||||
"name": "my-api-key",
|
||||
"expiration": "1d",
|
||||
"role_descriptors":
|
||||
{
|
||||
"role-a": {
|
||||
"cluster": ["all"],
|
||||
"indices": [
|
||||
{
|
||||
"names": ["index-a*"],
|
||||
"privileges": ["read"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"role-b": {
|
||||
"cluster": ["all"],
|
||||
"indices": [
|
||||
{
|
||||
"names": ["index-b*"],
|
||||
"privileges": ["all"]
|
||||
}]
|
||||
}
|
||||
}, "metadata":
|
||||
{ "application": "my-application",
|
||||
"environment": {
|
||||
"level": 1,
|
||||
"trusted": true,
|
||||
"tags": ["dev", "staging"]
|
||||
}
|
||||
}
|
||||
}`,
|
||||
};
|
||||
|
||||
export const LICENSED_SUPPORT_URL = 'https://support.elastic.co';
|
||||
|
|
|
@ -6,16 +6,27 @@
|
|||
*/
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { css } from '@emotion/react';
|
||||
import dedent from 'dedent';
|
||||
|
||||
import { useValues } from 'kea';
|
||||
|
||||
import {
|
||||
EuiButtonIcon,
|
||||
EuiContextMenuItem,
|
||||
EuiContextMenuPanel,
|
||||
EuiPopover,
|
||||
useGeneratedHtmlId,
|
||||
useEuiTheme,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import { NATIVE_CONNECTOR_DEFINITIONS, NativeConnector } from '@kbn/search-connectors';
|
||||
import { TryInConsoleButton } from '@kbn/try-in-console';
|
||||
|
||||
import { KibanaDeps } from '../../../../../../../common/types';
|
||||
import { NewConnectorLogic } from '../../../new_index/method_connector/new_connector_logic';
|
||||
import { SelfManagePreference } from '../create_connector';
|
||||
|
||||
import { ManualConfigurationFlyout } from './manual_configuration_flyout';
|
||||
|
@ -25,10 +36,18 @@ export interface ManualConfigurationProps {
|
|||
selfManagePreference: SelfManagePreference;
|
||||
}
|
||||
|
||||
interface ConnectorConfiguration {
|
||||
[key: string]: {
|
||||
value: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const ManualConfiguration: React.FC<ManualConfigurationProps> = ({
|
||||
isDisabled,
|
||||
selfManagePreference,
|
||||
}) => {
|
||||
const { euiTheme } = useEuiTheme();
|
||||
const { services } = useKibana<KibanaDeps>();
|
||||
const [isPopoverOpen, setPopover] = useState(false);
|
||||
const splitButtonPopoverId = useGeneratedHtmlId({
|
||||
prefix: 'splitButtonPopover',
|
||||
|
@ -40,9 +59,104 @@ export const ManualConfiguration: React.FC<ManualConfigurationProps> = ({
|
|||
const closePopover = () => {
|
||||
setPopover(false);
|
||||
};
|
||||
|
||||
const { selectedConnector, rawName } = useValues(NewConnectorLogic);
|
||||
const [isFlyoutVisible, setIsFlyoutVisible] = useState(false);
|
||||
const [flyoutContent, setFlyoutContent] = useState<'manual_config' | 'client'>();
|
||||
const getCodeSnippet = (): string => {
|
||||
const connectorInfo: NativeConnector | undefined = selectedConnector?.serviceType
|
||||
? NATIVE_CONNECTOR_DEFINITIONS[selectedConnector.serviceType]
|
||||
: undefined;
|
||||
if (!connectorInfo) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const dynamicConfigValues = Object.entries(
|
||||
connectorInfo.configuration as ConnectorConfiguration
|
||||
)
|
||||
.map(([key, config]) => {
|
||||
const defaultValue = config ? JSON.stringify(config.value) : null;
|
||||
return ` "${key}": ${defaultValue}`;
|
||||
})
|
||||
.join(',\n');
|
||||
const CONSOLE_SNIPPET = dedent` # Example of how to create a ${connectorInfo?.name} connector using the API
|
||||
# This also creates related resources like an index and an API key.
|
||||
# This is an alternative to using the UI creation flow.
|
||||
|
||||
# 1. Create an index
|
||||
PUT connector-${rawName}
|
||||
{
|
||||
"settings": {
|
||||
"index": {
|
||||
"number_of_shards": 3,
|
||||
"number_of_replicas": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
# 2. Create a connector
|
||||
PUT _connector/${rawName}
|
||||
{
|
||||
"name": "My ${connectorInfo?.name} connector",
|
||||
"index_name": "connector-${rawName}",
|
||||
"service_type": "${selectedConnector?.serviceType}"
|
||||
}
|
||||
# 3. Create an API key
|
||||
POST /_security/api_key
|
||||
{
|
||||
"name": "${rawName}-api-key",
|
||||
"role_descriptors": {
|
||||
"${selectedConnector?.serviceType}-api-key-role": {
|
||||
"cluster": [
|
||||
"monitor",
|
||||
"manage_connector"
|
||||
],
|
||||
"indices": [
|
||||
{
|
||||
"names": [
|
||||
"connector-${rawName}",
|
||||
".search-acl-filter-connector-${rawName}",
|
||||
".elastic-connectors*"
|
||||
],
|
||||
"privileges": [
|
||||
"all"
|
||||
],
|
||||
"allow_restricted_indices": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 🔧 Configure your connector
|
||||
# NOTE: Configuration keys differ per service type.
|
||||
PUT _connector/${rawName}/_configuration
|
||||
{
|
||||
"values": {
|
||||
${dynamicConfigValues}
|
||||
}
|
||||
}
|
||||
|
||||
# 🔌 Verify your connector is connected
|
||||
GET _connector/${rawName}
|
||||
|
||||
# 🔄 Sync data
|
||||
POST _connector/_sync_job
|
||||
{
|
||||
"id": "${rawName}",
|
||||
"job_type": "full"
|
||||
}
|
||||
|
||||
# ⏳ Check sync status
|
||||
GET _connector/_sync_job?connector_id=${rawName}&size=1
|
||||
|
||||
# Once the job completes, the status should return completed
|
||||
# 🎉 Verify that data is present in the index with the following API call
|
||||
GET connector-${rawName}/_count
|
||||
|
||||
# 🔎 Elasticsearch stores data in documents, which are JSON objects. List the individual documents with the following API call
|
||||
GET connector-${rawName}/_search
|
||||
`;
|
||||
return CONSOLE_SNIPPET;
|
||||
};
|
||||
|
||||
const items = [
|
||||
<EuiContextMenuItem
|
||||
|
@ -59,6 +173,33 @@ export const ManualConfiguration: React.FC<ManualConfigurationProps> = ({
|
|||
{ defaultMessage: 'Manual configuration' }
|
||||
)}
|
||||
</EuiContextMenuItem>,
|
||||
<EuiContextMenuItem
|
||||
key="edit"
|
||||
icon="console"
|
||||
onClick={() => {
|
||||
closePopover();
|
||||
}}
|
||||
css={css`
|
||||
.euiLink {
|
||||
color: ${euiTheme.colors.text};
|
||||
font-weight: ${euiTheme.font.weight.regular};
|
||||
}
|
||||
`}
|
||||
>
|
||||
<TryInConsoleButton
|
||||
application={services.application}
|
||||
sharePlugin={services.share}
|
||||
consolePlugin={services.console}
|
||||
content={i18n.translate(
|
||||
'xpack.enterpriseSearch.createConnector.flyoutManualConfigContent.TryInConsoleLabel',
|
||||
{
|
||||
defaultMessage: 'Run in Console',
|
||||
}
|
||||
)}
|
||||
type="link"
|
||||
request={getCodeSnippet()}
|
||||
/>
|
||||
</EuiContextMenuItem>,
|
||||
<EuiContextMenuItem
|
||||
key="share"
|
||||
icon="console"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue