Skip to content

Commit

Permalink
Jumpbox command always prompt for password and allow empty password (#…
Browse files Browse the repository at this point in the history
…3051)

* Always prompt user and allow empty password

* Bring back privateKey
  • Loading branch information
JasonLin0991 authored Jan 7, 2025
1 parent 3a80463 commit 7fc5abb
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions dev_tool/src/jumpbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ async function promptPassword(prompt: string): Promise<string> {
type: 'password',
name: 'password',
message: prompt,
validate: (value: string): boolean | string =>
value.length > 0 ? true : 'Password cannot be empty',
})

return response.password
Expand All @@ -216,32 +214,14 @@ async function attemptSSHConnection(
try {
// Read the private key file
const privateKey = readFileSync(privateKeyPath, 'utf8')
const keyPassword = await promptPassword('Enter SSH key password:')

try {
await ssh.connect({
host,
username,
privateKey,
})
} catch (err) {
if (
err instanceof Error &&
(err.message.includes('password') ||
err.message.includes('encrypted'))
) {
const keyPassword = await promptPassword(
'Enter SSH key password:'
)
await ssh.connect({
host,
username,
privateKey,
passphrase: keyPassword,
})
} else {
throw err
}
}
await ssh.connect({
host,
username,
privateKey,
passphrase: keyPassword,
})
} catch (err) {
if (err instanceof Error) {
throw new Error(`SSH connection failed: ${err.message}`)
Expand Down

0 comments on commit 7fc5abb

Please sign in to comment.