Skip to content

Commit 7e8a8f6

Browse files
authored
Generate and validate SCW artifacts (#272)
1 parent 2481b5a commit 7e8a8f6

File tree

16 files changed

+458
-8
lines changed

16 files changed

+458
-8
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Validate Artifacts
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
release:
8+
types:
9+
- created
10+
- edited
11+
- unpublished
12+
13+
jobs:
14+
validate_scw_artifact:
15+
name: Validate SCW Artifact
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v1
19+
- name: Set up Python 3.7
20+
uses: actions/setup-python@v1
21+
with:
22+
python-version: 3.7
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r lib/requirements.txt
27+
- name: Install requests library
28+
run: |
29+
pip install requests
30+
- name: Create artifact json file
31+
run: |
32+
python3 -B lib/generate_artifacts.py
33+
- name: Upload artifact
34+
uses: actions/upload-artifact@v1
35+
with:
36+
name: Secure Code Warrior Links
37+
path: scw_links.json
38+
- name: Validate links
39+
run: |
40+
python3 -B lib/validate_artifacts.py

.github/workflows/main.yml renamed to .github/workflows/validate_vrt.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ jobs:
1616
- name: Install dependencies
1717
run: |
1818
python -m pip install --upgrade pip
19-
pip install -r tests/requirements.txt
19+
pip install -r lib/requirements.txt
2020
- name: Lint with flake8
2121
run: |
2222
pip install flake8
2323
# stop the build if there are Python syntax errors or undefined names
24-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
24+
flake8 ./lib --count --select=E9,F63,F7,F82 --show-source --statistics
2525
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
26-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
26+
flake8 ./lib --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
2727
- name: Test with unittest
2828
run: |
29-
python3 -B validate_vrt.py
29+
python3 -B lib/validate_vrt.py

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ FROM python:3.6
33
RUN pip install jsonschema GitPython semantic_version
44

55
WORKDIR /tmp/vrt
6-
CMD [ "python3", "-B" , "./validate_vrt.py" ]
6+
CMD [ "python3", "-B" , "./lib/validate_vrt.py" ]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ Each mapping should be setup in the following structure:
166166
- [CWE](mappings/cwe/cwe.json)
167167
- [Remediation Advice](mappings/remediation_advice/remediation_advice.json)
168168

169+
#### Remediation Training
170+
- [Secure Code Warriors](remediation_training/)
171+
169172
## Supported Libraries
170173
- [Ruby](https://github.com/bugcrowd/vrt-ruby)
171174

lib/artifacts/__init__.py

Whitespace-only changes.

lib/artifacts/scw_artifact.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
import requests
3+
import utils.utils
4+
5+
BASE_SCW_URL = 'https://integration-api.securecodewarrior.com/api/v1/trial?id=bugcrowd&mappingList=vrt&mappingKey='
6+
OUTPUT_FILENAME = 'scw_links.json'
7+
8+
9+
def scw_url(vrt_id):
10+
return f'{BASE_SCW_URL}{vrt_id.replace(".", ":")}'
11+
12+
13+
def scw_mapping(vrt_id):
14+
path = scw_url(vrt_id)
15+
print('Fetching...')
16+
response = requests.get(path)
17+
if response.status_code == 200:
18+
print(f'Exists: {path}')
19+
return path + '&redirect=true'
20+
else:
21+
print(f'Not Found: {path}')
22+
return None
23+
24+
25+
def join_vrt_id(parent_id, child_id):
26+
return '.'.join([parent_id, child_id]) if parent_id is not None else child_id
27+
28+
29+
def generate_urls(vrt, content, parent_id=None):
30+
for node in vrt:
31+
vrt_id = join_vrt_id(parent_id, node['id'])
32+
content[vrt_id] = scw_mapping(vrt_id)
33+
if 'children' in node:
34+
content.update(
35+
generate_urls(
36+
node['children'],
37+
{},
38+
vrt_id
39+
)
40+
)
41+
42+
return content
43+
44+
45+
def write_artifact_file(mapping):
46+
with open(OUTPUT_FILENAME, 'w') as outfile:
47+
json.dump(mapping, outfile, indent=2, sort_keys=False)

lib/generate_artifacts.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from utils import utils
2+
from artifacts import scw_artifact
3+
4+
url_mapping = {}
5+
current_vrt = utils.get_json(utils.VRT_FILENAME)
6+
scw_artifact.write_artifact_file(
7+
scw_artifact.generate_urls(current_vrt['content'], url_mapping)
8+
)
File renamed without changes.

lib/tests/__init__.py

Whitespace-only changes.

tests/test_deprecated_mapping.py renamed to lib/tests/test_deprecated_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import utils
1+
from utils import utils
22
import unittest
33
from semantic_version import Version
44

0 commit comments

Comments
 (0)