@@ -134,9 +134,19 @@ func NewDBClient(conf *config.Config) (DBInterface, error) {
134
134
135
135
func (c * DBClient ) InsertContainerEventAzure (pushEvent model.AzureContainerPushEventPayload ) {
136
136
var (
137
- tx , _ = c .conn .Begin ()
138
- stmt , _ = tx .Prepare (string (InsertAzureContainerPushEvent ))
137
+ tx , err = c .conn .Begin ()
139
138
)
139
+ if err != nil {
140
+ log .Printf ("error beginning transaction: %v" , err )
141
+ return
142
+ }
143
+
144
+ stmt , err := tx .Prepare (string (InsertAzureContainerPushEvent ))
145
+ if err != nil {
146
+ log .Printf ("error preparing statement: %v" , err )
147
+ return
148
+ }
149
+
140
150
defer stmt .Close ()
141
151
142
152
currentTime := time .Now ().UTC ()
@@ -177,9 +187,21 @@ func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushE
177
187
178
188
func (c * DBClient ) InsertContainerEventQuay (pushEvent model.QuayImagePushPayload ) {
179
189
var (
180
- tx , _ = c .conn .Begin ()
181
- stmt , _ = tx .Prepare (string (InsertQuayContainerPushEvent ))
190
+ tx , err = c .conn .Begin ()
182
191
)
192
+
193
+ if err != nil {
194
+ log .Printf ("error beginning transaction: %v" , err )
195
+ return
196
+ }
197
+
198
+ stmt , err := tx .Prepare (string (InsertQuayContainerPushEvent ))
199
+ if err != nil {
200
+ log .Printf ("error preparing statement: %v" , err )
201
+ return
202
+ }
203
+
204
+
183
205
defer stmt .Close ()
184
206
185
207
currentTime := time .Now ().UTC ()
@@ -222,9 +244,19 @@ func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload
222
244
223
245
func (c * DBClient ) InsertContainerEventJfrog (pushEvent model.JfrogContainerPushEventPayload ) {
224
246
var (
225
- tx , _ = c .conn .Begin ()
226
- stmt , _ = tx .Prepare (string (InsertJfrogContainerPushEvent ))
247
+ tx , err = c .conn .Begin ()
227
248
)
249
+ if err != nil {
250
+ log .Printf ("error beginning transaction: %v" , err )
251
+ return
252
+ }
253
+
254
+ stmt , err := tx .Prepare (string (InsertJfrogContainerPushEvent ))
255
+ if err != nil {
256
+ log .Printf ("error preparing statement: %v" , err )
257
+ return
258
+ }
259
+
228
260
defer stmt .Close ()
229
261
230
262
currentTime := time .Now ().UTC ()
@@ -267,9 +299,18 @@ func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushE
267
299
268
300
func (c * DBClient ) InsertRakeesMetrics (metrics model.RakeesMetrics ) {
269
301
var (
270
- tx , _ = c .conn .Begin ()
271
- stmt , _ = tx .Prepare (string (InsertRakees ))
302
+ tx , err = c .conn .Begin ()
272
303
)
304
+ if err != nil {
305
+ log .Printf ("error beginning transaction: %v" , err )
306
+ return
307
+ }
308
+ stmt , err := tx .Prepare (string (InsertRakees ))
309
+ if err != nil {
310
+ log .Printf ("error preparing statement: %v" , err )
311
+ return
312
+ }
313
+
273
314
defer stmt .Close ()
274
315
275
316
currentTime := time .Now ().UTC ()
@@ -292,9 +333,18 @@ func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) {
292
333
293
334
func (c * DBClient ) InsertKetallEvent (metrics model.Resource ) {
294
335
var (
295
- tx , _ = c .conn .Begin ()
296
- stmt , _ = tx .Prepare (string (InsertKetall ))
336
+ tx , err = c .conn .Begin ()
297
337
)
338
+ if err != nil {
339
+ log .Printf ("error beginning transaction: %v" , err )
340
+ return
341
+ }
342
+ stmt , err := tx .Prepare (string (InsertKetall ))
343
+ if err != nil {
344
+ log .Printf ("error preparing statement: %v" , err )
345
+ return
346
+ }
347
+
298
348
defer stmt .Close ()
299
349
300
350
currentTime := time .Now ().UTC ()
@@ -316,9 +366,18 @@ func (c *DBClient) InsertKetallEvent(metrics model.Resource) {
316
366
317
367
func (c * DBClient ) InsertOutdatedEvent (metrics model.CheckResultfinal ) {
318
368
var (
319
- tx , _ = c .conn .Begin ()
320
- stmt , _ = tx .Prepare (string (InsertOutdated ))
369
+ tx , err = c .conn .Begin ()
321
370
)
371
+ if err != nil {
372
+ log .Printf ("error beginning transaction: %v" , err )
373
+ return
374
+ }
375
+ stmt , err := tx .Prepare (string (InsertOutdated ))
376
+ if err != nil {
377
+ log .Printf ("error preparing statement: %v" , err )
378
+ return
379
+ }
380
+
322
381
defer stmt .Close ()
323
382
324
383
currentTime := time .Now ().UTC ()
@@ -342,9 +401,18 @@ func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) {
342
401
343
402
func (c * DBClient ) InsertDeprecatedAPI (deprecatedAPI model.DeprecatedAPI ) {
344
403
var (
345
- tx , _ = c .conn .Begin ()
346
- stmt , _ = tx .Prepare (string (InsertDepricatedApi ))
404
+ tx , err = c .conn .Begin ()
347
405
)
406
+ if err != nil {
407
+ log .Printf ("error beginning transaction: %v" , err )
408
+ return
409
+ }
410
+ stmt , err := tx .Prepare (string (InsertDepricatedApi ))
411
+ if err != nil {
412
+ log .Printf ("error preparing statement: %v" , err )
413
+ return
414
+ }
415
+
348
416
defer stmt .Close ()
349
417
350
418
deprecated := uint8 (0 )
@@ -375,9 +443,18 @@ func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) {
375
443
376
444
func (c * DBClient ) InsertDeletedAPI (deletedAPI model.DeletedAPI ) {
377
445
var (
378
- tx , _ = c .conn .Begin ()
379
- stmt , _ = tx .Prepare (string (InsertDeletedApi ))
446
+ tx , err = c .conn .Begin ()
380
447
)
448
+ if err != nil {
449
+ log .Printf ("error beginning transaction: %v" , err )
450
+ return
451
+ }
452
+ stmt , err := tx .Prepare (string (InsertDeletedApi ))
453
+ if err != nil {
454
+ log .Printf ("error preparing statement: %v" , err )
455
+ return
456
+ }
457
+
381
458
defer stmt .Close ()
382
459
deleted := uint8 (0 )
383
460
if deletedAPI .Deleted {
@@ -409,9 +486,18 @@ func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) {
409
486
410
487
func (c * DBClient ) InsertKubvizEvent (metrics model.Metrics ) {
411
488
var (
412
- tx , _ = c .conn .Begin ()
413
- stmt , _ = tx .Prepare (string (InsertKubvizEvent ))
489
+ tx , err = c .conn .Begin ()
414
490
)
491
+ if err != nil {
492
+ log .Printf ("error beginning transaction: %v" , err )
493
+ return
494
+ }
495
+ stmt , err := tx .Prepare (string (InsertKubvizEvent ))
496
+ if err != nil {
497
+ log .Printf ("error preparing statement: %v" , err )
498
+ return
499
+ }
500
+
415
501
defer stmt .Close ()
416
502
eventJson , _ := json .Marshal (metrics .Event )
417
503
formattedFirstTimestamp := metrics .Event .FirstTimestamp .Time .UTC ().Format ("2006-01-02 15:04:05" )
@@ -471,9 +557,17 @@ func (c *DBClient) InsertContainerEvent(event string) {
471
557
472
558
func (c * DBClient ) InsertKubeScoreMetrics (metrics model.KubeScoreRecommendations ) {
473
559
var (
474
- tx , _ = c .conn .Begin ()
475
- stmt , _ = tx .Prepare (InsertKubeScore )
560
+ tx , err = c .conn .Begin ()
476
561
)
562
+ if err != nil {
563
+ log .Printf ("error beginning transaction: %v" , err )
564
+ return
565
+ }
566
+ stmt , err := tx .Prepare (InsertKubeScore )
567
+ if err != nil {
568
+ log .Printf ("error preparing statement: %v" , err )
569
+ return
570
+ }
477
571
defer stmt .Close ()
478
572
479
573
currentTime := time .Now ().UTC ()
@@ -497,9 +591,17 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) {
497
591
for _ , result := range finding .Results {
498
592
for _ , vulnerability := range result .Vulnerabilities {
499
593
var (
500
- tx , _ = c .conn .Begin ()
501
- stmt , _ = tx .Prepare (InsertTrivyVul )
594
+ tx , err = c .conn .Begin ()
502
595
)
596
+ if err != nil {
597
+ log .Printf ("error beginning transaction: %v" , err )
598
+ return
599
+ }
600
+ stmt , err := tx .Prepare (InsertTrivyVul )
601
+ if err != nil {
602
+ log .Printf ("error preparing statement: %v" , err )
603
+ return
604
+ }
503
605
if _ , err := stmt .Exec (
504
606
metrics .ID ,
505
607
metrics .ClusterName ,
@@ -528,9 +630,18 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) {
528
630
529
631
for _ , misconfiguration := range result .Misconfigurations {
530
632
var (
531
- tx , _ = c .conn .Begin ()
532
- stmt , _ = tx .Prepare (InsertTrivyMisconfig )
633
+ tx , err = c .conn .Begin ()
533
634
)
635
+ if err != nil {
636
+ log .Printf ("error beginning transaction: %v" , err )
637
+ return
638
+ }
639
+ stmt , err := tx .Prepare (InsertTrivyMisconfig )
640
+ if err != nil {
641
+ log .Printf ("error preparing statement: %v" , err )
642
+ return
643
+ }
644
+
534
645
defer stmt .Close ()
535
646
536
647
currentTime := time .Now ().UTC ()
@@ -567,9 +678,18 @@ func (c *DBClient) InsertTrivyImageMetrics(metrics model.TrivyImage) {
567
678
for _ , result := range metrics .Report .Results {
568
679
for _ , vulnerability := range result .Vulnerabilities {
569
680
var (
570
- tx , _ = c .conn .Begin ()
571
- stmt , _ = tx .Prepare (InsertTrivyImage )
681
+ tx , err = c .conn .Begin ()
572
682
)
683
+ if err != nil {
684
+ log .Printf ("error beginning transaction: %v" , err )
685
+ return
686
+ }
687
+ stmt , err := tx .Prepare (InsertTrivyImage )
688
+ if err != nil {
689
+ log .Printf ("error preparing statement: %v" , err )
690
+ return
691
+ }
692
+
573
693
if _ , err := stmt .Exec (
574
694
metrics .ID ,
575
695
metrics .ClusterName ,
@@ -606,9 +726,18 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
606
726
607
727
if result .CycloneDX != nil {
608
728
var (
609
- tx , _ = c .conn .Begin ()
610
- stmt , _ = tx .Prepare (InsertTrivySbom )
729
+ tx , err = c .conn .Begin ()
611
730
)
731
+ if err != nil {
732
+ log .Printf ("error beginning transaction: %v" , err )
733
+ return
734
+ }
735
+ stmt , err := tx .Prepare (InsertTrivySbom )
736
+ if err != nil {
737
+ log .Printf ("error preparing statement: %v" , err )
738
+ return
739
+ }
740
+
612
741
if _ ,err := stmt .Exec (
613
742
metrics .ID ,
614
743
result .CycloneDX .Metadata .Component .Name ,
@@ -733,9 +862,18 @@ func (c *DBClient) RetrieveKubvizEvent() ([]model.DbEvent, error) {
733
862
734
863
func (c * DBClient ) InsertContainerEventDockerHub (build model.DockerHubBuild ) {
735
864
var (
736
- tx , _ = c .conn .Begin ()
737
- stmt , _ = tx .Prepare (string (InsertDockerHubBuild ))
865
+ tx , err = c .conn .Begin ()
738
866
)
867
+ if err != nil {
868
+ log .Printf ("error beginning transaction: %v" , err )
869
+ return
870
+ }
871
+ stmt , err := tx .Prepare (string (InsertDockerHubBuild ))
872
+
873
+ if err != nil {
874
+ log .Printf ("error preparing statement: %v" , err )
875
+ return
876
+ }
739
877
defer stmt .Close ()
740
878
741
879
currentTime := time .Now ().UTC ()
0 commit comments