Skip to content

Commit

Permalink
feat: remove che-workspace-client lib
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Sep 22, 2023
1 parent 6d80df0 commit 9b3e810
Show file tree
Hide file tree
Showing 71 changed files with 425 additions and 327 deletions.
1 change: 0 additions & 1 deletion packages/dashboard-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
},
"dependencies": {
"@eclipse-che/devfile-converter": "0.0.1-ff55f9a",
"@eclipse-che/workspace-client": "0.0.1-1672830275",
"@patternfly/react-core": "^4.276.11",
"@patternfly/react-icons": "^4.93.7",
"@patternfly/react-table": "^4.113.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { BrandingData } from '../../../../services/bootstrap/branding.constant';
import {
ConnectionEvent,
WebsocketClient,
} from '../../../../services/dashboard-backend-client/websocketClient';
} from '../../../../services/backend-client/websocketClient';
import { FakeStoreBuilder } from '../../../../store/__mocks__/storeBuilder';

const failingMessage = 'WebSocket connections are failing';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
ConnectionEvent,
ConnectionListener,
WebsocketClient,
} from '../../../services/dashboard-backend-client/websocketClient';
} from '../../../services/backend-client/websocketClient';

type Props = MappedProps;

Expand Down
4 changes: 1 addition & 3 deletions packages/dashboard-frontend/src/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@
import 'reflect-metadata';
import { Container } from 'inversify';
import getDecorators from 'inversify-inject-decorators';
import { CheWorkspaceClient } from './services/workspace-client/cheworkspace/cheWorkspaceClient';
import { AppAlerts } from './services/alerts/appAlerts';
import { IssuesReporterService } from './services/bootstrap/issuesReporter';
import { DevWorkspaceClient } from './services/workspace-client/devworkspace/devWorkspaceClient';
import { DevWorkspaceDefaultPluginsHandler } from './services/workspace-client/devworkspace/DevWorkspaceDefaultPluginsHandler';
import { WorkspaceStoppedDetector } from './services/bootstrap/workspaceStoppedDetector';
import { WebsocketClient } from './services/dashboard-backend-client/websocketClient';
import { WebsocketClient } from './services/backend-client/websocketClient';

const container = new Container();
const { lazyInject } = getDecorators(container);

container.bind(IssuesReporterService).toSelf().inSingletonScope();
container.bind(WebsocketClient).toSelf().inSingletonScope();
container.bind(CheWorkspaceClient).toSelf().inSingletonScope();
container.bind(DevWorkspaceClient).toSelf().inSingletonScope();
container.bind(AppAlerts).toSelf().inSingletonScope();
container.bind(DevWorkspaceDefaultPluginsHandler).toSelf().inSingletonScope();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import mockAxios from 'axios';
import { getKubernetesNamespace, provisionKubernetesNamespace } from '../kubernetesNamespaceApi';

describe('Kubernetes namespace API', () => {
const mockGet = mockAxios.get as jest.Mock;
const mockPost = mockAxios.post as jest.Mock;

const namespace: che.KubernetesNamespace = { name: 'test-name', attributes: { phase: 'Active' } };

afterEach(() => {
jest.resetAllMocks();
});

describe('fetch namespace', () => {
it('should call "/api/kubernetes/namespace"', async () => {
mockGet.mockResolvedValueOnce({
data: expect.anything(),
});
await getKubernetesNamespace();

expect(mockGet).toBeCalledWith('/api/kubernetes/namespace');
expect(mockPost).not.toBeCalled();
});

it('should return a list of namespaces', async () => {
mockGet.mockResolvedValueOnce({
data: [namespace],
});

const res = await getKubernetesNamespace();

expect(res).toEqual([namespace]);
});
});

describe('provision namespace', () => {
it('should call "/api/kubernetes/namespace/provision"', async () => {
mockPost.mockResolvedValueOnce({
data: expect.anything(),
});
await provisionKubernetesNamespace();

expect(mockGet).not.toBeCalled();
expect(mockPost).toBeCalledWith('/api/kubernetes/namespace/provision');
});

it('should return a list of namespaces', async () => {
mockPost.mockResolvedValueOnce({
data: [namespace],
});

const res = await provisionKubernetesNamespace();

expect(res).toEqual([namespace]);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import mockAxios from 'axios';
import { IGitOauth } from '../../../store/GitOauthConfig/types';
import { deleteOAuthToken, getOAuthProviders, getOAuthToken } from '../oAuthApi';

describe('Open Authorization API', () => {
const mockGet = mockAxios.get as jest.Mock;
const mockDelete = mockAxios.delete as jest.Mock;

const oAuthProvider = { name: 'github', endpointUrl: 'https://github.com' } as IGitOauth;
const oAuthProviderToken = { token: 'dummy_token' };

afterEach(() => {
jest.resetAllMocks();
});

describe('fetch OAuthProviders', () => {
it('should call "/api/oauth"', async () => {
mockGet.mockResolvedValueOnce({
data: expect.anything(),
});
await getOAuthProviders();

expect(mockDelete).not.toBeCalled();
expect(mockGet).toBeCalledWith('/api/oauth');
});

it('should return a list of providers', async () => {
mockGet.mockResolvedValueOnce({
data: [oAuthProvider],
});

const res = await getOAuthProviders();

expect(res).toEqual([oAuthProvider]);
});
});

describe('fetch OAuthToken', () => {
it('should call "/api/oauth/token?oauth_provider=github"', async () => {
mockGet.mockResolvedValueOnce({
data: expect.anything(),
});

await getOAuthToken(oAuthProvider.name);

expect(mockDelete).not.toBeCalled();
expect(mockGet).toBeCalledWith('/api/oauth/token?oauth_provider=github');
});

it('should return the OAuth token', async () => {
mockGet.mockResolvedValueOnce({
data: oAuthProviderToken,
});

const res = await getOAuthToken(oAuthProvider.name);

expect(mockDelete).not.toBeCalled();
expect(res).toEqual(oAuthProviderToken);
});
});

describe('delete OAuthToken', () => {
it('should call "/api/oauth/token?oauth_provider=github"', async () => {
mockDelete.mockResolvedValueOnce(undefined);

await deleteOAuthToken(oAuthProvider.name);

expect(mockGet).not.toBeCalled();
expect(mockDelete).toBeCalledWith('/api/oauth/token?oauth_provider=github');
});

it('should return undefined', async () => {
mockDelete.mockResolvedValueOnce(undefined);

const res = await deleteOAuthToken(oAuthProvider.name);

expect(mockGet).not.toBeCalled();
expect(res).toBeUndefined();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ import axios from 'axios';
import { cheServerPrefix } from './const';
import { FactoryResolver } from '../helpers/types';

const factoryResolverEndpoint = '/factory/resolver';
const factoryEndpoint = '/factory';

export async function getFactoryResolver(
url: string,
overrideParams: { [params: string]: string } = {},
): Promise<FactoryResolver> {
const response = await axios.post(
`${cheServerPrefix}${factoryResolverEndpoint}`,
`${cheServerPrefix}${factoryEndpoint}/resolver`,
Object.assign({}, overrideParams, { url }),
);

return response.data;
}

export async function refreshFactoryOauthToken(url: string): Promise<void> {
await axios.post(`${cheServerPrefix}${factoryEndpoint}/token/refresh?url=${url}`);

return Promise.resolve();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import axios from 'axios';
import { cheServerPrefix } from './const';

export async function getKubernetesNamespace(): Promise<che.KubernetesNamespace[]> {
const response = await axios.get(`${cheServerPrefix}/kubernetes/namespace`);

return response.data;
}

export async function provisionKubernetesNamespace(): Promise<che.KubernetesNamespace> {
const response = await axios.post(`${cheServerPrefix}/kubernetes/namespace/provision`);

return response.data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import axios from 'axios';
import { cheServerPrefix } from './const';
import { api } from '@eclipse-che/common';
import { IGitOauth } from '../../store/GitOauthConfig/types';

export async function getOAuthProviders(): Promise<IGitOauth[]> {
const response = await axios.get(`${cheServerPrefix}/oauth`);

return response.data;
}

export async function getOAuthToken(provider: api.GitOauthProvider): Promise<{ token: string }> {
const response = await axios.get(`${cheServerPrefix}/oauth/token?oauth_provider=${provider}`);

return response.data;
}

export async function deleteOAuthToken(provider: api.GitOauthProvider): Promise<void> {
await axios.delete(`${cheServerPrefix}/oauth/token?oauth_provider=${provider}`);

return Promise.resolve();
}
4 changes: 2 additions & 2 deletions packages/dashboard-frontend/src/services/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import { Workspace } from '../workspace-adapter';
import { WorkspaceRunningError, WorkspaceStoppedDetector } from './workspaceStoppedDetector';
import { selectOpenVSXUrl } from '../../store/ServerConfig/selectors';
import { selectEmptyWorkspaceUrl } from '../../store/DevfileRegistries/selectors';
import { WebsocketClient } from '../dashboard-backend-client/websocketClient';
import { WebsocketClient } from '../backend-client/websocketClient';
import { selectEventsResourceVersion } from '../../store/Events/selectors';
import { selectPodsResourceVersion } from '../../store/Pods/selectors';
import { ChannelListener } from '../dashboard-backend-client/websocketClient/messageHandler';
import { ChannelListener } from '../backend-client/websocketClient/messageHandler';
import { selectApplications } from '../../store/ClusterInfo/selectors';
import { isAvailableEndpoint } from '../helpers/api-ping';
import { DEFAULT_REGISTRY } from '../../store/DevfileRegistries';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
import { AxiosError } from 'axios';
import common from '@eclipse-che/common';
import OAuthService from '..';
import { container } from '../../../inversify.config';
import { DevWorkspaceBuilder } from '../../../store/__mocks__/devWorkspaceBuilder';
import { CheWorkspaceClient } from '../../workspace-client/cheworkspace/cheWorkspaceClient';
import * as factoryApi from '../../backend-client/factoryApi';

const cheWorkspaceClient = container.get(CheWorkspaceClient);

const refreshFactoryOauthTokenSpy = jest.spyOn(
cheWorkspaceClient.restApiClient,
'refreshFactoryOauthToken',
);
const refreshFactoryOauthTokenSpy = jest.spyOn(factoryApi, 'refreshFactoryOauthToken');

const mockOpenOAuthPage = jest.fn().mockImplementation();
OAuthService.openOAuthPage = mockOpenOAuthPage;
Expand Down
7 changes: 2 additions & 5 deletions packages/dashboard-frontend/src/services/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

import common, { helpers } from '@eclipse-che/common';
import { OAuthResponse } from '../../store/FactoryResolver';
import { container } from '../../inversify.config';
import { CheWorkspaceClient } from '../workspace-client/cheworkspace/cheWorkspaceClient';
import devfileApi from '../devfileApi';

const WorkspaceClient = container.get(CheWorkspaceClient);
import { refreshFactoryOauthToken } from '../backend-client/factoryApi';

export default class OAuthService {
static openOAuthPage(authenticationUrl: string, redirectUrl: string): void {
Expand Down Expand Up @@ -44,7 +41,7 @@ export default class OAuthService {
}

try {
await WorkspaceClient.restApiClient.refreshFactoryOauthToken(project.git.remotes.origin);
await refreshFactoryOauthToken(project.git.remotes.origin);
} catch (e) {
if (!common.helpers.errors.includesAxiosResponse(e)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { getCustomEditor, isForbidden, isInternalServerError, isUnauthorized } from '../helpers';
import { CHE_EDITOR_YAML_PATH } from '../';
import { CHE_EDITOR_YAML_PATH } from '../helpers';
import { dump } from 'js-yaml';
import common from '@eclipse-che/common';
import devfileApi from '../../devfileApi';
Expand Down
Loading

0 comments on commit 9b3e810

Please sign in to comment.