Skip to content

Commit

Permalink
added field validation for editmeta response action
Browse files Browse the repository at this point in the history
  • Loading branch information
mctonderski-splunk committed Jun 14, 2024
1 parent 1aa1412 commit 61958ac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
36 changes: 35 additions & 1 deletion jira_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,7 +73,7 @@ def __init__(self):
self._jira = None
self._timezone = None

def initialize(self):
def _base_url(self):

config = self.get_config()

Expand Down Expand Up @@ -491,6 +492,35 @@ def _list_projects(self, param):

return action_result.set_status(phantom.APP_SUCCESS)

def _get_base_url(self, url):
parsed_url = urlparse(url)
return f"{parsed_url.scheme}://{parsed_url.netloc}"

def _update_base_url(self, url, new_base):
parsed_url = urlparse(url)
new_parsed_base = urlparse(new_base)
updated_url = urlunparse((
new_parsed_base.scheme, new_parsed_base.netloc,
parsed_url.path, parsed_url.params,
parsed_url.query, parsed_url.fragment
))
return updated_url

def _validate_and_update_custom_fields_url(self, custom_fields):
try:
allowed_values = custom_fields['custom_field']['allowed_values']
for value in allowed_values:
if 'self' in value:
self_url = value['self']
base_url = self._get_base_url(self_url)
if base_url != self._base_url:
value['self'] = self._update_base_url(self_url, self._base_url)
return custom_fields, None
except KeyError as e:
return False, f"Key error: {e}"
except Exception as e:
return False, f"Error: {e}"

def _get_custom_fields_for_issue(self, issue_id, action_result):

try:
Expand All @@ -514,6 +544,10 @@ 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

custom_fields, err = self._validate_and_update_custom_fields_url(custom_fields)
if err:
return action_result.set_status(phantom.APP_ERROR, err), 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):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ python-dateutil==2.9.0.post0
pytz==2024.1
requests_oauthlib==2.0.0
requests_toolbelt==1.0.0
urllib3==2.2.1

0 comments on commit 61958ac

Please sign in to comment.