-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
baseline2rdf.py
executable file
·66 lines (57 loc) · 2.13 KB
/
baseline2rdf.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
import argparse
rdjson = {
'source': {
'name': 'detect-secrets',
'url': 'https://github.com/Yelp/detect-secrets'
},
'severity': 'ERROR',
'diagnostics': []
}
def main(skip_audited: bool = False, verbose: bool = False):
baseline = json.load(sys.stdin)
if not baseline['results']:
baseline['results'] = {}
results = {}
for detects in baseline['results'].values():
for item in detects:
if skip_audited and 'is_secret' in item and not item['is_secret']:
if verbose:
print('Skipping verified secret in : %s' % item['filename'])
else:
key = '%s:%s' % (item['filename'], item['line_number'])
if key in results:
results[key]['message'] += '\n* ' + item['type']
else:
results[key] = {
'message': '\n* ' + item['type'],
'location': {
'path': item['filename'],
'range': {
'start': {
'line': item['line_number']
}
}
}
}
for result in results.values():
rdjson['diagnostics'].append(result)
try:
sys.stdout.write(json.dumps(rdjson, indent=2, ensure_ascii=False))
sys.stdout.write('\n')
except Exception as error:
sys.stderr.write('Error: %s\n' % error)
return 1
return 0
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--skip-audited', dest='skip_audited', action='store_true')
parser.add_argument('--no-skip-audited', dest='skip_audited', action='store_false')
parser.set_defaults(skip_audited=False)
parser.add_argument('--verbose', dest='verbose', action='store_true')
parser.set_defaults(verbose=False)
args = parser.parse_args()
sys.exit(main(skip_audited=args.skip_audited, verbose=args.verbose))