mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
always prepend key of github.com
This commit is contained in:
parent
bcb314ec07
commit
5f5991acde
3 changed files with 58 additions and 24 deletions
|
@ -14,7 +14,9 @@ parserOptions:
|
|||
project: ./tsconfig.json
|
||||
rules: # https://eslint.org/docs/rules/
|
||||
accessor-pairs: error
|
||||
array-bracket-newline: error
|
||||
array-bracket-newline:
|
||||
- error
|
||||
- consistent
|
||||
array-bracket-spacing:
|
||||
- error
|
||||
- never
|
||||
|
@ -311,4 +313,8 @@ rules: # https://eslint.org/docs/rules/
|
|||
- error
|
||||
- functions: false
|
||||
"@typescript-eslint/semi": error
|
||||
"@typescript-eslint/strict-boolean-expressions": error
|
||||
"@typescript-eslint/strict-boolean-expressions":
|
||||
- error
|
||||
- allowString: false
|
||||
allowNumber: false
|
||||
allowNullableObject: false
|
||||
|
|
35
lib/index.js
35
lib/index.js
|
@ -2723,6 +2723,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||
const fs_1 = __importDefault(__nccwpck_require__(147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(17));
|
||||
const core = __importStar(__nccwpck_require__(186));
|
||||
const KNOWN_HOSTS = [
|
||||
"github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==",
|
||||
];
|
||||
try {
|
||||
main();
|
||||
}
|
||||
|
@ -2748,7 +2751,16 @@ function main() {
|
|||
// create ".ssh" directory
|
||||
const sshDirName = createSshDirectory();
|
||||
// files to be created
|
||||
const files = [];
|
||||
const files = [
|
||||
{
|
||||
name: "known_hosts",
|
||||
contents: insertLf(buildKnownHostsArray(knownHosts).join("\n"), true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
},
|
||||
];
|
||||
if (shouldCreateKeyFile(path_1.default.join(sshDirName, name), ifKeyExists)) {
|
||||
files.push({
|
||||
name: name,
|
||||
|
@ -2759,16 +2771,6 @@ function main() {
|
|||
},
|
||||
});
|
||||
}
|
||||
if (knownHosts !== "unnecessary") {
|
||||
files.push({
|
||||
name: "known_hosts",
|
||||
contents: insertLf(knownHosts, true, true),
|
||||
options: {
|
||||
mode: 0o644,
|
||||
flag: "a",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (config !== "") {
|
||||
files.push({
|
||||
name: "config",
|
||||
|
@ -2872,6 +2874,17 @@ function shouldCreateKeyFile(keyFilePath, ifKeyExists) {
|
|||
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) {
|
||||
if (knownHosts === "unnecessary") {
|
||||
return KNOWN_HOSTS;
|
||||
}
|
||||
return KNOWN_HOSTS.concat(knownHosts);
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
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