Skip to content

Commit

Permalink
Merge remote-tracking branch 'ws/workspace' into workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
gaobinlong committed Aug 2, 2023
2 parents 2281089 + 5337ad7 commit b24d98e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
5 changes: 1 addition & 4 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ export class Server {
opensearch: opensearchStart,
savedObjects: savedObjectsStart,
});
await this.workspaces.start({
savedObjects: savedObjectsStart,
uiSettings: uiSettingsStart,
});
await this.workspaces.start();

this.coreStart = {
capabilities: capabilitiesStart,
Expand Down
39 changes: 7 additions & 32 deletions src/core/server/workspaces/workspaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ import { CoreContext } from '../core_context';
import { InternalHttpServiceSetup } from '../http';
import { Logger } from '../logging';
import { registerRoutes } from './routes';
import {
InternalSavedObjectsServiceSetup,
InternalSavedObjectsServiceStart,
} from '../saved_objects';
import { InternalSavedObjectsServiceSetup } from '../saved_objects';
import { IWorkspaceDBImpl } from './types';
import { WorkspacesClientWithSavedObject } from './workspaces_client';
import { UiSettingsServiceStart } from '../ui_settings/types';
import { WorkspaceSavedObjectsClientWrapper } from './saved_objects';

export interface WorkspacesServiceSetup {
Expand All @@ -33,47 +29,27 @@ export interface WorkspacesSetupDeps {
export type InternalWorkspacesServiceSetup = WorkspacesServiceSetup;
export type InternalWorkspacesServiceStart = WorkspacesServiceStart;

/** @internal */
export interface WorkspacesStartDeps {
savedObjects: InternalSavedObjectsServiceStart;
uiSettings: UiSettingsServiceStart;
}

export class WorkspacesService
implements CoreService<WorkspacesServiceSetup, WorkspacesServiceStart> {
private logger: Logger;
private client?: IWorkspaceDBImpl;
private startDeps?: WorkspacesStartDeps;

constructor(coreContext: CoreContext) {
this.logger = coreContext.logger.get('workspaces-service');
}

private proxyWorkspaceTrafficToRealHandler(setupDeps: WorkspacesSetupDeps) {
/**
* Proxy all {basePath}/w/{workspaceId}{osdPath*} paths to
* {basePath}{osdPath*} when workspace is enabled
*
* Return HTTP 404 if accessing {basePath}/w/{workspaceId} when workspace is disabled
* Proxy all {basePath}/w/{workspaceId}{osdPath*} paths to {basePath}{osdPath*}
*/
setupDeps.http.registerOnPreRouting(async (request, response, toolkit) => {
const regexp = /\/w\/([^\/]*)/;
const matchedResult = request.url.pathname.match(regexp);

if (matchedResult) {
if (this.startDeps) {
const savedObjectsClient = this.startDeps.savedObjects.getScopedClient(request);
const uiSettingsClient = this.startDeps.uiSettings.asScopedToClient(savedObjectsClient);
const workspacesEnabled = await uiSettingsClient.get<boolean>('workspace:enabled');

if (workspacesEnabled) {
const requestUrl = new URL(request.url.toString());
requestUrl.pathname = requestUrl.pathname.replace(regexp, '');
return toolkit.rewriteUrl(requestUrl.toString());
} else {
// If workspace was disable, return HTTP 404
return response.notFound();
}
}
const requestUrl = new URL(request.url.toString());
requestUrl.pathname = requestUrl.pathname.replace(regexp, '');
return toolkit.rewriteUrl(requestUrl.toString());
}
return toolkit.next();
});
Expand Down Expand Up @@ -108,8 +84,7 @@ export class WorkspacesService
};
}

public async start(deps: WorkspacesStartDeps): Promise<InternalWorkspacesServiceStart> {
this.startDeps = deps;
public async start(): Promise<InternalWorkspacesServiceStart> {
this.logger.debug('Starting SavedObjects service');

return {
Expand Down

0 comments on commit b24d98e

Please sign in to comment.