Skip to content

Commit

Permalink
feat: add workspace permission control interface (opensearch-project#41)
Browse files Browse the repository at this point in the history
* feat: add workspace permission control interface

Signed-off-by: Lin Wang <wonglam@amazon.com>

* feat: add request parameter for workspace permission control

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam authored and Hailong-am committed Jul 18, 2023
1 parent e63864d commit 2581b10
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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,
};
}

Expand Down

0 comments on commit 2581b10

Please sign in to comment.