Skip to content

Commit

Permalink
[Workspace] Add APIs to support plugin state in request (opensearch-p…
Browse files Browse the repository at this point in the history
…roject#6303) (opensearch-project#6547)

* feat: add APIs to support plugin state in request (wazuh#312)

* feat: add APIs to support plugin state in request

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add APIs to support plugin state in request

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: update CHANGELOG

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: update

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: use request app to store request workspace id

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: remove useless if

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>
(cherry picked from commit fc3fef2)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 6d881e0 commit 536d48a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/server/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export * from './from_root';
export * from './package_json';
export * from './streams';
export { getWorkspaceIdFromUrl, cleanWorkspaceId } from '../../utils';
export { updateWorkspaceState, getWorkspaceState } from './workspace';
19 changes: 19 additions & 0 deletions src/core/server/utils/workspace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { httpServerMock } from '../mocks';
import { getWorkspaceState, updateWorkspaceState } from './workspace';

describe('updateWorkspaceState', () => {
it('update with payload', () => {
const requestMock = httpServerMock.createOpenSearchDashboardsRequest();
updateWorkspaceState(requestMock, {
requestWorkspaceId: 'foo',
});
expect(getWorkspaceState(requestMock)).toEqual({
requestWorkspaceId: 'foo',
});
});
});
36 changes: 36 additions & 0 deletions src/core/server/utils/workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { OpenSearchDashboardsRequest, ensureRawRequest } from '../http/router';

export interface WorkspaceState {
requestWorkspaceId?: string;
}

/**
* This function will be used as a proxy
* because `ensureRequest` is only importable from core module.
*
* @param workspaceId string
* @returns void
*/
export const updateWorkspaceState = (
request: OpenSearchDashboardsRequest,
payload: Partial<WorkspaceState>
) => {
const rawRequest = ensureRawRequest(request);

rawRequest.app = {
...rawRequest.app,
...payload,
};
};

export const getWorkspaceState = (request: OpenSearchDashboardsRequest): WorkspaceState => {
const { requestWorkspaceId } = ensureRawRequest(request).app as WorkspaceState;
return {
requestWorkspaceId,
};
};

0 comments on commit 536d48a

Please sign in to comment.