From 5f5991acde8129cdbc68241e23f8507ce2caf776 Mon Sep 17 00:00:00 2001 From: shimataro Date: Thu, 3 Nov 2022 01:45:06 +0900 Subject: [PATCH] always prepend key of github.com --- .eslintrc.yml | 10 ++++++++-- lib/index.js | 35 ++++++++++++++++++++++++----------- src/main.ts | 37 ++++++++++++++++++++++++++----------- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 59697b3..c4a349d 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -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 diff --git a/lib/index.js b/lib/index.js index 8eebbb2..54a1263 100644 --- a/lib/index.js +++ b/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); +} /***/ }), diff --git a/src/main.ts b/src/main.ts index 1dbc3df..34a4536 100644 --- a/src/main.ts +++ b/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); +}