-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Jayarr03/main
Add files via upload
- Loading branch information
Showing
29 changed files
with
26,072 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Purpose | ||
|
||
The purpose of this script is to collect templates from a GitHub repo, download those locally to a local repo and then post those to the IriusRisk API. | ||
|
||
# Installation | ||
|
||
Run the setup.py script to install the script dependencies | ||
|
||
```python | ||
python .\setup.py install | ||
``` | ||
|
||
Update the config.py file with the required variables: | ||
```python | ||
# API URL and Token | ||
url = "https://insert_your_domain.iriusrisk.com/api/v2/templates/import" | ||
api_token = 'insert_your_api_token' | ||
|
||
# GitHub | ||
repo_url = "insert_your_repo_root_url" | ||
repo_sub_folder = "insert_your_sub_folder_if_needed" | ||
``` | ||
|
||
# Execute the download and import of templates | ||
|
||
```python | ||
python .\templates_manager.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
# API URL and Token | ||
url = "https:/your_url.iriusrisk.com/api/v2/templates/import" | ||
api_token = 'your_api_key' | ||
|
||
|
||
|
||
# GitHub | ||
repo_url = "https://github.com/iriusrisk/IriusRisk-Central.git" | ||
|
||
repo_sub_folder = "Templates" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='templates_manager', | ||
version='1.0', | ||
packages=find_packages(), | ||
install_requires=[ | ||
'certifi>=2024.2.2', | ||
'charset-normalizer>=3.3.2', | ||
'gitdb>=4.0.11', | ||
'GitPython>=3.1.43', | ||
'idna>=3.7', | ||
'pip>=22.3.1', | ||
'requests>=2.31.0', | ||
'setuptools>=65.5.1', | ||
'smmap>=5.0.1', | ||
'urllib3>=2.2.1', | ||
'wheel>=0.38.4' | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from git import Repo | ||
import requests | ||
import os | ||
import config | ||
|
||
# Set up the path for cloning | ||
repo_path = os.path.join(os.getcwd(), "cloned_repo") | ||
repo_url = config.repo_url | ||
|
||
# Clone the repository if the directory doesn't exist | ||
if not os.path.exists(repo_path): | ||
os.makedirs(repo_path) | ||
Repo.clone_from(repo_url, repo_path) | ||
print("Repository cloned successfully.") | ||
print("Working on importing templates now...") | ||
else: | ||
print("Directory already exists and is assumed to contain the necessary files.") | ||
print("Working on importing templates now...") | ||
|
||
def get_files(directory, extension): | ||
for root, dirs, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith(extension): | ||
yield os.path.join(root, file) | ||
|
||
# Define the directory where the Templates folder is located | ||
templates_dir = os.path.join(repo_path, config.repo_sub_folder) | ||
|
||
# Example usage: finding all XML files in the Templates directory | ||
files_to_process = list(get_files(templates_dir, ".xml")) | ||
|
||
# API URL and Token | ||
url = config.url | ||
api_token = config.api_token | ||
|
||
# Iterate over each XML file and send it | ||
for file_path in files_to_process: | ||
with open(file_path, 'rb') as f: | ||
# Use the filename (without extension) as the name | ||
file_name = os.path.basename(file_path) | ||
file_base_name = os.path.splitext(file_name)[0] | ||
|
||
# Define the payload | ||
files = { | ||
'file': (file_name, f, 'application/xml'), | ||
'name': (None, file_base_name.replace("-"," ").capitalize()), # Using the filename without extension as the name | ||
'referenceId': (None, file_base_name.lower()) # You may modify 'referenceId' as needed | ||
} | ||
|
||
headers = { | ||
'Accept': 'application/hal+json', | ||
'api-token': api_token | ||
} | ||
|
||
# Send the request | ||
response = requests.post(url, headers=headers, files=files) | ||
|
||
if response.status_code == 200: | ||
print(file_base_name, "Successfully Imported!!!") | ||
else: | ||
print(f"File: {file_name}, Status Code: {response.status_code}, Response: {response.text}") |
Binary file not shown.
25,945 changes: 25,945 additions & 0 deletions
25,945
Templates/Diagram_It_Webinar_Series/IoT - Wearable Device.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Purpose | ||
|
||
These templates were published by IriusRisk to assist programs with a first set of threat models. |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# PURPOSE | ||
|
||
These files were submitted by community members for usage by the at large IriusRisk enterprise or community |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.