Skip to content

Commit

Permalink
Allow Harbormaster HTTP steps to pass credentials
Browse files Browse the repository at this point in the history
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
  • Loading branch information
epriestley committed Apr 16, 2014
1 parent c402d7d commit 803c50c
Showing 1 changed file with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@ public function getDescription() {
$domain = id(new PhutilURI($uri))->getDomain();
}

return pht(
'Make an HTTP %s request to %s.',
$this->formatSettingForDescription('method', 'POST'),
$this->formatValueForDescription($domain));
$method = $this->formatSettingForDescription('method', 'POST');
$domain = $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(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {

$viewer = PhabricatorUser::getOmnipotentUser();
$settings = $this->getSettings();
$variables = $build_target->getVariables();

Expand All @@ -41,10 +52,21 @@ public function execute(

$method = nonempty(idx($settings, 'method'), 'POST');

list($status, $body, $headers) = id(new HTTPSFuture($uri))
$future = id(new HTTPSFuture($uri))
->setMethod($method)
->setTimeout(60)
->resolve();
->setTimeout(60);

$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->finalize($start);
Expand All @@ -66,6 +88,14 @@ public function getFieldSpecifications() {
'type' => 'select',
'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,
),
);
}

Expand Down

0 comments on commit 803c50c

Please sign in to comment.