Differential D8600 Diff 20391 src/applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php
Show All 28 Lines | public function execute( | ||||
$uri = $this->mergeVariables( | $uri = $this->mergeVariables( | ||||
'vurisprintf', | 'vurisprintf', | ||||
$settings['uri'], | $settings['uri'], | ||||
$variables); | $variables); | ||||
$log_body = $build->createLog($build_target, $uri, 'http-body'); | $log_body = $build->createLog($build_target, $uri, 'http-body'); | ||||
$start = $log_body->start(); | $start = $log_body->start(); | ||||
$method = 'POST'; | $method = nonempty(idx($settings, 'method'), 'POST'); | ||||
if ($settings['method'] !== '') { | |||||
$method = $settings['method']; | |||||
} | |||||
list($status, $body, $headers) = id(new HTTPSFuture($uri)) | list($status, $body, $headers) = id(new HTTPSFuture($uri)) | ||||
->setMethod($method) | ->setMethod($method) | ||||
->setTimeout(60) | ->setTimeout(60) | ||||
->resolve(); | ->resolve(); | ||||
$log_body->append($body); | $log_body->append($body); | ||||
$log_body->finalize($start); | $log_body->finalize($start); | ||||
if ($status->getStatusCode() != 200) { | if ($status->getStatusCode() != 200) { | ||||
$build->setBuildStatus(HarbormasterBuild::STATUS_FAILED); | $build->setBuildStatus(HarbormasterBuild::STATUS_FAILED); | ||||
} | } | ||||
} | } | ||||
public function validateSettings() { | public function getFieldSpecifications() { | ||||
$settings = $this->getSettings(); | |||||
if ($settings['uri'] === null || !is_string($settings['uri'])) { | |||||
return false; | |||||
} | |||||
$methods = array( | |||||
'GET' => true, | |||||
'POST' => true, | |||||
'DELETE' => true, | |||||
'PUT' => true, | |||||
); | |||||
$method = idx($settings, 'method'); | |||||
if (strlen($method)) { | |||||
if (empty($methods[$method])) { | |||||
return false; | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
public function getSettingDefinitions() { | |||||
return array( | return array( | ||||
'uri' => array( | 'uri' => array( | ||||
'name' => 'URI', | 'name' => pht('URI'), | ||||
'description' => pht('The URI to request.'), | 'type' => 'text', | ||||
'type' => BuildStepImplementation::SETTING_TYPE_STRING, | 'required' => true, | ||||
), | ), | ||||
'method' => array( | 'method' => array( | ||||
'name' => 'Method', | 'name' => pht('HTTP Method'), | ||||
'description' => | 'type' => 'select', | ||||
pht('Request type. Should be GET, POST, PUT, or DELETE.'), | 'options' => array_fuse(array('POST', 'GET', 'PUT', 'DELETE')), | ||||
'type' => BuildStepImplementation::SETTING_TYPE_STRING, | |||||
), | ), | ||||
); | ); | ||||
} | } | ||||
} | } |