mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-04 11:51:02 +01:00
51fb1ca16d
Summary: Fixes T4122. Ref T2230. Instead of storing credentials on each repository, store them in Passphrase. This allows easy creation/management of many repositories which share credentials. Test Plan: - Upgraded repositories. - Created and edited repositories. - Pulled HTTP and SSH repositories. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2230, T4122 Differential Revision: https://secure.phabricator.com/D7629
57 lines
1.4 KiB
PHP
Executable file
57 lines
1.4 KiB
PHP
Executable file
#!/usr/bin/env php
|
|
<?php
|
|
|
|
// This is a wrapper script for Git, Mercurial, and Subversion. It primarily
|
|
// serves to inject "-o StrictHostKeyChecking=no" into the SSH arguments.
|
|
|
|
$root = dirname(dirname(dirname(__FILE__)));
|
|
require_once $root.'/scripts/__init_script__.php';
|
|
|
|
$target_name = getenv('PHABRICATOR_SSH_TARGET');
|
|
if (!$target_name) {
|
|
throw new Exception(pht("No 'PHABRICATOR_SSH_TARGET' in environment!"));
|
|
}
|
|
|
|
$viewer = PhabricatorUser::getOmnipotentUser();
|
|
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
|
->setViewer($viewer)
|
|
->withCallsigns(array($target_name))
|
|
->executeOne();
|
|
if (!$repository) {
|
|
throw new Exception(pht('No repository with callsign "%s"!', $target_name));
|
|
}
|
|
|
|
$pattern = array();
|
|
$arguments = array();
|
|
|
|
$pattern[] = 'ssh';
|
|
|
|
$pattern[] = '-o';
|
|
$pattern[] = 'StrictHostKeyChecking=no';
|
|
|
|
$credential_phid = $repository->getCredentialPHID();
|
|
if ($credential_phid) {
|
|
$key = PassphraseSSHKey::loadFromPHID($credential_phid, $viewer);
|
|
|
|
$pattern[] = '-l %P';
|
|
$arguments[] = $key->getUsernameEnvelope();
|
|
$pattern[] = '-i %P';
|
|
$arguments[] = $key->getKeyfileEnvelope();
|
|
}
|
|
|
|
$pattern[] = '--';
|
|
|
|
$passthru_args = array_slice($argv, 1);
|
|
foreach ($passthru_args as $passthru_arg) {
|
|
$pattern[] = '%s';
|
|
$arguments[] = $passthru_arg;
|
|
}
|
|
|
|
$pattern = implode(' ', $pattern);
|
|
array_unshift($arguments, $pattern);
|
|
|
|
$err = newv('PhutilExecPassthru', $arguments)
|
|
->execute();
|
|
|
|
exit($err);
|