Skip to content

Commit

Permalink
Add kubectxt listing
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf committed Jun 2, 2024
1 parent 12de70e commit c9d8eba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "server.js",
"description": "WurmTerm, a friendly wurm walking along your SSH sessions. Backend service.",
"license": "GPL-3.0",
"version": "0.9.6",
"version": "0.9.8",
"repository": {
"type": "git",
"url": "https://github.com/lwindolf/wurmterm-backend.git"
Expand Down
22 changes: 21 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// vim: set ts=4 sw=4:
/*jshint esversion: 6 */
/*
Copyright (C) 2015-2023 Lars Windolf <lars.windolf@gmx.de>
Copyright (C) 2015-2024 Lars Windolf <lars.windolf@gmx.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -43,6 +43,24 @@ process.on('uncaughtException', function (err) {
const validIpAddressRegex = /^([a-zA-Z0-9]+@){0,1}(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
const validHostnameRegex = /^([a-zA-Z0-9]+@){0,1}(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;

// get history of kubectl contexts
function get_kubectxt(socket) {
try {
const cmd = 'kubectl config view -o jsonpath="{.contexts}"';
exec(cmd, (error, stdout, stderr) => {
if (error)
throw (error);

socket.send(JSON.stringify({
cmd: 'kubectxt',
result: stdout
}));
});
} catch (e) {
return { cmd: 'kubectxt', error: e };
}
}

// get history of SSH commands
function get_history(socket) {
try {
Expand Down Expand Up @@ -305,6 +323,8 @@ wsServer.on('connection', (ws, req, client) => {
return get_probes(ws);
if (cmd === 'history')
return get_history(ws);
if (cmd === 'kubectxt')
return get_kubectxt(ws);

if (cmd === 'run') {
// we expect message in format "run <host>:::<id>:::<cmd>"
Expand Down

0 comments on commit c9d8eba

Please sign in to comment.