mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
Feature/append config known hosts (#47)
* * append to "config" and "known_hosts" instead of overwriting * * refactor options * * add test * * fix test * * print created files twice * * print the contents of known_hosts and config * * fix revision for test * * fix revision * * add LF to known_hosts / config * * append LF to config and known_hosts * * fix test * * reject overwriting private-key and public-key * * update test (will cause error) * * revert verify.yml * * update README and CHANGELOG * * fix example in README * * update CHANGELOG
This commit is contained in:
parent
3e015c8816
commit
0374d240c3
5 changed files with 85 additions and 20 deletions
30
src/main.ts
30
src/main.ts
|
@ -6,8 +6,8 @@ import * as core from "@actions/core";
|
|||
interface FileInfo
|
||||
{
|
||||
name: string;
|
||||
mode: number;
|
||||
contents: string;
|
||||
options: fs.WriteFileOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,23 +21,35 @@ function main(): void
|
|||
const files: FileInfo[] = [
|
||||
{
|
||||
name: name,
|
||||
mode: 0o400,
|
||||
contents: core.getInput("private-key"),
|
||||
options: {
|
||||
mode: 0o400,
|
||||
flag: "ax",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: `${name}.pub`,
|
||||
mode: 0o444,
|
||||
contents: core.getInput("public-key"),
|
||||
options: {
|
||||
mode: 0o444,
|
||||
flag: "ax",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "known_hosts",
|
||||
mode: 0o644,
|
||||
contents: core.getInput("known-hosts"),
|
||||
contents: core.getInput("known-hosts") + "\n",
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "config",
|
||||
mode: 0o644,
|
||||
contents: core.getInput("config"),
|
||||
contents: core.getInput("config") + "\n",
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -53,9 +65,7 @@ function main(): void
|
|||
for(const file of files)
|
||||
{
|
||||
const fileName = path.join(dirName, file.name);
|
||||
fs.writeFileSync(fileName, file.contents, {
|
||||
mode: file.mode,
|
||||
});
|
||||
fs.writeFileSync(fileName, file.contents, file.options);
|
||||
}
|
||||
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue