1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Allow Harbormaster HTTP steps to pass credentials

Summary: Fixes T4590. Use the credentials custom field to allow Harbormaster HTTP requests to include usernames/passwords.

Test Plan: Ran a build plan with credentials, verified they were sent to the remote server.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4590

Differential Revision: https://secure.phabricator.com/D8786
This commit is contained in:
epriestley 2014-04-16 13:01:38 -07:00
parent c402d7d307
commit 803c50c1e7

View file

@ -18,16 +18,27 @@ final class HarbormasterHTTPRequestBuildStepImplementation
$domain = id(new PhutilURI($uri))->getDomain(); $domain = id(new PhutilURI($uri))->getDomain();
} }
return pht( $method = $this->formatSettingForDescription('method', 'POST');
'Make an HTTP %s request to %s.', $domain = $this->formatValueForDescription($domain);
$this->formatSettingForDescription('method', 'POST'),
$this->formatValueForDescription($domain)); if ($this->getSetting('credential')) {
return pht(
'Make an authenticated HTTP %s request to %s.',
$method,
$domain);
} else {
return pht(
'Make an HTTP %s request to %s.',
$method,
$domain);
}
} }
public function execute( public function execute(
HarbormasterBuild $build, HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) { HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
$settings = $this->getSettings(); $settings = $this->getSettings();
$variables = $build_target->getVariables(); $variables = $build_target->getVariables();
@ -41,10 +52,21 @@ final class HarbormasterHTTPRequestBuildStepImplementation
$method = nonempty(idx($settings, 'method'), 'POST'); $method = nonempty(idx($settings, 'method'), 'POST');
list($status, $body, $headers) = id(new HTTPSFuture($uri)) $future = id(new HTTPSFuture($uri))
->setMethod($method) ->setMethod($method)
->setTimeout(60) ->setTimeout(60);
->resolve();
$credential_phid = $this->getSetting('credential');
if ($credential_phid) {
$key = PassphrasePasswordKey::loadFromPHID(
$credential_phid,
$viewer);
$future->setHTTPBasicAuthCredentials(
$key->getUsernameEnvelope()->openEnvelope(),
$key->getPasswordEnvelope());
}
list($status, $body, $headers) = $future->resolve();
$log_body->append($body); $log_body->append($body);
$log_body->finalize($start); $log_body->finalize($start);
@ -66,6 +88,14 @@ final class HarbormasterHTTPRequestBuildStepImplementation
'type' => 'select', 'type' => 'select',
'options' => array_fuse(array('POST', 'GET', 'PUT', 'DELETE')), 'options' => array_fuse(array('POST', 'GET', 'PUT', 'DELETE')),
), ),
'credential' => array(
'name' => pht('Credentials'),
'type' => 'credential',
'credential.type'
=> PassphraseCredentialTypePassword::CREDENTIAL_TYPE,
'credential.provides'
=> PassphraseCredentialTypePassword::PROVIDES_TYPE,
),
); );
} }