1
0
Fork 0
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:
shimataro 2022-11-03 01:45:06 +09:00
parent bcb314ec07
commit 5f5991acde
No known key found for this signature in database
GPG key ID: BE92C05736911A9D
3 changed files with 58 additions and 24 deletions

View file

@ -14,7 +14,9 @@ parserOptions:
project: ./tsconfig.json project: ./tsconfig.json
rules: # https://eslint.org/docs/rules/ rules: # https://eslint.org/docs/rules/
accessor-pairs: error accessor-pairs: error
array-bracket-newline: error array-bracket-newline:
- error
- consistent
array-bracket-spacing: array-bracket-spacing:
- error - error
- never - never
@ -311,4 +313,8 @@ rules: # https://eslint.org/docs/rules/
- error - error
- functions: false - functions: false
"@typescript-eslint/semi": error "@typescript-eslint/semi": error
"@typescript-eslint/strict-boolean-expressions": error "@typescript-eslint/strict-boolean-expressions":
- error
- allowString: false
allowNumber: false
allowNullableObject: false

View file

@ -2723,6 +2723,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const fs_1 = __importDefault(__nccwpck_require__(147)); const fs_1 = __importDefault(__nccwpck_require__(147));
const path_1 = __importDefault(__nccwpck_require__(17)); const path_1 = __importDefault(__nccwpck_require__(17));
const core = __importStar(__nccwpck_require__(186)); const core = __importStar(__nccwpck_require__(186));
const KNOWN_HOSTS = [
"github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==",
];
try { try {
main(); main();
} }
@ -2748,7 +2751,16 @@ function main() {
// create ".ssh" directory // create ".ssh" directory
const sshDirName = createSshDirectory(); const sshDirName = createSshDirectory();
// files to be created // 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)) { if (shouldCreateKeyFile(path_1.default.join(sshDirName, name), ifKeyExists)) {
files.push({ files.push({
name: name, 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 !== "") { if (config !== "") {
files.push({ files.push({
name: "config", 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.`); 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);
}
/***/ }), /***/ }),

View file

@ -9,6 +9,10 @@ interface FileInfo {
options: fs.WriteFileOptions; options: fs.WriteFileOptions;
} }
const KNOWN_HOSTS = [
"github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==",
];
try { try {
main(); main();
} catch (err) { } catch (err) {
@ -36,7 +40,16 @@ function main(): void {
const sshDirName = createSshDirectory(); const sshDirName = createSshDirectory();
// files to be created // 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)) { if (shouldCreateKeyFile(path.join(sshDirName, name), ifKeyExists)) {
files.push({ files.push({
name: name, 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 !== "") { if (config !== "") {
files.push({ files.push({
name: "config", 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.`); 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);
}