Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
41 changes: 41 additions & 0 deletions .github/workflows/generate_artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Generate Artifacts

on:
push:
branches:
- master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be PR's as well to test how it it outputs prior to the merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to the noisy nature of the command making a bunch of requests to check if they 404 we want to limit it as much as possible, but can adjust moving forward.

Essentially the current setup is to generate every time on a merge to master, or direct push to master, and releases. The other PR: #278 would instead make this a check whether or not it is up to date and require updating.

pull_request:
types:
- closed
branches:
- master
release:
types:
- created

jobs:
generate_scw_artifact:
name: Generate SCW Artifact
runs-on: ubuntu-latest
if: github.event.pull_request == null || github.event.pull_request.merged == true
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
- name: Install requests library
run: |
pip install requests
- name: Create artifact json file
run: |
python3 -B artifacts.py
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
name: Source Code Warrior Links
path: scw_links.json
File renamed without changes.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ Each mapping should be setup in the following structure:
- [CWE](mappings/cwe/cwe.json)
- [Remediation Advice](mappings/remediation_advice/remediation_advice.json)

#### Remediation Training
- [Source Code Warriors](https://github.com/bugcrowd/vulnerability-rating-taxonomy/commit/ff2999c74ac4f10a6346edd2becfc78a730a09ae/checks?check_suite_id=361261433)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is referencing the artifact via the commit hash. Will this link need to be updated for every build ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now yes, but only on a new release. before we get to that I want to build a little meta page that gets generated and committed with the artifact, so the link will be removed from this page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this to just point to the main tab temporarily and mention that it is a temporary holding place before we make the meta page.

Training links can be found in the actions artifacts tab in github.

## Supported Libraries
- [Ruby](https://github.com/bugcrowd/vrt-ruby)

Expand Down
8 changes: 8 additions & 0 deletions artifacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from tests import utils
from artifacts import scw_artifact

url_mapping = {}
current_vrt = utils.get_json(utils.VRT_FILENAME)
scw_artifact.write_artifact_file(
scw_artifact.generate_urls(current_vrt['content'], url_mapping)
)
Empty file added artifacts/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions artifacts/scw_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json
import requests
import tests.utils

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now some of these test utils are used to build an artifacts, would it make sense to move them to out from tests ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! thoughts on a good place to put them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a new dir called utils or maybe all code (non json taxonomy/schema stuff) should go under lib

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure of what the convention is with python but utils sounds like a good name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated file locations. I put everything under lib so it doesn't look so messy and segregates the main taxonomy/schema from dev concerns.


BASE_SCW_URL = 'https://integration-api.securecodewarrior.com/api/v1/trial?id=bugcrowd&mappingList=vrt&mappingKey='
OUTPUT_FILENAME = 'scw_links.json'

def scw_url(vrt_id):
return f'{BASE_SCW_URL}{vrt_id.replace(".", ":")}'

def scw_mapping(vrt_id):
path = scw_url(vrt_id)
print('Fetching...')
response = requests.get(path)
if response.status_code == 200:
print(f'Exists: {path}')
return path + '&redirect=true'
else:
print(f'Not Found: {path}')
return None

def join_vrt_id(parent_id, child_id):
return '.'.join([parent_id, child_id]) if parent_id is not None else child_id

def generate_urls(vrt, content, parent_id = None):
for node in vrt:
vrt_id = join_vrt_id(parent_id, node['id'])
content[vrt_id] = {
'source_code_warrior': scw_mapping(vrt_id),
}
if 'children' in node:
children = node['children']
child_content = {}
content[vrt_id]['children'] = generate_urls(children, child_content, vrt_id)

return content

def write_artifact_file(mapping):
with open(OUTPUT_FILENAME, 'w') as outfile:
json.dump(mapping, outfile, indent=2, sort_keys=False)
Empty file added tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/test_vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_changelog_updated(self):
and prompts the user if it isn't
"""
p = subprocess.Popen('git diff HEAD --stat --staged CHANGELOG.md | wc -l', shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
out, _err = p.communicate()
self.assertGreater(int(out), 0, 'CHANGELOG.md not updated')

def validate_schema(self, schema_file, data_file):
Expand Down