5
5
import json
6
6
import logging
7
7
import sys
8
- import timestring
9
8
10
9
from blackduck .HubRestApi import HubInstance
11
10
12
11
parser = argparse .ArgumentParser ("Retreive BOM component info for the given project and version" )
13
12
parser .add_argument ("project_name" )
14
13
parser .add_argument ("version" )
15
14
group = parser .add_mutually_exclusive_group ()
15
+ group .add_argument ("-l" , "--limit" , default = 10 , help = "Set limit on number of components to retrieve" )
16
16
group .add_argument ("-u" , "--unreviewed" , action = 'store_true' )
17
17
group .add_argument ("-r" , "--reviewed" , action = 'store_true' )
18
18
parser .add_argument ("-v" , "--vulnerabilities" , action = 'store_true' , help = "Get the vulnerability info for each of the components" )
19
+ parser .add_argument ("-c" , "--custom_fields" , action = 'store_true' , help = "Get the custom field info for each of the components" )
19
20
20
21
args = parser .parse_args ()
21
22
31
32
32
33
components_url = hub .get_link (version , "components" )
33
34
34
- response = hub .execute_get (components_url )
35
+ components_url += "?limit={}" .format (args .limit )
36
+
37
+ custom_headers = {'Accept' : 'application/vnd.blackducksoftware.bill-of-materials-6+json' }
38
+
39
+ response = hub .execute_get (components_url , custom_headers = custom_headers )
35
40
if response .status_code == 200 :
36
41
components = response .json ()
37
42
components = components .get ('items' , [])
49
54
if response .status_code == 200 :
50
55
vulnerabilities = response .json ().get ('items' , [])
51
56
component ['vulnerabilities' ] = vulnerabilities
57
+
58
+ if args .custom_fields :
59
+ for component in components :
60
+ custom_fields_url = hub .get_link (component , "custom-fields" )
61
+ response = hub .execute_get (custom_fields_url , custom_headers = custom_headers )
62
+ custom_fields = []
63
+ if response .status_code == 200 :
64
+ custom_fields = response .json ().get ('items' , [])
65
+ component ['custom_fields' ] = custom_fields
66
+
52
67
print (json .dumps (components ))
0 commit comments