From d4d8fe2c0cd274960ddaf97c2747d85f2a4f1f9a Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 7 Feb 2022 17:48:58 +0200 Subject: [PATCH] Move kibana version to route deps --- x-pack/plugins/cases/server/client/client.ts | 9 --------- x-pack/plugins/cases/server/client/factory.ts | 3 --- x-pack/plugins/cases/server/client/mocks.ts | 1 - x-pack/plugins/cases/server/client/types.ts | 3 +-- x-pack/plugins/cases/server/plugin.ts | 2 +- x-pack/plugins/cases/server/routes/api/cases/get_case.ts | 7 ++----- .../cases/server/routes/api/comments/get_all_comment.ts | 4 ++-- x-pack/plugins/cases/server/routes/api/types.ts | 3 ++- .../routes/api/user_actions/get_all_user_actions.ts | 4 ++-- x-pack/test/cases_api_integration/common/lib/utils.ts | 4 ++-- 10 files changed, 12 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/cases/server/client/client.ts b/x-pack/plugins/cases/server/client/client.ts index 8b351be229379..266c988212cdf 100644 --- a/x-pack/plugins/cases/server/client/client.ts +++ b/x-pack/plugins/cases/server/client/client.ts @@ -17,7 +17,6 @@ import { createMetricsSubClient, MetricsSubClient } from './metrics/client'; * Client wrapper that contains accessor methods for individual entities within the cases system. */ export class CasesClient { - private readonly _kibanaVersion: CasesClientArgs['kibanaVersion']; private readonly _casesClientInternal: CasesClientInternal; private readonly _cases: CasesSubClient; private readonly _attachments: AttachmentsSubClient; @@ -26,7 +25,6 @@ export class CasesClient { private readonly _metrics: MetricsSubClient; constructor(args: CasesClientArgs) { - this._kibanaVersion = args.kibanaVersion; this._casesClientInternal = createCasesClientInternal(args); this._cases = createCasesSubClient(args, this, this._casesClientInternal); this._attachments = createAttachmentsSubClient(args, this, this._casesClientInternal); @@ -35,13 +33,6 @@ export class CasesClient { this._metrics = createMetricsSubClient(args, this); } - /** - * Retrieves the current kibana version - */ - public get kibanaVersion() { - return this._kibanaVersion; - } - /** * Retrieves an interface for interacting with cases entities. */ diff --git a/x-pack/plugins/cases/server/client/factory.ts b/x-pack/plugins/cases/server/client/factory.ts index b3d711949dfb9..3cbcee62d8c09 100644 --- a/x-pack/plugins/cases/server/client/factory.ts +++ b/x-pack/plugins/cases/server/client/factory.ts @@ -10,7 +10,6 @@ import { SavedObjectsServiceStart, Logger, ElasticsearchClient, - PluginInitializerContext, } from 'kibana/server'; import { SecurityPluginSetup, SecurityPluginStart } from '../../../security/server'; import { SAVED_OBJECT_TYPES } from '../../common/constants'; @@ -32,7 +31,6 @@ import { AuthorizationAuditLogger } from '../authorization'; import { CasesClient, createCasesClient } from '.'; interface CasesClientFactoryArgs { - kibanaVersion: PluginInitializerContext['env']['packageInfo']['version']; securityPluginSetup?: SecurityPluginSetup; securityPluginStart?: SecurityPluginStart; getSpace: GetSpaceFn; @@ -123,7 +121,6 @@ export class CasesClientFactory { lensEmbeddableFactory: this.options.lensEmbeddableFactory, authorization: auth, actionsClient: await this.options.actionsPluginStart.getActionsClientWithRequest(request), - kibanaVersion: this.options.kibanaVersion, }); } } diff --git a/x-pack/plugins/cases/server/client/mocks.ts b/x-pack/plugins/cases/server/client/mocks.ts index 0a9119fdff227..ecedc7cb05071 100644 --- a/x-pack/plugins/cases/server/client/mocks.ts +++ b/x-pack/plugins/cases/server/client/mocks.ts @@ -83,7 +83,6 @@ export interface CasesClientMock extends CasesClient { export const createCasesClientMock = (): CasesClientMock => { const client: PublicContract = { - kibanaVersion: '8.2.0', cases: createCasesSubClientMock(), attachments: createAttachmentsSubClientMock(), userActions: createUserActionsSubClientMock(), diff --git a/x-pack/plugins/cases/server/client/types.ts b/x-pack/plugins/cases/server/client/types.ts index 5412ccde57134..e3d7b8a541b9d 100644 --- a/x-pack/plugins/cases/server/client/types.ts +++ b/x-pack/plugins/cases/server/client/types.ts @@ -6,7 +6,7 @@ */ import type { PublicMethodsOf } from '@kbn/utility-types'; -import { SavedObjectsClientContract, Logger, PluginInitializerContext } from 'kibana/server'; +import { SavedObjectsClientContract, Logger } from 'kibana/server'; import { User } from '../../common/api'; import { Authorization } from '../authorization/authorization'; import { @@ -24,7 +24,6 @@ import { LensServerPluginSetup } from '../../../lens/server'; * Parameters for initializing a cases client */ export interface CasesClientArgs { - readonly kibanaVersion: PluginInitializerContext['env']['packageInfo']['version']; readonly caseConfigureService: CaseConfigureService; readonly caseService: CasesService; readonly connectorMappingsService: ConnectorMappingsService; diff --git a/x-pack/plugins/cases/server/plugin.ts b/x-pack/plugins/cases/server/plugin.ts index 2bf9c876e6f9c..5881b7b7633be 100644 --- a/x-pack/plugins/cases/server/plugin.ts +++ b/x-pack/plugins/cases/server/plugin.ts @@ -103,6 +103,7 @@ export class CasePlugin { initCaseApi({ logger: this.log, router, + kibanaVersion: this.kibanaVersion, }); } @@ -123,7 +124,6 @@ export class CasePlugin { */ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion lensEmbeddableFactory: this.lensEmbeddableFactory!, - kibanaVersion: this.kibanaVersion, }); const client = core.elasticsearch.client; diff --git a/x-pack/plugins/cases/server/routes/api/cases/get_case.ts b/x-pack/plugins/cases/server/routes/api/cases/get_case.ts index 2b87636a491f6..5e45b30f626f7 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/get_case.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/get_case.ts @@ -11,7 +11,7 @@ import { RouteDeps } from '../types'; import { getWarningHeader, wrapError } from '../utils'; import { CASE_DETAILS_URL } from '../../../../common/constants'; -export function initGetCaseApi({ router, logger }: RouteDeps) { +export function initGetCaseApi({ router, logger, kibanaVersion }: RouteDeps) { router.get( { path: CASE_DETAILS_URL, @@ -34,10 +34,7 @@ export function initGetCaseApi({ router, logger }: RouteDeps) { return response.ok({ headers: { - ...getWarningHeader( - casesClient.kibanaVersion, - 'Deprecated query parameter includeComments' - ), + ...getWarningHeader(kibanaVersion, 'Deprecated query parameter includeComments'), }, body: await casesClient.cases.get({ id, diff --git a/x-pack/plugins/cases/server/routes/api/comments/get_all_comment.ts b/x-pack/plugins/cases/server/routes/api/comments/get_all_comment.ts index d154c400345e8..9b311013ca2fa 100644 --- a/x-pack/plugins/cases/server/routes/api/comments/get_all_comment.ts +++ b/x-pack/plugins/cases/server/routes/api/comments/get_all_comment.ts @@ -14,7 +14,7 @@ import { CASE_COMMENTS_URL } from '../../../../common/constants'; /** * @deprecated since version 8.1.0 */ -export function initGetAllCommentsApi({ router, logger }: RouteDeps) { +export function initGetAllCommentsApi({ router, logger, kibanaVersion }: RouteDeps) { router.get( { path: CASE_COMMENTS_URL, @@ -30,7 +30,7 @@ export function initGetAllCommentsApi({ router, logger }: RouteDeps) { return response.ok({ headers: { - ...getWarningHeader(client.kibanaVersion), + ...getWarningHeader(kibanaVersion), }, body: await client.attachments.getAll({ caseID: request.params.case_id, diff --git a/x-pack/plugins/cases/server/routes/api/types.ts b/x-pack/plugins/cases/server/routes/api/types.ts index 9211aee5606a6..e3aa6e0e970fa 100644 --- a/x-pack/plugins/cases/server/routes/api/types.ts +++ b/x-pack/plugins/cases/server/routes/api/types.ts @@ -5,13 +5,14 @@ * 2.0. */ -import type { Logger } from 'kibana/server'; +import type { Logger, PluginInitializerContext } from 'kibana/server'; import type { CasesRouter } from '../../types'; export interface RouteDeps { router: CasesRouter; logger: Logger; + kibanaVersion: PluginInitializerContext['env']['packageInfo']['version']; } export interface TotalCommentByCase { diff --git a/x-pack/plugins/cases/server/routes/api/user_actions/get_all_user_actions.ts b/x-pack/plugins/cases/server/routes/api/user_actions/get_all_user_actions.ts index 655d65430ddb9..113596e560ab1 100644 --- a/x-pack/plugins/cases/server/routes/api/user_actions/get_all_user_actions.ts +++ b/x-pack/plugins/cases/server/routes/api/user_actions/get_all_user_actions.ts @@ -14,7 +14,7 @@ import { CASE_USER_ACTIONS_URL } from '../../../../common/constants'; /** * @deprecated since version 8.1.0 */ -export function initGetAllCaseUserActionsApi({ router, logger }: RouteDeps) { +export function initGetAllCaseUserActionsApi({ router, logger, kibanaVersion }: RouteDeps) { router.get( { path: CASE_USER_ACTIONS_URL, @@ -35,7 +35,7 @@ export function initGetAllCaseUserActionsApi({ router, logger }: RouteDeps) { return response.ok({ headers: { - ...getWarningHeader(casesClient.kibanaVersion), + ...getWarningHeader(kibanaVersion), }, body: await casesClient.userActions.getAll({ caseId }), }); diff --git a/x-pack/test/cases_api_integration/common/lib/utils.ts b/x-pack/test/cases_api_integration/common/lib/utils.ts index cda5d6dcbeaa1..10ccac3c12139 100644 --- a/x-pack/test/cases_api_integration/common/lib/utils.ts +++ b/x-pack/test/cases_api_integration/common/lib/utils.ts @@ -1133,9 +1133,9 @@ export const getServiceNowSimulationServer = async (): Promise<{ }; /** + * Extracts the warning value a warning header that is formatted according to RFC 7234. + * For example for the string 299 Kibana-8.1.0 "Deprecation endpoint", the return value is Deprecation endpoint. * - * @param warningHeader - * @returns */ export const extractWarningValueFromWarningHeader = (warningHeader: string) => { const firstQuote = warningHeader.indexOf('"');