From 42b1d2883a601996b4205d99f023ec5e825d4328 Mon Sep 17 00:00:00 2001 From: Rabeco <106360860+Jayarr03@users.noreply.github.com> Date: Sun, 12 May 2024 22:33:03 -0400 Subject: [PATCH 1/2] Original Commit Added RAPID_ITP to create an issue tracker profile quickly --- Integrations/Rapid_ITP/Readme.md | 50 ++++++ Integrations/Rapid_ITP/config.py | 1 + Integrations/Rapid_ITP/create_itp_jira.py | 182 ++++++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 Integrations/Rapid_ITP/Readme.md create mode 100644 Integrations/Rapid_ITP/config.py create mode 100644 Integrations/Rapid_ITP/create_itp_jira.py diff --git a/Integrations/Rapid_ITP/Readme.md b/Integrations/Rapid_ITP/Readme.md new file mode 100644 index 0000000..11849de --- /dev/null +++ b/Integrations/Rapid_ITP/Readme.md @@ -0,0 +1,50 @@ +# Purpose +The purpose of this script is to provide assistance in creating an issue tracker profile through the IriusRisk API. + +# Process + +Creating an Issue Tracker profile from the API involves four API calls from initial creation to final publication. + +**Call 1 - POST the unpublished ITP** +- This performs the initial creation of the Issue Tracker profile. + +**Call 2 - FETCH the unpublished ITP available options** +- This fetch collects the additional required information about the ITP. For example, the types of issues allowed or any additional fields that are required from Jira. + +**Call 3 - PUT the additional requirements to the ITP** +- This call updates the ITP based on what was available from the previous FETCH call. +- This would include information like issueType and additional fields. + +**Call 4 - POST to publish the ITP** +- This call transitions the unpublished ITP to published. + +# Requirements + +**Setup the virtual environment** +```bash +python3 -m venv IriusRisk-API && cd IriusRisk-API/ && source bin/activate && echo Virtual envrionment created and active && git clone github.com/iriusrisk/IriusRisk-Central.git && echo IriusRisk Github repo cloned +``` +**Install the script dependencies** +```bash +pip install requests argparse +``` + +**Add the url of the Jira instance to the config.py file.** + +```bash +vim config.py +``` +```bash +jira_url = "https://.atlassian.net" +# Creating the Issue Tracker Profile + +**Call the script and provide the following arguments** + +```bash +python3 IriusRisk-Central/Integrations/Rapid_ITP/create_itp_jira.py/ --subDomain r1 --apiKey --jiraUserName --jiraKey --projectKey +``` + +Additional descriptions can be found by requesting help from the script. +```bash +% python3 create_itp_jira.py --help +``` \ No newline at end of file diff --git a/Integrations/Rapid_ITP/config.py b/Integrations/Rapid_ITP/config.py new file mode 100644 index 0000000..826850d --- /dev/null +++ b/Integrations/Rapid_ITP/config.py @@ -0,0 +1 @@ +jira_url = "https://iriusrisk.atlassian.net" diff --git a/Integrations/Rapid_ITP/create_itp_jira.py b/Integrations/Rapid_ITP/create_itp_jira.py new file mode 100644 index 0000000..8a89918 --- /dev/null +++ b/Integrations/Rapid_ITP/create_itp_jira.py @@ -0,0 +1,182 @@ +import requests +import json +import argparse +import config + + +# Create ArgumentParser object +parser = argparse.ArgumentParser(description='Creates and publishes an issue tracker profile quickly.') + +# Add arguments +parser.add_argument('--subDomain', help='Enter the subdomain of your instance') +parser.add_argument('--apiKey', help='Enter the API key for this domain') +parser.add_argument('--jiraUserName', help='Enter your Jira user ID') +parser.add_argument('--jiraKey', help='Enter the JIRA API Key') +parser.add_argument('--projectKey', help='Enter your Jira Project Key') + +# Parse the arguments +args = parser.parse_args() + +# Access the arguments + +# FIRST API CALL TO CREATE THE UNPUBLISHED AND INCOMPLETE ITP + +url = f"https://{args.subDomain}.iriusrisk.com/api/v2/issue-tracker-profiles" + +payload = json.dumps({ + "issueTrackerType": "jira", + "name": "Standard-Jira", + "url": config.jira_url, + "projectId": args.projectKey, + #leave the proxy field blank unless needed + "proxyUrl": "", + "proxyUsername": "", + "proxyPassword": "", + "username": args.jiraUserName, + "password": args.jiraKey, + "issueLinkType": "Relates", + "weaknessPriority": "Highest", + "userAsReporter": "TRUE", + #"tags": [ + #"", + #"" + #], + #"severityLevels": [ + #"", + #"" + #], + #"priorityLevels": [ + #"", + #"" + #], + "openIssueStates": [ + "Proposed", + "To Do" + ], + "closedIssueStates": [ + "Done" + ], + "rejectedIssueStates": [ + "Won't Do" + ] +}) +headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/hal+json', + 'api-token': args.apiKey +} + +create_response = requests.post(url, headers=headers, data=payload) + +if create_response.status_code == 200: + print(create_response.status_code, "- Unpublished ITP Created") + +else: + print("Creation Failed...","\n",create_response.text) + +# Parse the JSON response +response_data = json.loads(create_response.text) + +# Extract the 'id' value and store it as a variable +id_value = response_data['id'] +print(create_response.status_code," ITP ID - ",id_value, " Available for Updating") + +# 2nd API call to fetch and additional required information that needs to be mapped for this ITP. + +url = f"https://{args.subDomain}.iriusrisk.com/api/v2/issue-tracker-profiles/{id_value}/fetch" + +payload = { +} +headers = { + 'Accept': 'application/hal+json', + 'api-token': args.apiKey +} + +response = requests.post(url, headers=headers, data=payload) + +if response.status_code == 200: + print(response.status_code," ITP Details Fetched, ready to update") +else: + print("ITP FETCH FAILED...","\n",response.text) + +# 3rd API call to add additional required fields +url = f"https://{args.subDomain}.iriusrisk.com/api/v2/issue-tracker-profiles/{id_value}" + +payload = json.dumps({ + "issueTrackerType": "jira", + "name": "Standard-Jira", + "url": config.jira_url, + "projectId": args.projectKey, + #leave the proxy field blank unless needed + "proxyUrl": "", + "proxyUsername": "", + "proxyPassword": "", + "username": args.jiraUserName, + "password": args.jiraKey, + "openIssueStates": [ + "Proposed", + "To Do" + ], + "closedIssueStates": [ + "Done" + ], + "rejectedIssueStates": [ + "Won't Do" + ], + "issueLinkType": "Relates", + "weaknessPriority": "Highest", + "userAsReporter": "TRUE", + "issueType": "Task" +}) +headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/hal+json', + 'api-token': args.apiKey +} + +response = requests.put(url, headers=headers, data=payload) + +if response.status_code == 200: + print(response.status_code, "- Unpublished ITP Updated with Required Information") +else: + print(response.status_code, " Update ITP Failed", response.text) + +#4th API call to publish this ITP + +url = f"https://{args.subDomain}.iriusrisk.com/api/v2/issue-tracker-profiles/{id_value}/publish" + +payload = { + "id": id_value, + "published": { + "name": "Standard-Jira", + "issueTrackerType": "jira", + "url": config.jira_url, + "projectId": args.projectKey, + "proxyUrl": "", + "proxyUsername": "", + "proxyPassword": "", + "username": args.jiraUserName, + "password": args.jiraKey, + "issueLinkType": "Relates", + "weaknessPriority": "Highest", + "userAsReporter": "TRUE", + "openIssueStates": ["Proposed", "To Do"], + "closedIssueStates": ["Done"], + "rejectedIssueStates": ["Won't Do"], + "issueType": "Task" + } +} + +headers = { + 'Accept': 'application/hal+json', + 'api-token': args.apiKey, + 'Content-Type': 'application/json' +} + +response = requests.post(url, headers=headers, json=payload) +if response.status_code == 200: + print(response.status_code, "- ITP was successfully published") +else: + print(response.text) + + From 06e9c47125aeb8e0f4a9973fb09638d9c30b0451 Mon Sep 17 00:00:00 2001 From: Rabeco <106360860+Jayarr03@users.noreply.github.com> Date: Sun, 12 May 2024 22:35:16 -0400 Subject: [PATCH 2/2] Update Readme.md --- Integrations/Rapid_ITP/Readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Integrations/Rapid_ITP/Readme.md b/Integrations/Rapid_ITP/Readme.md index 11849de..14fb372 100644 --- a/Integrations/Rapid_ITP/Readme.md +++ b/Integrations/Rapid_ITP/Readme.md @@ -25,6 +25,7 @@ Creating an Issue Tracker profile from the API involves four API calls from init python3 -m venv IriusRisk-API && cd IriusRisk-API/ && source bin/activate && echo Virtual envrionment created and active && git clone github.com/iriusrisk/IriusRisk-Central.git && echo IriusRisk Github repo cloned ``` **Install the script dependencies** + ```bash pip install requests argparse ``` @@ -36,6 +37,7 @@ vim config.py ``` ```bash jira_url = "https://.atlassian.net" +``` # Creating the Issue Tracker Profile **Call the script and provide the following arguments** @@ -47,4 +49,4 @@ python3 IriusRisk-Central/Integrations/Rapid_ITP/create_itp_jira.py/ --subDomain Additional descriptions can be found by requesting help from the script. ```bash % python3 create_itp_jira.py --help -``` \ No newline at end of file +```