Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from eclipse-che/che#12306
Browse files Browse the repository at this point in the history
Add ssh-plugin
  • Loading branch information
vparfonov committed Feb 26, 2019
2 parents 3ca14ec + 3ffc7c9 commit ea3edba
Show file tree
Hide file tree
Showing 15 changed files with 613 additions and 2 deletions.
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
node_modules
# Dependency directories
node_modules/

# Logs
yarn-error.log

# IntelliJ
.idea

# VS Code
.vscode/*

# Generated files
*.theia


# MacOS
.DS_Store
.theia
.idea
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CheWorkspaceMainImpl } from './che-workspace-main';
import { CheFactoryMainImpl } from './che-factory-main';
import { CheVariablesMainImpl } from './che-variables-main';
import { CheTaskMainImpl } from './che-task-main';
import { CheSshMainImpl } from './che-ssh-main';

@injectable()
export class CheApiProvider implements MainPluginApiProvider {
Expand All @@ -25,6 +26,7 @@ export class CheApiProvider implements MainPluginApiProvider {
rpc.set(PLUGIN_RPC_CONTEXT.CHE_FACTORY_MAIN, new CheFactoryMainImpl(container));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_VARIABLES_MAIN, new CheVariablesMainImpl(container, rpc));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_TASK_MAIN, new CheTaskMainImpl(container, rpc));
rpc.set(PLUGIN_RPC_CONTEXT.CHE_SSH_MAIN, new CheSshMainImpl(container));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*********************************************************************
* Copyright (c) 2019 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
**********************************************************************/

import { che as cheApi } from '@eclipse-che/api';
import { interfaces } from 'inversify';
import { CheApiService, CheSshMain } from '../common/che-protocol';

export class CheSshMainImpl implements CheSshMain {

private readonly cheApiService: CheApiService;

constructor(container: interfaces.Container) {
this.cheApiService = container.get(CheApiService);
}

async $generate(service: string, name: string): Promise<cheApi.ssh.SshPair> {
return this.cheApiService.generateSshKey(service, name);
}

async $create(sshKeyPair: cheApi.ssh.SshPair): Promise<void> {
return this.cheApiService.createSshKey(sshKeyPair);
}

async $get(service: string, name: string): Promise<cheApi.ssh.SshPair> {
return this.cheApiService.getSshKey(service, name);
}

async $getAll(service: string): Promise<cheApi.ssh.SshPair[]> {
return this.cheApiService.getAllSshKey(service);
}

async $deleteKey(service: string, name: string): Promise<void> {
return this.cheApiService.deleteSshKey(service, name);
}

}
19 changes: 19 additions & 0 deletions extensions/eclipse-che-theia-plugin-ext/src/common/che-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export interface CheFactoryMain {
$getFactoryById(factoryId: string): Promise<cheApi.factory.Factory>;
}

export interface CheSsh {
}

export interface CheSshMain {
$generate(service: string, name: string): Promise<cheApi.ssh.SshPair>;
$create(sshKeyPair: cheApi.ssh.SshPair): Promise<void>;
$get(service: string, name: string): Promise<cheApi.ssh.SshPair>;
$getAll(service: string): Promise<cheApi.ssh.SshPair[]>;
$deleteKey(service: string, name: string): Promise<void>;
}

/**
* Variables plugin API
*/
Expand Down Expand Up @@ -336,6 +347,9 @@ export const PLUGIN_RPC_CONTEXT = {
CHE_VARIABLES_MAIN: <ProxyIdentifier<CheVariablesMain>>createProxyIdentifier<CheVariablesMain>('CheVariablesMain'),
CHE_TASK: <ProxyIdentifier<CheTask>>createProxyIdentifier<CheTask>('CheTask'),
CHE_TASK_MAIN: <ProxyIdentifier<CheTaskMain>>createProxyIdentifier<CheTaskMain>('CheTaskMain'),

CHE_SSH: <ProxyIdentifier<CheSsh>>createProxyIdentifier<CheSsh>('CheSsh'),
CHE_SSH_MAIN: <ProxyIdentifier<CheSshMain>>createProxyIdentifier<CheSshMain>('CheSshMain'),
};

