Prepare the connector Get API for versioning (#166894)

Part of: https://github.com/elastic/response-ops-team/issues/125

This PR intends to prepare the `GET
${BASE_ACTION_API_PATH}/connector/{id}` API for versioning as shown in
the above issue.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Ersin Erdal 2023-10-07 12:17:24 +02:00 committed by GitHub
parent 062b1c7970
commit e9777f67bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 396 additions and 180 deletions

View file

@ -0,0 +1,12 @@
/*
* 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.
*/
export { getConnectorParamsSchema } from './schemas/latest';
export type { GetConnectorParams } from './types/latest';
export { getConnectorParamsSchema as getConnectorParamsSchemaV1 } from './schemas/v1';
export type { GetConnectorParams as GetConnectorParamsV1 } from './types/v1';

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export * from './v1';

View file

@ -0,0 +1,12 @@
/*
* 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 { schema } from '@kbn/config-schema';
export const getConnectorParamsSchema = schema.object({
id: schema.string(),
});

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export * from './v1';

View file

@ -0,0 +1,11 @@
/*
* 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 type { TypeOf } from '@kbn/config-schema';
import { getConnectorParamsSchemaV1 } from '..';
export type GetConnectorParams = TypeOf<typeof getConnectorParamsSchemaV1>;

View file

@ -6,15 +6,21 @@
*/
// Latest
export type { ConnectorResponse, ActionTypeConfig } from './types/latest';
export { connectorResponseSchema } from './schemas/latest';
export { connectorTypesResponseSchema } from './schemas/latest';
export type { ConnectorResponse, AllConnectorsResponse } from './types/latest';
export {
connectorResponseSchema,
allConnectorsResponseSchema,
connectorTypesResponseSchema,
} from './schemas/latest';
// v1
export type {
ConnectorResponse as ConnectorResponseV1,
ActionTypeConfig as ActionTypeConfigV1,
AllConnectorsResponse as AllConnectorsResponseV1,
ConnectorTypesResponse as ConnectorTypesResponseV1,
} from './types/v1';
export { connectorResponseSchema as connectorResponseSchemaV1 } from './schemas/v1';
export type { ConnectorTypesResponse as ConnectorTypesResponseV1 } from './types/v1';
export { connectorTypesResponseSchema as connectorTypesResponseSchemaV1 } from './schemas/v1';
export {
connectorResponseSchema as connectorResponseSchemaV1,
allConnectorsResponseSchema as connectorWithExtraFindDataSchemaV1,
connectorTypesResponseSchema as connectorTypesResponseSchemaV1,
} from './schemas/v1';

View file

@ -6,4 +6,5 @@
*/
export { connectorResponseSchema } from './v1';
export { allConnectorsResponseSchema } from './v1';
export { connectorTypesResponseSchema } from './v1';

View file

@ -16,6 +16,9 @@ export const connectorResponseSchema = schema.object({
is_preconfigured: schema.boolean(),
is_deprecated: schema.boolean(),
is_system_action: schema.boolean(),
});
export const allConnectorsResponseSchema = connectorResponseSchema.extends({
referenced_by_count: schema.number(),
});

View file

@ -6,21 +6,28 @@
*/
import { TypeOf } from '@kbn/config-schema';
import { connectorResponseSchemaV1, connectorTypesResponseSchemaV1 } from '..';
import {
connectorResponseSchemaV1,
connectorTypesResponseSchemaV1,
allConnectorsResponseSchema,
} from '..';
export type ActionTypeConfig = Record<string, unknown>;
type ConnectorResponseSchemaType = TypeOf<typeof connectorResponseSchemaV1>;
type AllConnectorsResponseSchemaType = TypeOf<typeof allConnectorsResponseSchema>;
export interface ConnectorResponse<Config extends ActionTypeConfig = ActionTypeConfig> {
export interface ConnectorResponse {
id: ConnectorResponseSchemaType['id'];
name: ConnectorResponseSchemaType['name'];
config?: Config;
config?: ConnectorResponseSchemaType['config'];
connector_type_id: ConnectorResponseSchemaType['connector_type_id'];
is_missing_secrets?: ConnectorResponseSchemaType['is_missing_secrets'];
is_preconfigured: ConnectorResponseSchemaType['is_preconfigured'];
is_deprecated: ConnectorResponseSchemaType['is_deprecated'];
is_system_action: ConnectorResponseSchemaType['is_system_action'];
referenced_by_count: ConnectorResponseSchemaType['referenced_by_count'];
}
export interface AllConnectorsResponse extends ConnectorResponse {
referenced_by_count: AllConnectorsResponseSchemaType['referenced_by_count'];
}
type ConnectorTypesResponseSchemaType = TypeOf<typeof connectorTypesResponseSchemaV1>;

View file

@ -24,8 +24,9 @@ import { AuditLogger } from '@kbn/security-plugin/server';
import { RunNowResult } from '@kbn/task-manager-plugin/server';
import { IEventLogClient } from '@kbn/event-log-plugin/server';
import { KueryNode } from '@kbn/es-query';
import { FindConnectorResult } from '../application/connector/types';
import { ConnectorWithExtraFindData } from '../application/connector/types';
import { ConnectorType } from '../application/connector/types';
import { get } from '../application/connector/methods/get';
import { getAll } from '../application/connector/methods/get_all';
import { listTypes } from '../application/connector/methods/list_types';
import {
@ -396,7 +397,7 @@ export class ActionsClient {
}
/**
* Get an action
* Get a connector
*/
public async get({
id,
@ -405,79 +406,15 @@ export class ActionsClient {
id: string;
throwIfSystemAction?: boolean;
}): Promise<ActionResult> {
try {
await this.context.authorization.ensureAuthorized({ operation: 'get' });
} catch (error) {
this.context.auditLogger?.log(
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
error,
})
);
throw error;
}
const foundInMemoryConnector = this.context.inMemoryConnectors.find(
(connector) => connector.id === id
);
/**
* Getting system connector is not allowed
* if throwIfSystemAction is set to true.
* Default behavior is to throw
*/
if (
foundInMemoryConnector !== undefined &&
foundInMemoryConnector.isSystemAction &&
throwIfSystemAction
) {
throw Boom.notFound(`Connector ${id} not found`);
}
if (foundInMemoryConnector !== undefined) {
this.context.auditLogger?.log(
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
})
);
return {
id,
actionTypeId: foundInMemoryConnector.actionTypeId,
name: foundInMemoryConnector.name,
isPreconfigured: foundInMemoryConnector.isPreconfigured,
isSystemAction: foundInMemoryConnector.isSystemAction,
isDeprecated: isConnectorDeprecated(foundInMemoryConnector),
};
}
const result = await this.context.unsecuredSavedObjectsClient.get<RawAction>('action', id);
this.context.auditLogger?.log(
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
})
);
return {
id,
actionTypeId: result.attributes.actionTypeId,
isMissingSecrets: result.attributes.isMissingSecrets,
name: result.attributes.name,
config: result.attributes.config,
isPreconfigured: false,
isSystemAction: false,
isDeprecated: isConnectorDeprecated(result.attributes),
};
return get({ context: this.context, id, throwIfSystemAction });
}
/**
* Get all connectors with in-memory connectors
*/
public async getAll({ includeSystemActions = false } = {}): Promise<FindConnectorResult[]> {
public async getAll({ includeSystemActions = false } = {}): Promise<
ConnectorWithExtraFindData[]
> {
return getAll({ context: this.context, includeSystemActions });
}

View file

@ -0,0 +1,102 @@
/*
* 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 Boom from '@hapi/boom';
import { getConnectorSo } from '../../../../data/connector';
import { connectorSchema } from '../../schemas';
import { Connector } from '../../types';
import { ConnectorAuditAction, connectorAuditEvent } from '../../../../lib/audit_events';
import { isConnectorDeprecated } from '../../lib';
import { GetParams } from './types';
export async function get({
context,
id,
throwIfSystemAction = true,
}: GetParams): Promise<Connector> {
try {
await context.authorization.ensureAuthorized({ operation: 'get' });
} catch (error) {
context.auditLogger?.log(
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
error,
})
);
throw error;
}
const foundInMemoryConnector = context.inMemoryConnectors.find(
(connector) => connector.id === id
);
/**
* Getting system connector is not allowed
* if throwIfSystemAction is set to true.
* Default behavior is to throw
*/
if (
foundInMemoryConnector !== undefined &&
foundInMemoryConnector.isSystemAction &&
throwIfSystemAction
) {
throw Boom.notFound(`Connector ${id} not found`);
}
let connector: Connector;
if (foundInMemoryConnector !== undefined) {
context.auditLogger?.log(
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
})
);
connector = {
id,
actionTypeId: foundInMemoryConnector.actionTypeId,
name: foundInMemoryConnector.name,
isPreconfigured: foundInMemoryConnector.isPreconfigured,
isSystemAction: foundInMemoryConnector.isSystemAction,
isDeprecated: isConnectorDeprecated(foundInMemoryConnector),
};
} else {
const result = await getConnectorSo({
unsecuredSavedObjectsClient: context.unsecuredSavedObjectsClient,
id,
});
context.auditLogger?.log(
connectorAuditEvent({
action: ConnectorAuditAction.GET,
savedObject: { type: 'action', id },
})
);
connector = {
id,
actionTypeId: result.attributes.actionTypeId,
isMissingSecrets: result.attributes.isMissingSecrets,
name: result.attributes.name,
config: result.attributes.config,
isPreconfigured: false,
isSystemAction: false,
isDeprecated: isConnectorDeprecated(result.attributes),
};
}
// Try to validate the connector, but don't throw.
try {
connectorSchema.validate(connector);
} catch (e) {
context.logger.warn(`Error validating connector: ${connector.id}, ${e}`);
}
return connector;
}

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export { get } from './get';

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export type { GetParams } from './params';

