Skip to content

Commit 2288e06

Browse files
committed
Open URI to be handled by Code-based editor.
- Automatically open a vscode://redhat.devspaces-remote-ssh URI that will be handled by an active Code based editor with redhat.devspaces-remote-ssh extension installed - Replace the usage of the page URL with the vscode-based URI - Use innerText instead of innerHTML for clipboard copying in pre tags - pre tags should automatically wrap text Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent 08a7c34 commit 2288e06

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

build/scripts/code-sshd-page/page-style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pre {
1616
display: table-cell;
1717
width: 98%;
1818
padding: 10px;
19+
white-space: pre-wrap;
20+
overflow-wrap: anywhere;
21+
word-break: break-all;
1922
}
2023

2124
/* Inline code */

build/scripts/code-sshd-page/page-utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
function copyToClipboard(id) {
1111
var copyText = document.getElementById(id);
12-
navigator.clipboard.writeText(copyText.innerHTML);
12+
navigator.clipboard.writeText(copyText.innerText);
1313
}
1414

1515
function initializePlatformContent() {
@@ -37,3 +37,8 @@ function syncDocsContent() {
3737
var manualElem = document.getElementById("docs-manual");
3838
docsElem.innerHTML = useExtension ? extensionElem.innerHTML : manualElem.innerHTML;
3939
}
40+
41+
function openDevspacesURI(namespace, podName, userName, dwName, encodedKeyMessage, encodedUrl) {
42+
const gatewayLink = `vscode://redhat.devspaces-remote-ssh?namespace=${namespace}&podName=${podName}&userName=${userName}&dwName=${dwName}&key=${encodedKeyMessage}&url=${encodedUrl}`;
43+
window.open(gatewayLink, "_self");
44+
}

build/scripts/code-sshd-page/server.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const port = 3400;
1616

1717
let username = "UNKNOWN";
1818
try {
19-
username = fs.readFileSync(`/sshd/username`, 'utf8');
19+
username = fs.readFileSync('/sshd/username', 'utf8');
2020
} catch (error) {
2121
// continue
2222
}
@@ -28,21 +28,30 @@ const server = http.createServer((req, res) => {
2828

2929
let hasUserPrefSSHKey = fs.existsSync('/etc/ssh/dwo_ssh_key.pub');
3030

31-
let pubKey = "PUBLIC KEY COULD NOT BE DISPLAYED";
31+
let userPubKey = "PUBLIC KEY COULD NOT BE DISPLAYED";
3232
try {
33-
pubKey = fs.readFileSync('/etc/ssh/dwo_ssh_key.pub', 'utf8');
33+
userPubKey = fs.readFileSync('/etc/ssh/dwo_ssh_key.pub', 'utf8');
34+
} catch (err) {
35+
// continue
36+
}
37+
38+
let userKey = '';
39+
try {
40+
userKey = fs.readFileSync('/etc/ssh/dwo_ssh_key', 'utf8');
3441
} catch (err) {
3542
// continue
3643
}
3744

3845
let genKey = "PRIVATE KEY NOT FOUND";
3946
try {
40-
genKey = fs.readFileSync(`/sshd/ssh_client_key`, 'utf8');
47+
genKey = fs.readFileSync('/sshd/ssh_client_key', 'utf8');
4148
} catch (err) {
4249
// continue
4350
}
4451

45-
let keyMessage = hasUserPrefSSHKey ? pubKey : genKey;
52+
let keyMessage = hasUserPrefSSHKey ? userPubKey : genKey;
53+
let encodedKeyMessage = Buffer.from(hasUserPrefSSHKey ? userKey : genKey).toString('base64url');
54+
let encodedUrl = encodeURIComponent(process.env["CHE_DASHBOARD_URL"]);
4655

4756
res.end(`
4857
<!DOCTYPE html>
@@ -75,10 +84,22 @@ const server = http.createServer((req, res) => {
7584
<li class="extension-li"><code>Remote - SSH</code> from the <a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh">VS Code Marketplace</a> <b>OR</b> <code>Open Remote - SSH</code> from the <a href="https://open-vsx.org/extension/jeanp413/open-remote-ssh">OpenVSX Registry</a></li>
7685
</ul>
7786
</li>
78-
<li class="extension-li">From the "Remote Explorer" view, select the <code>Connect to Dev Spaces</code> command and input the URL of this page.</li>
79-
<ul>
80-
<li class="extension-li">It should be of the form : <code>https://$\{CLUSTER_URL\}/$\{USER\}/$\{DEVWORKSPACE_NAME\}/3400/</code></li>
81-
</ul>
87+
<li class="extension-li">Click the URI below (you may need to accept the prompt allowing this page to open the link with your VS Code-based editor) <b>OR</b> from the "Remote Explorer" view, select the <code>Connect to Dev Spaces</code> command and input the URI below.</li>
88+
<div class="parent">
89+
<div>
90+
<a href="vscode://redhat.devspaces-remote-ssh?namespace=${process.env["DEVWORKSPACE_NAMESPACE"]}&podName=${process.env["HOSTNAME"]}&userName=${username}&dwName=${process.env["DEVWORKSPACE_NAME"]}&key=${encodedKeyMessage}&url=${encodedUrl}">
91+
<pre id="uri-connection">vscode://redhat.devspaces-remote-ssh?namespace=${process.env["DEVWORKSPACE_NAMESPACE"]}&podName=${process.env["HOSTNAME"]}&userName=${username}&dwName=${process.env["DEVWORKSPACE_NAME"]}&key=${encodedKeyMessage}&url=${encodedUrl}</pre>
92+
</a>
93+
</div>
94+
<div class="clipboard">
95+
<a href="#">
96+
<svg class="clipboard-img-pre" onclick="copyToClipboard('uri-connection')" title="Copy" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 20 20">
97+
<path fill="currentColor" d="M12 0H2C.9 0 0 .9 0 2v10h1V2c0-.6.4-1 1-1h10V0z"></path>
98+
<path fill="currentColor" d="M18 20H8c-1.1 0-2-.9-2-2V8c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2v10c0 1.1-.9 2-2 2zM8 7c-.6 0-1 .4-1 1v10c0 .6.4 1 1 1h10c.6 0 1-.4 1-1V8c0-.6-.4-1-1-1H8z"></path>
99+
</svg>
100+
</a>
101+
</div>
102+
</div>
82103
</ol>
83104
</div>
84105
<div id="docs-manual" hidden>
@@ -136,7 +157,10 @@ const server = http.createServer((req, res) => {
136157
<p>If the connection fails for an unknown reason, consider disabling the setting <code>remote.SSH.useExecServer</code> (set to false)</p>
137158
<p>For any other issues, relating to the use of a VS Code-based editor and the "Remote - SSH", the "Remote - SSH" logs from the "Output" view are very helpful in diagnosing the issue.</p>
138159
</div>
139-
<script>initializePlatformContent();</script>
160+
<script>
161+
initializePlatformContent();
162+
openDevspacesURI("${process.env["DEVWORKSPACE_NAMESPACE"]}", "${process.env["HOSTNAME"]}", "${username}", "${process.env["DEVWORKSPACE_NAME"]}", "${encodedKeyMessage}", "${encodedUrl}");
163+
</script>
140164
</body>
141165
</html>
142166
`);

0 commit comments

Comments
 (0)