From 9de2ce1617e5a624ff1c221e676b405964077c11 Mon Sep 17 00:00:00 2001 From: Christian Menapace <49369365+cmenapace@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:55:45 +0200 Subject: [PATCH] Jira API Configuration Add Proxy --- application/forms/Config/ConfigForm.php | 11 +++++++++++ library/Jira/RestApi.php | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/application/forms/Config/ConfigForm.php b/application/forms/Config/ConfigForm.php index f44758f..b693def 100644 --- a/application/forms/Config/ConfigForm.php +++ b/application/forms/Config/ConfigForm.php @@ -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 :' + ), + 'required' => false, + ] ); $this->addElement( diff --git a/library/Jira/RestApi.php b/library/Jira/RestApi.php index 5c1b378..872ebe4 100644 --- a/library/Jira/RestApi.php +++ b/library/Jira/RestApi.php @@ -31,12 +31,15 @@ class RestApi protected $enumCustomFields; - public function __construct($baseUrl, $username, $password) + protected $proxy; + + public function __construct($baseUrl, $username, $password, $proxy) { $this->username = $username; $this->password = $password; $this->baseUrlForLink = $baseUrl; $this->baseUrl = \rtrim($baseUrl, '/') . '/rest'; + $this->proxy = $proxy; $this->serverInfo = $this->get('serverInfo')->getResult(); } @@ -62,7 +65,7 @@ public static function fromConfig() $user = $config->get('api', 'username'); $pass = $config->get('api', 'password'); - $api = new static($url, $user, $pass); + $api = new static($url, $user, $pass, $proxy); return $api; } @@ -447,6 +450,10 @@ protected function request($method, $url, $body = null) CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, ); + + if($this->proxy) { + $opts[CURLOPT_PROXY] = $this->proxy; + } curl_setopt_array($curl, $opts); // TODO: request headers, validate status code