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
48
src/main.ts
48
src/main.ts
|
@ -3,6 +3,13 @@ import * as path from "path";
|
|||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
interface FileInfo
|
||||
{
|
||||
name: string;
|
||||
mode: number;
|
||||
contents: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* main function
|
||||
*/
|
||||
|
@ -10,6 +17,26 @@ function main(): void
|
|||
{
|
||||
try
|
||||
{
|
||||
const name = core.getInput("name") as string;
|
||||
const files: FileInfo[] = [
|
||||
{
|
||||
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, {
|
||||
|
@ -17,19 +44,16 @@ function main(): void
|
|||
mode: 0o700,
|
||||
});
|
||||
|
||||
const privateKey = core.getInput("private-key") as string;
|
||||
const publicKey = core.getInput("public-key") as string;
|
||||
const name = core.getInput("name") as string;
|
||||
// create files
|
||||
for(const file of files)
|
||||
{
|
||||
const fileName = path.join(dirName, file.name);
|
||||
fs.writeFileSync(fileName, file.contents, {
|
||||
mode: file.mode,
|
||||
});
|
||||
}
|
||||
|
||||
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.`);
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue