mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
Feature/known_hosts (#25)
* * add "known-hosts" option * * update CHANGELOG * * update README * * update actions.yml * * update example of known-hosts * * fix message
This commit is contained in:
parent
b9c6c52737
commit
3d8365bb3a
6 changed files with 75 additions and 25 deletions
38
lib/main.js
38
lib/main.js
|
@ -15,23 +15,39 @@ const core = __importStar(require("@actions/core"));
|
|||
*/
|
||||
function main() {
|
||||
try {
|
||||
const name = core.getInput("name");
|
||||
const files = [
|
||||
{
|
||||
name: name,
|
||||
mode: 0o400,
|
||||
contents: core.getInput("private-key"),
|
||||
},
|
||||
{
|
||||
name: `${name}.pub`,
|
||||
mode: 0o444,
|
||||
contents: core.getInput("public-key"),
|
||||
},
|
||||
{
|
||||
name: "known_hosts",
|
||||
mode: 0o644,
|
||||
contents: core.getInput("known-hosts"),
|
||||
},
|
||||
];
|
||||
// create ".ssh" directory
|
||||
const home = getHomeDirectory();
|
||||
const dirName = path.resolve(home, ".ssh");
|
||||
fs.mkdirSync(dirName, {
|
||||
recursive: true,
|
||||
mode: 0o700,
|
||||
});
|
||||
const privateKey = core.getInput("private-key");
|
||||
const publicKey = core.getInput("public-key");
|
||||
const name = core.getInput("name");
|
||||
const fileName = path.join(dirName, name);
|
||||
fs.writeFileSync(fileName, privateKey, {
|
||||
mode: 0o400,
|
||||
});
|
||||
fs.writeFileSync(`${fileName}.pub`, publicKey, {
|
||||
mode: 0o444,
|
||||
});
|
||||
console.log(`SSH key has been stored to ${fileName} successfully.`);
|
||||
// create files
|
||||
for (const file of files) {
|
||||
const fileName = path.join(dirName, file.name);
|
||||
fs.writeFileSync(fileName, file.contents, {
|
||||
mode: file.mode,
|
||||
});
|
||||
}
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
}
|
||||
catch (err) {
|
||||
core.setFailed(err.message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue