14
14
from pprint import pprint
15
15
import array as arr
16
16
17
+ from urllib3 .exceptions import ReadTimeoutError
18
+
17
19
http .client ._MAXHEADERS = 1000
18
20
19
21
logging .basicConfig (
@@ -52,8 +54,8 @@ def RepWarning(msg):
52
54
parser .add_argument ("--dryrun" , dest = 'dry_run' , type = int , default = 0 , help = "Dry run test (0=no 1=yes)" )
53
55
54
56
parser .add_argument ("--no-verify" , dest = 'verify' , action = 'store_false' , help = "Disable TLS certificate verification" )
55
- parser .add_argument ("-t" , "-- timeout" , default = 15 , type = int , help = "Adjust the (HTTP) session timeout value (default: 15s )" )
56
- parser .add_argument ("-r" , "- -retries" , default = 3 , type = int , help = "Adjust the number of retries on failure (default: 3)" )
57
+ parser .add_argument ("-- timeout" , default = 60 , type = int , help = "Adjust the (HTTP) session timeout value (default: 60s )" )
58
+ parser .add_argument ("--retries" , default = 3 , type = int , help = "Adjust the number of retries on failure (default: 3)" )
57
59
58
60
args = parser .parse_args ()
59
61
@@ -64,8 +66,8 @@ def RepWarning(msg):
64
66
# access the Black Duck platform
65
67
bd = Client (
66
68
base_url = args .base_url ,
67
- token = access_token ,
68
69
verify = args .verify ,
70
+ token = access_token ,
69
71
timeout = args .timeout ,
70
72
retries = args .retries ,
71
73
)
@@ -205,8 +207,9 @@ def RepWarning(msg):
205
207
break
206
208
207
209
my_statistics ['_cntComponents' ] += 1
208
- RepDebug (4 , ' Component: %s (%s)' %
209
- (this_comp_data ['componentName' ], this_comp_data ['componentVersionName' ]))
210
+ comp_label = "{} ({})" .format (this_comp_data ['componentName' ], this_comp_data ['componentVersionName' ])
211
+
212
+ RepDebug (4 , ' Component: %s' % comp_label )
210
213
211
214
if this_comp_data ['inputExternalIds' ].__len__ () > 0 :
212
215
inputExternalIds = this_comp_data ['inputExternalIds' ][0 ]
@@ -218,46 +221,69 @@ def RepWarning(msg):
218
221
219
222
# refresh the copyrights for this component
220
223
if this_comp_data ['origins' ].__len__ () > 0 :
221
- url = this_comp_data ['origins' ][0 ]['origin' ]
222
- else :
223
- # no origins
224
- RepWarning ('No origin defined for [%s]' % this_comp_data ['componentVersion' ])
225
- # url = this_comp_data['componentVersion']
226
- url = ''
227
-
228
- if len (url ) > 0 :
229
- # refresh end point
230
- url += "/copyrights-refresh"
231
-
232
- if args .dry_run != 0 :
233
- RepDebug (1 , "DryRun: %s" % url )
234
- else :
235
- try :
236
- response = bd .session .put (url , data = None , ** refresh_kwargs )
237
- RepDebug (5 ,'Refresh response %s' % response )
238
- except ReadTimeoutError :
239
- print ('Failed to confirm copyrights refresh' )
240
-
241
- my_statistics ['_cntRefresh' ] += 1
224
+
225
+ n_origin = 0
226
+
227
+ for this_origin in this_comp_data ['origins' ]:
228
+
229
+ n_origin += 1
230
+ origin_id = this_origin ['externalId' ]
231
+ url = this_origin ['origin' ]
232
+
233
+ # refresh with end point
234
+ url += "/copyrights-refresh"
235
+
236
+ status = - 1
237
+
238
+ if args .dry_run != 0 :
239
+ RepDebug (1 , "DryRun: no=%d origin=%s url=%s" % (n_origin , origin_id , url ))
240
+ else :
241
+ try :
242
+ response = bd .session .put (url , data = None , ** refresh_kwargs )
243
+ RepDebug (5 ,'Refresh response: origin [%s] [%s]' % (this_origin , response ))
244
+ my_statistics ['_cntRefresh' ] += 1
245
+ status = 0
246
+
247
+ except Exception :
248
+ print ('Failed to confirm copyrights refresh' )
249
+ status = 1
250
+
251
+
252
+ # if recording the data - perhaps outputting to a CSV file
253
+ if args .dump_data :
254
+ my_data = {}
255
+ my_data ['componentName' ] = this_comp_data ['componentName' ]
256
+ my_data ['componentVersion' ] = this_comp_data ['componentVersionName' ]
257
+ my_data ['status' ] = status
258
+ my_data ['url' ] = url
259
+
260
+ if hasattr (args , 'debug' ) and 5 <= args .debug :
261
+ pprint (my_data )
262
+
263
+ # add to our list
264
+ all_my_comp_data .append (my_data )
242
265
243
266
else :
267
+ # no origins defined
268
+ RepWarning ('No origin(s) defined for [%s]' % comp_label )
244
269
my_statistics ['_cntNoOrigins' ] += 1
270
+ origin_id = ''
271
+ status = 3
245
272
url = 'n/a'
246
273
274
+ # if recording the data
275
+ if args .dump_data :
276
+ my_data = {}
277
+ my_data ['componentName' ] = this_comp_data ['componentName' ]
278
+ my_data ['componentVersion' ] = this_comp_data ['componentVersionName' ]
279
+ my_data ['status' ] = status
280
+ my_data ['url' ] = url
247
281
248
- # if recording the data - perhaps outputting to a CSV file
249
- if args .dump_data :
250
- my_data = {}
251
- my_data ['componentName' ] = this_comp_data ['componentName' ]
252
- my_data ['componentVersion' ] = this_comp_data ['componentVersionName' ]
253
- my_data ['url' ] = url
254
-
255
- if hasattr (args , 'debug' ) and 5 <= args .debug :
256
- pprint (my_data )
257
-
258
- # add to our list
259
- all_my_comp_data .append (my_data )
282
+ if hasattr (args , 'debug' ) and 5 <= args .debug :
283
+ pprint (my_data )
260
284
285
+ # add to our list
286
+ all_my_comp_data .append (my_data )
261
287
262
288
# end of processing loop
263
289
@@ -280,6 +306,7 @@ def RepWarning(msg):
280
306
field_names = [
281
307
'Component' ,
282
308
'Component Version' ,
309
+ 'Status' ,
283
310
'Url'
284
311
]
285
312
@@ -290,6 +317,7 @@ def RepWarning(msg):
290
317
row_data = {
291
318
'Component' : my_comp_data ['componentName' ],
292
319
'Component Version' : my_comp_data ['componentVersion' ],
320
+ 'Status' : my_comp_data ['status' ],
293
321
'Url' : my_comp_data ['url' ]
294
322
}
295
323
writer .writerow (row_data )
0 commit comments