Skip to content

Commit

Permalink
Merge pull request #42 from Jayarr03/main
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
iresolis authored Apr 25, 2024
2 parents 6596bc0 + 276243e commit 0bd9641
Show file tree
Hide file tree
Showing 29 changed files with 26,072 additions and 30 deletions.
28 changes: 28 additions & 0 deletions Integrations/Templates_Manager/Readme.md
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
```
12 changes: 12 additions & 0 deletions Integrations/Templates_Manager/config.py
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"
20 changes: 20 additions & 0 deletions Integrations/Templates_Manager/setup.py
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'
],
)
61 changes: 61 additions & 0 deletions Integrations/Templates_Manager/templates_manager.py
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 Templates/Diagram_It_Webinar_Series/IoT - Wearable Device.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Templates/IR_Published_Templates/README.MD
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.
30 changes: 0 additions & 30 deletions Templates/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions Templates/Submitted_Templates/README.MD
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.

0 comments on commit 0bd9641

Please sign in to comment.