mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
Feature/GitHub key (#122)
* always prepend key of github.com * update README and CHANGELOG * update tests * test to connect bitbucket.org * update test * update rest tests
This commit is contained in:
parent
bcb314ec07
commit
1512adeca4
11 changed files with 644 additions and 255 deletions
37
src/main.ts
37
src/main.ts
|
@ -9,6 +9,10 @@ interface FileInfo {
|
|||
options: fs.WriteFileOptions;
|
||||
}
|
||||
|
||||
const KNOWN_HOSTS = [
|
||||
"github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==",
|
||||
];
|
||||
|
||||
try {
|
||||
main();
|
||||
} catch (err) {
|
||||
|
@ -36,7 +40,16 @@ function main(): void {
|
|||
const sshDirName = createSshDirectory();
|
||||
|
||||
// files to be created
|
||||
const files: FileInfo[] = [];
|
||||
const files: FileInfo[] = [
|
||||
{
|
||||
name: "known_hosts",
|
||||
contents: insertLf(buildKnownHostsArray(knownHosts).join("\n"), true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
},
|
||||
];
|
||||
if (shouldCreateKeyFile(path.join(sshDirName, name), ifKeyExists)) {
|
||||
files.push({
|
||||
name: name,
|
||||
|
@ -47,16 +60,6 @@ function main(): void {
|
|||
},
|
||||
});
|
||||
}
|
||||
if (knownHosts !== "unnecessary") {
|
||||
files.push({
|
||||
name: "known_hosts",
|
||||
contents: insertLf(knownHosts, true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (config !== "") {
|
||||
files.push({
|
||||
name: "config",
|
||||
|
@ -175,3 +178,15 @@ function shouldCreateKeyFile(keyFilePath: string, ifKeyExists: string): boolean
|
|||
throw new Error(`SSH key is already installed. Set "if_key_exists" to "replace" or "ignore" in order to avoid this error.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* build array of known_hosts
|
||||
* @param knownHosts known_hosts
|
||||
* @returns array of known_hosts
|
||||
*/
|
||||
function buildKnownHostsArray(knownHosts: string): string[] {
|
||||
if (knownHosts === "unnecessary") {
|
||||
return KNOWN_HOSTS;
|
||||
}
|
||||
return KNOWN_HOSTS.concat(knownHosts);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue