Skip to content

Commit 0bd366f

Browse files
committed
fixes missing error handling, only building postgresql on tags
1 parent bd2ac2c commit 0bd366f

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

.github/workflows/devguard-scanner.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
devguard-token: ${{ secrets.DEVGUARD_TOKEN }}
122122

123123
postgresql-pipeline:
124-
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main'
124+
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/')'
125125
uses: l3montree-dev/devguard-action/.github/workflows/full-nix.yml@nix
126126
permissions:
127127
contents: read

vulndb/vulndb_service.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,10 @@ func (s *VulnDBService) applyFromWorkingDir(ctx context.Context, tx pgx.Tx, work
541541
if err != nil {
542542
return fmt.Errorf("could not calculate integrity information: %w", err)
543543
}
544-
valid, err := validateIntegrityInformation(workingDir, integrityGroundTruth, localIntegrity)
544+
err = validateIntegrityInformation(workingDir, integrityGroundTruth, localIntegrity)
545545
if err != nil {
546546
return fmt.Errorf("could not validate integrity: %w", err)
547547
}
548-
if !valid {
549-
return nil
550-
}
551548
return nil
552549
}
553550

@@ -787,25 +784,31 @@ type integrityInformation struct {
787784
ImportTimestamp time.Time `json:"import_timestamp"`
788785
}
789786

790-
func validateIntegrityInformation(workingDir string, groundTruth integrityInformation, localIntegrityInformation []tableIntegrityInformation) (bool, error) {
787+
func validateIntegrityInformation(workingDir string, groundTruth integrityInformation, localIntegrityInformation []tableIntegrityInformation) error {
788+
didErr := false
791789
for _, tableIntegrity := range localIntegrityInformation {
792790
found := false
793791
for _, tableGroundTruth := range groundTruth.TableIntegrity {
794792
if tableGroundTruth.TableName == tableIntegrity.TableName {
795793
if !tableIntegrity.isEqual(tableGroundTruth) {
796794
slog.Error("invalid checksum when importing", "table", tableIntegrity.TableName, "expectedCount", tableGroundTruth.TotalCount, "actualCount", tableIntegrity.TotalCount, "expectedChecksum", fmt.Sprintf("%x", tableGroundTruth.Checksum), "actualChecksum", fmt.Sprintf("%x", tableIntegrity.Checksum))
797-
return false, nil
795+
796+
didErr = true
798797
} else {
799798
found = true
800799
break
801800
}
802801
}
803802
}
804803
if !found {
805-
return false, fmt.Errorf("could not find integrity information for table %s", tableIntegrity.TableName)
804+
return fmt.Errorf("could not find integrity information for table %s", tableIntegrity.TableName)
806805
}
807806
}
808-
return true, nil
807+
if didErr {
808+
return fmt.Errorf("integrity validation failed for one or more tables when importing from %s", workingDir)
809+
}
810+
811+
return nil
809812
}
810813

811814
func calculateTotalIntegrityInformation(ctx context.Context, tx pgx.Tx) ([]tableIntegrityInformation, error) {
@@ -879,6 +882,7 @@ func calculateTotalIntegrityInformation(ctx context.Context, tx pgx.Tx) ([]table
879882
UNION ALL SELECT table_name, row_count, checksum FROM malicious_affected_components_integrity
880883
`
881884

885+
slog.Info("start calculating integrity information")
882886
start := time.Now()
883887
rows, err := tx.Query(ctx, query)
884888
if err != nil {
@@ -897,7 +901,10 @@ func calculateTotalIntegrityInformation(ctx context.Context, tx pgx.Tx) ([]table
897901
if err := rows.Err(); err != nil {
898902
return nil, fmt.Errorf("could not read integrity rows: %w", err)
899903
}
900-
slog.Info("calculated integrity information", "tables", len(results), "time", time.Since(start))
904+
slog.Info("finished calculating integrity information", "took", time.Since(start).Round(time.Millisecond))
905+
for _, r := range results {
906+
slog.Info("integrity", "table", r.TableName, "rows", r.TotalCount, "checksum", fmt.Sprintf("%x", r.Checksum))
907+
}
901908

902909
return results, nil
903910
}

0 commit comments

Comments
 (0)