mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Search] Integrate updateConnectorNameAndDescription with Connectors API (#175037)
This commit is contained in:
parent
88a34837ac
commit
a15798303a
10 changed files with 101 additions and 48 deletions
|
@ -7,10 +7,10 @@
|
|||
*/
|
||||
|
||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||
import { ConnectorsAPIUpdateResponse } from '../types/connectors_api';
|
||||
import { Result } from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
export const deleteConnectorSecret = async (client: ElasticsearchClient, id: string) => {
|
||||
return await client.transport.request<ConnectorsAPIUpdateResponse>({
|
||||
return await client.transport.request<Result>({
|
||||
method: 'DELETE',
|
||||
path: `/_connector/_secret/${id}`,
|
||||
});
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { ElasticsearchClient } from '@kbn/core/server';
|
||||
|
||||
import { errors } from '@elastic/elasticsearch';
|
||||
|
||||
import { updateConnectorNameAndDescription } from './update_connector_name_and_description';
|
||||
|
||||
describe('updateConnectorNameAndDescription lib function', () => {
|
||||
const mockClient = {
|
||||
transport: {
|
||||
request: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should update connector name and description', async () => {
|
||||
mockClient.transport.request.mockImplementation(() => ({ result: 'updated' }));
|
||||
|
||||
await expect(
|
||||
updateConnectorNameAndDescription(
|
||||
mockClient as unknown as ElasticsearchClient,
|
||||
'connectorId',
|
||||
{
|
||||
name: 'connector-name',
|
||||
description: 'connector-description',
|
||||
}
|
||||
)
|
||||
).resolves.toEqual({ result: 'updated' });
|
||||
expect(mockClient.transport.request).toHaveBeenCalledWith({
|
||||
body: {
|
||||
name: 'connector-name',
|
||||
description: 'connector-description',
|
||||
},
|
||||
method: 'PUT',
|
||||
path: '/_connector/connectorId/_name',
|
||||
});
|
||||
});
|
||||
|
||||
it('should not index document if there is no connector', async () => {
|
||||
mockClient.transport.request.mockImplementationOnce(() => {
|
||||
return Promise.reject(
|
||||
new errors.ResponseError({
|
||||
statusCode: 404,
|
||||
body: {
|
||||
error: {
|
||||
type: `document_missing_exception`,
|
||||
},
|
||||
},
|
||||
} as any)
|
||||
);
|
||||
});
|
||||
await expect(
|
||||
updateConnectorNameAndDescription(
|
||||
mockClient as unknown as ElasticsearchClient,
|
||||
'connectorId',
|
||||
{
|
||||
name: 'connector-name',
|
||||
description: 'connector-description',
|
||||
}
|
||||
)
|
||||
).rejects.toEqual(
|
||||
new errors.ResponseError({
|
||||
statusCode: 404,
|
||||
body: {
|
||||
error: {
|
||||
type: `document_missing_exception`,
|
||||
},
|
||||
},
|
||||
} as any)
|
||||
);
|
||||
});
|
||||
});
|
|
@ -6,37 +6,24 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { WriteResponseBase } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { Result } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { ElasticsearchClient } from '@kbn/core/server';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
import { CONNECTORS_INDEX } from '..';
|
||||
|
||||
import { Connector, ConnectorDocument } from '../types/connectors';
|
||||
import { Connector } from '../types/connectors';
|
||||
|
||||
export const updateConnectorNameAndDescription = async (
|
||||
client: ElasticsearchClient,
|
||||
connectorId: string,
|
||||
connectorUpdates: Partial<Pick<Connector, 'name' | 'description'>>
|
||||
): Promise<WriteResponseBase> => {
|
||||
const connectorResult = await client.get<ConnectorDocument>({
|
||||
id: connectorId,
|
||||
index: CONNECTORS_INDEX,
|
||||
): Promise<Result> => {
|
||||
const { name, description } = connectorUpdates;
|
||||
const result = await client.transport.request<Result>({
|
||||
method: 'PUT',
|
||||
path: `/_connector/${connectorId}/_name`,
|
||||
body: {
|
||||
name,
|
||||
description,
|
||||
},
|
||||
});
|
||||
const connector = connectorResult._source;
|
||||
if (connector) {
|
||||
const result = await client.index<ConnectorDocument>({
|
||||
document: { ...connector, ...connectorUpdates },
|
||||
id: connectorId,
|
||||
index: CONNECTORS_INDEX,
|
||||
});
|
||||
await client.indices.refresh({ index: CONNECTORS_INDEX });
|
||||
return result;
|
||||
} else {
|
||||
throw new Error(
|
||||
i18n.translate('searchConnectors.server.connectors.serviceType.error', {
|
||||
defaultMessage: 'Could not find document',
|
||||
})
|
||||
);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@ import { errors } from '@elastic/elasticsearch';
|
|||
|
||||
import { updateConnectorScheduling } from './update_connector_scheduling';
|
||||
|
||||
describe('addConnector lib function', () => {
|
||||
describe('updateConnectorScheduling lib function', () => {
|
||||
const mockClient = {
|
||||
transport: {
|
||||
request: jest.fn(),
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { Result } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { ElasticsearchClient } from '@kbn/core/server';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { isNotFoundException } from '../utils/identify_exceptions';
|
||||
|
||||
import { SchedulingConfiguraton } from '../types/connectors';
|
||||
import { ConnectorsAPIUpdateResponse } from '../types/connectors_api';
|
||||
|
||||
export const updateConnectorScheduling = async (
|
||||
client: ElasticsearchClient,
|
||||
|
@ -19,7 +19,7 @@ export const updateConnectorScheduling = async (
|
|||
scheduling: SchedulingConfiguraton
|
||||
) => {
|
||||
try {
|
||||
const result = await client.transport.request<ConnectorsAPIUpdateResponse>({
|
||||
const result = await client.transport.request<Result>({
|
||||
method: 'PUT',
|
||||
path: `/_connector/${connectorId}/_scheduling`,
|
||||
body: {
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
*/
|
||||
|
||||
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
|
||||
import { ConnectorsAPIUpdateResponse } from '../types/connectors_api';
|
||||
import { Result } from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
export const updateConnectorSecret = async (
|
||||
client: ElasticsearchClient,
|
||||
value: string,
|
||||
secretId: string
|
||||
) => {
|
||||
return await client.transport.request<ConnectorsAPIUpdateResponse>({
|
||||
return await client.transport.request<Result>({
|
||||
method: 'PUT',
|
||||
path: `/_connector/_secret/${secretId}`,
|
||||
body: {
|
||||
|
|
|
@ -10,23 +10,10 @@
|
|||
|
||||
import { ConnectorSyncJob, Connector } from './connectors';
|
||||
|
||||
enum Result {
|
||||
created = 'created',
|
||||
updated = 'updated',
|
||||
deleted = 'deleted',
|
||||
not_found = 'not_found',
|
||||
no_op = 'noop',
|
||||
}
|
||||
|
||||
export interface ConnectorAPIListConnectorsResponse {
|
||||
count: number;
|
||||
results: Connector[];
|
||||
}
|
||||
|
||||
export interface ConnectorsAPIUpdateResponse {
|
||||
result: Result;
|
||||
}
|
||||
|
||||
export interface ConnectorsAPISyncJobResponse {
|
||||
count: number;
|
||||
results: ConnectorSyncJob[];
|
||||
|
|
|
@ -42474,7 +42474,6 @@
|
|||
"searchConnectors.nativeConnectors.usernameLabel": "Nom d'utilisateur",
|
||||
"searchConnectors.server.connectors.configuration.error": "Connecteur introuvable",
|
||||
"searchConnectors.server.connectors.scheduling.error": "Document introuvable",
|
||||
"searchConnectors.server.connectors.serviceType.error": "Document introuvable",
|
||||
"searchConnectors.syncJobType.full": "Contenu entier",
|
||||
"searchConnectors.syncJobType.incremental": "Contenu progressif",
|
||||
"searchConnectors.syncStatus.canceled": "Annulation de la synchronisation",
|
||||
|
|
|
@ -42466,7 +42466,6 @@
|
|||
"searchConnectors.nativeConnectors.usernameLabel": "ユーザー名",
|
||||
"searchConnectors.server.connectors.configuration.error": "コネクターが見つかりませんでした",
|
||||
"searchConnectors.server.connectors.scheduling.error": "ドキュメントが見つかりませんでした",
|
||||
"searchConnectors.server.connectors.serviceType.error": "ドキュメントが見つかりませんでした",
|
||||
"searchConnectors.syncJobType.full": "完全なコンテンツ",
|
||||
"searchConnectors.syncJobType.incremental": "増分コンテンツ",
|
||||
"searchConnectors.syncStatus.canceled": "同期のキャンセル中",
|
||||
|
|
|
@ -42446,7 +42446,6 @@
|
|||
"searchConnectors.nativeConnectors.usernameLabel": "用户名",
|
||||
"searchConnectors.server.connectors.configuration.error": "找不到连接器",
|
||||
"searchConnectors.server.connectors.scheduling.error": "无法找到文档",
|
||||
"searchConnectors.server.connectors.serviceType.error": "无法找到文档",
|
||||
"searchConnectors.syncJobType.full": "完整内容",
|
||||
"searchConnectors.syncJobType.incremental": "增量同步",
|
||||
"searchConnectors.syncStatus.canceled": "正在取消同步",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue