Skip to content

Commit

Permalink
Move kibana version to route deps
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 7, 2022
1 parent 8e4a776 commit d4d8fe2
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 28 deletions.
9 changes: 0 additions & 9 deletions x-pack/plugins/cases/server/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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.
*/
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/cases/server/client/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -123,7 +121,6 @@ export class CasesClientFactory {
lensEmbeddableFactory: this.options.lensEmbeddableFactory,
authorization: auth,
actionsClient: await this.options.actionsPluginStart.getActionsClientWithRequest(request),
kibanaVersion: this.options.kibanaVersion,
});
}
}
1 change: 0 additions & 1 deletion x-pack/plugins/cases/server/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export interface CasesClientMock extends CasesClient {

export const createCasesClientMock = (): CasesClientMock => {
const client: PublicContract<CasesClient> = {
kibanaVersion: '8.2.0',
cases: createCasesSubClientMock(),
attachments: createAttachmentsSubClientMock(),
userActions: createUserActionsSubClientMock(),
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/cases/server/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class CasePlugin {
initCaseApi({
logger: this.log,
router,
kibanaVersion: this.kibanaVersion,
});
}

Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions x-pack/plugins/cases/server/routes/api/cases/get_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/routes/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }),
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/cases_api_integration/common/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('"');
Expand Down

0 comments on commit d4d8fe2

Please sign in to comment.