mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +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:
parent
c402d7d307
commit
803c50c1e7
1 changed files with 37 additions and 7 deletions
|
@ -18,16 +18,27 @@ final class HarbormasterHTTPRequestBuildStepImplementation
|
|||
$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();
|
||||
|
||||
|
@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue