Skip to content

Commit

Permalink
Support new notebooks URL (opensearch-project#94) (opensearch-project#99
Browse files Browse the repository at this point in the history
)

Signed-off-by: Joshua Li <joshuali925@gmail.com>
(cherry picked from commit 047eb96f528e05ad3dc792174c6b04cd1794dd41)

Co-authored-by: Joshua Li <joshuali925@gmail.com>
  • Loading branch information
opensearch-trigger-bot[bot] and joshuali925 authored Apr 19, 2023
1 parent 4713e2e commit 418d742
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
35 changes: 35 additions & 0 deletions server/utils/__tests__/validationHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = {
},
}

const createReportDefinitionNotebookPostNavBarInput: ReportDefinitionSchemaType = {
report_params: {
report_name: 'test notebooks report',
report_source: REPORT_TYPE.notebook,
description: 'Hi this is your Notebook on demand',
core_params: {
base_url: `/app/observability-notebooks#/${SAMPLE_SAVED_OBJECT_ID}`,
window_width: 1300,
window_height: 900,
report_format: FORMAT.pdf,
time_duration: 'PT5M',
origin: 'http://localhost:5601',
},
},
delivery: {
configIds: [],
title: 'title',
textDescription: 'text description',
htmlDescription: 'html description'
},
trigger: {
trigger_type: TRIGGER_TYPE.onDemand,
},
}

describe('test input validation', () => {
test('create report with correct saved object id', async () => {
const savedObjectIds = [`dashboard:${SAMPLE_SAVED_OBJECT_ID}`];
Expand Down Expand Up @@ -143,6 +168,16 @@ describe('test input validation', () => {
expect(report).toBeDefined();
});

test('create notebook report definition with notebook base url format', async () => {
const savedObjectIds = [`notebook:${SAMPLE_SAVED_OBJECT_ID}`];
const client = mockOpenSearchClient(savedObjectIds);
const report = await validateReportDefinition(
client,
createReportDefinitionNotebookPostNavBarInput
);
expect(report).toBeDefined();
});

test('create report definition with non-exist saved object id', async () => {
const savedObjectIds = ['dashboard:fake-id'];
const client = mockOpenSearchClient(savedObjectIds);
Expand Down
6 changes: 3 additions & 3 deletions server/utils/validationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const isValidRelativeUrl = (relativeUrl: string) => {
) {
normalizedRelativeUrl = path.posix.normalize(relativeUrl);
}

// check pattern
// ODFE pattern: /app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g
// AES pattern: /_plugin/kibana/app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g
Expand All @@ -37,7 +37,7 @@ export const isValidRelativeUrl = (relativeUrl: string) => {
export const regexDuration = /^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
export const regexEmailAddress = /\S+@\S+\.\S+/;
export const regexReportName = /^[\w\-\s\(\)\[\]\,\_\-+]+$/;
export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|observability-dashboards|notebooks-dashboards\?view=output_only(&security_tenant=.+)?)(\?security_tenant=.+)?#\/(notebooks\/|view\/|edit\/)?[^\/]+$/;
export const regexRelativeUrl = /^\/(_plugin\/kibana\/|_dashboards\/)?app\/(dashboards|visualize|discover|observability-dashboards|observability-notebooks|notebooks-dashboards\?view=output_only(&security_tenant=.+)?)(\?security_tenant=.+)?#\/(notebooks\/|view\/|edit\/)?[^\/]+$/;

export const validateReport = async (
client: ILegacyScopedClusterClient,
Expand Down Expand Up @@ -122,7 +122,7 @@ const validateSavedObject = async (
index: '.kibana',
id: savedObjectId,
};
exist = await client.callAsCurrentUser('exists', params);
exist = await client.callAsCurrentUser('exists', params);
}
if (!exist) {
throw Error(`saved object with id ${savedObjectId} does not exist`);
Expand Down

0 comments on commit 418d742

Please sign in to comment.