View file

@ -0,0 +1,14 @@
/*
* 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 { ActionsClientContext } from '../../../../../actions_client';
export interface GetParams {
context: ActionsClientContext;
id: string;
throwIfSystemAction?: boolean;
}

View file

@ -9,17 +9,17 @@
* Get all actions with in-memory connectors
*/
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { connectorSchema } from '../../schemas';
import { connectorWithExtraFindDataSchema } from '../../schemas';
import { findConnectorsSo, searchConnectorsSo } from '../../../../data/connector';
import { GetAllParams, InjectExtraFindDataParams } from './types';
import { ConnectorAuditAction, connectorAuditEvent } from '../../../../lib/audit_events';
import { connectorFromSavedObject, isConnectorDeprecated } from '../../lib';
import { FindConnectorResult } from '../../types';
import { ConnectorWithExtraFindData } from '../../types';
export async function getAll({
context,
includeSystemActions = false,
}: GetAllParams): Promise<FindConnectorResult[]> {
}: GetAllParams): Promise<ConnectorWithExtraFindData[]> {
try {
await context.authorization.ensureAuthorized({ operation: 'get' });
} catch (error) {
@ -63,27 +63,29 @@ export async function getAll({
})),
].sort((a, b) => a.name.localeCompare(b.name));
mergedResult.forEach((connector) => {
const connectors = await injectExtraFindData({
kibanaIndices: context.kibanaIndices,
scopedClusterClient: context.scopedClusterClient,
connectors: mergedResult,
});
connectors.forEach((connector) => {
// Try to validate the connectors, but don't throw.
try {
connectorSchema.validate(connector);
connectorWithExtraFindDataSchema.validate(connector);
} catch (e) {
context.logger.warn(`Error validating connector: ${connector.id}, ${e}`);
}
});
return await injectExtraFindData({
kibanaIndices: context.kibanaIndices,
scopedClusterClient: context.scopedClusterClient,
connectors: mergedResult,
});
return connectors;
}
async function injectExtraFindData({
kibanaIndices,
scopedClusterClient,
connectors,
}: InjectExtraFindDataParams): Promise<FindConnectorResult[]> {
}: InjectExtraFindDataParams): Promise<ConnectorWithExtraFindData[]> {
const aggs: Record<string, estypes.AggregationsAggregationContainer> = {};
for (const connector of connectors) {
aggs[connector.id] = {

View file

@ -17,3 +17,7 @@ export const connectorSchema = schema.object({
isDeprecated: schema.boolean(),
isSystemAction: schema.boolean(),
});
export const connectorWithExtraFindDataSchema = connectorSchema.extends({
referencedByCount: schema.number(),
});

View file

@ -6,22 +6,22 @@
*/
import { TypeOf } from '@kbn/config-schema';
import { connectorSchema } from '../schemas';
import { ActionTypeConfig } from '../../../types';
import { connectorSchema, connectorWithExtraFindDataSchema } from '../schemas';
type ConnectorSchemaType = TypeOf<typeof connectorSchema>;
type ConnectorWithExtraFindDataSchema = TypeOf<typeof connectorWithExtraFindDataSchema>;
export interface Connector<Config extends ActionTypeConfig = ActionTypeConfig> {
export interface Connector {
id: ConnectorSchemaType['id'];
actionTypeId: ConnectorSchemaType['actionTypeId'];
name: ConnectorSchemaType['name'];
isMissingSecrets?: ConnectorSchemaType['isMissingSecrets'];
config?: Config;
config?: ConnectorSchemaType['config'];
isPreconfigured: ConnectorSchemaType['isPreconfigured'];
isDeprecated: ConnectorSchemaType['isDeprecated'];
isSystemAction: ConnectorSchemaType['isSystemAction'];
}
export interface FindConnectorResult extends Connector {
referencedByCount: number;
export interface ConnectorWithExtraFindData extends Connector {
referencedByCount: ConnectorWithExtraFindDataSchema['referencedByCount'];
}

View file

@ -5,5 +5,5 @@
* 2.0.
*/
export type { Connector, FindConnectorResult } from './connector';
export type { Connector, ConnectorWithExtraFindData } from './connector';
export type { ConnectorType } from './connector_type';

View file

@ -0,0 +1,16 @@
/*
* 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 { GetConnectorSoResult, GetConnectorSoParams } from './types';
import { RawAction } from '../../types';
export const getConnectorSo = async ({
unsecuredSavedObjectsClient,
id,
}: GetConnectorSoParams): Promise<GetConnectorSoResult> => {
return unsecuredSavedObjectsClient.get<RawAction>('action', id);
};

View file

@ -7,3 +7,4 @@
export { findConnectorsSo } from './find_connectors_so';
export { searchConnectorsSo } from './search_connectors_so';
export { getConnectorSo } from './get_connector_so';

View file

@ -0,0 +1,11 @@
/*
* 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 { SavedObject } from '@kbn/core-saved-objects-common/src/server_types';
import { RawAction } from '../../../types';
export type GetConnectorSoResult = SavedObject<RawAction>;

View file

@ -5,5 +5,10 @@
* 2.0.
*/
export type { SearchConnectorsSoParams, FindConnectorsSoParams } from './params';
export type {
SearchConnectorsSoParams,
FindConnectorsSoParams,
GetConnectorSoParams,
} from './params';
export type { FindConnectorsSoResult } from './find_connectors_so_result';
export type { GetConnectorSoResult } from './get_connector_so_result';

View file

@ -18,3 +18,8 @@ export interface SearchConnectorsSoParams {
export interface FindConnectorsSoParams {
unsecuredSavedObjectsClient: SavedObjectsClientContract;
}
export interface GetConnectorSoParams {
unsecuredSavedObjectsClient: SavedObjectsClientContract;
id: string;
}

View file

@ -26,7 +26,7 @@ export type {
ActionsApiRequestHandlerContext,
} from './types';
export type { FindConnectorResult as FindActionResult } from './application/connector/types';
export type { ConnectorWithExtraFindData as FindActionResult } from './application/connector/types';
export type { PluginSetupContract, PluginStartContract } from './plugin';

View file

@ -5,14 +5,14 @@
* 2.0.
*/
import { getActionRoute } from './get';
import { getConnectorRoute } from './get';
import { httpServiceMock } from '@kbn/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { mockHandlerArguments } from './legacy/_mock_handler_arguments';
import { actionsClientMock } from '../actions_client/actions_client.mock';
import { verifyAccessAndContext } from './verify_access_and_context';
import { licenseStateMock } from '../../../lib/license_state.mock';
import { mockHandlerArguments } from '../../legacy/_mock_handler_arguments';
import { actionsClientMock } from '../../../actions_client/actions_client.mock';
import { verifyAccessAndContext } from '../../verify_access_and_context';
jest.mock('./verify_access_and_context', () => ({
jest.mock('../../verify_access_and_context', () => ({
verifyAccessAndContext: jest.fn(),
}));
@ -21,12 +21,12 @@ beforeEach(() => {
(verifyAccessAndContext as jest.Mock).mockImplementation((license, handler) => handler);
});
describe('getActionRoute', () => {
describe('getConnectorRoute', () => {
it('gets an action with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();
getActionRoute(router, licenseState);
getConnectorRoute(router, licenseState);
const [config, handler] = router.get.mock.calls[0];
@ -90,7 +90,7 @@ describe('getActionRoute', () => {
const licenseState = licenseStateMock.create();
const router = httpServiceMock.createRouter();
getActionRoute(router, licenseState);
getConnectorRoute(router, licenseState);
const [, handler] = router.get.mock.calls[0];
@ -126,7 +126,7 @@ describe('getActionRoute', () => {
throw new Error('OMG');
});
getActionRoute(router, licenseState);
getConnectorRoute(router, licenseState);
const [, handler] = router.get.mock.calls[0];

View file

@ -0,0 +1,40 @@
/*
* 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 { IRouter } from '@kbn/core/server';
import {
getConnectorParamsSchemaV1,
GetConnectorParamsV1,
} from '../../../../common/routes/connector/apis/get';
import { transformGetConnectorResponseV1 } from './transforms';
import { ILicenseState } from '../../../lib';
import { BASE_ACTION_API_PATH } from '../../../../common';
import { ActionsRequestHandlerContext } from '../../../types';
import { verifyAccessAndContext } from '../../verify_access_and_context';
export const getConnectorRoute = (
router: IRouter<ActionsRequestHandlerContext>,
licenseState: ILicenseState
) => {
router.get(
{
path: `${BASE_ACTION_API_PATH}/connector/{id}`,
validate: {
params: getConnectorParamsSchemaV1,
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
const actionsClient = (await context.actions).getActionsClient();
const { id }: GetConnectorParamsV1 = req.params;
return res.ok({
body: transformGetConnectorResponseV1(await actionsClient.get({ id })),
});
})
)
);
};

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export { getConnectorRoute } from './get';

View file

@ -0,0 +1,10 @@
/*
* 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.
*/
export { transformGetConnectorResponse } from './transform_connector_response/latest';
export { transformGetConnectorResponse as transformGetConnectorResponseV1 } from './transform_connector_response/v1';

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export { transformGetConnectorResponse } from './v1';

View file

@ -0,0 +1,25 @@
/*
* 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 { ConnectorResponseV1 } from '../../../../../../common/routes/connector/response';
import { Connector } from '../../../../../application/connector/types';
export const transformGetConnectorResponse = ({
actionTypeId,
isPreconfigured,
isMissingSecrets,
isDeprecated,
isSystemAction,
...res
}: Connector): ConnectorResponseV1 => ({
...res,
connector_type_id: actionTypeId,
is_preconfigured: isPreconfigured,
is_deprecated: isDeprecated,
is_missing_secrets: isMissingSecrets,
is_system_action: isSystemAction,
});

View file

@ -6,7 +6,7 @@
*/
import { IRouter } from '@kbn/core/server';
import { ConnectorResponseV1 } from '../../../../common/routes/connector/response';
import { AllConnectorsResponseV1 } from '../../../../common/routes/connector/response';
import { transformGetAllConnectorsResponseV1 } from './transforms';
import { ActionsRequestHandlerContext } from '../../../types';
import { BASE_ACTION_API_PATH } from '../../../../common';
@ -27,7 +27,7 @@ export const getAllConnectorsRoute = (
const actionsClient = (await context.actions).getActionsClient();
const result = await actionsClient.getAll();
const responseBody: ConnectorResponseV1[] = transformGetAllConnectorsResponseV1(result);
const responseBody: AllConnectorsResponseV1[] = transformGetAllConnectorsResponseV1(result);
return res.ok({ body: responseBody });
})
)

View file

@ -5,12 +5,12 @@
* 2.0.
*/
import { FindConnectorResult } from '../../../../../application/connector/types';
import { ConnectorResponseV1 } from '../../../../../../common/routes/connector/response';
import { ConnectorWithExtraFindData } from '../../../../../application/connector/types';
import { AllConnectorsResponseV1 } from '../../../../../../common/routes/connector/response';
export const transformGetAllConnectorsResponse = (
results: FindConnectorResult[]
): ConnectorResponseV1[] => {
results: ConnectorWithExtraFindData[]
): AllConnectorsResponseV1[] => {
return results.map(
({
id,

View file

@ -1,56 +0,0 @@
/*
* 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 { schema } from '@kbn/config-schema';
import { IRouter } from '@kbn/core/server';
import { ILicenseState } from '../lib';
import { BASE_ACTION_API_PATH, RewriteResponseCase } from '../../common';
import { ActionResult, ActionsRequestHandlerContext } from '../types';
import { verifyAccessAndContext } from './verify_access_and_context';
const paramSchema = schema.object({
id: schema.string(),
});
const rewriteBodyRes: RewriteResponseCase<ActionResult> = ({
actionTypeId,
isPreconfigured,
isMissingSecrets,
isDeprecated,
isSystemAction,
...res
}) => ({
...res,
connector_type_id: actionTypeId,
is_preconfigured: isPreconfigured,
is_deprecated: isDeprecated,
is_missing_secrets: isMissingSecrets,
is_system_action: isSystemAction,
});
export const getActionRoute = (
router: IRouter<ActionsRequestHandlerContext>,
licenseState: ILicenseState
) => {
router.get(
{
path: `${BASE_ACTION_API_PATH}/connector/{id}`,
validate: {
params: paramSchema,
},
},
router.handleLegacyErrors(
verifyAccessAndContext(licenseState, async function (context, req, res) {
const actionsClient = (await context.actions).getActionsClient();
const { id } = req.params;
return res.ok({
body: rewriteBodyRes(await actionsClient.get({ id })),
});
})
)
);
};

View file

@ -14,7 +14,7 @@ import { ActionsRequestHandlerContext } from '../types';
import { createActionRoute } from './create';
import { deleteActionRoute } from './delete';
import { executeActionRoute } from './execute';
import { getActionRoute } from './get';
import { getConnectorRoute } from './connector/get';
import { updateActionRoute } from './update';
import { getOAuthAccessToken } from './get_oauth_access_token';
import { defineLegacyRoutes } from './legacy';
@ -36,7 +36,7 @@ export function defineRoutes(opts: RouteOptions) {
createActionRoute(router, licenseState);
deleteActionRoute(router, licenseState);
getActionRoute(router, licenseState);
getConnectorRoute(router, licenseState);
getAllConnectorsRoute(router, licenseState);
updateActionRoute(router, licenseState);
listTypesRoute(router, licenseState);

View file

@ -35,7 +35,7 @@ export type ActionTypeParams = Record<string, unknown>;
export type ConnectorTokenClientContract = PublicMethodsOf<ConnectorTokenClient>;
import type { ActionExecutionSource } from './lib';
import { Connector, FindConnectorResult } from './application/connector/types';
import { Connector, ConnectorWithExtraFindData } from './application/connector/types';
export type { ActionExecutionSource } from './lib';
export { ActionExecutionSourceType } from './lib';
@ -78,17 +78,17 @@ export interface ActionTypeExecutorOptions<
source?: ActionExecutionSource<unknown>;
}
export type ActionResult<Config extends ActionTypeConfig = ActionTypeConfig> = Connector<Config>;
export type ActionResult = Connector;
export interface InMemoryConnector<
Config extends ActionTypeConfig = ActionTypeConfig,
Secrets extends ActionTypeSecrets = ActionTypeSecrets
> extends ActionResult<Config> {
> extends ActionResult {
secrets: Secrets;
config: Config;
}
export type FindActionResult = FindConnectorResult;
export type FindActionResult = ConnectorWithExtraFindData;
// signature of the action type executor function
export type ExecutorType<