diff --git a/common/index.ts b/common/index.ts index 1066d948..a7da183f 100644 --- a/common/index.ts +++ b/common/index.ts @@ -29,10 +29,6 @@ export const PLUGIN_NAME = 'reports-dashboards'; export const API_PREFIX = '/api/reporting'; -export const NOTIFICATION_API = { - SEND: '/_plugins/_notifications/send', -}; - const BASE_REPORTS_URI = '/_plugins/_reports'; export const OPENSEARCH_REPORTS_API = { diff --git a/server/backend/opendistro-notification-plugin.ts b/server/backend/opendistro-notification-plugin.ts deleted file mode 100644 index 17dc6984..00000000 --- a/server/backend/opendistro-notification-plugin.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -import { NOTIFICATION_API } from '../../common'; - -export default function (Client: any, config: any, components: any) { - const clientAction = components.clientAction.factory; - - Client.prototype.notification = components.clientAction.namespaceFactory(); - const notification = Client.prototype.notification.prototype; - - notification.send = clientAction({ - url: { - fmt: `${NOTIFICATION_API.SEND}`, - }, - method: 'POST', - needBody: true, - }); -} diff --git a/server/executor/createScheduledReport.ts b/server/executor/createScheduledReport.ts index 585ce4c4..b6718a28 100644 --- a/server/executor/createScheduledReport.ts +++ b/server/executor/createScheduledReport.ts @@ -35,7 +35,6 @@ import { createSavedSearchReport } from '../routes/utils/savedSearchReportHelper import { ReportSchemaType } from '../model'; import { CreateReportResultType } from '../routes/utils/types'; import { createVisualReport } from '../routes/utils/visual_report/visualReportHelper'; -import { deliverReport } from '../routes/lib/deliverReport'; import { updateReportState } from '../routes/lib/updateReportState'; export const createScheduledReport = async ( @@ -43,7 +42,6 @@ export const createScheduledReport = async ( report: ReportSchemaType, opensearchClient: ILegacyClusterClient, opensearchReportsClient: ILegacyClusterClient, - notificationClient: ILegacyClusterClient, logger: Logger ) => { let createReportResult: CreateReportResultType; @@ -76,17 +74,6 @@ export const createScheduledReport = async ( // } await updateReportState(reportId, opensearchReportsClient, REPORT_STATE.created); - - // deliver report - if (deliveryType == DELIVERY_TYPE.channel) { - await deliverReport( - report, - notificationClient, - opensearchReportsClient, - reportId, - logger - ); - } } catch (error) { // update report instance with "error" state //TODO: save error detail and display on UI diff --git a/server/executor/executor.ts b/server/executor/executor.ts index 2b3fb63f..e60a9cc6 100644 --- a/server/executor/executor.ts +++ b/server/executor/executor.ts @@ -33,7 +33,6 @@ import { BackendReportInstanceType } from 'server/model/backendModel'; async function pollAndExecuteJob( opensearchReportsClient: ILegacyClusterClient, - notificationClient: ILegacyClusterClient, opensearchClient: ILegacyClusterClient, logger: Logger ) { @@ -60,7 +59,6 @@ async function pollAndExecuteJob( reportMetadata, opensearchClient, opensearchReportsClient, - notificationClient, logger ); } else { diff --git a/server/plugin.ts b/server/plugin.ts index c7c83b6c..b01d2dda 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -35,7 +35,6 @@ import { import { setIntervalAsync } from 'set-interval-async/dynamic'; import { Semaphore, SemaphoreInterface, withTimeout } from 'async-mutex'; import opensearchReportsPlugin from './backend/opensearch-reports-plugin'; -import notificationPlugin from './backend/opendistro-notification-plugin'; import { ReportsDashboardsPluginSetup, ReportsDashboardsPluginStart, @@ -89,12 +88,6 @@ export class ReportsDashboardsPlugin } ); - const notificationClient: ILegacyClusterClient = core.opensearch.legacy.createClient( - 'notification', - { - plugins: [notificationPlugin], - } - ); // Register server side APIs registerRoutes(router, accessInfo); @@ -106,7 +99,6 @@ export class ReportsDashboardsPlugin return { logger: this.logger, semaphore: this.semaphore, - notificationClient, opensearchReportsClient, }; } @@ -124,12 +116,6 @@ export class ReportsDashboardsPlugin } ); - const notificationClient: ILegacyClusterClient = core.opensearch.legacy.createClient( - 'notification', - { - plugins: [notificationPlugin], - } - ); const opensearchClient: ILegacyClusterClient = core.opensearch.legacy.client; /* diff --git a/server/routes/lib/createReport.ts b/server/routes/lib/createReport.ts index 3d1f4d27..2c83e6b6 100644 --- a/server/routes/lib/createReport.ts +++ b/server/routes/lib/createReport.ts @@ -42,7 +42,6 @@ import { ReportSchemaType } from '../../model'; import { CreateReportResultType } from '../utils/types'; import { createVisualReport } from '../utils/visual_report/visualReportHelper'; import { SetCookie, Headers } from 'puppeteer-core'; -import { deliverReport } from './deliverReport'; import { updateReportState } from './updateReportState'; import { saveReport } from './saveReport'; import { SemaphoreInterface } from 'async-mutex'; @@ -61,10 +60,6 @@ export const createReport = async ( //@ts-ignore const semaphore: SemaphoreInterface = context.reporting_plugin.semaphore; // @ts-ignore - const notificationClient: ILegacyScopedClusterClient = context.reporting_plugin.notificationClient.asScoped( - request - ); - // @ts-ignore const opensearchReportsClient: ILegacyScopedClusterClient = context.reporting_plugin.opensearchReportsClient.asScoped( request ); @@ -82,7 +77,6 @@ export const createReport = async ( const { report_definition: { report_params: reportParams, - delivery: { delivery_type: deliveryType }, }, } = report; const { report_source: reportSource } = reportParams; @@ -154,17 +148,6 @@ export const createReport = async ( // if (!savedReportId) { // await updateReportState(reportId, opensearchReportsClient, REPORT_STATE.created); // } - - // deliver report - if (!savedReportId && deliveryType == DELIVERY_TYPE.channel) { - await deliverReport( - report, - notificationClient, - opensearchReportsClient, - reportId, - logger - ); - } } catch (error) { // update report instance with "error" state // TODO: save error detail and display on UI diff --git a/server/routes/lib/deliverReport.ts b/server/routes/lib/deliverReport.ts deleted file mode 100644 index 6de0aea9..00000000 --- a/server/routes/lib/deliverReport.ts +++ /dev/null @@ -1,133 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -import { ChannelSchemaType, ReportSchemaType } from 'server/model'; -import { - ILegacyScopedClusterClient, - ILegacyClusterClient, - Logger, -} from '../../../../../src/core/server'; -import { DELIVERY_TYPE, REPORT_STATE } from '../utils/constants'; -import { composeEmbeddedHtml } from '../utils/notification/deliveryContentHelper'; -import { updateReportState } from './updateReportState'; - -export const deliverReport = async ( - report: ReportSchemaType, - notificationClient: ILegacyScopedClusterClient | ILegacyClusterClient, - opensearchReportsClient: ILegacyClusterClient | ILegacyScopedClusterClient, - reportId: string, - logger: Logger -) => { - const { - report_definition: { - delivery: { - delivery_params: deliveryParams, - delivery_type: deliveryType, - }, - }, - } = report; - // check delivery type - if (deliveryType === DELIVERY_TYPE.channel) { - // deliver through one of [Slack, Chime, Email] - const { - query_url: queryUrl, - report_definition: { - report_params: { - report_name: reportName, - core_params: { origin }, - }, - }, - } = report; - const { htmlDescription } = deliveryParams as ChannelSchemaType; - const originalQueryUrl = origin + queryUrl; - /** - * have to manually compose the url because the OpenSearch Dashboards url for AES is.../_plugin/kibana/app/reports-dashboards#/report_details/${reportId} - * while default OpenSearch Dashboards is just .../app/reports-dashboards#/report_details/${reportId} - */ - const reportDetailUrl = `${originalQueryUrl.replace( - /\/app\/.*$/i, - '' - )}/app/reports-dashboards#/report_details/${reportId}`; - - const embeddedHtml = composeEmbeddedHtml( - htmlDescription, - originalQueryUrl, - reportDetailUrl, - reportName - ); - - const reqBody = { - ...deliveryParams, - htmlDescription: embeddedHtml, - refTag: reportId, - }; - - // send email - const notificationResp = await notificationClient.callAsInternalUser( - // @ts-ignore - 'notification.send', - { - body: reqBody, - } - ); - - /** - * notification plugin response example: - * { - "refTag": "jeWuU3UBp8p83fn6xwzB", - "recipients": [ - { - "recipient": "opensearch@amazon.com", - "statusCode": 200, - "statusText": "Success" - }, - { - "recipient": "wrong.opensearch@amazon.com", - "statusCode": 503, - "statusText": "sendEmail Error, SES status:400:Optional[Bad Request]" - } - ] - } - */ - logger.info( - `notification plugin response: ${JSON.stringify(notificationResp)}` - ); - - notificationResp.recipients.map((recipient: any) => { - if (recipient.statusCode !== 200) { - throw new Error( - `Fail to deliver report ${JSON.stringify( - notificationResp.recipients - )}` - ); - } - }); - } - - // update report state - // TODO: temporarily disable the following, will add back - // await updateReportState(reportId, opensearchReportsClient, REPORT_STATE.shared); -};