Skip to content
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

Remove server side workspace feature flag check #69

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading