Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f #86

Merged
merged 2 commits into from
Jun 18, 2024
Merged

f #86

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions media/codesphere-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 30 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@
"Other"
],
"pricing": "Free",
"enabledApiProposals": [
"resolvers",
"terminalDataWriteEvent",
"contribViewsRemote"
],
"activationEvents": [
"onResolveAuthority:codesphere",
"onView:remoteHosts",
"*"
],
"capabilities": {
"untrustedWorkspaces": {
"supported": true
}
},
"main": "./dist/extension.js",
"contributes": {
"viewsContainers": {
Expand All @@ -29,6 +41,14 @@
"title": "Codesphere",
"icon": "media/codesphere.svg"
}
],
"panel": [
{
"id": "ci-pipeline",
"title": "Ci-Pipeline",
"icon": "media/codesphere.svg",
"order": 10
}
]
},
"views": {
Expand All @@ -52,6 +72,15 @@
"icon": "media/Codesphere.svg",
"contextualTitle": "Codesphere"
}
],
"ci-pipeline": [
{
"type": "webview",
"id": "ci-pipeline",
"name": "Ci-Pipeline",
"contextualTitle": "Ci Pipeline",
"when": "codesphere.isLoggedIn && codesphere.workspaceOverview"
}
]
},
"menus": {
Expand Down Expand Up @@ -99,7 +128,7 @@
"title": "Back to menu"
}
],
"extensionKind": ["workspace"]
"extensionKind": ["ui"]
},
"extensionPack": [
"ms-vscode-remote.vscode-remote-extensionpack"
Expand Down
138 changes: 138 additions & 0 deletions src/CiPipelineProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import * as vscode from "vscode";
import { getNonce } from "./ts/getNonce";
import * as wsLib from 'ws';
const { setupWs,
request,
getUaSocket,
checkCiPipelineStructure
} = require('./ts/wsService');

export class CiPipelineProvider implements vscode.WebviewViewProvider {
_view?: vscode.WebviewView;
_doc?: vscode.TextDocument;

constructor(private readonly _extensionUri: vscode.Uri, public extensionContext: vscode.ExtensionContext) {}



public resolveWebviewView(webviewView: vscode.WebviewView) {
this._view = webviewView;
let cache = this.extensionContext.globalState;

webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,

localResourceRoots: [this._extensionUri],
};

webviewView.webview.html = this._getHtmlWebview(webviewView.webview);

webviewView.webview.onDidReceiveMessage(async (data) => {
let socket: any;
let uaSocket = getUaSocket();

switch (data.type) {
case "getCiPipelineStages": {
const socketURL = `wss://${data.value.dataCenterId}.codesphere.com/workspace-proxy`;
console.log(socketURL + `socketURL`);
const accessToken = await this.extensionContext.secrets.get("codesphere.accessToken") as string;
const workspaceID: number = parseInt(data.value.workspaceId);
socket = await setupWs(new wsLib.WebSocket(socketURL), "workspace-proxy", accessToken, cache, workspaceID);

uaSocket = getUaSocket();
let ciStructure: any;
const ciPipelineCheck = checkCiPipelineStructure(uaSocket, 324);
ciPipelineCheck.then((ci: any) => {
ciStructure = ci;
console.log('ciStructure: ' + JSON.stringify(ciStructure));
this._view?.webview.postMessage({
type: "CIPipelineStages",
value: {
'CIArray': `${JSON.stringify(ciStructure)}`
}
});
}
);

await request(uaSocket, "pipelineStream", { workspaceId: workspaceID}, "workspace-proxy", 324);

break;
}

case "currentWorkspace": {
const workspace: any = await cache.get("codesphere.workspaceOverview");

const workspaceId = workspace.id;
const teamId = workspace.teamId;
const dataCenterId = workspace.dataCenterId;

this._view?.webview.postMessage({
type: "currentWorkspace",
value: {
'currentWorkspace': `${workspaceId}`,
'teamId': `${teamId}`,
'dcId': `${dataCenterId}`
}
});

break;
}
}
});
}


public updateWebviewContent() {
if (this._view) {
this._view.webview.html = this._getHtmlWebview(this._view.webview);
}
}

public revive(panel: vscode.WebviewView) {
this._view = panel;
}


private _getHtmlWebview(webview: vscode.Webview) {
const styleResetUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "media", "reset.css")
);
const scriptUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled/cipipeline.js")
);
const styleMainUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "out", "compiled/cipipeline.css")
);
const styleVSCodeUri = webview.asWebviewUri(
vscode.Uri.joinPath(this._extensionUri, "media", "vscode.css")
);

// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();

return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--
Use a content security policy to only allow loading images from https or from our extension directory,
and only allow scripts that have a specific nonce.
-->
<meta http-equiv="Content-Security-Policy" content="img-src https: data:; style-src 'unsafe-inline' ${
webview.cspSource
}; script-src 'nonce-${nonce}';">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="${styleResetUri}" rel="stylesheet">
<link href="${styleVSCodeUri}" rel="stylesheet">
<link href="${styleMainUri}" rel="stylesheet">
<script nonce="${nonce}">
const vscode = acquireVsCodeApi();
</script>
</head>
<body>
<script nonce="${nonce}" src="${scriptUri}"></script>
</body>
</html>`;
}
}
15 changes: 14 additions & 1 deletion src/SidebarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
vscode.commands.executeCommand('setContext', 'codesphere.isLoggedIn', true);
cache.update("codesphere.isLoggedIn", true);
webviewView.webview.html = this._getHtmlWebviewOverview(webviewView.webview);
cache.update('codesphere.workspaceOverview', cache.get('codesphere.currentWorkspace'));
vscode.commands.executeCommand('setContext', 'codesphere.workspaceOverview', cache.get('codesphere.currentWorkspace'));
console.log('Congratulations, your extension "codesphere" is now active! You are logged in.');

let currentWorkspace = parseInt(cache.get('codesphere.currentWorkspace') as string);
Expand Down Expand Up @@ -128,14 +130,19 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
cache.update("codesphere.activeTunnel", {});
}

if (!cache.get("codesphere.workspaceOverview")) {
cache.update("codesphere.workspaceOverview", '');
}

cache.setKeysForSync(["codesphere.isLoggedIn",
"codesphere.accessTokenCache",
"codesphere.teams",
"codesphere.workspaces",
"codesphere.userData",
"codesphere.lastCode",
"codesphere.activeTunnel",
"codesphere.currentWorkspace"]);
"codesphere.currentWorkspace",
"codesphere.workspaceOverview"]);

webviewView.webview.onDidReceiveMessage(async (data) => {
let socket: any;
Expand Down Expand Up @@ -670,6 +677,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
return;
}
webviewView.webview.html = this._getHtmlWebviewOverview(webviewView.webview);
vscode.commands.executeCommand('setContext', 'codesphere.workspaceOverview', data.value.workspaceId);
const workspacesInTeam: any = cache.get("codesphere.workspaces");
const teamId = data.value.teamId;

Expand All @@ -679,6 +687,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
);

cache.update("codesphere.currentconnectedWorkspace", selectedWorkspace);
cache.update("codesphere.workspaceOverview", selectedWorkspace);

if (selectedWorkspace === cache.get("codesphere.currentWorkspace")) {
vscode.commands.executeCommand('codesphere.openOverView', selectedWorkspace);
Expand All @@ -694,6 +703,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
} else {
console.error("Workspace not found with ID:", data.value.workspaceId);
}

break;
}

Expand All @@ -717,8 +727,11 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
if (!data.value) {
return;
}
// todo: check wether it is mandatory to erease the currentWorkspace context. I dont think so but at the moment i dont want to destroy anything
webviewView.webview.html = this._getHtmlForWebviewAfterSignIn(webviewView.webview);
vscode.commands.executeCommand('setContext', 'codesphere.currentWorkspace', "");
vscode.commands.executeCommand('setContext', 'codesphere.workspaceOverview', '');
cache.update('codesphere.workspaceOverview', '');
vscode.commands.executeCommand('codesphere.backToMenu');
break;
}
Expand Down
29 changes: 24 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import { SidebarProvider } from './SidebarProvider';
import { FileTreeProvider } from './FileTreeProvider';
import { CiPipelineProvider } from './CiPipelineProvider';
import { NoCurrentWorkspaceProvider } from './NoCurrentWorkspaceProvider';
import { reloadCache } from './ts/reloadCache';
import { exec } from 'child_process';
Expand All @@ -16,14 +17,25 @@ function getWorkspaceRootPath(): string {
}

export function activate(context: vscode.ExtensionContext) {

vscode.ExtensionKind.UI;
//testing

const config = vscode.workspace.getConfiguration('remote.tunnels');

// Beispielhafte Einstellungen abrufen und anzeigen
const portMappings = config.get('portMappings');
const auth = config.get('auth');
const connectionTimeout = config.get('connectionTimeout');

console.log('portMappings: ', portMappings);
console.log('auth: ', auth);
console.log('connectionTimeout: ', connectionTimeout);

const sidebarProvider = new SidebarProvider(context.extensionUri, context);
const noCurrentWorkspaceProvider = new NoCurrentWorkspaceProvider(context.extensionUri);
const rootPath: string = getWorkspaceRootPath();
const fileTreeProvider = new FileTreeProvider(rootPath);
console.log('roothPath is: ', rootPath);
const ciPipelineProvider = new CiPipelineProvider(context.extensionUri, context);

const remoteName = vscode.env.remoteName;
console.log('remote name ' + remoteName);
Expand All @@ -37,8 +49,6 @@ export function activate(context: vscode.ExtensionContext) {
const machineId = vscode.env.machineId;
console.log('machine id ' + machineId);

const config = vscode.workspace.getConfiguration('remote.tunnels');

console.log('config ' + JSON.stringify(config));

context.subscriptions.push(
Expand All @@ -62,6 +72,13 @@ export function activate(context: vscode.ExtensionContext) {
)
);

context.subscriptions.push(
vscode.window.registerWebviewViewProvider(
'ci-pipeline',
ciPipelineProvider
)
);

const userData: any = context.globalState.get("codesphere.userData");
const gitEmail: string = userData.email || "";
let gitFirstName: string = userData.firstName || "";
Expand Down Expand Up @@ -219,4 +236,6 @@ export function activate(context: vscode.ExtensionContext) {


// This method is called when your extension is deactivated
export function deactivate() {}
export function deactivate() {

}
30 changes: 30 additions & 0 deletions src/ts/wsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,35 @@ const isVSIX = async (deploymentSocket: any) => {
});
};

const checkCiPipelineStructure = async (deploymentSocket: any, endpointId: number) => {
return new Promise((resolve, reject) => {
const messageHandler = (msg: any) => {
try {
let msgTest = msg.toString();
let parsedMsg = JSON.parse(msgTest);

if (msgTest.includes(`"endpointId":${endpointId}`)) {
console.log(`ci-Structure` + msgTest)
deploymentSocket.off("message", messageHandler);
deploymentSocket.off("error", errorHandler);
resolve(parsedMsg.reply);
}
} catch (error) {
console.error("Error parsing message:", error);
reject(error);
}
};

const errorHandler = (err: any) => {
console.log("Socket exited with error:" + err);
reject(err);
};

deploymentSocket.on("message", messageHandler);
deploymentSocket.on("error", errorHandler);
});
};




Expand All @@ -535,6 +564,7 @@ module.exports = {
getRemoteURL,
getGitHubToken,
isVSIX,
checkCiPipelineStructure,
getUaSocket: () => uaSocket,
getDsSocket: () => dsSocket
};
Loading
Loading