Skip to content

Commit

Permalink
merge get collabGUID func
Browse files Browse the repository at this point in the history
Signed-off-by: jnathangreeg <[email protected]>
  • Loading branch information
jnathangreeg committed Dec 30, 2024
1 parent 395f7ca commit 60e1b6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
17 changes: 17 additions & 0 deletions infrastructure/backend_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2889,6 +2889,23 @@ def get_jira_config(self):
r = self.get(url, params={"customerGUID": self.selected_tenant_id})
assert 200 <= r.status_code < 300, f"{inspect.currentframe().f_code.co_name}, url: '{url}', customer: '{self.customer}' code: {r.status_code}, message: '{r.text}'"
return r.json()

def get_jira_collaboration_guid_by_site_name(self, site_name: str):
config = self.get_jira_config()
jira_connections = config.get("jiraConnections", [])
if not jira_connections:
raise Exception("No Jira connections found in the response")

for connection in jira_connections:
selected_site = connection.get("selectedSite", {})
if selected_site.get("name") == site_name:
collabGUID = connection.get("jiraCollabGUID", "")
if collabGUID:
return collabGUID
else:
raise Exception(f"Jira collaboration GUID is empty or missing for site '{site_name}'")

raise Exception(f"No Jira collaboration found for site '{site_name}'")

def update_jira_config(self, body: dict):
url = API_INTEGRATIONS + "/jira/configV2"
Expand Down
32 changes: 7 additions & 25 deletions tests_scripts/helm/jira_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def setup_jira_config(self):
jiraStatus = next((status for status in connectionStatus if status['provider'] == 'jira'), None)
assert jiraStatus, "Jira is missing form connection status"
assert jiraStatus['status'] == "connected", "Jira is not connected"
jiraCollaborationGUID = self.get_jira_collaboration_guid_by_site_name(self.site_name)
jiraCollaborationGUID = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)

Logger.logger.info('get cyberarmor-io site')
projectsResp = self.backend.search_jira_projects(body={'innerFilters': [{'jiraCollabGUID': jiraCollaborationGUID}]})
Expand Down Expand Up @@ -118,24 +118,6 @@ def setup_jira_config(self):
self.project = project
self.issueType = issueType

def get_jira_collaboration_guid_by_site_name(self, site_name: str):
config = self.backend.get_jira_config()
jira_connections = config.get("jiraConnections", [])
if not jira_connections:
raise Exception("No Jira connections found in the response")

for connection in jira_connections:
selected_site = connection.get("selectedSite", {})
if selected_site.get("name") == site_name:
collabGUID = connection.get("jiraCollabGUID", "")
if collabGUID:
return collabGUID
else:
raise Exception(f"Jira collaboration GUID is empty or missing for site '{site_name}'")

raise Exception(f"No Jira collaboration found for site '{site_name}'")



def setup_cluster_and_run_posture_scan(self):
cluster, namespace = self.setup(apply_services=False)
Expand Down Expand Up @@ -172,7 +154,7 @@ def create_jira_issue_for_posture(self):

Logger.logger.info(f"Create Jira issue for resource {resourceHash} and control {controlId}")
issue = self.test_obj["issueTemplate"].copy()
issue["collaborationGUID"] = self.get_jira_collaboration_guid_by_site_name(self.site_name)
issue["collaborationGUID"] = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)
issue['siteId'] = self.site['id']
issue['projectId'] = self.project['id']
issue['issueTypeId'] = self.issueType['id']
Expand Down Expand Up @@ -216,7 +198,7 @@ def create_jira_issue_for_security_risks(self):

Logger.logger.info(f"Create Jira issue for resource {resourceHash} and security_risk_id {security_risk_id}")
issue = self.test_obj["issueTemplate"].copy()
issue["collaborationGUID"] = self.get_jira_collaboration_guid_by_site_name(self.site_name)
issue["collaborationGUID"] = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)
issue['issueType'] = "securityIssue"
issue['siteId'] = self.site['id']
issue['projectId'] = self.project['id']
Expand Down Expand Up @@ -307,7 +289,7 @@ def wait_for_vuln_results(self):
def create_vuln_tickets(self):
Logger.logger.info('create global ticket for CVE')
issue = self.test_obj["issueTemplate"].copy()
issue["collaborationGUID"] = self.get_jira_collaboration_guid_by_site_name(self.site_name)
issue["collaborationGUID"] = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)
issue['issueType'] = "vulnerability"
issue['siteId'] = self.site['id']
issue['projectId'] = self.project['id']
Expand All @@ -318,7 +300,7 @@ def create_vuln_tickets(self):
assert globalCVEicket, "Jira ticket is empty"

