mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
refactor creating ".ssh" directoy
This commit is contained in:
parent
37d0a89301
commit
a94b58995c
2 changed files with 37 additions and 20 deletions
28
lib/index.js
28
lib/index.js
|
@ -601,15 +601,10 @@ function main() {
|
|||
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,
|
||||
});
|
||||
const sshDirName = createSshDirectory();
|
||||
// files to be created
|
||||
const files = [];
|
||||
if (shouldCreateKeyFile(path__WEBPACK_IMPORTED_MODULE_1___default().join(dirName, name), ifKeyExists)) {
|
||||
if (shouldCreateKeyFile(path__WEBPACK_IMPORTED_MODULE_1___default().join(sshDirName, name), ifKeyExists)) {
|
||||
files.push({
|
||||
name: name,
|
||||
contents: insertLf(key, false, true),
|
||||
|
@ -641,14 +636,27 @@ function main() {
|
|||
}
|
||||
// create files
|
||||
for (const file of files) {
|
||||
const fileName = path__WEBPACK_IMPORTED_MODULE_1___default().join(dirName, file.name);
|
||||
const fileName = path__WEBPACK_IMPORTED_MODULE_1___default().join(sshDirName, file.name);
|
||||
fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(fileName, file.contents, file.options);
|
||||
}
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
console.log(`SSH key has been stored to ${sshDirName} successfully.`);
|
||||
}
|
||||
/**
|
||||
* create ".ssh" directory
|
||||
* @returns directory name
|
||||
*/
|
||||
function createSshDirectory() {
|
||||
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,
|
||||
});
|
||||
return dirName;
|
||||
}
|
||||
/**
|
||||
* get home directory
|
||||
* @returns home directory
|
||||
* @returns home directory name
|
||||
*/
|
||||
function getHomeDirectory() {
|
||||
const homeEnv = getHomeEnv();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue