Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: yubonluo <[email protected]>
  • Loading branch information
yubonluo committed Apr 11, 2024
1 parent b342950 commit 27d95fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/plugins/workspace/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ export class WorkspacePlugin implements Plugin<WorkspacePluginSetup, WorkspacePl
}

if (!!applicationConfig) {
const [coreStart] = await core.getStartServices();
const scopeClient = coreStart.opensearch.client.asScoped(request);
[configGroups, configUsers] = await getApplicationOSDAdminConfig(
{ applicationConfig },
scopeClient
request
);
} else {
[configGroups, configUsers] = await getOSDAdminConfig(this.globalConfig$);
Expand Down
18 changes: 5 additions & 13 deletions src/plugins/workspace/server/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { AuthStatus } from '../../../core/server';
import { coreMock, httpServerMock, httpServiceMock } from '../../../core/server/mocks';
import { httpServerMock, httpServiceMock } from '../../../core/server/mocks';
import {
generateRandomId,
getApplicationOSDAdminConfig,
Expand Down Expand Up @@ -156,12 +156,8 @@ describe('workspace utils', () => {
const mockDependencies: AppPluginSetupDependencies = {
applicationConfig: applicationConfigMock,
};
const coreStart = coreMock.createInternalStart();
const scopedClusterClientMock = coreStart.opensearch.client.asScoped();
const [groups, users] = await getApplicationOSDAdminConfig(
mockDependencies,
scopedClusterClientMock
);
const mockRequest = httpServerMock.createOpenSearchDashboardsRequest();
const [groups, users] = await getApplicationOSDAdminConfig(mockDependencies, mockRequest);
expect(groups).toEqual(['group1', 'group2']);
expect(users).toEqual(['user1', 'user2']);
});
Expand All @@ -179,12 +175,8 @@ describe('workspace utils', () => {
const mockDependencies: AppPluginSetupDependencies = {
applicationConfig: applicationConfigMock,
};
const coreStart = coreMock.createInternalStart();
const scopedClusterClientMock = coreStart.opensearch.client.asScoped();
const [groups, users] = await getApplicationOSDAdminConfig(
mockDependencies,
scopedClusterClientMock
);
const mockRequest = httpServerMock.createOpenSearchDashboardsRequest();
const [groups, users] = await getApplicationOSDAdminConfig(mockDependencies, mockRequest);
expect(groups).toEqual([]);
expect(users).toEqual([]);
});
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/workspace/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { first } from 'rxjs/operators';
import {
AuthStatus,
HttpAuth,
IScopedClusterClient,
OpenSearchDashboardsRequest,
Principals,
PrincipalType,
Expand Down Expand Up @@ -91,9 +90,9 @@ export const stringToArray = (adminConfig: string | undefined) => {

export const getApplicationOSDAdminConfig = async (
{ applicationConfig }: AppPluginSetupDependencies,
scopeClient: IScopedClusterClient
request: OpenSearchDashboardsRequest
) => {
const applicationConfigClient = applicationConfig.getConfigurationClient(scopeClient);
const applicationConfigClient = applicationConfig.getConfigurationClient(request);

const [groupsResult, usersResult] = await Promise.all([
applicationConfigClient
Expand Down

0 comments on commit 27d95fe

Please sign in to comment.