forked from keighl/mandrill
-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (61 loc) · 2.77 KB
/
nancy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: Sonatype Nancy - Every week
on:
schedule:
- cron: "0 0 * * 1"
jobs:
security:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up Go 1.x in order to write go.list file
uses: actions/setup-go@v2
with:
go-version: ^1.15
- name: Install Sonatype Nancy
run: wget https://github.com/sonatype-nexus-community/nancy/releases/download/v1.0.36/nancy-v1.0.36-linux-amd64 && mv nancy-v1.0.36-linux-amd64 nancy && chmod +x nancy
- name: Generate json output
run: echo $(go list -json -deps | ./nancy sleuth -o json > /tmp/results.json)
- name: Check if there are vulnerable packages
id: run_nancy
run: |
cat >> pretty.py <<EOL
import json
import sys
with open('/tmp/results.json') as json_file:
data1 = json.loads(json_file.read())
if 'audited' not in data1:
print('\x1b[1;32;49m' + 'No vulnerable packages 🎉' + '\x1b[0m')
sys.exit(0)
vulnerable = False
for item in data1['audited']:
if len(item['Vulnerabilities']) == 0:
continue
print('\x1b[1;31;49m' + '{}'.format(item['Coordinates']) + '\x1b[0m')
for elem in item['Vulnerabilities']:
if float(elem['CvssScore']) >= 7.5:
print('\x1b[1;31;49m' + '🐛 Sonatype OSS Index ID: {}'.format(elem['ID']) + '\x1b[0m')
elif float(elem['CvssScore']) < 7.5 and float(elem['CvssScore']) >= 4.5:
print('\x1b[1;33;49m' + '🐛 Sonatype OSS Index ID: {}'.format(elem['ID']) + '\x1b[0m')
else:
print('🐛 Sonatype OSS Index ID: {}'.format(elem['ID']))
print('🆔 CVE: {}'.format(elem['Cve']))
print('⚠️ CVSS: {}'.format(elem['CvssVector']))
print("📋 Description: {}".format(elem['Description']))
print("👉 More info: https://ossindex.sonatype.org/vulnerability/{}\n".format(elem['ID']))
vulnerable = True
if vulnerable:
sys.exit(1)
print('\x1b[1;32;49m' + 'No vulnerable packages 🎉' + '\x1b[0m')
sys.exit(0)
EOL
python3 pretty.py
- name: Send slack message
uses: slackapi/[email protected]
if: failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
MESSAGE: ${{ join(steps.run_nancy.outputs.*, '\n') }}
BUILD_URL: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
with:
payload: '{"message":"$MESSAGE", "url":"$BUILD_URL"}'