@@ -133,10 +133,19 @@ func NewDBClient(conf *config.Config) (DBInterface, error) {
133
133
}
134
134
135
135
func (c * DBClient ) InsertContainerEventAzure (pushEvent model.AzureContainerPushEventPayload ) {
136
- var (
137
- tx , _ = c .conn .Begin ()
138
- stmt , _ = tx .Prepare (string (InsertAzureContainerPushEvent ))
139
- )
136
+
137
+ tx , err := c .conn .Begin ()
138
+ if err != nil {
139
+ log .Printf ("error beginning transaction: %v" , err )
140
+ return
141
+ }
142
+
143
+ stmt , err := tx .Prepare (string (InsertAzureContainerPushEvent ))
144
+ if err != nil {
145
+ log .Printf ("error preparing statement: %v" , err )
146
+ return
147
+ }
148
+
140
149
defer stmt .Close ()
141
150
142
151
currentTime := time .Now ().UTC ()
@@ -176,10 +185,18 @@ func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushE
176
185
}
177
186
178
187
func (c * DBClient ) InsertContainerEventQuay (pushEvent model.QuayImagePushPayload ) {
179
- var (
180
- tx , _ = c .conn .Begin ()
181
- stmt , _ = tx .Prepare (string (InsertQuayContainerPushEvent ))
182
- )
188
+ tx , err := c .conn .Begin ()
189
+ if err != nil {
190
+ log .Printf ("error beginning transaction: %v" , err )
191
+ return
192
+ }
193
+
194
+ stmt , err := tx .Prepare (string (InsertQuayContainerPushEvent ))
195
+ if err != nil {
196
+ log .Printf ("error preparing statement: %v" , err )
197
+ return
198
+ }
199
+
183
200
defer stmt .Close ()
184
201
185
202
currentTime := time .Now ().UTC ()
@@ -221,10 +238,18 @@ func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload
221
238
}
222
239
223
240
func (c * DBClient ) InsertContainerEventJfrog (pushEvent model.JfrogContainerPushEventPayload ) {
224
- var (
225
- tx , _ = c .conn .Begin ()
226
- stmt , _ = tx .Prepare (string (InsertJfrogContainerPushEvent ))
227
- )
241
+ tx , err := c .conn .Begin ()
242
+ if err != nil {
243
+ log .Printf ("error beginning transaction: %v" , err )
244
+ return
245
+ }
246
+
247
+ stmt , err := tx .Prepare (string (InsertJfrogContainerPushEvent ))
248
+ if err != nil {
249
+ log .Printf ("error preparing statement: %v" , err )
250
+ return
251
+ }
252
+
228
253
defer stmt .Close ()
229
254
230
255
currentTime := time .Now ().UTC ()
@@ -266,10 +291,17 @@ func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushE
266
291
}
267
292
268
293
func (c * DBClient ) InsertRakeesMetrics (metrics model.RakeesMetrics ) {
269
- var (
270
- tx , _ = c .conn .Begin ()
271
- stmt , _ = tx .Prepare (string (InsertRakees ))
272
- )
294
+ tx , err := c .conn .Begin ()
295
+ if err != nil {
296
+ log .Printf ("error beginning transaction: %v" , err )
297
+ return
298
+ }
299
+ stmt , err := tx .Prepare (string (InsertRakees ))
300
+ if err != nil {
301
+ log .Printf ("error preparing statement: %v" , err )
302
+ return
303
+ }
304
+
273
305
defer stmt .Close ()
274
306
275
307
currentTime := time .Now ().UTC ()
@@ -291,10 +323,17 @@ func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) {
291
323
}
292
324
293
325
func (c * DBClient ) InsertKetallEvent (metrics model.Resource ) {
294
- var (
295
- tx , _ = c .conn .Begin ()
296
- stmt , _ = tx .Prepare (string (InsertKetall ))
297
- )
326
+ tx , err := c .conn .Begin ()
327
+ if err != nil {
328
+ log .Printf ("error beginning transaction: %v" , err )
329
+ return
330
+ }
331
+ stmt , err := tx .Prepare (string (InsertKetall ))
332
+ if err != nil {
333
+ log .Printf ("error preparing statement: %v" , err )
334
+ return
335
+ }
336
+
298
337
defer stmt .Close ()
299
338
300
339
currentTime := time .Now ().UTC ()
@@ -315,10 +354,17 @@ func (c *DBClient) InsertKetallEvent(metrics model.Resource) {
315
354
}
316
355
317
356
func (c * DBClient ) InsertOutdatedEvent (metrics model.CheckResultfinal ) {
318
- var (
319
- tx , _ = c .conn .Begin ()
320
- stmt , _ = tx .Prepare (string (InsertOutdated ))
321
- )
357
+ tx , err := c .conn .Begin ()
358
+ if err != nil {
359
+ log .Printf ("error beginning transaction: %v" , err )
360
+ return
361
+ }
362
+ stmt , err := tx .Prepare (string (InsertOutdated ))
363
+ if err != nil {
364
+ log .Printf ("error preparing statement: %v" , err )
365
+ return
366
+ }
367
+
322
368
defer stmt .Close ()
323
369
324
370
currentTime := time .Now ().UTC ()
@@ -341,10 +387,17 @@ func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) {
341
387
}
342
388
343
389
func (c * DBClient ) InsertDeprecatedAPI (deprecatedAPI model.DeprecatedAPI ) {
344
- var (
345
- tx , _ = c .conn .Begin ()
346
- stmt , _ = tx .Prepare (string (InsertDepricatedApi ))
347
- )
390
+ tx , err := c .conn .Begin ()
391
+ if err != nil {
392
+ log .Printf ("error beginning transaction: %v" , err )
393
+ return
394
+ }
395
+ stmt , err := tx .Prepare (string (InsertDepricatedApi ))
396
+ if err != nil {
397
+ log .Printf ("error preparing statement: %v" , err )
398
+ return
399
+ }
400
+
348
401
defer stmt .Close ()
349
402
350
403
deprecated := uint8 (0 )
@@ -374,10 +427,17 @@ func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) {
374
427
}
375
428
376
429
func (c * DBClient ) InsertDeletedAPI (deletedAPI model.DeletedAPI ) {
377
- var (
378
- tx , _ = c .conn .Begin ()
379
- stmt , _ = tx .Prepare (string (InsertDeletedApi ))
380
- )
430
+ tx , err := c .conn .Begin ()
431
+ if err != nil {
432
+ log .Printf ("error beginning transaction: %v" , err )
433
+ return
434
+ }
435
+ stmt , err := tx .Prepare (string (InsertDeletedApi ))
436
+ if err != nil {
437
+ log .Printf ("error preparing statement: %v" , err )
438
+ return
439
+ }
440
+
381
441
defer stmt .Close ()
382
442
deleted := uint8 (0 )
383
443
if deletedAPI .Deleted {
@@ -408,10 +468,17 @@ func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) {
408
468
}
409
469
410
470
func (c * DBClient ) InsertKubvizEvent (metrics model.Metrics ) {
411
- var (
412
- tx , _ = c .conn .Begin ()
413
- stmt , _ = tx .Prepare (string (InsertKubvizEvent ))
414
- )
471
+ tx , err := c .conn .Begin ()
472
+ if err != nil {
473
+ log .Printf ("error beginning transaction: %v" , err )
474
+ return
475
+ }
476
+ stmt , err := tx .Prepare (string (InsertKubvizEvent ))
477
+ if err != nil {
478
+ log .Printf ("error preparing statement: %v" , err )
479
+ return
480
+ }
481
+
415
482
defer stmt .Close ()
416
483
eventJson , _ := json .Marshal (metrics .Event )
417
484
formattedFirstTimestamp := metrics .Event .FirstTimestamp .Time .UTC ().Format ("2006-01-02 15:04:05" )
@@ -470,10 +537,16 @@ func (c *DBClient) InsertContainerEvent(event string) {
470
537
}
471
538
472
539
func (c * DBClient ) InsertKubeScoreMetrics (metrics model.KubeScoreRecommendations ) {
473
- var (
474
- tx , _ = c .conn .Begin ()
475
- stmt , _ = tx .Prepare (InsertKubeScore )
476
- )
540
+ tx , err := c .conn .Begin ()
541
+ if err != nil {
542
+ log .Printf ("error beginning transaction: %v" , err )
543
+ return
544
+ }
545
+ stmt , err := tx .Prepare (InsertKubeScore )
546
+ if err != nil {
547
+ log .Printf ("error preparing statement: %v" , err )
548
+ return
549
+ }
477
550
defer stmt .Close ()
478
551
479
552
currentTime := time .Now ().UTC ()
@@ -496,10 +569,16 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) {
496
569
for _ , finding := range metrics .Report .Findings {
497
570
for _ , result := range finding .Results {
498
571
for _ , vulnerability := range result .Vulnerabilities {
499
- var (
500
- tx , _ = c .conn .Begin ()
501
- stmt , _ = tx .Prepare (InsertTrivyVul )
502
- )
572
+ tx , err := c .conn .Begin ()
573
+ if err != nil {
574
+ log .Printf ("error beginning transaction: %v" , err )
575
+ return
576
+ }
577
+ stmt , err := tx .Prepare (InsertTrivyVul )
578
+ if err != nil {
579
+ log .Printf ("error preparing statement: %v" , err )
580
+ return
581
+ }
503
582
if _ , err := stmt .Exec (
504
583
metrics .ID ,
505
584
metrics .ClusterName ,
@@ -527,10 +606,17 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) {
527
606
}
528
607
529
608
for _ , misconfiguration := range result .Misconfigurations {
530
- var (
531
- tx , _ = c .conn .Begin ()
532
- stmt , _ = tx .Prepare (InsertTrivyMisconfig )
533
- )
609
+ tx , err := c .conn .Begin ()
610
+ if err != nil {
611
+ log .Printf ("error beginning transaction: %v" , err )
612
+ return
613
+ }
614
+ stmt , err := tx .Prepare (InsertTrivyMisconfig )
615
+ if err != nil {
616
+ log .Printf ("error preparing statement: %v" , err )
617
+ return
618
+ }
619
+
534
620
defer stmt .Close ()
535
621
536
622
currentTime := time .Now ().UTC ()
@@ -566,10 +652,17 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) {
566
652
func (c * DBClient ) InsertTrivyImageMetrics (metrics model.TrivyImage ) {
567
653
for _ , result := range metrics .Report .Results {
568
654
for _ , vulnerability := range result .Vulnerabilities {
569
- var (
570
- tx , _ = c .conn .Begin ()
571
- stmt , _ = tx .Prepare (InsertTrivyImage )
572
- )
655
+ tx , err := c .conn .Begin ()
656
+ if err != nil {
657
+ log .Printf ("error beginning transaction: %v" , err )
658
+ return
659
+ }
660
+ stmt , err := tx .Prepare (InsertTrivyImage )
661
+ if err != nil {
662
+ log .Printf ("error preparing statement: %v" , err )
663
+ return
664
+ }
665
+
573
666
if _ , err := stmt .Exec (
574
667
metrics .ID ,
575
668
metrics .ClusterName ,
@@ -605,11 +698,18 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
605
698
result := metrics .Report
606
699
607
700
if result .CycloneDX != nil {
608
- var (
609
- tx , _ = c .conn .Begin ()
610
- stmt , _ = tx .Prepare (InsertTrivySbom )
611
- )
612
- if _ ,err := stmt .Exec (
701
+ tx , err := c .conn .Begin ()
702
+ if err != nil {
703
+ log .Printf ("error beginning transaction: %v" , err )
704
+ return
705
+ }
706
+ stmt , err := tx .Prepare (InsertTrivySbom )
707
+ if err != nil {
708
+ log .Printf ("error preparing statement: %v" , err )
709
+ return
710
+ }
711
+
712
+ if _ , err := stmt .Exec (
613
713
metrics .ID ,
614
714
result .CycloneDX .Metadata .Component .Name ,
615
715
result .CycloneDX .Metadata .Component .PackageURL ,
@@ -619,18 +719,18 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
619
719
result .CycloneDX .BOMFormat ,
620
720
result .CycloneDX .Metadata .Component .Version ,
621
721
result .CycloneDX .Metadata .Component .MIMEType ,
622
- ); err != nil {
722
+ ); err != nil {
623
723
log .Fatal (err )
624
724
}
625
- if err := tx .Commit ();err != nil {
725
+ if err := tx .Commit (); err != nil {
626
726
log .Fatal (err )
627
727
}
628
728
stmt .Close ()
629
- }else {
729
+ } else {
630
730
log .Println ("sbom payload not available for db insertion, skipping db insertion" )
631
731
632
732
}
633
-
733
+
634
734
}
635
735
func (c * DBClient ) Close () {
636
736
_ = c .conn .Close ()
@@ -732,10 +832,17 @@ func (c *DBClient) RetrieveKubvizEvent() ([]model.DbEvent, error) {
732
832
}
733
833
734
834
func (c * DBClient ) InsertContainerEventDockerHub (build model.DockerHubBuild ) {
735
- var (
736
- tx , _ = c .conn .Begin ()
737
- stmt , _ = tx .Prepare (string (InsertDockerHubBuild ))
738
- )
835
+ tx , err := c .conn .Begin ()
836
+ if err != nil {
837
+ log .Printf ("error beginning transaction: %v" , err )
838
+ return
839
+ }
840
+ stmt , err := tx .Prepare (string (InsertDockerHubBuild ))
841
+
842
+ if err != nil {
843
+ log .Printf ("error preparing statement: %v" , err )
844
+ return
845
+ }
739
846
defer stmt .Close ()
740
847
741
848
currentTime := time .Now ().UTC ()
0 commit comments