Skip to content

Commit

Permalink
[8.6] [Enterprise Search] Set featureset on native connector creation (
Browse files Browse the repository at this point in the history
…elastic#146534) (elastic#146543)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Enterprise Search] Set featureset on native connector creation
(elastic#146534)](elastic#146534)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sander
Philipse","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-29T13:16:26Z","message":"[Enterprise
Search] Set featureset on native connector creation (elastic#146534)\n\nThis
moves setting native connector features to selecting a
connector\r\ntype.","sha":"7c557a26cd1b35e94a1c1b7a88e85ac38d3cd6e3","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","auto-backport","Team:EnterpriseSearch","v8.6.0","v8.7.0"],"number":146534,"url":"https://github.com/elastic/kibana/pull/146534","mergeCommit":{"message":"[Enterprise
Search] Set featureset on native connector creation (elastic#146534)\n\nThis
moves setting native connector features to selecting a
connector\r\ntype.","sha":"7c557a26cd1b35e94a1c1b7a88e85ac38d3cd6e3"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/146534","number":146534,"mergeCommit":{"message":"[Enterprise
Search] Set featureset on native connector creation (elastic#146534)\n\nThis
moves setting native connector features to selecting a
connector\r\ntype.","sha":"7c557a26cd1b35e94a1c1b7a88e85ac38d3cd6e3"}}]}]
BACKPORT-->

Co-authored-by: Sander Philipse <[email protected]>
  • Loading branch information
kibanamachine and sphilipse authored Nov 29, 2022
1 parent 85e6fc5 commit 6249c39
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -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',
},
};
9 changes: 8 additions & 1 deletion x-pack/plugins/enterprise_search/common/types/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,28 @@
* 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 {
connectorId: string;
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 };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand All @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const SelectConnectorLogic = kea<
} else {
actions.makeRequest({
connectorId: values.index.connector.id,
nativeConnector: values.selectedNativeConnector,
serviceType: values.selectedNativeConnector.serviceType,
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* 2.0.
*/

import { ConnectorConfiguration } from '../../../../../../common/types/connectors';

export interface NativeConnector {
configuration: ConnectorConfiguration;
docsUrl: string;
externalAuthDocsUrl?: string;
externalDocsUrl: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};
Loading

0 comments on commit 6249c39

Please sign in to comment.