Skip to content

Commit

Permalink
update base path (opensearch-project#112)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhongnan Su <szhongna@amazon.com>
  • Loading branch information
zhongnansu authored Jul 6, 2021
1 parent bf290c3 commit 02d3b1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions dashboards-reports/server/routes/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export enum SELECTOR {
// https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-from-size.html
export const DEFAULT_MAX_SIZE = 10000;

// AES uses 9200, with server.basePath = '/_plugin/kibana'
// Managed service uses 9200, with server.basePath = '/_plugin/kibana'
export const LOCAL_HOST = 'http://localhost:9200';
// AES specific server base path
export const BASE_PATH = '/_plugin/kibana';
// Managed service specific server base path
export const BASE_PATH = '/_dashboards';

export const DEFAULT_REPORT_HEADER = '<h1>OpenSearch Dashboards Reports</h1>';

Expand Down
19 changes: 10 additions & 9 deletions dashboards-reports/server/utils/validationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ import {
import { REPORT_TYPE } from '../../server/routes/utils/constants';

export const isValidRelativeUrl = (relativeUrl: string) => {
let normalizedRelativeUrl = relativeUrl
let normalizedRelativeUrl = relativeUrl;
if (!relativeUrl.includes('notebooks-dashboards')) {
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
// Open Source pattern: /app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g
// Managed Service pattern: /_dashboards/app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g
const isValid = regexRelativeUrl.test(normalizedRelativeUrl);
return isValid;
};
Expand All @@ -52,10 +52,12 @@ export const isValidRelativeUrl = (relativeUrl: string) => {
* moment.js isValid() API fails to validate time duration, so use regex
* https://github.com/moment/moment/issues/1805
**/
export const regexDuration = /^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
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\/app|app)\/(dashboards|visualize|discover|notebooks-dashboards\?view=output_only)(\?security_tenant=.+|)#\/(view\/|edit\/)?[^\/]+$/;
export const regexRelativeUrl =
/^\/(_dashboards\/app|app)\/(dashboards|visualize|discover|notebooks-dashboards\?view=output_only)(\?security_tenant=.+|)#\/(view\/|edit\/)?[^\/]+$/;

export const validateReport = async (
client: ILegacyScopedClusterClient,
Expand Down Expand Up @@ -122,14 +124,13 @@ const validateSavedObject = async (
if (getType(source) === 'notebook') {
// no backend check for notebooks because we would just be checking against the notebooks api again
exist = true;
}
else {
} else {
savedObjectId = `${getType(source)}:${getId(url)}`;
const params: RequestParams.Exists = {
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 02d3b1a

Please sign in to comment.