From 66d7b54cddd740c56774fa0d43b23b53f922c2e7 Mon Sep 17 00:00:00 2001 From: Maciej Tonderski Date: Fri, 12 Jul 2024 12:30:56 +0200 Subject: [PATCH] PAPP-3712 - accomodate case where JIRA is behind proxy --- .pre-commit-config.yaml | 2 +- README.md | 2 +- jira.json | 2 +- jira_connector.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f20accf..aa68080 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/phantomcyber/dev-cicd-tools - rev: v1.17 + rev: v1.18 hooks: - id: org-hook - id: package-app-dependencies diff --git a/README.md b/README.md index 6fdf117..f8ee9ee 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Connector Version: 3.7.2 Product Vendor: Atlassian Product Name: Jira Product Version Supported (regex): ".\*" -Minimum Product Version: 6.1.1 +Minimum Product Version: 6.2.1 This app integrates with JIRA to perform several ticket management actions diff --git a/jira.json b/jira.json index 1a49460..6818af5 100644 --- a/jira.json +++ b/jira.json @@ -16,7 +16,7 @@ "product_vendor": "Atlassian", "product_name": "Jira", "product_version_regex": ".*", - "min_phantom_version": "6.1.1", + "min_phantom_version": "6.2.1", "latest_tested_versions": [ "On prem v8.21.0", "Cloud Copyright (c) 2002 - 2023 Atlassian Corporation Pty Ltd." diff --git a/jira_connector.py b/jira_connector.py index 4b13194..e097705 100644 --- a/jira_connector.py +++ b/jira_connector.py @@ -22,6 +22,7 @@ import time from builtins import str from datetime import datetime +from urllib.parse import urlparse, urlunparse import dateutil import phantom.app as phantom @@ -491,6 +492,30 @@ def _list_projects(self, param): return action_result.set_status(phantom.APP_SUCCESS) + def _get_base_url_from_url_path(self, url): + parsed_url = urlparse(url) + return f"{parsed_url.scheme}://{parsed_url.netloc}" + + def _update_base_url_in_url_path(self, url, new_base): + parsed_url = urlparse(url) + new_parsed_base = urlparse(new_base) + return urlunparse(( + new_parsed_base.scheme, new_parsed_base.netloc, + parsed_url.path, parsed_url.params, + parsed_url.query, parsed_url.fragment + )) + + def _validate_and_update_custom_fields_url(self, custom_fields): + allowed_values = custom_fields['custom_field']['allowed_values'] + for value in allowed_values: + if 'self' not in value: + continue + self_url = value['self'] + base_url = self._get_base_url_from_url_path(self_url) + if base_url != self._base_url: + value['self'] = self._update_base_url_in_url_path(self_url, self._base_url) + return custom_fields + def _get_custom_fields_for_issue(self, issue_id, action_result): try: @@ -514,6 +539,11 @@ def _get_custom_fields_for_issue(self, issue_id, action_result): {}".format(error_message) return action_result.set_status(phantom.APP_ERROR, error_text), None, None + try: + custom_fields = self._validate_and_update_custom_fields_url(custom_fields) + except KeyError: + return action_result.set_status(phantom.APP_ERROR, "Unable to validate custom fields"), None, None + return phantom.APP_SUCCESS, custom_fields, fields_meta def _replace_custom_id_with_name(self, input_fields, custom_id_to_name, action_result):