* [Connectors][API] Updated connectors with enabledAfterImport flag * fixed functional tests * added new field to connectors API docs * added update unit test * fixed test * renamed enableAfterImport to isMissingSecrets * removed onExport * revert the logic of true/false for isMissingSecrets * fixed test * fixed tests * added unit test * fixed docs * fixed import text and button labels * fixed import text * fixed text
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
/*
|
|
* 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 'kibana/server';
|
|
import { ActionResult, ActionsRequestHandlerContext } from '../types';
|
|
import { ILicenseState } from '../lib';
|
|
import { BASE_ACTION_API_PATH, RewriteRequestCase, RewriteResponseCase } from '../../common';
|
|
import { verifyAccessAndContext } from './verify_access_and_context';
|
|
import { CreateOptions } from '../actions_client';
|
|
|
|
export const bodySchema = schema.object({
|
|
name: schema.string(),
|
|
connector_type_id: schema.string(),
|
|
config: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }),
|
|
secrets: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }),
|
|
});
|
|
|
|
const rewriteBodyReq: RewriteRequestCase<CreateOptions['action']> = ({
|
|
connector_type_id: actionTypeId,
|
|
name,
|
|
config,
|
|
secrets,
|
|
}) => ({ actionTypeId, name, config, secrets });
|
|
const rewriteBodyRes: RewriteResponseCase<ActionResult> = ({
|
|
actionTypeId,
|
|
isPreconfigured,
|
|
isMissingSecrets,
|
|
...res
|
|
}) => ({
|
|
...res,
|
|
connector_type_id: actionTypeId,
|
|
is_preconfigured: isPreconfigured,
|
|
is_missing_secrets: isMissingSecrets,
|
|
});
|
|
|
|
export const createActionRoute = (
|
|
router: IRouter<ActionsRequestHandlerContext>,
|
|
licenseState: ILicenseState
|
|
) => {
|
|
router.post(
|
|
{
|
|
path: `${BASE_ACTION_API_PATH}/connector`,
|
|
validate: {
|
|
body: bodySchema,
|
|
},
|
|
},
|
|
router.handleLegacyErrors(
|
|
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
|
const actionsClient = context.actions.getActionsClient();
|
|
const action = rewriteBodyReq(req.body);
|
|
return res.ok({
|
|
body: rewriteBodyRes(await actionsClient.create({ action })),
|
|
});
|
|
})
|
|
)
|
|
);
|
|
};
|