forked from che-incubator/che-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
96 lines (83 loc) · 4.35 KB
/
extension.ts
File metadata and controls
96 lines (83 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**********************************************************************
* Copyright (c) 2022-2025 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
***********************************************************************/
/* eslint-disable header/header */
if (Reflect.metadata === undefined) {
// tslint:disable-next-line:no-require-imports no-var-requires
require('reflect-metadata');
}
import { Container } from 'inversify';
import * as vscode from 'vscode';
import { Api } from './api/api';
import { DevfileService } from './api/devfile-service';
import { K8SService } from './api/k8s-service';
import { K8sDevfileServiceImpl } from './impl/k8s-devfile-service-impl';
import { K8SServiceImpl } from './impl/k8s-service-impl';
import { K8sDevWorkspaceEnvVariables } from './impl/k8s-devworkspace-env-variables';
import { WorkspaceService } from './api/workspace-service';
import { K8sWorkspaceServiceImpl } from './impl/k8s-workspace-service-impl';
import { GithubService } from './api/github-service';
import { GithubServiceImpl } from './impl/github-service-impl';
import { TelemetryService } from './api/telemetry-service';
import { K8sTelemetryServiceImpl } from './impl/k8s-telemetry-service-impl';
import * as axios from 'axios';
import { Logger } from './logger';
export async function activate(_extensionContext: vscode.ExtensionContext): Promise<Api> {
const container = new Container();
container.bind(K8sDevfileServiceImpl).toSelf().inSingletonScope();
container.bind(DevfileService).to(K8sDevfileServiceImpl).inSingletonScope();
container.bind(WorkspaceService).to(K8sWorkspaceServiceImpl).inSingletonScope();
container.bind(K8SServiceImpl).toSelf().inSingletonScope();
container.bind(K8SService).to(K8SServiceImpl).inSingletonScope();
container.bind(K8sDevWorkspaceEnvVariables).toSelf().inSingletonScope();
container.bind(Symbol.for('AxiosInstance')).toConstantValue(axios);
container.bind(GithubServiceImpl).toSelf().inSingletonScope();
container.bind(GithubService).to(GithubServiceImpl).inSingletonScope();
container.bind(TelemetryService).to(K8sTelemetryServiceImpl).inSingletonScope();
container.bind(Logger).toSelf().inSingletonScope();
const devfileService = container.get(DevfileService) as DevfileService;
const workspaceService = container.get(WorkspaceService) as WorkspaceService;
const githubService = container.get(GithubService) as GithubService;
const telemetryService = container.get(TelemetryService) as TelemetryService;
const api: Api = {
getDevfileService(): DevfileService {
return devfileService;
},
getWorkspaceService(): WorkspaceService {
return workspaceService;
},
getGithubService(): GithubService {
return githubService;
},
getTelemetryService(): TelemetryService {
return telemetryService;
},
};
const k8sDevWorkspaceEnvVariables = container.get(K8sDevWorkspaceEnvVariables);
const dashboardUrl = k8sDevWorkspaceEnvVariables.getDashboardURL();
const workspaceNamespace = k8sDevWorkspaceEnvVariables.getWorkspaceNamespace();
const workspaceName = k8sDevWorkspaceEnvVariables.getWorkspaceName();
const projectsRoot = k8sDevWorkspaceEnvVariables.getProjectsRoot();
_extensionContext.environmentVariableCollection.replace('DASHBOARD_URL', dashboardUrl);
_extensionContext.environmentVariableCollection.replace('WORKSPACE_NAME', workspaceName);
_extensionContext.environmentVariableCollection.replace('WORKSPACE_NAMESPACE', workspaceNamespace);
_extensionContext.environmentVariableCollection.replace('PROJECTS_ROOT', projectsRoot);
await container.get(K8SServiceImpl).ensureKubernetesServiceHostWhitelisted();
_extensionContext.subscriptions.push(
vscode.commands.registerCommand('che-api.test-github-proxy', async () => {
try {
const user = await githubService.getUser();
vscode.window.showInformationMessage(`Success! GitHub user: ${user.login}`);
} catch (e: any) {
vscode.window.showErrorMessage(`Failed to get GitHub user: ${e.message}`);
}
})
);
return api;
}