From 630990705b5924167107abb792905713f1a43ea4 Mon Sep 17 00:00:00 2001 From: Christian Menapace <49369365+cmenapace@users.noreply.github.com> Date: Tue, 30 Apr 2024 13:07:58 +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..e5108c7 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; } @@ -448,6 +451,10 @@ protected function request($method, $url, $body = null) CURLOPT_SSL_VERIFYPEER => false, ); + if ($this->proxy) { + $opts[CURLOPT_PROXY] = $this->proxy; + } + curl_setopt_array($curl, $opts); // TODO: request headers, validate status code