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

feat: add workspace permission control interface #41

Merged
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
2 changes: 2 additions & 0 deletions src/core/server/workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export {
} from './workspaces_service';

export { WorkspaceAttribute, WorkspaceFindOptions } from './types';

export { WorkspacePermissionControl } from './workspace_permission_control';
23 changes: 23 additions & 0 deletions src/core/server/workspaces/workspace_permission_control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { OpenSearchDashboardsRequest } from '../http';

export enum WorkspacePermissionMode {
Read,
Admin,
}

export class WorkspacePermissionControl {
public async validate(
workspaceId: string,
permissionModeOrModes: WorkspacePermissionMode | WorkspacePermissionMode[],
request: OpenSearchDashboardsRequest
) {
return true;
}

public async setup() {}
}
11 changes: 11 additions & 0 deletions src/core/server/workspaces/workspaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import {
} from '../saved_objects';
import { IWorkspaceDBImpl } from './types';
import { WorkspacesClientWithSavedObject } from './workspaces_client';
import { WorkspacePermissionControl } from './workspace_permission_control';

export interface WorkspacesServiceSetup {
client: IWorkspaceDBImpl;
permissionControl: WorkspacePermissionControl;
}

export interface WorkspacesServiceStart {
client: IWorkspaceDBImpl;
permissionControl: WorkspacePermissionControl;
}

export interface WorkspacesSetupDeps {
Expand All @@ -40,6 +43,8 @@ export class WorkspacesService
implements CoreService<WorkspacesServiceSetup, WorkspacesServiceStart> {
private logger: Logger;
private client?: IWorkspaceDBImpl;
private permissionControl?: WorkspacePermissionControl;

constructor(coreContext: CoreContext) {
this.logger = coreContext.logger.get('workspaces-service');
}
Expand All @@ -65,7 +70,11 @@ export class WorkspacesService
this.logger.debug('Setting up Workspaces service');

this.client = new WorkspacesClientWithSavedObject(setupDeps);
this.permissionControl = new WorkspacePermissionControl();

await this.client.setup(setupDeps);
await this.permissionControl.setup();

this.proxyWorkspaceTrafficToRealHandler(setupDeps);

registerRoutes({
Expand All @@ -76,6 +85,7 @@ export class WorkspacesService

return {
client: this.client,
permissionControl: this.permissionControl,
};
}

Expand All @@ -84,6 +94,7 @@ export class WorkspacesService

return {
client: this.client as IWorkspaceDBImpl,
permissionControl: this.permissionControl as WorkspacePermissionControl,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Could you give an example of how will we use permissionControl?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As my understanding. The permissionControl will be a result of setup method. After setup called, we will pass them to anywhere that dependencies on workspace permissionControl.

};
}

Expand Down
Loading