Logger.logger.info('create ticket for workload CVE')
issue["collaborationGUID"] = self.get_jira_collaboration_guid_by_site_name(self.site_name)
issue["collaborationGUID"] = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)
issue['owner'] = {"cluster": self.vulnWL['cluster'], "namespace": self.vulnWL['namespace'], "kind": self.vulnWL['kind'], "name": self.vulnWL['name']}
issue['fields']['summary'] = f"Jira System Test CVE Issue for workload cluster:{self.cluster} namespace:{self.namespace} image:{self.vulnImage['repository']}"
workloadCVEicket = self.backend.create_jira_issue(issue)
Expand All @@ -329,15 +311,15 @@ def create_vuln_tickets(self):

Logger.logger.info('create global ticket for image')
del issue['owner']
issue["collaborationGUID"] = self.get_jira_collaboration_guid_by_site_name(self.site_name)
issue["collaborationGUID"] = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)
issue['issueType'] = "image"
issue['subjects'] = [{"imageRepository": self.vulnImage['repository']}]
issue['fields']['summary'] = f"Jira System Test global Issue image:{self.vulnImage['repository']}"
globalImageTicket = self.backend.create_jira_issue(issue)
assert globalImageTicket, "Jira ticket is empty"

Logger.logger.info('create ticket for image in workload')
issue["collaborationGUID"] = self.get_jira_collaboration_guid_by_site_name(self.site_name)
issue["collaborationGUID"] = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)
issue['owner'] = {"cluster": self.vulnWL['cluster'], "namespace": self.vulnWL['namespace'], "kind": self.vulnWL['kind'], "name": self.vulnWL['name']}
issue['fields']['summary'] = f"Jira System Test image Issue for workload cluster:{self.cluster} namespace:{self.namespace} image:{self.vulnImage['repository']}"
workloadImageTicket = self.backend.create_jira_issue(issue)
Expand Down
13 changes: 2 additions & 11 deletions tests_scripts/workflows/jira_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, test_obj=None, backend=None, kubernetes_obj=None, test_driver
self.fw_name = None
self.cluster = None
self.wait_for_agg_to_end = False
self.site_name = "cyberarmor-io"


def start(self):
Expand All @@ -48,7 +49,7 @@ def start(self):


Logger.logger.info("Stage 1: Create new workflows")
jiraCollaborationGUID = self.get_jira_collaboration_guid()
jiraCollaborationGUID = self.backend.get_jira_collaboration_guid_by_site_name(self.site_name)
workflow_body = self.build_securityRisk_workflow_body(name=SECURITY_RISKS_WORKFLOW_NAME_JIRA + self.cluster, severities=SEVERITIES_MEDIUM, jiraCollaborationGUID=jiraCollaborationGUID, siteId=get_env("JIRA_SITE_ID"), projectId=get_env("JIRA_PROJECT_ID"), cluster=self.cluster, namespace=self.namespace, category=SECURITY_RISKS, securityRiskIDs=SECURITY_RISKS_ID, issueTypeId=get_env("JIRA_ISSUE_TYPE_ID"))
self.create_and_assert_workflow(workflow_body, EXPECTED_CREATE_RESPONSE, update=False)
workflow_body = self.build_vulnerabilities_workflow_body(name=VULNERABILITIES_WORKFLOW_NAME_JIRA + self.cluster, severities=SEVERITIES_HIGH, jiraCollaborationGUID=jiraCollaborationGUID, siteId=get_env("JIRA_SITE_ID"), projectId=get_env("JIRA_PROJECT_ID"), cluster=self.cluster, namespace=self.namespace, category=VULNERABILITIES, cvss=6, issueTypeId=get_env("JIRA_ISSUE_TYPE_ID"))
Expand Down Expand Up @@ -82,16 +83,6 @@ def cleanup(self, **kwargs):
self.delete_and_assert_workflow(self.return_workflow_guid(VULNERABILITIES_WORKFLOW_NAME_JIRA + self.cluster))
return super().cleanup(**kwargs)

def get_jira_collaboration_guid(self):
config = self.backend.get_jira_config()
jira_connections = config.get("jiraConnections", [])
if not jira_connections:
raise Exception("No Jira connections found in the response")
collabGUID = jira_connections[0].get("jiraCollabGUID", "")
if not collabGUID:
raise Exception("Jira collaboration GUID is empty or missing")
return collabGUID


def assert_jira_tickets_was_created(self, begin_time, cluster_name, attempts=20, sleep_time=20):

Expand Down

0 comments on commit 60e1b6c

Please sign in to comment.