|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import Joi from 'joi'; |
| 8 | +import Hapi from 'hapi'; |
| 9 | +import { Legacy } from 'kibana'; |
| 10 | +import KbnServer from '../../../../../../../src/legacy/server/kbn_server'; |
| 11 | +import { PluginStartContract } from '../../../../../../plugins/encrypted_saved_objects/server'; |
| 12 | + |
| 13 | +interface CheckAADRequest extends Hapi.Request { |
| 14 | + payload: { |
| 15 | + spaceId?: string; |
| 16 | + type: string; |
| 17 | + id: string; |
| 18 | + }; |
| 19 | +} |
| 20 | + |
| 21 | +// eslint-disable-next-line import/no-default-export |
| 22 | +export default function(kibana: any) { |
| 23 | + return new kibana.Plugin({ |
| 24 | + require: ['actions', 'alerting', 'encryptedSavedObjects'], |
| 25 | + name: 'aad-fixtures', |
| 26 | + init(server: Legacy.Server) { |
| 27 | + const newPlatform = ((server as unknown) as KbnServer).newPlatform; |
| 28 | + const esoPlugin = newPlatform.start.plugins.encryptedSavedObjects as PluginStartContract; |
| 29 | + |
| 30 | + server.route({ |
| 31 | + method: 'POST', |
| 32 | + path: '/api/check_aad', |
| 33 | + options: { |
| 34 | + validate: { |
| 35 | + payload: Joi.object() |
| 36 | + .keys({ |
| 37 | + spaceId: Joi.string().optional(), |
| 38 | + type: Joi.string().required(), |
| 39 | + id: Joi.string().required(), |
| 40 | + }) |
| 41 | + .required(), |
| 42 | + }, |
| 43 | + }, |
| 44 | + async handler(request: CheckAADRequest) { |
| 45 | + let namespace: string | undefined; |
| 46 | + const spacesPlugin = server.plugins.spaces; |
| 47 | + if (spacesPlugin && request.payload.spaceId) { |
| 48 | + namespace = spacesPlugin.spaceIdToNamespace(request.payload.spaceId); |
| 49 | + } |
| 50 | + await esoPlugin.getDecryptedAsInternalUser(request.payload.type, request.payload.id, { |
| 51 | + namespace, |
| 52 | + }); |
| 53 | + return { success: true }; |
| 54 | + }, |
| 55 | + }); |
| 56 | + }, |
| 57 | + }); |
| 58 | +} |
0 commit comments