Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jira API Communication Add Proxy #136

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions application/forms/Config/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ protected function assemble()
'label' => $this->translate('Scheme'),
'description' => $this->translate('Protocol used by Jira (http / https)'),
]
)->addElement(
'text',
'proxy',
[
'label' => $this->translate('Proxy Server'),
'description' => $this->translate(
'Proxy Server used to connect to Jira if needed, '
. 'format <hostname or IP>:<port>'
),
'required' => false,
]
);

$this->addElement(
Expand Down
12 changes: 10 additions & 2 deletions library/Jira/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ class RestApi

protected $enumCustomFields;

public function __construct($baseUrl, $username, $password)
protected $proxy;

public function __construct($baseUrl, $username, $password, ?string $proxy)
{
$this->username = $username;
$this->password = $password;
$this->baseUrlForLink = $baseUrl;
$this->baseUrl = \rtrim($baseUrl, '/') . '/rest';
$this->proxy = $proxy;
$this->serverInfo = $this->get('serverInfo')->getResult();
}

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

$user = $config->get('api', 'username');
$pass = $config->get('api', 'password');
$proxy = $config->get('api', 'proxy');

$api = new static($url, $user, $pass);
$api = new static($url, $user, $pass, $proxy);

return $api;
}
Expand Down Expand Up @@ -450,6 +454,10 @@ protected function request($method, $url, $body = null)

$curl = $this->curl();

if ($this->proxy) {
$opts[CURLOPT_PROXY] = $this->proxy;
}

curl_setopt_array($curl, $opts);
// TODO: request headers, validate status code

Expand Down
Loading