Skip to content

Commit 91b10ac

Browse files
cmenapacenilmerg
authored andcommitted
Jira API Configuration Add Proxy
1 parent 489814d commit 91b10ac

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

application/forms/Config/ConfigForm.php

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ protected function assemble()
5858
'label' => $this->translate('Scheme'),
5959
'description' => $this->translate('Protocol used by Jira (http / https)'),
6060
]
61+
)->addElement(
62+
'text',
63+
'proxy',
64+
[
65+
'label' => $this->translate('Proxy Server'),
66+
'description' => $this->translate(
67+
'Proxy Server used to connect to Jira if needed, '
68+
. 'format <hostname or IP>:<port>'
69+
),
70+
'required' => false,
71+
]
6172
);
6273

6374
$this->addElement(

library/Jira/RestApi.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ class RestApi
3131

3232
protected $enumCustomFields;
3333

34-
public function __construct($baseUrl, $username, $password)
34+
protected $proxy;
35+
36+
public function __construct($baseUrl, $username, $password, ?string $proxy)
3537
{
3638
$this->username = $username;
3739
$this->password = $password;
3840
$this->baseUrlForLink = $baseUrl;
3941
$this->baseUrl = \rtrim($baseUrl, '/') . '/rest';
42+
$this->proxy = $proxy;
4043
$this->serverInfo = $this->get('serverInfo')->getResult();
4144
}
4245

@@ -61,8 +64,9 @@ public static function fromConfig()
6164

6265
$user = $config->get('api', 'username');
6366
$pass = $config->get('api', 'password');
67+
$proxy = $config->get('api', 'proxy');
6468

65-
$api = new static($url, $user, $pass);
69+
$api = new static($url, $user, $pass, $proxy);
6670

6771
return $api;
6872
}
@@ -450,6 +454,10 @@ protected function request($method, $url, $body = null)
450454

451455
$curl = $this->curl();
452456

457+
if ($this->proxy) {
458+
$opts[CURLOPT_PROXY] = $this->proxy;
459+
}
460+
453461
curl_setopt_array($curl, $opts);
454462
// TODO: request headers, validate status code
455463

0 commit comments

Comments
 (0)