// Theia RPC protocol
Expand All @@ -362,6 +376,11 @@ export interface CheApiService {
deleteUserPreferences(): Promise<void>;
deleteUserPreferences(list: string[] | undefined): Promise<void>;

generateSshKey(service: string, name: string): Promise<cheApi.ssh.SshPair>;
createSshKey(sshKeyPair: cheApi.ssh.SshPair): Promise<void>;
getSshKey(service: string, name: string): Promise<cheApi.ssh.SshPair>;
deleteSshKey(service: string, name: string): Promise<void>;
getAllSshKey(service: string): Promise<cheApi.ssh.SshPair[]>;
}

export const CHE_TASK_SERVICE_PATH = '/che-task-service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,74 @@ export class CheApiServiceImpl implements CheApiService {
}
}

async generateSshKey(service: string, name: string): Promise<cheApi.ssh.SshPair> {
try {
const client = await this.getCheApiClient();
if (client) {
return client.generateSshKey(service, name);
}

throw new Error(`Unable to generate SSH Key for ${service}:${name}`);
} catch (e) {
console.error(e);
throw new Error(e);
}
}

async createSshKey(sshKeyPair: cheApi.ssh.SshPair): Promise<void> {
try {
const client = await this.getCheApiClient();
if (client) {
return client.createSshKey(sshKeyPair);
}

throw new Error('Unable to create SSH Key');
} catch (e) {
console.error(e);
throw new Error(e);
}
}

async getSshKey(service: string, name: string): Promise<cheApi.ssh.SshPair> {
try {
const client = await this.getCheApiClient();
if (client) {
return await client.getSshKey(service, name);
}

throw new Error(`Unable to get SSH Key for ${service}:${name}`);
} catch (e) {
console.error(e);
throw new Error(e);
}
}

async getAllSshKey(service: string): Promise<cheApi.ssh.SshPair[]> {
try {
const client = await this.getCheApiClient();
if (client) {
return client.getAllSshKey(service);
}
throw new Error(`Unable to get SSH Keys for ${service}`);
} catch (e) {
console.error(e);
throw new Error(e);
}
}

async deleteSshKey(service: string, name: string): Promise<void> {
try {
const client = await this.getCheApiClient();
if (client) {
return client.deleteSshKey(service, name);
}
throw new Error(`Unable to delete SSH Key for ${service}:${name}`);
} catch (e) {
console.error(e);
throw new Error(e);
}
}

private async getCheApiClient(): Promise<IRemoteAPI> {
const cheApiInternalVar = process.env.CHE_API_INTERNAL;
const cheMachineToken = process.env.CHE_MACHINE_TOKEN;
Expand Down
24 changes: 23 additions & 1 deletion extensions/eclipse-che-theia-plugin-ext/src/plugin/che-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CheVariablesImpl } from './che-variables';
import { PLUGIN_RPC_CONTEXT } from '../common/che-protocol';
import { CheFactoryImpl } from './che-factory';
import { CheTaskImpl } from './che-task-impl';
import { CheSshImpl } from './che-ssh';

export interface CheApiFactory {
(plugin: Plugin): typeof che;
Expand All @@ -27,6 +28,7 @@ export function createAPIFactory(rpc: RPCProtocol): CheApiFactory {
const cheFactoryImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_FACTORY, new CheFactoryImpl(rpc));
const cheVariablesImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_VARIABLES, new CheVariablesImpl(rpc));
const cheTaskImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_TASK, new CheTaskImpl(rpc));
const cheSshImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_SSH, new CheSshImpl(rpc));

