Skip to content

Commit

Permalink
[Security Solutions] Removes tech debt of exporting all from linter r…
Browse files Browse the repository at this point in the history
…ule for cases plugin in the server section (#120411) (#120564)

## Summary

See: #110903, #120234

This removes all the top level API `export *` spots from:
* `cases` plugin within the server section

This reduces the number of metrics and warning about undocumented functions.

In the file `cases/server/index.ts` I now put the advice of:

```
// Careful of exporting anything from this file as any file(s) you export here will cause your functions to be exposed as public.
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here.
// When you do have to add things here you might want to consider creating a package such to share with other plugins instead as packages
// are easier to break down.
// See: https://docs.elastic.dev/kibana-dev-docs/key-concepts/platform-intro#public-plugin-api
```

# Conflicts:
#	x-pack/plugins/cases/server/client/alerts/get.ts
#	x-pack/plugins/cases/server/client/cases/update.ts
#	x-pack/plugins/cases/server/client/metrics/get_case_metrics.ts
#	x-pack/plugins/cases/server/client/sub_cases/client.ts
#	x-pack/plugins/cases/server/routes/api/utils.test.ts
#	x-pack/plugins/cases/server/routes/api/utils.ts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
FrankHassanabad and kibanamachine authored Dec 7, 2021
1 parent a07e827 commit 27f1a43
Show file tree
Hide file tree
Showing 48 changed files with 90 additions and 70 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/authorization/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PluginStartContract as FeaturesPluginStart } from '../../../features/se
import { AuthFilterHelpers, GetSpaceFn, OwnerEntity } from './types';
import { getOwnersFilter } from './utils';
import { AuthorizationAuditLogger, OperationDetails } from '.';
import { createCaseError } from '../common';
import { createCaseError } from '../common/error';

/**
* This class handles ensuring that the user making a request has the correct permissions
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/alerts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { CaseStatuses } from '../../../common/api';
import { AlertInfo } from '../../common';
import { AlertInfo } from '../../common/types';

interface Alert {
id: string;
Expand Down
9 changes: 3 additions & 6 deletions x-pack/plugins/cases/server/client/attachments/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ import {
} from '../../services/user_actions/helpers';

import { AttachmentService, CasesService, CaseUserActionService } from '../../services';
import {
createCaseError,
CommentableCase,
createAlertUpdateRequest,
isCommentRequestTypeGenAlert,
} from '../../common';
import { CommentableCase } from '../../common/models';
import { createCaseError } from '../../common/error';
import { createAlertUpdateRequest, isCommentRequestTypeGenAlert } from '../../common/utils';
import { CasesClientArgs, CasesClientInternal } from '..';

import { decodeCommentRequest } from '../utils';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/client/attachments/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
} from '../../../common/constants';
import { CasesClientArgs } from '../types';
import { buildCommentUserActionItem } from '../../services/user_actions/helpers';
import { createCaseError, checkEnabledCaseConnectorOrThrow } from '../../common';
import { createCaseError } from '../../common/error';
import { checkEnabledCaseConnectorOrThrow } from '../../common/utils';
import { Operations } from '../../authorization';

/**
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/server/client/attachments/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {
} from '../../../common/api';
import { ENABLE_CASE_CONNECTOR } from '../../../common/constants';
import {
createCaseError,
checkEnabledCaseConnectorOrThrow,
defaultSortField,
transformComments,
flattenCommentSavedObject,
flattenCommentSavedObjects,
getIDsAndIndicesAsArrays,
} from '../../common';
} from '../../common/utils';
import { createCaseError } from '../../common/error';
import { defaultPage, defaultPerPage } from '../../routes/api';
import { CasesClientArgs } from '../types';
import { combineFilters, stringToKueryNode } from '../utils';
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/cases/server/client/attachments/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import Boom from '@hapi/boom';

import { SavedObjectsClientContract, Logger } from 'kibana/server';
import { LensServerPluginSetup } from '../../../../lens/server';
import { checkEnabledCaseConnectorOrThrow, CommentableCase, createCaseError } from '../../common';
import { CommentableCase } from '../../common/models';
import { createCaseError } from '../../common/error';
import { checkEnabledCaseConnectorOrThrow } from '../../common/utils';
import { buildCommentUserActionItem } from '../../services/user_actions/helpers';
import { CaseResponse, CommentPatchRequest, CommentRequest } from '../../../common/api';
import { CASE_SAVED_OBJECT, SUB_CASE_SAVED_OBJECT } from '../../../common/constants';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/client/cases/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { ENABLE_CASE_CONNECTOR, MAX_TITLE_LENGTH } from '../../../common/constan
import { buildCaseUserActionItem } from '../../services/user_actions/helpers';

import { Operations } from '../../authorization';
import { createCaseError, flattenCaseSavedObject, transformNewCase } from '../../common';
import { createCaseError } from '../../common/error';
import { flattenCaseSavedObject, transformNewCase } from '../../common/utils';
import { CasesClientArgs } from '..';

/**
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/cases/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SavedObject, SavedObjectsClientContract, SavedObjectsFindResponse } fro
import { CommentAttributes, SubCaseAttributes, OWNER_FIELD } from '../../../common/api';
import { ENABLE_CASE_CONNECTOR, MAX_CONCURRENT_SEARCHES } from '../../../common/constants';
import { CasesClientArgs } from '..';
import { createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { AttachmentService, CasesService } from '../../services';
import { buildCaseUserActionItem } from '../../services/user_actions/helpers';
import { Operations, OwnerEntity } from '../../authorization';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/client/cases/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
excess,
} from '../../../common/api';

import { createCaseError, transformCases } from '../../common';
import { createCaseError } from '../../common/error';
import { transformCases } from '../../common/utils';
import { constructQueryOptions } from '../utils';
import { includeFieldsRequiredForAuthentication } from '../../authorization/utils';
import { Operations } from '../../authorization';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/client/cases/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
CaseAttributes,
} from '../../../common/api';
import { ENABLE_CASE_CONNECTOR } from '../../../common/constants';
import { countAlertsForID, createCaseError, flattenCaseSavedObject } from '../../common';
import { createCaseError } from '../../common/error';
import { countAlertsForID, flattenCaseSavedObject } from '../../common/utils';
import { CasesClientArgs } from '..';
import { Operations } from '../../authorization';
import { combineAuthorizedAndOwnerFilter } from '../utils';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/client/cases/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { ENABLE_CASE_CONNECTOR } from '../../../common/constants';
import { buildCaseUserActionItem } from '../../services/user_actions/helpers';

import { createIncident, getCommentContextFromAttributes } from './utils';
import { createCaseError, flattenCaseSavedObject, getAlertInfoFromComments } from '../../common';
import { createCaseError } from '../../common/error';
import { flattenCaseSavedObject, getAlertInfoFromComments } from '../../common/utils';
import { CasesClient, CasesClientArgs, CasesClientInternal } from '..';
import { Operations } from '../../authorization';
import { casesConnectors } from '../../connectors';
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/cases/server/client/cases/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ import {
} from '../../../common/constants';
import { buildCaseUserActions } from '../../services/user_actions/helpers';
import { getCaseToUpdate } from '../utils';

import { createCaseError } from '../../common/error';
import { CasesService } from '../../services';
import {
createAlertUpdateRequest,
createCaseError,
flattenCaseSavedObject,
isCommentRequestTypeAlertOrGenAlert,
} from '../../common';
} from '../../common/utils';
import { UpdateAlertRequest } from '../alerts/types';
import { CasesClientInternal } from '../client_internal';
import { CasesClientArgs } from '..';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/cases/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
transformers,
transformFields,
} from './utils';
import { flattenCaseSavedObject } from '../../common';
import { flattenCaseSavedObject } from '../../common/utils';
import { SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { casesConnectors } from '../../connectors';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/configure/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
throwErrors,
} from '../../../common/api';
import { MAX_CONCURRENT_SEARCHES, SUPPORTED_CONNECTORS } from '../../../common/constants';
import { createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { CasesClientInternal } from '../client_internal';
import { CasesClientArgs } from '../types';
import { getMappings } from './get_mappings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { ConnectorMappingsAttributes } from '../../../common/api';
import { ACTION_SAVED_OBJECT_TYPE } from '../../../../actions/server';
import { createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { CasesClientArgs } from '..';
import { CreateMappingsArgs } from './types';
import { casesConnectors } from '../../connectors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { SavedObjectsFindResponse } from 'kibana/server';
import { ConnectorMappings } from '../../../common/api';
import { ACTION_SAVED_OBJECT_TYPE } from '../../../../actions/server';
import { createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { CasesClientArgs } from '..';
import { MappingsArgs } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { ConnectorMappingsAttributes } from '../../../common/api';
import { ACTION_SAVED_OBJECT_TYPE } from '../../../../actions/server';
import { createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { CasesClientArgs } from '..';
import { UpdateMappingsArgs } from './types';
import { casesConnectors } from '../../connectors';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/stats/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
CasesStatusRequestRt,
} from '../../../common/api';
import { Operations } from '../../authorization';
import { createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { constructQueryOptions } from '../utils';

/**
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/server/client/sub_cases/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ import {
import { CASE_COMMENT_SAVED_OBJECT, SUB_CASE_SAVED_OBJECT } from '../../../common/constants';
import { getCaseToUpdate } from '../utils';
import { buildSubCaseUserActions } from '../../services/user_actions/helpers';
import { createCaseError } from '../../common/error';
import {
createAlertUpdateRequest,
createCaseError,
isCommentRequestTypeAlertOrGenAlert,
flattenSubCaseSavedObject,
} from '../../common';
} from '../../common/utils';
import { UpdateAlertRequest } from '../../client/alerts/types';
import { CasesClientArgs } from '../types';
import { CasesClientInternal } from '../client_internal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { CaseUserActionResponse } from '../../../common/api';
import { SUB_CASE_SAVED_OBJECT } from '../../../common/constants';
import { SUB_CASE_REF_NAME } from '../../common';
import { SUB_CASE_REF_NAME } from '../../common/constants';
import { extractAttributesWithoutSubCases } from './get';

describe('get', () => {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/cases/server/client/user_actions/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
CaseUserActionResponse,
} from '../../../common/api';
import { SUB_CASE_SAVED_OBJECT } from '../../../common/constants';
import { createCaseError, checkEnabledCaseConnectorOrThrow, SUB_CASE_REF_NAME } from '../../common';
import { createCaseError } from '../../common/error';
import { checkEnabledCaseConnectorOrThrow } from '../../common/utils';
import { SUB_CASE_REF_NAME } from '../../common/constants';
import { CasesClientArgs } from '..';
import { Operations } from '../../authorization';
import { UserActionGet } from './client';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { CaseConnector, CaseType, ConnectorTypes } from '../../common/api';
import { newCase } from '../routes/api/__mocks__/request_responses';
import { transformNewCase } from '../common';
import { transformNewCase } from '../common/utils';
import { sortToSnake } from './utils';

describe('utils', () => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/server/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
isCommentRequestTypeAlertOrGenAlert,
isCommentRequestTypeUser,
isCommentRequestTypeActions,
SavedObjectFindOptionsKueryNode,
} from '../common';
} from '../common/utils';
import { SavedObjectFindOptionsKueryNode } from '../common/types';

export const decodeCommentRequest = (comment: CommentRequest) => {
if (isCommentRequestTypeUser(comment)) {
Expand Down
13 changes: 6 additions & 7 deletions x-pack/plugins/cases/server/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* 2.0.
*/

