Skip to content

Commit

Permalink
fix(chalice): fixed update JIRA integration (openreplay#2096)
Browse files Browse the repository at this point in the history
fix(chalice): fixed JIRA URL validation
fix(chalice): fixed add/update JIRA token

(cherry picked from commit 2569713)
  • Loading branch information
tahayk committed Apr 16, 2024
1 parent cff7874 commit 156e1f9
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions api/chalicelib/core/integration_jira_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ def __init__(self, tenant_id, user_id):
self._user_id = user_id
self.integration = self.get()

if self.integration is None:
return
self.integration["valid"] = True
if not self.integration["url"].endswith('atlassian.net'):
self.integration["valid"] = False
@staticmethod
def __validate(data):
data["valid"] = JIRAIntegration.__is_valid_url(data["url"])

@staticmethod
def __is_valid_url(url):
return url.endswith('atlassian.net') or url.endswith('atlassian.net/')

@property
def provider(self):
return PROVIDER

@property
def issue_handler(self):
if self.integration["url"].endswith('atlassian.net') and self._issue_handler is None:
if JIRAIntegration.__is_valid_url(self.integration["url"]) and self._issue_handler is None:
try:
self._issue_handler = JIRACloudIntegrationIssue(token=self.integration["token"],
username=self.integration["username"],
Expand All @@ -55,9 +57,7 @@ def get(self):

if data is None:
return
data["valid"] = True
if not data["url"].endswith('atlassian.net'):
data["valid"] = False
JIRAIntegration.__validate(data)
return data

def get_obfuscated(self):
Expand All @@ -81,16 +81,17 @@ def update(self, changes, obfuscate=False):
**changes})
)
w = helper.dict_to_camel_case(cur.fetchone())
JIRAIntegration.__validate(w)
if obfuscate:
w["token"] = obfuscate_string(w["token"])
return self.get()
return w

# TODO: make this generic for all issue tracking integrations
def _add(self, data):
print("a pretty defined abstract method")
return

def add(self, username, token, url):
def add(self, username, token, url, obfuscate=False):
with pg_client.PostgresClient() as cur:
cur.execute(
cur.mogrify("""\
Expand All @@ -101,7 +102,11 @@ def add(self, username, token, url):
"token": token, "url": url})
)
w = helper.dict_to_camel_case(cur.fetchone())
return self.get()
JIRAIntegration.__validate(w)
if obfuscate:
w["token"] = obfuscate_string(w["token"])

return w

def delete(self):
with pg_client.PostgresClient() as cur:
Expand All @@ -120,13 +125,14 @@ def add_edit(self, data: schemas.IssueTrackingJiraSchema):
"username": data.username,
"token": data.token if len(data.token) > 0 and data.token.find("***") == -1 \
else self.integration.token,
"url": data.url
"url": str(data.url)
},
obfuscate=True
)
else:
return self.add(
username=data.username,
token=data.token,
url=str(data.url)
url=str(data.url),
obfuscate=True
)

0 comments on commit 156e1f9

Please sign in to comment.