1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +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();
}
$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.',
$this->formatSettingForDescription('method', 'POST'),
$this->formatValueForDescription($domain));
$method,
$domain);
}
}
public function execute(
HarbormasterBuild $build,
HarbormasterBuildTarget $build_target) {
$viewer = PhabricatorUser::getOmnipotentUser();
$settings = $this->getSettings();
$variables = $build_target->getVariables();
@ -41,10 +52,21 @@ final class HarbormasterHTTPRequestBuildStepImplementation
$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);
@ -66,6 +88,14 @@ final class HarbormasterHTTPRequestBuildStepImplementation
'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,
),
);
}