feature: Adds eslint rules.
This commit is contained in:
parent
57a82a15e9
commit
abc60691c6
26 changed files with 123 additions and 94 deletions
|
@ -4,7 +4,7 @@ import { run as connection } from "./commands/connections.js";
|
|||
import { run as backends } from "./commands/backends.js";
|
||||
import { run as users } from "./commands/users.js";
|
||||
|
||||
export type PrintLine = (...str: any[]) => void;
|
||||
export type PrintLine = (...str: unknown[]) => void;
|
||||
export type KeyboardRead = (disableEcho?: boolean) => Promise<string>;
|
||||
|
||||
type Command = (
|
||||
|
@ -12,7 +12,7 @@ type Command = (
|
|||
println: PrintLine,
|
||||
axios: Axios,
|
||||
apiKey: string,
|
||||
keyboardRead: KeyboardRead
|
||||
keyboardRead: KeyboardRead,
|
||||
) => Promise<void>;
|
||||
|
||||
type Commands = {
|
||||
|
@ -30,7 +30,9 @@ export const commands: Commands = [
|
|||
printf(`${command.name}: ${command.description}\n`);
|
||||
});
|
||||
|
||||
printf("\nRun a command of your choosing with --help to see more options.\n");
|
||||
printf(
|
||||
"\nRun a command of your choosing with --help to see more options.\n",
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -43,21 +45,21 @@ export const commands: Commands = [
|
|||
{
|
||||
name: "conn",
|
||||
description: "Manages connections for NextNet",
|
||||
run: connection
|
||||
run: connection,
|
||||
},
|
||||
{
|
||||
name: "user",
|
||||
description: "Manages users for NextNet",
|
||||
run: users
|
||||
run: users,
|
||||
},
|
||||
{
|
||||
name: "backend",
|
||||
description: "Manages backends for NextNet",
|
||||
run: backends
|
||||
run: backends,
|
||||
},
|
||||
{
|
||||
name: "back",
|
||||
description: "(alias) Manages backends for NextNet",
|
||||
run: backends
|
||||
}
|
||||
run: backends,
|
||||
},
|
||||
];
|
||||
|
|
|
@ -119,8 +119,7 @@ export async function run(
|
|||
password?: string;
|
||||
},
|
||||
) => {
|
||||
// Yes it can index for what we need it to do.
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Yes it can index for what we need it to do.
|
||||
const isUnsupportedPlatform: boolean = !addRequiredOptions[provider];
|
||||
|
||||
if (isUnsupportedPlatform) {
|
||||
|
@ -141,9 +140,8 @@ export async function run(
|
|||
connectionDetails = options.customParameters;
|
||||
} else if (provider == "ssh") {
|
||||
for (const argument of addRequiredOptions["ssh"]) {
|
||||
// No.
|
||||
// @ts-expect-error
|
||||
const hasArgument = options[argument] as any;
|
||||
// @ts-expect-error: No.
|
||||
const hasArgument = options[argument];
|
||||
|
||||
if (!hasArgument) {
|
||||
return println("ERROR: Missing argument '%s'\n", argument);
|
||||
|
@ -177,8 +175,7 @@ export async function run(
|
|||
connectionDetails = JSON.stringify(unstringifiedArguments);
|
||||
} else if (provider == "passyfire") {
|
||||
for (const argument of addRequiredOptions["passyfire"]) {
|
||||
// No.
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: No.
|
||||
const hasArgument = options[argument];
|
||||
|
||||
if (!hasArgument) {
|
||||
|
@ -218,7 +215,9 @@ export async function run(
|
|||
}
|
||||
|
||||
if (options.userAsk) {
|
||||
while (true) {
|
||||
let shouldContinueAsking: boolean = true;
|
||||
|
||||
while (shouldContinueAsking) {
|
||||
println("Creating a user.\nUsername: ");
|
||||
const username = await readKeyboard();
|
||||
|
||||
|
@ -247,14 +246,12 @@ export async function run(
|
|||
});
|
||||
|
||||
println("\nShould we continue creating users? (y/n) ");
|
||||
const shouldContinueAsking = (await readKeyboard())
|
||||
shouldContinueAsking = (await readKeyboard())
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.startsWith("y");
|
||||
|
||||
println("\n\n");
|
||||
|
||||
if (!shouldContinueAsking) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,6 +417,7 @@ export async function run(
|
|||
// We don't know what we're recieving. We just try to parse it (hence the any type)
|
||||
// {} is more accurate but TS yells at us if we do that :(
|
||||
|
||||
// eslint-disable-next-line
|
||||
let parsedJSONData: any | undefined;
|
||||
|
||||
try {
|
||||
|
|
|
@ -382,6 +382,8 @@ export async function run(
|
|||
if (options.tail) {
|
||||
let previousEntries: string[] = [];
|
||||
|
||||
// FIXME?
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const response = await axios.post("/api/v1/forward/connections", {
|
||||
token,
|
||||
|
@ -407,6 +409,7 @@ export async function run(
|
|||
simplifiedArray,
|
||||
previousEntries,
|
||||
);
|
||||
|
||||
const removedItems: string[] = difference(
|
||||
previousEntries,
|
||||
simplifiedArray,
|
||||
|
|
|
@ -80,8 +80,7 @@ export async function run(
|
|||
|
||||
password = passwordConfirmOne;
|
||||
} else {
|
||||
// From the first check we do, we know this is safe (you MUST specify a password)
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: From the first check we do, we know this is safe (you MUST specify a password)
|
||||
password = options.password;
|
||||
}
|
||||
|
||||
|
@ -120,7 +119,7 @@ export async function run(
|
|||
return;
|
||||
}
|
||||
|
||||
let response = await axios.post("/api/v1/users/remove", {
|
||||
const response = await axios.post("/api/v1/users/remove", {
|
||||
token: apiKey,
|
||||
uid,
|
||||
});
|
||||
|
|
|
@ -31,7 +31,7 @@ const serverBaseURL: string =
|
|||
|
||||
const axios = baseAxios.create({
|
||||
baseURL: serverBaseURL,
|
||||
validateStatus: () => true
|
||||
validateStatus: () => true,
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -70,7 +70,9 @@ const server: ssh2.Server = new ssh2.Server({
|
|||
server.on("connection", client => {
|
||||
let token: string = "";
|
||||
|
||||
// eslint-disable-next-line
|
||||
let username: string = "";
|
||||
// eslint-disable-next-line
|
||||
let password: string = "";
|
||||
|
||||
client.on("authentication", async auth => {
|
||||
|
@ -79,11 +81,11 @@ server.on("connection", client => {
|
|||
username: auth.username,
|
||||
password: auth.password,
|
||||
});
|
||||
|
||||
|
||||
if (response.status == 403) {
|
||||
return auth.reject(["password", "publickey"]);
|
||||
}
|
||||
|
||||
|
||||
token = response.data.token;
|
||||
|
||||
username = auth.username;
|
||||
|
@ -133,12 +135,12 @@ server.on("connection", client => {
|
|||
|
||||
auth.accept();
|
||||
} else {
|
||||
return auth.reject(["password", "publickey"]);
|
||||
return auth.reject(["password", "publickey"]);
|
||||
}
|
||||
});
|
||||
|
||||
client.on("ready", () => {
|
||||
client.on("session", (accept, reject) => {
|
||||
client.on("session", accept => {
|
||||
const conn = accept();
|
||||
|
||||
conn.on("exec", async (accept, reject, info) => {
|
||||
|
@ -149,32 +151,32 @@ server.on("connection", client => {
|
|||
}
|
||||
|
||||
// Matches on ; and &&
|
||||
const commandsRecv = info.command.split(/;|&&/).map((i) => i.trim());
|
||||
const commandsRecv = info.command.split(/;|&&/).map(i => i.trim());
|
||||
|
||||
function println(...data: any[]) {
|
||||
function println(...data: unknown[]) {
|
||||
stream.write(format(...data).replaceAll("\n", "\r\n"));
|
||||
};
|
||||
}
|
||||
|
||||
for (const command of commandsRecv) {
|
||||
const argv = parseArgsStringToArgv(command);
|
||||
|
||||
|
||||
if (argv[0] == "exit") {
|
||||
stream.close();
|
||||
} else {
|
||||
const command = commands.find(i => i.name == argv[0]);
|
||||
|
||||
|
||||
if (!command) {
|
||||
stream.write(
|
||||
`Unknown command ${argv[0]}.\r\n`,
|
||||
);
|
||||
stream.write(`Unknown command ${argv[0]}.\r\n`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
await command.run(argv, println, axios, token, (disableEcho) => readFromKeyboard(stream, disableEcho));
|
||||
|
||||
await command.run(argv, println, axios, token, disableEcho =>
|
||||
readFromKeyboard(stream, disableEcho),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return stream.close();
|
||||
});
|
||||
|
||||
|
@ -191,26 +193,28 @@ server.on("connection", client => {
|
|||
"Welcome to NextNet LOM. Run 'help' to see commands.\r\n\r\n~$ ",
|
||||
);
|
||||
|
||||
function println(...data: any[]) {
|
||||
function println(...data: unknown[]) {
|
||||
stream.write(format(...data).replaceAll("\n", "\r\n"));
|
||||
};
|
||||
}
|
||||
|
||||
// FIXME (greysoh): wtf? this isn't setting correctly.
|
||||
// @eslint-disable-next-line
|
||||
while (true) {
|
||||
const line = await readFromKeyboard(stream);
|
||||
stream.write("\r\n");
|
||||
|
||||
|
||||
if (line == "") {
|
||||
stream.write(`~$ `);
|
||||
continue;
|
||||
}
|
||||
|
||||
const argv = parseArgsStringToArgv(line);
|
||||
|
||||
|
||||
if (argv[0] == "exit") {
|
||||
stream.close();
|
||||
} else {
|
||||
const command = commands.find(i => i.name == argv[0]);
|
||||
|
||||
|
||||
if (!command) {
|
||||
stream.write(
|
||||
`Unknown command ${argv[0]}. Run 'help' to see commands.\r\n~$ `,
|
||||
|
@ -218,8 +222,10 @@ server.on("connection", client => {
|
|||
|
||||
continue;
|
||||
}
|
||||
|
||||
await command.run(argv, println, axios, token, (disableEcho) => readFromKeyboard(stream, disableEcho));
|
||||
|
||||
await command.run(argv, println, axios, token, disableEcho =>
|
||||
readFromKeyboard(stream, disableEcho),
|
||||
);
|
||||
stream.write("~$ ");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ export class SSHCommand extends Command {
|
|||
hasRecievedExitSignal: boolean;
|
||||
println: PrintLine;
|
||||
|
||||
exitEventHandlers: ((...any: any[]) => void)[];
|
||||
exitEventHandlers: ((...any: unknown[]) => void)[];
|
||||
parent: SSHCommand | null;
|
||||
|
||||
/**
|
||||
|
@ -81,11 +81,11 @@ export class SSHCommand extends Command {
|
|||
action(fn: (...args: any[]) => void | Promise<void>): this {
|
||||
super.action(fn);
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: This parameter is private, but we need control over it.
|
||||
// prettier-ignore
|
||||
const oldActionHandler: (...args: any[]) => void | Promise<void> = this._actionHandler;
|
||||
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Overriding private parameters (but this works)
|
||||
this._actionHandler = async (...args: any[]): Promise<void> => {
|
||||
if (this.hasRecievedExitSignal) return;
|
||||
await oldActionHandler(...args);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue