mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
adding "keep_ssh_dir" option
This commit is contained in:
parent
f5671c022c
commit
d6eeb85df6
2 changed files with 33 additions and 3 deletions
|
@ -25,6 +25,10 @@ inputs:
|
|||
description: "replace / ignore / fail"
|
||||
required: false
|
||||
default: "fail"
|
||||
keep_ssh_dir:
|
||||
description: "Set true if you DO NOT want to remove .ssh directory"
|
||||
required: false
|
||||
default: ""
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "lib/index.js"
|
||||
|
|
32
src/main.ts
32
src/main.ts
|
@ -111,10 +111,14 @@ function setup(): void {
|
|||
* cleanup function
|
||||
*/
|
||||
function cleanup(): void {
|
||||
// remove ".ssh" directory
|
||||
const sshDirName = removeSshDirectory();
|
||||
if (shouldRemoveSshDirectory()) {
|
||||
// remove ".ssh" directory
|
||||
const sshDirName = removeSshDirectory();
|
||||
|
||||
console.log(`SSH key in ${sshDirName} has been removed successfully.`);
|
||||
console.log(`SSH key in ${sshDirName} has been removed successfully.`);
|
||||
} else {
|
||||
console.log(`Skip directory deletion.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,6 +240,28 @@ function shouldCreateKeyFile(keyFilePath: string, ifKeyExists: string): boolean
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* should remove SSH directory?
|
||||
* @returns Yes/No
|
||||
*/
|
||||
function shouldRemoveSshDirectory(): boolean {
|
||||
const keepsSshDir = core.getInput("keep_ssh_dir", {
|
||||
required: true,
|
||||
});
|
||||
|
||||
// empty string or falsy value in YAML
|
||||
switch (keepsSshDir.toLowerCase()) {
|
||||
case "":
|
||||
case "false":
|
||||
case "no":
|
||||
case "off":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* build array of known_hosts
|
||||
* @param knownHosts known_hosts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue