@eightshone/sshman
Version:
A simple cli ssh manager
27 lines • 930 B
JavaScript
import { homedir } from "os";
import { CONNECTION_REGEX } from "./consts.js";
function parseConnectionString(connectionString) {
const match = connectionString.match(CONNECTION_REGEX);
const sshConfig = {
name: `auto-save-${match[1]}@${match[3]}`,
username: match[1],
usePassword: match[2] ? true : false,
host: match[3],
port: match[4] ? parseInt(match[4], 10) : 22,
};
if (sshConfig.usePassword) {
sshConfig.password = match[2];
}
else if (sshConfig.usePassword === false) {
// had to do this because of typescript
sshConfig.privateKey = `${homedir()}/.ssh/id_rsa`;
}
if (match) {
return sshConfig;
}
else {
throw new Error("Invalid connection string format. Expected format: username[:password]@server[:port]");
}
}
export default parseConnectionString;
//# sourceMappingURL=parseConnectionString.js.map