1
0
Fork 0
mirror of https://github.com/shimataro/ssh-key-action.git synced 2025-06-19 22:52:10 +10:00

* add "known-hosts" option

This commit is contained in:
shimataro 2019-09-29 12:10:04 +09:00
parent b9c6c52737
commit 51640f7b37
No known key found for this signature in database
GPG key ID: BE92C05736911A9D
4 changed files with 67 additions and 24 deletions

View file

@ -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 keys have been stored to ${dirName} successfully.`);
}
catch (err) {
core.setFailed(err.message);