mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Enterprise Search] Set featureset on native connector creation (#146534)
This moves setting native connector features to selecting a connector type.
This commit is contained in:
parent
3a92e247a6
commit
7c557a26cd
8 changed files with 203 additions and 129 deletions
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { FeatureName, NativeConnector } from '../types/connectors';
|
||||
|
||||
export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | undefined> = {
|
||||
mongodb: {
|
||||
configuration: {
|
||||
host: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mongodb.configuration.hostLabel',
|
||||
{
|
||||
defaultMessage: 'Host',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
user: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mongodb.configuration.usernameLabel',
|
||||
{
|
||||
defaultMessage: 'Username',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
password: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mongodb.configuration.passwordLabel',
|
||||
{
|
||||
defaultMessage: 'Password',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
database: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mongodb.configuration.databaseLabel',
|
||||
{
|
||||
defaultMessage: 'Database',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
collection: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mongodb.configuration.collectionLabel',
|
||||
{
|
||||
defaultMessage: 'Collection',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
direct_connection: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mongodb.configuration.directConnectionLabel',
|
||||
{
|
||||
defaultMessage: 'Direct connection (true/false)',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
},
|
||||
features: {
|
||||
[FeatureName.FILTERING_ADVANCED_CONFIG]: true,
|
||||
[FeatureName.FILTERING_RULES]: true,
|
||||
},
|
||||
name: i18n.translate('xpack.enterpriseSearch.nativeConnectors.mongodb.name', {
|
||||
defaultMessage: 'MongoDB',
|
||||
}),
|
||||
serviceType: 'mongodb',
|
||||
},
|
||||
mysql: {
|
||||
configuration: {
|
||||
host: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mysql.configuration.hostLabel',
|
||||
{
|
||||
defaultMessage: 'Host',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
port: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mysql.configuration.portLabel',
|
||||
{
|
||||
defaultMessage: 'Port',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
user: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mysql.configuration.usernameLabel',
|
||||
{
|
||||
defaultMessage: 'Username',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
password: {
|
||||
value: '',
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mysql.configuration.passwordLabel',
|
||||
{
|
||||
defaultMessage: 'Password',
|
||||
}
|
||||
),
|
||||
},
|
||||
database: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.nativeConnectors.mysql.configuration.databasesLabel',
|
||||
{
|
||||
defaultMessage: 'Databases',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
},
|
||||
features: {},
|
||||
name: i18n.translate('xpack.enterpriseSearch.nativeConnectors.mysql.name', {
|
||||
defaultMessage: 'MySQL',
|
||||
}),
|
||||
serviceType: 'mysql',
|
||||
},
|
||||
};
|
|
@ -113,7 +113,7 @@ export interface Connector {
|
|||
configuration: ConnectorConfiguration;
|
||||
description: string | null;
|
||||
error: string | null;
|
||||
features: Record<FeatureName, boolean | null> | null;
|
||||
features: Partial<Record<FeatureName, boolean>> | null;
|
||||
filtering: FilteringConfig[];
|
||||
id: string;
|
||||
index_name: string;
|
||||
|
@ -164,3 +164,10 @@ export interface ConnectorSyncJob {
|
|||
}
|
||||
|
||||
export type ConnectorSyncJobDocument = Omit<ConnectorSyncJob, 'id'>;
|
||||
|
||||
export interface NativeConnector {
|
||||
configuration: ConnectorConfiguration;
|
||||
features: Connector['features'];
|
||||
name: string;
|
||||
serviceType: string;
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { ConnectorStatus } from '../../../../../common/types/connectors';
|
||||
import { createApiLogic } from '../../../shared/api_logic/create_api_logic';
|
||||
import { HttpLogic } from '../../../shared/http';
|
||||
import { NativeConnector } from '../../components/search_index/connector/types';
|
||||
|
||||
export interface SetNativeConnectorArgs {
|
||||
connectorId: string;
|
||||
nativeConnector: NativeConnector;
|
||||
serviceType: string;
|
||||
}
|
||||
|
||||
export interface SetNativeConnectorResponse {
|
||||
|
@ -20,30 +19,14 @@ export interface SetNativeConnectorResponse {
|
|||
nativeConnector: NativeConnector;
|
||||
}
|
||||
|
||||
export const setNativeConnector = async ({
|
||||
connectorId,
|
||||
nativeConnector,
|
||||
}: SetNativeConnectorArgs) => {
|
||||
const { configuration, serviceType } = nativeConnector;
|
||||
|
||||
export const setNativeConnector = async ({ connectorId, serviceType }: SetNativeConnectorArgs) => {
|
||||
await HttpLogic.values.http.put(
|
||||
`/internal/enterprise_search/connectors/${connectorId}/service_type`,
|
||||
`/internal/enterprise_search/connectors/${connectorId}/configure_native`,
|
||||
{
|
||||
body: JSON.stringify({ serviceType }),
|
||||
body: JSON.stringify({ service_type: serviceType }),
|
||||
}
|
||||
);
|
||||
|
||||
await HttpLogic.values.http.post(
|
||||
`/internal/enterprise_search/connectors/${connectorId}/configuration`,
|
||||
{
|
||||
body: JSON.stringify(configuration),
|
||||
}
|
||||
);
|
||||
|
||||
await HttpLogic.values.http.put(`/internal/enterprise_search/connectors/${connectorId}/status`, {
|
||||
body: JSON.stringify({ status: ConnectorStatus.NEEDS_CONFIGURATION }),
|
||||
});
|
||||
|
||||
return { connectorId };
|
||||
};
|
||||
|
||||
|
|
|
@ -13,62 +13,6 @@ import { NativeConnector } from './types';
|
|||
|
||||
export const NATIVE_CONNECTORS: NativeConnector[] = [
|
||||
{
|
||||
configuration: {
|
||||
host: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mongodb.configuration.hostLabel',
|
||||
{
|
||||
defaultMessage: 'Host',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
user: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mongodb.configuration.usernameLabel',
|
||||
{
|
||||
defaultMessage: 'Username',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
password: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mongodb.configuration.passwordLabel',
|
||||
{
|
||||
defaultMessage: 'Password',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
database: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mongodb.configuration.databaseLabel',
|
||||
{
|
||||
defaultMessage: 'Database',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
collection: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mongodb.configuration.collectionLabel',
|
||||
{
|
||||
defaultMessage: 'Collection',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
direct_connection: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mongodb.configuration.directConnectionLabel',
|
||||
{
|
||||
defaultMessage: 'Direct connection (true/false)',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
},
|
||||
docsUrl: docLinks.connectorsMongoDB,
|
||||
externalAuthDocsUrl: 'https://www.mongodb.com/docs/atlas/app-services/authentication/',
|
||||
externalDocsUrl: 'https://www.mongodb.com/docs/',
|
||||
|
@ -78,53 +22,6 @@ export const NATIVE_CONNECTORS: NativeConnector[] = [
|
|||
serviceType: 'mongodb',
|
||||
},
|
||||
{
|
||||
configuration: {
|
||||
host: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mysql.configuration.hostLabel',
|
||||
{
|
||||
defaultMessage: 'Host',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
port: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mysql.configuration.portLabel',
|
||||
{
|
||||
defaultMessage: 'Port',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
user: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mysql.configuration.usernameLabel',
|
||||
{
|
||||
defaultMessage: 'Username',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
password: {
|
||||
value: '',
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mysql.configuration.passwordLabel',
|
||||
{
|
||||
defaultMessage: 'Password',
|
||||
}
|
||||
),
|
||||
},
|
||||
database: {
|
||||
label: i18n.translate(
|
||||
'xpack.enterpriseSearch.content.nativeConnectors.mysql.configuration.databasesLabel',
|
||||
{
|
||||
defaultMessage: 'Databases',
|
||||
}
|
||||
),
|
||||
value: '',
|
||||
},
|
||||
},
|
||||
docsUrl: docLinks.connectorsMySQL,
|
||||
externalDocsUrl: 'https://dev.mysql.com/doc/',
|
||||
name: i18n.translate('xpack.enterpriseSearch.content.nativeConnectors.mysql.name', {
|
||||
|
|
|
@ -82,7 +82,7 @@ export const SelectConnectorLogic = kea<
|
|||
} else {
|
||||
actions.makeRequest({
|
||||
connectorId: values.index.connector.id,
|
||||
nativeConnector: values.selectedNativeConnector,
|
||||
serviceType: values.selectedNativeConnector.serviceType,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { ConnectorConfiguration } from '../../../../../../common/types/connectors';
|
||||
|
||||
export interface NativeConnector {
|
||||
configuration: ConnectorConfiguration;
|
||||
docsUrl: string;
|
||||
externalAuthDocsUrl?: string;
|
||||
externalDocsUrl: string;
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
|
||||
|
||||
import { CONNECTORS_INDEX } from '../..';
|
||||
import { NATIVE_CONNECTOR_DEFINITIONS } from '../../../common/connectors/native_connectors';
|
||||
import { Connector, ConnectorStatus } from '../../../common/types/connectors';
|
||||
|
||||
export const configureNativeConnector = async (
|
||||
client: IScopedClusterClient,
|
||||
connectorId: string,
|
||||
serviceType: string
|
||||
): Promise<boolean> => {
|
||||
const nativeConnector = NATIVE_CONNECTOR_DEFINITIONS[serviceType];
|
||||
|
||||
if (!nativeConnector) {
|
||||
throw new Error(`Could not find connector definition for service type ${serviceType}`);
|
||||
}
|
||||
|
||||
const result = await client.asCurrentUser.update<Connector>({
|
||||
doc: {
|
||||
configuration: nativeConnector.configuration,
|
||||
features: nativeConnector.features,
|
||||
name: nativeConnector.name,
|
||||
service_type: serviceType,
|
||||
status: ConnectorStatus.NEEDS_CONFIGURATION,
|
||||
},
|
||||
id: connectorId,
|
||||
index: CONNECTORS_INDEX,
|
||||
refresh: true,
|
||||
});
|
||||
|
||||
return result.result === 'updated' ? true : false;
|
||||
};
|
|
@ -20,6 +20,7 @@ import { ErrorCode } from '../../../common/types/error_codes';
|
|||
import { addConnector } from '../../lib/connectors/add_connector';
|
||||
import { fetchSyncJobsByConnectorId } from '../../lib/connectors/fetch_sync_jobs';
|
||||
import { cancelSyncs } from '../../lib/connectors/post_cancel_syncs';
|
||||
import { configureNativeConnector } from '../../lib/connectors/put_configure_native';
|
||||
import { updateFiltering } from '../../lib/connectors/put_update_filtering';
|
||||
import { updateFilteringDraft } from '../../lib/connectors/put_update_filtering_draft';
|
||||
import { startConnectorSync } from '../../lib/connectors/start_sync';
|
||||
|
@ -271,6 +272,23 @@ export function registerConnectorRoutes({ router, log }: RouteDependencies) {
|
|||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/enterprise_search/connectors/{connectorId}/configure_native',
|
||||
validate: {
|
||||
body: schema.object({ service_type: schema.string() }),
|
||||
params: schema.object({
|
||||
connectorId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
elasticsearchErrorHandler(log, async (context, request, response) => {
|
||||
const { client } = (await context.core).elasticsearch;
|
||||
await configureNativeConnector(client, request.params.connectorId, request.body.service_type);
|
||||
return response.ok();
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/enterprise_search/connectors/{connectorId}/name_and_description',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue