mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
Change code style to 1TBS
This commit is contained in:
parent
b38d88da8a
commit
37d0a89301
4 changed files with 186 additions and 207 deletions
118
lib/index.js
118
lib/index.js
|
@ -590,66 +590,61 @@ __nccwpck_require__.r(__webpack_exports__);
|
|||
* main function
|
||||
*/
|
||||
function main() {
|
||||
try {
|
||||
// parameters
|
||||
const key = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("key", {
|
||||
required: true,
|
||||
// parameters
|
||||
const key = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("key", {
|
||||
required: true,
|
||||
});
|
||||
const name = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("name");
|
||||
const knownHosts = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("known_hosts", {
|
||||
required: true,
|
||||
});
|
||||
const config = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("config");
|
||||
const ifKeyExists = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("if_key_exists");
|
||||
// create ".ssh" directory
|
||||
const home = getHomeDirectory();
|
||||
const dirName = path__WEBPACK_IMPORTED_MODULE_1___default().resolve(home, ".ssh");
|
||||
fs__WEBPACK_IMPORTED_MODULE_0___default().mkdirSync(dirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
// files to be created
|
||||
const files = [];
|
||||
if (shouldCreateKeyFile(path__WEBPACK_IMPORTED_MODULE_1___default().join(dirName, name), ifKeyExists)) {
|
||||
files.push({
|
||||
name: name,
|
||||
contents: insertLf(key, false, true),
|
||||
options: {
|
||||
mode: 0o400,
|
||||
flag: "wx",
|
||||
},
|
||||
});
|
||||
const name = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("name");
|
||||
const knownHosts = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("known_hosts", {
|
||||
required: true,
|
||||
});
|
||||
const config = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("config");
|
||||
const ifKeyExists = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("if_key_exists");
|
||||
// create ".ssh" directory
|
||||
const home = getHomeDirectory();
|
||||
const dirName = path__WEBPACK_IMPORTED_MODULE_1___default().resolve(home, ".ssh");
|
||||
fs__WEBPACK_IMPORTED_MODULE_0___default().mkdirSync(dirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
// files to be created
|
||||
const files = [];
|
||||
if (shouldCreateKeyFile(path__WEBPACK_IMPORTED_MODULE_1___default().join(dirName, name), ifKeyExists)) {
|
||||
files.push({
|
||||
name: name,
|
||||
contents: insertLf(key, false, true),
|
||||
options: {
|
||||
mode: 0o400,
|
||||
flag: "wx",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (knownHosts !== "unnecessary") {
|
||||
files.push({
|
||||
name: "known_hosts",
|
||||
contents: insertLf(knownHosts, true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (config !== "") {
|
||||
files.push({
|
||||
name: "config",
|
||||
contents: insertLf(config, true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
});
|
||||
}
|
||||
// create files
|
||||
for (const file of files) {
|
||||
const fileName = path__WEBPACK_IMPORTED_MODULE_1___default().join(dirName, file.name);
|
||||
fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(fileName, file.contents, file.options);
|
||||
}
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
}
|
||||
catch (err) {
|
||||
_actions_core__WEBPACK_IMPORTED_MODULE_2__.setFailed(err.message);
|
||||
if (knownHosts !== "unnecessary") {
|
||||
files.push({
|
||||
name: "known_hosts",
|
||||
contents: insertLf(knownHosts, true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (config !== "") {
|
||||
files.push({
|
||||
name: "config",
|
||||
contents: insertLf(config, true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
});
|
||||
}
|
||||
// create files
|
||||
for (const file of files) {
|
||||
const fileName = path__WEBPACK_IMPORTED_MODULE_1___default().join(dirName, file.name);
|
||||
fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(fileName, file.contents, file.options);
|
||||
}
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
}
|
||||
/**
|
||||
* get home directory
|
||||
|
@ -724,7 +719,14 @@ function shouldCreateKeyFile(keyFilePath, ifKeyExists) {
|
|||
throw new Error(`SSH key is already installed. Set "if_key_exists" to "replace" or "ignore" in order to avoid this error.`);
|
||||
}
|
||||
}
|
||||
main();
|
||||
try {
|
||||
main();
|
||||
}
|
||||
catch (err) {
|
||||
if (err instanceof Error) {
|
||||
_actions_core__WEBPACK_IMPORTED_MODULE_2__.setFailed(err);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue