Skip to content

Commit c931081

Browse files
committed
use the shim
1 parent 79a9288 commit c931081

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed

x-pack/legacy/plugins/reporting/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import {
1717
runValidations,
1818
} from './server/lib';
1919
import { config as reportingConfig } from './config';
20-
import { logConfiguration } from './log_configuration';
2120
import { createBrowserDriverFactory } from './server/browsers';
2221
import { registerReportingUsageCollector } from './server/usage';
2322
import { ReportingConfigOptions, ReportingPluginSpecOptions, ServerFacade } from './types.d';
23+
import { logConfiguration } from './log_configuration';
24+
import { makeServerFacade } from './make_server_facade';
2425

2526
const kbToBase64Length = (kb: number) => {
2627
return Math.floor((kb * 1024 * 8) / 6);
@@ -70,28 +71,28 @@ export const reporting = (kibana: any) => {
7071
},
7172
},
7273

73-
// TODO: Decouple Hapi: Build a server facade object based on the server to
74-
// pass through to the libs. Do not pass server directly
7574
async init(server: ServerFacade) {
75+
const serverFacade = makeServerFacade(server);
76+
7677
const exportTypesRegistry = getExportTypesRegistry();
7778

7879
let isCollectorReady = false;
7980
// Register a function with server to manage the collection of usage stats
80-
const { usageCollection } = server.newPlatform.setup.plugins;
81+
const { usageCollection } = serverFacade.newPlatform.setup.plugins;
8182
registerReportingUsageCollector(
8283
usageCollection,
83-
server,
84+
serverFacade,
8485
() => isCollectorReady,
8586
exportTypesRegistry
8687
);
8788

88-
const logger = LevelLogger.createForServer(server, [PLUGIN_ID]);
89-
const browserDriverFactory = await createBrowserDriverFactory(server);
89+
const logger = LevelLogger.createForServer(serverFacade, [PLUGIN_ID]);
90+
const browserDriverFactory = await createBrowserDriverFactory(serverFacade);
9091

91-
logConfiguration(server, logger);
92-
runValidations(server, logger, browserDriverFactory);
92+
logConfiguration(serverFacade, logger);
93+
runValidations(serverFacade, logger, browserDriverFactory);
9394

94-
const { xpack_main: xpackMainPlugin } = server.plugins;
95+
const { xpack_main: xpackMainPlugin } = serverFacade.plugins;
9596
mirrorPluginStatus(xpackMainPlugin, this);
9697
const checkLicense = checkLicenseFactory(exportTypesRegistry);
9798
(xpackMainPlugin as any).status.once('green', () => {
@@ -104,7 +105,7 @@ export const reporting = (kibana: any) => {
104105
isCollectorReady = true;
105106

106107
// Reporting routes
107-
registerRoutes(server, exportTypesRegistry, browserDriverFactory, logger);
108+
registerRoutes(serverFacade, exportTypesRegistry, browserDriverFactory, logger);
108109
},
109110

110111
deprecations({ unused }: any) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { ServerFacade } from './types';
8+
9+
export function makeServerFacade(server: ServerFacade): ServerFacade {
10+
return {
11+
config: server.config,
12+
info: server.info,
13+
route: server.route.bind(server),
14+
newPlatform: server.newPlatform,
15+
plugins: {
16+
elasticsearch: server.plugins.elasticsearch,
17+
xpack_main: server.plugins.xpack_main,
18+
security: server.plugins.security,
19+
},
20+
savedObjects: server.savedObjects,
21+
uiSettingsServiceFactory: server.uiSettingsServiceFactory,
22+
log: server.log.bind(server),
23+
};
24+
}

x-pack/legacy/plugins/reporting/server/lib/get_user.js renamed to x-pack/legacy/plugins/reporting/server/lib/get_user.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export function getUserFactory(server) {
8-
return async request => {
7+
import { RequestFacade, ServerFacade } from '../../types';
8+
9+
export function getUserFactory(server: ServerFacade) {
10+
return async (request: RequestFacade) => {
911
if (!server.plugins.security) {
1012
return null;
1113
}

x-pack/legacy/plugins/reporting/server/lib/level_logger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
type ServerLog = (tags: string[], msg: string) => void;
7+
import { ServerFacade } from '../../types';
88

99
const trimStr = (toTrim: string) => {
1010
return typeof toTrim === 'string' ? toTrim.trim() : toTrim;
@@ -16,12 +16,12 @@ export class LevelLogger {
1616

1717
public warn: (msg: string, tags?: string[]) => void;
1818

19-
static createForServer(server: any, tags: string[]) {
20-
const serverLog: ServerLog = (tgs: string[], msg: string) => server.log(tgs, msg);
19+
static createForServer(server: ServerFacade, tags: string[]) {
20+
const serverLog: ServerFacade['log'] = (tgs: string[], msg: string) => server.log(tgs, msg);
2121
return new LevelLogger(serverLog, tags);
2222
}
2323

24-
constructor(logger: ServerLog, tags: string[]) {
24+
constructor(logger: ServerFacade['log'], tags: string[]) {
2525
this._logger = logger;
2626
this._tags = tags;
2727

x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const authorizedUserPreRoutingFactory = function authorizedUserPreRouting
1414
const config = server.config();
1515

1616
return async function authorizedUserPreRouting(request) {
17+
console.log('how are you');
1718
const xpackInfo = server.plugins.xpack_main.info;
1819

1920
if (!xpackInfo || !xpackInfo.isAvailable()) {

x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { RequestFacade } from '../../../types';
99
export function makeRequestFacade(request: RequestFacade): RequestFacade {
1010
return {
1111
headers: request.headers,
12+
auth: request.auth, // for getUser
1213
params: request.params,
1314
payload: request.payload,
1415
query: request.query,

x-pack/legacy/plugins/reporting/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface ServerFacade {
8080
newPlatform: Legacy.Server['newPlatform'];
8181
plugins: {
8282
elasticsearch: LegacyPlugins['elasticsearch'];
83+
security: LegacyPlugins['security'];
8384
xpack_main: XPackMainPlugin & {
8485
status?: any;
8586
};
@@ -101,6 +102,7 @@ export type EnqueueJobFn = <JobParamsType>(
101102
export interface RequestFacade {
102103
getBasePath: Legacy.Request['getBasePath'];
103104
getSavedObjectsClient: Legacy.Request['getSavedObjectsClient'];
105+
auth: Legacy.Request['auth'];
104106
headers: Legacy.Request['headers'];
105107
params: Legacy.Request['params'];
106108
payload: JobParamPostPayload | GenerateExportTypePayload;

0 commit comments

Comments
 (0)