[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class HarbormasterHTTPRequestBuildStepImplementation 4 extends HarbormasterBuildStepImplementation { 5 6 public function getName() { 7 return pht('Make HTTP Request'); 8 } 9 10 public function getGenericDescription() { 11 return pht('Make an HTTP request.'); 12 } 13 14 public function getDescription() { 15 $domain = null; 16 $uri = $this->getSetting('uri'); 17 if ($uri) { 18 $domain = id(new PhutilURI($uri))->getDomain(); 19 } 20 21 $method = $this->formatSettingForDescription('method', 'POST'); 22 $domain = $this->formatValueForDescription($domain); 23 24 if ($this->getSetting('credential')) { 25 return pht( 26 'Make an authenticated HTTP %s request to %s.', 27 $method, 28 $domain); 29 } else { 30 return pht( 31 'Make an HTTP %s request to %s.', 32 $method, 33 $domain); 34 } 35 } 36 37 public function execute( 38 HarbormasterBuild $build, 39 HarbormasterBuildTarget $build_target) { 40 41 $viewer = PhabricatorUser::getOmnipotentUser(); 42 $settings = $this->getSettings(); 43 $variables = $build_target->getVariables(); 44 45 $uri = $this->mergeVariables( 46 'vurisprintf', 47 $settings['uri'], 48 $variables); 49 50 $log_body = $build->createLog($build_target, $uri, 'http-body'); 51 $start = $log_body->start(); 52 53 $method = nonempty(idx($settings, 'method'), 'POST'); 54 55 $future = id(new HTTPSFuture($uri)) 56 ->setMethod($method) 57 ->setTimeout(60); 58 59 $credential_phid = $this->getSetting('credential'); 60 if ($credential_phid) { 61 $key = PassphrasePasswordKey::loadFromPHID( 62 $credential_phid, 63 $viewer); 64 $future->setHTTPBasicAuthCredentials( 65 $key->getUsernameEnvelope()->openEnvelope(), 66 $key->getPasswordEnvelope()); 67 } 68 69 list($status, $body, $headers) = $this->resolveFuture( 70 $build, 71 $build_target, 72 $future); 73 74 $log_body->append($body); 75 $log_body->finalize($start); 76 77 if ($status->getStatusCode() != 200) { 78 $build->setBuildStatus(HarbormasterBuild::STATUS_FAILED); 79 } 80 } 81 82 public function getFieldSpecifications() { 83 return array( 84 'uri' => array( 85 'name' => pht('URI'), 86 'type' => 'text', 87 'required' => true, 88 ), 89 'method' => array( 90 'name' => pht('HTTP Method'), 91 'type' => 'select', 92 'options' => array_fuse(array('POST', 'GET', 'PUT', 'DELETE')), 93 ), 94 'credential' => array( 95 'name' => pht('Credentials'), 96 'type' => 'credential', 97 'credential.type' 98 => PassphraseCredentialTypePassword::CREDENTIAL_TYPE, 99 'credential.provides' 100 => PassphraseCredentialTypePassword::PROVIDES_TYPE, 101 ), 102 ); 103 } 104 105 public function supportsWaitForMessage() { 106 return true; 107 } 108 109 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |