Path: blob/master/src/applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php
12256 views
<?php12final class HarbormasterHTTPRequestBuildStepImplementation3extends HarbormasterBuildStepImplementation {45public function getName() {6return pht('Make HTTP Request');7}89public function getGenericDescription() {10return pht('Make an HTTP request.');11}1213public function getBuildStepGroupKey() {14return HarbormasterExternalBuildStepGroup::GROUPKEY;15}1617public function getDescription() {18$domain = null;19$uri = $this->getSetting('uri');20if ($uri) {21$domain = id(new PhutilURI($uri))->getDomain();22}2324$method = $this->formatSettingForDescription('method', 'POST');25$domain = $this->formatValueForDescription($domain);2627if ($this->getSetting('credential')) {28return pht(29'Make an authenticated HTTP %s request to %s.',30$method,31$domain);32} else {33return pht(34'Make an HTTP %s request to %s.',35$method,36$domain);37}38}3940public function execute(41HarbormasterBuild $build,42HarbormasterBuildTarget $build_target) {4344$viewer = PhabricatorUser::getOmnipotentUser();4546if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {47$this->logSilencedCall($build, $build_target, pht('HTTP Request'));48throw new HarbormasterBuildFailureException();49}5051$settings = $this->getSettings();52$variables = $build_target->getVariables();5354$uri = $this->mergeVariables(55'vurisprintf',56$settings['uri'],57$variables);5859$method = nonempty(idx($settings, 'method'), 'POST');6061$future = id(new HTTPSFuture($uri))62->setMethod($method)63->setTimeout(60);6465$credential_phid = $this->getSetting('credential');66if ($credential_phid) {67$key = PassphrasePasswordKey::loadFromPHID(68$credential_phid,69$viewer);70$future->setHTTPBasicAuthCredentials(71$key->getUsernameEnvelope()->openEnvelope(),72$key->getPasswordEnvelope());73}7475$this->resolveFutures(76$build,77$build_target,78array($future));7980$this->logHTTPResponse($build, $build_target, $future, $uri);8182list($status) = $future->resolve();83if ($status->isError()) {84throw new HarbormasterBuildFailureException();85}86}8788public function getFieldSpecifications() {89return array(90'uri' => array(91'name' => pht('URI'),92'type' => 'text',93'required' => true,94),95'method' => array(96'name' => pht('HTTP Method'),97'type' => 'select',98'options' => array_fuse(array('POST', 'GET', 'PUT', 'DELETE')),99),100'credential' => array(101'name' => pht('Credentials'),102'type' => 'credential',103'credential.type'104=> PassphrasePasswordCredentialType::CREDENTIAL_TYPE,105'credential.provides'106=> PassphrasePasswordCredentialType::PROVIDES_TYPE,107),108);109}110111public function supportsWaitForMessage() {112return true;113}114115}116117118