Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/step/HarbormasterHTTPRequestBuildStepImplementation.php
12256 views
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 getBuildStepGroupKey() {
15
return HarbormasterExternalBuildStepGroup::GROUPKEY;
16
}
17
18
public function getDescription() {
19
$domain = null;
20
$uri = $this->getSetting('uri');
21
if ($uri) {
22
$domain = id(new PhutilURI($uri))->getDomain();
23
}
24
25
$method = $this->formatSettingForDescription('method', 'POST');
26
$domain = $this->formatValueForDescription($domain);
27
28
if ($this->getSetting('credential')) {
29
return pht(
30
'Make an authenticated HTTP %s request to %s.',
31
$method,
32
$domain);
33
} else {
34
return pht(
35
'Make an HTTP %s request to %s.',
36
$method,
37
$domain);
38
}
39
}
40
41
public function execute(
42
HarbormasterBuild $build,
43
HarbormasterBuildTarget $build_target) {
44
45
$viewer = PhabricatorUser::getOmnipotentUser();
46
47
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
48
$this->logSilencedCall($build, $build_target, pht('HTTP Request'));
49
throw new HarbormasterBuildFailureException();
50
}
51
52
$settings = $this->getSettings();
53
$variables = $build_target->getVariables();
54
55
$uri = $this->mergeVariables(
56
'vurisprintf',
57
$settings['uri'],
58
$variables);
59
60
$method = nonempty(idx($settings, 'method'), 'POST');
61
62
$future = id(new HTTPSFuture($uri))
63
->setMethod($method)
64
->setTimeout(60);
65
66
$credential_phid = $this->getSetting('credential');
67
if ($credential_phid) {
68
$key = PassphrasePasswordKey::loadFromPHID(
69
$credential_phid,
70
$viewer);
71
$future->setHTTPBasicAuthCredentials(
72
$key->getUsernameEnvelope()->openEnvelope(),
73
$key->getPasswordEnvelope());
74
}
75
76
$this->resolveFutures(
77
$build,
78
$build_target,
79
array($future));
80
81
$this->logHTTPResponse($build, $build_target, $future, $uri);
82
83
list($status) = $future->resolve();
84
if ($status->isError()) {
85
throw new HarbormasterBuildFailureException();
86
}
87
}
88
89
public function getFieldSpecifications() {
90
return array(
91
'uri' => array(
92
'name' => pht('URI'),
93
'type' => 'text',
94
'required' => true,
95
),
96
'method' => array(
97
'name' => pht('HTTP Method'),
98
'type' => 'select',
99
'options' => array_fuse(array('POST', 'GET', 'PUT', 'DELETE')),
100
),
101
'credential' => array(
102
'name' => pht('Credentials'),
103
'type' => 'credential',
104
'credential.type'
105
=> PassphrasePasswordCredentialType::CREDENTIAL_TYPE,
106
'credential.provides'
107
=> PassphrasePasswordCredentialType::PROVIDES_TYPE,
108
),
109
);
110
}
111
112
public function supportsWaitForMessage() {
113
return true;
114
}
115
116
}
117
118