return function (plugin: Plugin): typeof che {
const workspace: typeof che.workspace = {
Expand Down Expand Up @@ -86,6 +88,25 @@ export function createAPIFactory(rpc: RPCProtocol): CheApiFactory {
}
};

const ssh: typeof che.ssh = {
deleteKey(service: string, name: string): Promise<void> {
return cheSshImpl.delete(service, name);
},
generate(service: string, name: string): Promise<cheApi.ssh.SshPair> {
return cheSshImpl.generate(service, name);

},
create(sshKeyPair: cheApi.ssh.SshPair): Promise<void> {
return cheSshImpl.create(sshKeyPair);
},
getAll(service: string): Promise<cheApi.ssh.SshPair[]> {
return cheSshImpl.getAll(service);
},
get(service: string, name: string): Promise<cheApi.ssh.SshPair> {
return cheSshImpl.get(service, name);
}
};

const task: typeof che.task = {
registerTaskRunner(type: string, runner: che.TaskRunner): Promise<che.Disposable> {
return cheTaskImpl.registerTaskRunner(type, runner);
Expand All @@ -99,7 +120,8 @@ export function createAPIFactory(rpc: RPCProtocol): CheApiFactory {
workspace,
factory,
variables,
task
task,
ssh
};
};

Expand Down
78 changes: 78 additions & 0 deletions extensions/eclipse-che-theia-plugin-ext/src/plugin/che-ssh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*********************************************************************
* Copyright (c) 2019 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
**********************************************************************/

import { RPCProtocol } from '@theia/plugin-ext/lib/api/rpc-protocol';
import { PLUGIN_RPC_CONTEXT, CheSshMain, CheSsh } from '../common/che-protocol';
import { che as cheApi } from '@eclipse-che/api';

export class CheSshImpl implements CheSsh {

private readonly sshMain: CheSshMain;

constructor(rpc: RPCProtocol) {
this.sshMain = rpc.getProxy(PLUGIN_RPC_CONTEXT.CHE_SSH_MAIN);
}

/**
* @inheritDoc
*/
async generate(service: string, name: string): Promise<cheApi.ssh.SshPair> {
try {
return this.sshMain.$generate(service, name);
} catch (e) {
throw new Error(e);
}
}

/**
* @inheritDoc
*/
async create(sshKeyPair: cheApi.ssh.SshPair): Promise<void> {
try {
return this.sshMain.$create(sshKeyPair);
} catch (e) {
throw new Error(e);
}
}

/**
* @inheritDoc
*/
async getAll(service: string): Promise<cheApi.ssh.SshPair[]> {
try {
return this.sshMain.$getAll(service);
} catch (e) {
throw new Error(e);
}
}

/**
* @inheritDoc
*/
async get(service: string, name: string): Promise<cheApi.ssh.SshPair> {
try {
return this.sshMain.$get(service, name);
} catch (e) {
throw new Error(e);
}
}

/**
* @inheritDoc
*/
async delete(service: string, name: string): Promise<void> {
try {
return this.sshMain.$deleteKey(service, name);
} catch (e) {
throw new Error(e);
}
}

}
3 changes: 3 additions & 0 deletions extensions/eclipse-che-theia-plugin-ext/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module.exports = {
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
],
exclude: /node_modules/
Expand Down
12 changes: 12 additions & 0 deletions extensions/eclipse-che-theia-plugin/src/che-proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ declare module '@eclipse-che/plugin' {
export function getById(id: string): PromiseLike<cheApi.factory.Factory>;
}

export namespace ssh {
export function generate(service: string, name: string): Promise<cheApi.ssh.SshPair>;

export function create(sshKeyPair: cheApi.ssh.SshPair): Promise<void>;

export function get(service: string, name: string): Promise<cheApi.ssh.SshPair>;

export function getAll(service: string): Promise<cheApi.ssh.SshPair[]>;

export function deleteKey(service: string, name: string): Promise<void>;
}

/**
* Namespace for variables substitution functionality.
*/
Expand Down
3 changes: 3 additions & 0 deletions plugins/ssh-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
node_modules/
lib/
15 changes: 15 additions & 0 deletions plugins/ssh-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Theia - SSH Plug-in

The SSH Plug-in allows to manage the SSH public/private key pairs stored in Che workspace.

![Theia](https://user-images.githubusercontent.com/7668752/46194687-ca8b0d80-c30a-11e8-9eb1-fe8e6232486c.png)

Adds the following commands (shortcut `F1`):
- SSH: generate key pair...
- SSH: create key pair...
- SSH: view public key...
- SSH: delete key pair...

## License

[EPL-2.0](http://www.eclipse.org/legal/epl-2.0)
Loading

0 comments on commit ea3edba

Please sign in to comment.