// TODO: https://github.com/elastic/kibana/issues/110896
/* eslint-disable @kbn/eslint/no_export_all */
// Careful of exporting anything from this file as any file(s) you export here will cause your functions to be exposed as public.
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here.

export * from './models';
export * from './utils';
export * from './types';
export * from './error';
export * from './constants';
// When you do have to add things here you might want to consider creating a package such to share with other plugins instead as packages
// are easier to break down.
// See: https://docs.elastic.dev/kibana-dev-docs/key-concepts/platform-intro#public-plugin-api
10 changes: 7 additions & 3 deletions x-pack/plugins/cases/server/common/models/commentable_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ import {
MAX_DOCS_PER_PAGE,
SUB_CASE_SAVED_OBJECT,
} from '../../../common/constants';
import { flattenCommentSavedObjects, flattenSubCaseSavedObject, transformNewComment } from '..';
import { AttachmentService, CasesService } from '../../services';
import { createCaseError } from '../error';
import { countAlertsForID } from '../index';
import { getOrUpdateLensReferences } from '../utils';
import {
countAlertsForID,
flattenCommentSavedObjects,
flattenSubCaseSavedObject,
transformNewComment,
getOrUpdateLensReferences,
} from '../utils';

interface UpdateCommentResp {
comment: SavedObjectsUpdateResponse<CommentAttributes>;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SavedObjectReference,
} from 'kibana/server';
import { flatMap, uniqWith, isEmpty, xorWith } from 'lodash';
import { AlertInfo } from '.';
import { AlertInfo } from './types';
import { LensServerPluginSetup } from '../../../lens/server';

