mirror of
https://github.com/webfactory/ssh-agent.git
synced 2024-11-22 01:00:50 +00:00
[regex] made comment regex more permissive
This commit is contained in:
parent
dc588b651f
commit
d5393dd488
1 changed files with 14 additions and 13 deletions
23
dist/index.js
vendored
23
dist/index.js
vendored
|
@ -390,32 +390,33 @@ try {
|
||||||
console.log('Configuring deployment key(s)');
|
console.log('Configuring deployment key(s)');
|
||||||
|
|
||||||
child_process.execFileSync(sshAddCmd, ['-L']).toString().trim().split(/\r?\n/).forEach(function(key) {
|
child_process.execFileSync(sshAddCmd, ['-L']).toString().trim().split(/\r?\n/).forEach(function(key) {
|
||||||
const parts = key.match(/\bgithub\.com[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
|
const parts = key.match(/\b([_.a-z0-9-]+)[:/]([_.a-z0-9-]+\/[_.a-z0-9-]+)/i);
|
||||||
|
|
||||||
if (!parts) {
|
if (!parts) {
|
||||||
if (logPublicKey) {
|
if (logPublicKey) {
|
||||||
console.log(`Comment for (public) key '${key}' does not match GitHub URL pattern. Not treating it as a GitHub deploy key.`);
|
console.log(`Comment for (public) key '${key}' does not match ${url} pattern. Not treating it as a deploy key.`);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sha256 = crypto.createHash('sha256').update(key).digest('hex');
|
const sha256 = crypto.createHash('sha256').update(key).digest('hex');
|
||||||
const ownerAndRepo = parts[1].replace(/\.git$/, '');
|
const url = parts[1]
|
||||||
|
const ownerAndRepo = parts[2].replace(/\.git$/, '');
|
||||||
|
|
||||||
fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });
|
fs.writeFileSync(`${homeSsh}/key-${sha256}`, key + "\n", { mode: '600' });
|
||||||
|
|
||||||
child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "https://github.com/${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --replace-all url."git@key-${sha256}.${url}:${ownerAndRepo}".insteadOf "https://${url}/${ownerAndRepo}"`);
|
||||||
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "git@github.com:${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.${url}:${ownerAndRepo}".insteadOf "git@${url}:${ownerAndRepo}"`);
|
||||||
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.github.com:${ownerAndRepo}".insteadOf "ssh://git@github.com/${ownerAndRepo}"`);
|
child_process.execSync(`${gitCmd} config --global --add url."git@key-${sha256}.${url}:${ownerAndRepo}".insteadOf "ssh://git@${url}/${ownerAndRepo}"`);
|
||||||
|
|
||||||
const sshConfig = `\nHost key-${sha256}.github.com\n`
|
const sshConfig = `\nHost key-${sha256}.${url}\n`
|
||||||
+ ` HostName github.com\n`
|
+ ` HostName ${url}\n`
|
||||||
+ ` IdentityFile ${homeSsh}/key-${sha256}\n`
|
+ ` IdentityFile ${homeSsh}/key-${sha256}\n`
|
||||||
+ ` IdentitiesOnly yes\n`;
|
+ ` IdentitiesOnly yes\n`;
|
||||||
|
|
||||||
fs.appendFileSync(`${homeSsh}/config`, sshConfig);
|
fs.appendFileSync(`${homeSsh}/config`, sshConfig);
|
||||||
|
|
||||||
console.log(`Added deploy-key mapping: Use identity '${homeSsh}/key-${sha256}' for GitHub repository ${ownerAndRepo}`);
|
console.log(`Added deploy-key mapping: Use identity '${homeSsh}/key-${sha256}' for ${url} repository ${ownerAndRepo}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Reference in a new issue