-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Reporting] Use spaceId from request in export generation #76998
Changes from all commits
4571497
17d3b1a
7a9fa14
4dc59f5
3ac614a
f5efc5b
77e4ad0
8e31474
db65847
1bab508
545c277
7300e9b
3b2b45c
c28c048
1b0f545
c7b1da7
98e3db0
a5c2171
9a33e8b
068219a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import Hapi from 'hapi'; | ||
import * as Rx from 'rxjs'; | ||
import { first, map, take } from 'rxjs/operators'; | ||
import { | ||
|
@@ -14,24 +15,27 @@ import { | |
SavedObjectsClientContract, | ||
SavedObjectsServiceStart, | ||
UiSettingsServiceStart, | ||
} from 'src/core/server'; | ||
} from '../../../../src/core/server'; | ||
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server'; | ||
import { LicensingPluginSetup } from '../../licensing/server'; | ||
import { SecurityPluginSetup } from '../../security/server'; | ||
import { DEFAULT_SPACE_ID } from '../../spaces/common/constants'; | ||
import { SpacesPluginSetup } from '../../spaces/server'; | ||
import { ReportingConfig } from './'; | ||
import { HeadlessChromiumDriverFactory } from './browsers/chromium/driver_factory'; | ||
import { checkLicense, getExportTypesRegistry } from './lib'; | ||
import { checkLicense, getExportTypesRegistry, LevelLogger } from './lib'; | ||
import { ESQueueInstance } from './lib/create_queue'; | ||
import { screenshotsObservableFactory, ScreenshotsObservableFn } from './lib/screenshots'; | ||
import { ReportingStore } from './lib/store'; | ||
|
||
export interface ReportingInternalSetup { | ||
basePath: Pick<BasePath, 'set'>; | ||
router: IRouter; | ||
features: FeaturesPluginSetup; | ||
elasticsearch: ElasticsearchServiceSetup; | ||
licensing: LicensingPluginSetup; | ||
basePath: BasePath['get']; | ||
router: IRouter; | ||
security?: SecurityPluginSetup; | ||
spaces?: SpacesPluginSetup; | ||
} | ||
|
||
export interface ReportingInternalStart { | ||
|
@@ -50,7 +54,7 @@ export class ReportingCore { | |
private exportTypesRegistry = getExportTypesRegistry(); | ||
private config?: ReportingConfig; | ||
|
||
constructor() {} | ||
constructor(private logger: LevelLogger) {} | ||
|
||
/* | ||
* Register setupDeps | ||
|
@@ -180,14 +184,58 @@ export class ReportingCore { | |
return this.getPluginSetupDeps().elasticsearch; | ||
} | ||
|
||
public async getSavedObjectsClient(fakeRequest: KibanaRequest) { | ||
private async getSavedObjectsClient(request: KibanaRequest) { | ||
const { savedObjects } = await this.getPluginStartDeps(); | ||
return savedObjects.getScopedClient(fakeRequest) as SavedObjectsClientContract; | ||
return savedObjects.getScopedClient(request) as SavedObjectsClientContract; | ||
} | ||
|
||
public async getUiSettingsServiceFactory(savedObjectsClient: SavedObjectsClientContract) { | ||
const { uiSettings: uiSettingsService } = await this.getPluginStartDeps(); | ||
const scopedUiSettingsService = uiSettingsService.asScopedToClient(savedObjectsClient); | ||
return scopedUiSettingsService; | ||
} | ||
|
||
public getSpaceId(request: KibanaRequest): string | undefined { | ||
const spacesService = this.getPluginSetupDeps().spaces?.spacesService; | ||
if (spacesService) { | ||
const spaceId = spacesService?.getSpaceId(request); | ||
|
||
if (spaceId !== DEFAULT_SPACE_ID) { | ||
this.logger.info(`Request uses Space ID: ` + spaceId); | ||
return spaceId; | ||
} else { | ||
this.logger.info(`Request uses default Space`); | ||
} | ||
} | ||
} | ||
|
||
public getFakeRequest(baseRequest: object, spaceId?: string) { | ||
const fakeRequest = KibanaRequest.from({ | ||
path: '/', | ||
route: { settings: {} }, | ||
url: { href: '/' }, | ||
raw: { req: { url: '/' } }, | ||
...baseRequest, | ||
} as Hapi.Request); | ||
|
||
const spacesService = this.getPluginSetupDeps().spaces?.spacesService; | ||
if (spacesService) { | ||
if (spaceId && spaceId !== DEFAULT_SPACE_ID) { | ||
this.logger.info(`Generating request for space: ` + spaceId); | ||
this.getPluginSetupDeps().basePath.set(fakeRequest, `/s/${spaceId}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @jportner Thanks for your help in figuring this part out! Please take a look at how I am using your advice and let me know if you have any thoughts about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed offline -- looks great! |
||
} | ||
} | ||
|
||
return fakeRequest; | ||
} | ||
|
||
public async getUiSettingsClient(request: KibanaRequest) { | ||
const spacesService = this.getPluginSetupDeps().spaces?.spacesService; | ||
const spaceId = this.getSpaceId(request); | ||
if (spacesService && spaceId) { | ||
this.logger.info(`Creating UI Settings Client for space: ${spaceId}`); | ||
} | ||
const savedObjectsClient = await this.getSavedObjectsClient(request); | ||
return await this.getUiSettingsServiceFactory(savedObjectsClient); | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basePath.get
was actually never being called in Reporting. Instead, we've been getting the base path (for full URLs) usingconfig.kbnConfig.get('server', 'basePath')