import {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/connectors/case/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import * as i18n from './translations';

import { GetActionTypeParams, isCommentGeneratedAlert, separator } from '..';
import { createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { CasesClient } from '../../client';

const supportedSubActions: string[] = ['create', 'update', 'addComment'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { AuthenticatedUser } from '../../../../../security/server';
import { securityMock } from '../../../../../security/server/mocks';
import { nullUser } from '../../../common';
import { nullUser } from '../../../common/utils';

function createAuthenticationMock({
currentUser,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/routes/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Boom, boomify, isBoom } from '@hapi/boom';

import { schema } from '@kbn/config-schema';
import { CustomHttpResponseOptions, ResponseError } from 'kibana/server';
import { isCaseError } from '../../common';
import { isCaseError } from '../../common/error';

/**
* Transforms an error into the correct format for a kibana response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
MAX_DOCS_PER_PAGE,
SAVED_OBJECT_TYPES,
} from '../../../common/constants';
import { createCaseError, defaultSortField } from '../../common';
import { defaultSortField } from '../../common/utils';
import { createCaseError } from '../../common/error';
import { ESCaseAttributes } from '../../services/cases/types';

export async function handleExport({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
noneConnectorId,
} from '../../../common/api';
import { CASE_SAVED_OBJECT } from '../../../common/constants';
import { getNoneCaseConnector } from '../../common';
import { getNoneCaseConnector } from '../../common/utils';
import { createExternalService, ESCaseConnectorWithId } from '../../services/test_utils';
import { caseConnectorIdMigration } from './cases';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
transformConnectorIdToReference,
transformPushConnectorIdToReference,
} from '../../services/user_actions/transform';
import { CONNECTOR_ID_REFERENCE_NAME, PUSH_CONNECTOR_ID_REFERENCE_NAME } from '../../common';
import {
CONNECTOR_ID_REFERENCE_NAME,
PUSH_CONNECTOR_ID_REFERENCE_NAME,
} from '../../common/constants';

interface UnsanitizedCaseConnector {
connector_id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { SavedObjectSanitizedDoc } from 'kibana/server';
import { ACTION_SAVED_OBJECT_TYPE } from '../../../../actions/server';
import { ConnectorTypes } from '../../../common/api';
import { CASE_CONFIGURE_SAVED_OBJECT, SECURITY_SOLUTION_OWNER } from '../../../common/constants';
import { getNoneCaseConnector, CONNECTOR_ID_REFERENCE_NAME } from '../../common';
import { CONNECTOR_ID_REFERENCE_NAME } from '../../common/constants';
import { getNoneCaseConnector } from '../../common/utils';
import { ESCaseConnectorWithId } from '../../services/test_utils';
import { ESCasesConfigureAttributes } from '../../services/configure/types';
import { configureConnectorIdMigration } from './configuration';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { ConnectorTypes } from '../../../common/api';
import { addOwnerToSO, SanitizedCaseOwner } from '.';
import { transformConnectorIdToReference } from '../../services/user_actions/transform';
import { CONNECTOR_ID_REFERENCE_NAME } from '../../common';
import { CONNECTOR_ID_REFERENCE_NAME } from '../../common/constants';

interface UnsanitizedConfigureConnector {
connector_id: string;
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/services/alerts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import type { PublicMethodsOf } from '@kbn/utility-types';
import { ElasticsearchClient, Logger } from 'kibana/server';
import { CaseStatuses } from '../../../common/api';
import { MAX_ALERTS_PER_SUB_CASE, MAX_CONCURRENT_SEARCHES } from '../../../common/constants';
import { AlertInfo, createCaseError } from '../../common';
import { createCaseError } from '../../common/error';
import { AlertInfo } from '../../common/types';
import { UpdateAlertRequest } from '../../client/alerts/types';
import {
ALERT_WORKFLOW_STATUS,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/services/cases/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
} from 'kibana/server';
import { ACTION_SAVED_OBJECT_TYPE } from '../../../../actions/server';
import { loggerMock } from '@kbn/logging/mocks';
import { getNoneCaseConnector, CONNECTOR_ID_REFERENCE_NAME } from '../../common';
import { CONNECTOR_ID_REFERENCE_NAME } from '../../common/constants';
import { getNoneCaseConnector } from '../../common/utils';
import { CasesService } from '.';
import {
createESJiraConnector,
Expand Down
Loading

0 comments on commit 27f1a43

Please sign in to comment.