-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johan
committed
Sep 27, 2019
1 parent
b7da675
commit 28b66f0
Showing
9 changed files
with
167 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { command } from "../../../types/Command"; | ||
|
||
const description = "Config commands"; | ||
|
||
export default command({ description }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
ConfigCreationData, | ||
empty | ||
} from "../../../../types/ConfigCreationData"; | ||
import { command } from "../../../../types/Command"; | ||
import { prompt } from "../../../ssh/config"; | ||
|
||
const description = "Creates new SSH configuration"; | ||
|
||
const hint = "<hostName> <userName> <keyFile> <passPhrase> <addToAgent>"; | ||
|
||
const run = (...args: string[]): void => { | ||
// const data: ConfigCreationData = { ...empty, ...args }; | ||
const [ | ||
host, | ||
userName, | ||
privateKey, | ||
passPhrase, | ||
addKeyToAgent, | ||
createKeyFile | ||
] = args; | ||
|
||
const initialValues: ConfigCreationData = { | ||
...empty, | ||
...{ | ||
host, | ||
userName, | ||
privateKey, | ||
passPhrase, | ||
addKeyToAgent: addKeyToAgent === "true", | ||
createKeyFile: createKeyFile === "true" | ||
} | ||
}; | ||
|
||
prompt(initialValues).then(data => { | ||
console.log(data); | ||
}); | ||
}; | ||
|
||
export default command({ description, hint, run }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { command } from "../../../../types/Command"; | ||
|
||
const description = "SSH Config commands"; | ||
|
||
export default command({ description }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import chalk from "chalk"; | ||
import flexi from "flexi-path"; | ||
|
||
import config, { SshConfig } from "../../../ssh/config"; | ||
import { command } from "../../../../types/Command"; | ||
|
||
interface ConfigOptions extends SshConfig { | ||
keyFileExists: boolean; | ||
keyFileAddedToAgent: boolean; | ||
} | ||
|
||
const description = "Displays current SSH configuration"; | ||
|
||
const run = (): void => { | ||
const currentConfig = config.get(); | ||
|
||
if (currentConfig === null) { | ||
console.log(chalk.red("SSH configuration does not exist")); | ||
return; | ||
} | ||
|
||
const keyFileExists = flexi.exists(currentConfig.privateKey); | ||
const keyFileAddedToAgent = false; | ||
|
||
const result: ConfigOptions = { | ||
...currentConfig, | ||
...{ keyFileExists, keyFileAddedToAgent } | ||
}; | ||
console.log(JSON.stringify(result, null, 2)); | ||
}; | ||
|
||
export default command({ description, run }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
import { SshConfig } from "."; | ||
import flexi from "flexi-path"; | ||
import { homedir } from "os"; | ||
import sshConfig, { SshConfig } from "./SshConfig"; | ||
|
||
export default interface ConfigCreationData extends SshConfig { | ||
export interface ConfigCreationData extends SshConfig { | ||
passPhrase: string; | ||
createKeyFile: boolean; | ||
addKeyToAgent: boolean; | ||
} | ||
|
||
export const empty = (): ConfigCreationData => ({ | ||
...sshConfig.empty, | ||
...{ | ||
passPhrase: "", | ||
createKeyFile: false, | ||
addKeyToAgent: false | ||
} | ||
}); | ||
|
||
export const defaults: ConfigCreationData = { | ||
host: "192.168.1.1", | ||
userName: "admin", | ||
privateKey: flexi.path(homedir()).append(".ssh/id_rsa").path, | ||
passPhrase: "", | ||
createKeyFile: true, | ||
addKeyToAgent: true | ||
}; | ||
|
||
export default { | ||
defaults, | ||
empty | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters