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 21, 2023
1 parent 6d80df0 commit 7d0f152
Show file tree
Hide file tree
Showing 69 changed files with 331 additions and 323 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
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,27 @@
/*
* 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';

Check failure on line 15 in packages/dashboard-frontend/src/services/backend-client/kubernetesNamespaceApi.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

'api' is defined but never used

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,38 @@
/*
* 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';

export async function getOAuthProviders(): Promise<
{
name: api.GitOauthProvider;
endpointUrl: string;
}[]
> {
const response = await axios.get(`${cheServerPrefix}/resolver`);

return response.data;
}

export async function getOAuthToken(provider: api.GitOauthProvider): Promise<void> {
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/

import * as DwApi from '../../dashboard-backend-client/devWorkspaceApi';
import * as DwApi from '../../backend-client/devWorkspaceApi';
import devfileApi from '../../devfileApi';
import { api } from '@eclipse-che/common';
import { createHash } from 'crypto';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { container } from '../../../../inversify.config';
import { DevWorkspaceBuilder } from '../../../../store/__mocks__/devWorkspaceBuilder';
import { DevWorkspaceClient } from '../devWorkspaceClient';
import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi';
import * as DwApi from '../../../backend-client/devWorkspaceApi';

describe('DevWorkspace client, changeWorkspaceStatus', () => {
let client: DevWorkspaceClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import { container } from '../../../../inversify.config';
import { DevWorkspaceClient } from '../devWorkspaceClient';
import * as DwtApi from '../../../dashboard-backend-client/devWorkspaceTemplateApi';
import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi';
import * as DwtApi from '../../../backend-client/devWorkspaceTemplateApi';
import * as DwApi from '../../../backend-client/devWorkspaceApi';
import devfileApi from '../../../devfileApi';

describe('DevWorkspace client, create', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import { container } from '../../../../inversify.config';
import { DevWorkspaceClient } from '../devWorkspaceClient';
import mockAxios from 'axios';
import { dashboardBackendPrefix } from '../../../dashboard-backend-client/const';
import { dashboardBackendPrefix } from '../../../backend-client/const';
import getDevWorkspaceTemplate from './__mocks__/devWorkspaceSpecTemplates';
import devfileApi from '../../../devfileApi';
import * as DwtApi from '../../../dashboard-backend-client/devWorkspaceTemplateApi';
import * as DwtApi from '../../../backend-client/devWorkspaceTemplateApi';

describe('DevWorkspace client editor update', () => {
const namespace = 'admin-che';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { container } from '../../../../inversify.config';
import { DevWorkspaceBuilder } from '../../../../store/__mocks__/devWorkspaceBuilder';
import { DevWorkspaceClient } from '../devWorkspaceClient';
import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi';
import * as DwApi from '../../../backend-client/devWorkspaceApi';
import mockAxios from 'axios';

/* eslint-disable @typescript-eslint/no-non-null-assertion */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { container } from '../../../../inversify.config';
import { DevWorkspaceBuilder } from '../../../../store/__mocks__/devWorkspaceBuilder';
import { DevWorkspaceClient } from '../devWorkspaceClient';
import * as DwApi from '../../../dashboard-backend-client/devWorkspaceApi';
import * as DwApi from '../../../backend-client/devWorkspaceApi';

describe('DevWorkspace client, update', () => {
let client: DevWorkspaceClient;
Expand Down
Loading

0 comments on commit 7d0f152

Please sign in to comment.