-
Notifications
You must be signed in to change notification settings - Fork 105
Generate artifacts workflow #272
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
Changes from 5 commits
4100367
5652a50
14dfaca
cc44bda
830e809
d66cc6d
4e7d89f
89aa929
04d0d5d
577aa81
b7226ea
376e0fb
60a2abb
078a678
6de1cd3
e2fae9c
a713308
66df782
4a7fead
671347c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Generate Artifacts | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
||
| Training links can be found in the actions artifacts tab in github. | ||
|
|
||
| ## Supported Libraries | ||
| - [Ruby](https://github.com/bugcrowd/vrt-ruby) | ||
|
|
||
|
|
||
| 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) | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import json | ||
| import requests | ||
| import tests.utils | ||
|
||
|
|
||
| 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) | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.