Skip to content

Commit

Permalink
[Cases] Integrating file service and registering file kinds (#152031)
Browse files Browse the repository at this point in the history
This PR registers three file kinds for cases. One for each instance of
cases (stack, observability, and security). Each solution needs separate
http tags for the routes that are generated by the file service to
implement RBAC.

I refactored the logic to remove some duplication across the three
plugins since we're essentially registering the same http tags with
slightly different names.

This PR shouldn't affect any of the current functionality.

Notable changes:
- I split up the constants.ts file, really the only change is adding the
file kinds logic to generate the http tags the rest is copy/paste
- Refactored the logic to generate the `api` http tags for each plugin
- Registered the three file kinds

Issues: #151780
#151933

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
jonathan-buttner and kibanamachine authored Mar 2, 2023
1 parent 54b2a4a commit 7d81cf2
Show file tree
Hide file tree
Showing 29 changed files with 1,115 additions and 115 deletions.
31 changes: 31 additions & 0 deletions x-pack/plugins/cases/common/constants/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 { CASE_VIEW_PAGE_TABS } from '../types';

/**
* Application
*/

export const APP_ID = 'cases' as const;
export const FEATURE_ID = 'generalCases' as const;
export const APP_OWNER = 'cases' as const;
export const APP_PATH = '/app/management/insightsAndAlerting/cases' as const;
export const CASES_CREATE_PATH = '/create' as const;
export const CASES_CONFIGURE_PATH = '/configure' as const;
export const CASE_VIEW_PATH = '/:detailName' as const;
export const CASE_VIEW_COMMENT_PATH = `${CASE_VIEW_PATH}/:commentId` as const;
export const CASE_VIEW_ALERT_TABLE_PATH =
`${CASE_VIEW_PATH}/?tabId=${CASE_VIEW_PAGE_TABS.ALERTS}` as const;
export const CASE_VIEW_TAB_PATH = `${CASE_VIEW_PATH}/?tabId=:tabId` as const;

/**
* The main Cases application is in the stack management under the
* Alerts and Insights section. To do that, Cases registers to the management
* application. This constant holds the application ID of the management plugin
*/
export const STACK_APP_ID = 'management' as const;
14 changes: 14 additions & 0 deletions x-pack/plugins/cases/common/constants/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 type { HttpApiTagOperation, Owner } from './types';

export const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 MiB

export const constructFilesHttpOperationTag = (owner: Owner, operation: HttpApiTagOperation) => {
return `${owner}FilesCases${operation}`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,15 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CASE_VIEW_PAGE_TABS } from './types';
import type { CasesFeaturesAllRequired } from './ui/types';

export const DEFAULT_DATE_FORMAT = 'dateFormat' as const;
export const DEFAULT_DATE_FORMAT_TZ = 'dateFormat:tz' as const;

/**
* Application
*/
import type { CasesFeaturesAllRequired } from '../ui/types';

export const APP_ID = 'cases' as const;
export const FEATURE_ID = 'generalCases' as const;
export const APP_OWNER = 'cases' as const;
export const APP_PATH = '/app/management/insightsAndAlerting/cases' as const;
export const CASES_CREATE_PATH = '/create' as const;
export const CASES_CONFIGURE_PATH = '/configure' as const;
export const CASE_VIEW_PATH = '/:detailName' as const;
export const CASE_VIEW_COMMENT_PATH = `${CASE_VIEW_PATH}/:commentId` as const;
export const CASE_VIEW_ALERT_TABLE_PATH =
`${CASE_VIEW_PATH}/?tabId=${CASE_VIEW_PAGE_TABS.ALERTS}` as const;
export const CASE_VIEW_TAB_PATH = `${CASE_VIEW_PATH}/?tabId=:tabId` as const;
export * from './owners';
export * from './files';
export * from './application';

/**
* The main Cases application is in the stack management under the
* Alerts and Insights section. To do that, Cases registers to the management
* application. This constant holds the application ID of the management plugin
*/
export const STACK_APP_ID = 'management' as const;
export const DEFAULT_DATE_FORMAT = 'dateFormat' as const;
export const DEFAULT_DATE_FORMAT_TZ = 'dateFormat:tz' as const;

/**
* Saved objects
Expand Down Expand Up @@ -111,37 +92,6 @@ export const CONNECTORS_URL = `${ACTION_URL}/connectors` as const;
*/
export const MAX_ALERTS_PER_CASE = 1000 as const;

/**
* Owner
*/
export const SECURITY_SOLUTION_OWNER = 'securitySolution' as const;
export const OBSERVABILITY_OWNER = 'observability' as const;
export const GENERAL_CASES_OWNER = APP_ID;

export const OWNER_INFO = {
[SECURITY_SOLUTION_OWNER]: {
id: SECURITY_SOLUTION_OWNER,
appId: 'securitySolutionUI',
label: 'Security',
iconType: 'logoSecurity',
appRoute: '/app/security',
},
[OBSERVABILITY_OWNER]: {
id: OBSERVABILITY_OWNER,
appId: 'observability-overview',
label: 'Observability',
iconType: 'logoObservability',
appRoute: '/app/observability',
},
[GENERAL_CASES_OWNER]: {
id: GENERAL_CASES_OWNER,
appId: 'management',
label: 'Stack',
iconType: 'casesApp',
appRoute: '/app/management/insightsAndAlerting',
},
} as const;

/**
* Searching
*/
Expand Down Expand Up @@ -186,6 +136,20 @@ export const UPDATE_CASES_CAPABILITY = 'update_cases' as const;
export const DELETE_CASES_CAPABILITY = 'delete_cases' as const;
export const PUSH_CASES_CAPABILITY = 'push_cases' as const;

/**
* Cases API Tags
*/

/**
* This tag registered for the cases suggest user profiles API
*/
export const SUGGEST_USER_PROFILES_API_TAG = 'casesSuggestUserProfiles';

/**
* This tag is registered for the security bulk get API
*/
export const BULK_GET_USER_PROFILES_API_TAG = 'bulkGetUserProfiles';

/**
* User profiles
*/
Expand Down
110 changes: 110 additions & 0 deletions x-pack/plugins/cases/common/constants/mime_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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.
*/

/**
* These were retrieved from https://www.iana.org/assignments/media-types/media-types.xhtml#image
*/
const imageMimeTypes = [
'image/aces',
'image/apng',
'image/avci',
'image/avcs',
'image/avif',
'image/bmp',
'image/cgm',
'image/dicom-rle',
'image/dpx',
'image/emf',
'image/example',
'image/fits',
'image/g3fax',
'image/heic',
'image/heic-sequence',
'image/heif',
'image/heif-sequence',
'image/hej2k',
'image/hsj2',
'image/jls',
'image/jp2',
'image/jpeg',
'image/jph',
'image/jphc',
'image/jpm',
'image/jpx',
'image/jxr',
'image/jxrA',
'image/jxrS',
'image/jxs',
'image/jxsc',
'image/jxsi',
'image/jxss',
'image/ktx',
'image/ktx2',
'image/naplps',
'image/png',
'image/prs.btif',
'image/prs.pti',
'image/pwg-raster',
'image/svg+xml',
'image/t38',
'image/tiff',
'image/tiff-fx',
'image/vnd.adobe.photoshop',
'image/vnd.airzip.accelerator.azv',
'image/vnd.cns.inf2',
'image/vnd.dece.graphic',
'image/vnd.djvu',
'image/vnd.dwg',
'image/vnd.dxf',
'image/vnd.dvb.subtitle',
'image/vnd.fastbidsheet',
'image/vnd.fpx',
'image/vnd.fst',
'image/vnd.fujixerox.edmics-mmr',
'image/vnd.fujixerox.edmics-rlc',
'image/vnd.globalgraphics.pgb',
'image/vnd.microsoft.icon',
'image/vnd.mix',
'image/vnd.ms-modi',
'image/vnd.mozilla.apng',
'image/vnd.net-fpx',
'image/vnd.pco.b16',
'image/vnd.radiance',
'image/vnd.sealed.png',
'image/vnd.sealedmedia.softseal.gif',
'image/vnd.sealedmedia.softseal.jpg',
'image/vnd.svf',
'image/vnd.tencent.tap',
'image/vnd.valve.source.texture',
'image/vnd.wap.wbmp',
'image/vnd.xiff',
'image/vnd.zbrush.pcx',
'image/webp',
'image/wmf',
];

const textMimeTypes = ['text/plain', 'text/csv', 'text/json', 'application/json'];

const compressionMimeTypes = [
'application/zip',
'application/gzip',
'application/x-bzip',
'application/x-bzip2',
'application/x-7z-compressed',
'application/x-tar',
];

const pdfMimeTypes = ['application/pdf'];

export const ALLOWED_MIME_TYPES = [
...imageMimeTypes,
...textMimeTypes,
...compressionMimeTypes,
...pdfMimeTypes,
];

export const IMAGE_MIME_TYPES = new Set(imageMimeTypes);
50 changes: 50 additions & 0 deletions x-pack/plugins/cases/common/constants/owners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 { APP_ID } from './application';
import type { Owner } from './types';

/**
* Owner
*/
export const SECURITY_SOLUTION_OWNER = 'securitySolution' as const;
export const OBSERVABILITY_OWNER = 'observability' as const;
export const GENERAL_CASES_OWNER = APP_ID;

export const OWNERS = [SECURITY_SOLUTION_OWNER, OBSERVABILITY_OWNER, GENERAL_CASES_OWNER] as const;

interface RouteInfo {
id: Owner;
appId: string;
label: string;
iconType: string;
appRoute: string;
}

export const OWNER_INFO: Record<Owner, RouteInfo> = {
[SECURITY_SOLUTION_OWNER]: {
id: SECURITY_SOLUTION_OWNER,
appId: 'securitySolutionUI',
label: 'Security',
iconType: 'logoSecurity',
appRoute: '/app/security',
},
[OBSERVABILITY_OWNER]: {
id: OBSERVABILITY_OWNER,
appId: 'observability-overview',
label: 'Observability',
iconType: 'logoObservability',
appRoute: '/app/observability',
},
[GENERAL_CASES_OWNER]: {
id: GENERAL_CASES_OWNER,
appId: 'management',
label: 'Stack',
iconType: 'casesApp',
appRoute: '/app/management/insightsAndAlerting',
},
} as const;
16 changes: 16 additions & 0 deletions x-pack/plugins/cases/common/constants/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 type { OWNERS } from './owners';

export enum HttpApiTagOperation {
Read = 'Read',
Create = 'Create',
Delete = 'Delete',
}

export type Owner = typeof OWNERS[number];
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ export { StatusAll } from './ui/types';

export { getCreateConnectorUrl, getAllConnectorsUrl } from './utils/connectors_api';
export { createUICapabilities } from './utils/capabilities';
export { getApiTags } from './utils/api_tags';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d81cf2

Please sign in to comment.