Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original Commit #47

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Integrations/Rapid_ITP/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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://<yourJiraUrl>.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 <apikey> --jiraUserName <[email protected]> --jiraKey <jira api key> --projectKey <jira project key>
```

Additional descriptions can be found by requesting help from the script.
```bash
% python3 create_itp_jira.py --help
```
1 change: 1 addition & 0 deletions Integrations/Rapid_ITP/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jira_url = "https://iriusrisk.atlassian.net"
182 changes: 182 additions & 0 deletions Integrations/Rapid_ITP/create_itp_jira.py
Original file line number Diff line number Diff line change
@@ -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": [
#"<string>",
#"<string>"
#],
#"severityLevels": [
#"<string>",
#"<string>"
#],
#"priorityLevels": [
#"<string>",
#"<string>"
#],
"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)