@@ -23,10 +23,11 @@ import (
2323 "github.com/interlynk-io/sbomqs/pkg/sbom"
2424)
2525
26- func ScoreSBOM (ctx context.Context , config Config , paths []string ) ([]ScoreResult , error ) {
26+ func ScoreSBOM (ctx context.Context , config Config , paths []string ) ([]Result , error ) {
2727 log := logger .FromContext (ctx )
28- var results []ScoreResult
29- var anyProcessed bool
28+
29+ // var results []Result
30+ // var anyProcessed bool
3031
3132 // Validate paths
3233 validPaths := validatePaths (ctx , paths )
@@ -39,69 +40,68 @@ func ScoreSBOM(ctx context.Context, config Config, paths []string) ([]ScoreResul
3940 return nil , fmt .Errorf ("failed to validate SBOM configuration: %w" , err )
4041 }
4142
42- // 3) Process each valid input
43- log . Debugf ( "processing %d SBOM inputs" , len ( validPaths ))
43+ results := make ([] Result , 0 , len ( validPaths ))
44+ var anyProcessed bool
4445
45- for _ , p := range validPaths {
46+ for _ , path := range validPaths {
4647 switch {
47- case IsURL (p ):
48- log .Debugf ("processing URL: %s" , p )
48+ case IsURL (path ):
49+ log .Debugf ("processing URL: %s" , path )
50+
51+ // sbomFile, sig, err := processURLInput(ctx, p, config)
52+ // if err != nil {
53+ // log.Warnf("failed to process URL %s: %v", p, err)
54+ // continue
55+ // }
56+ // func() {
57+ // defer func() {
58+ // _ = sbomFile.Close()
59+ // _ = os.Remove(sbomFile.Name())
60+ // }()
61+ // res, err := processSBOMInput(ctx, sbomFile, sig, config, p)
62+ // if err != nil {
63+ // log.Warnf("failed to score SBOM from URL %s: %v", p, err)
64+ // return
65+ // }
66+ // results = append(results, res)
67+ // anyProcessed = true
68+ // }()
69+
70+ case IsDir (path ):
71+ // dirResults := processDirectory(ctx, p, config)
72+ // if len(dirResults) > 0 {
73+ // results = append(results, dirResults...)
74+ // anyProcessed = true
75+ // }
4976
50- sbomFile , sig , err := processURLInput (ctx , p , config ) // returns *os.File (temp) + signature bundle
77+ default :
78+ log .Debugf ("processing file: %s" , path )
79+
80+ file , err := getFileHandle (ctx , path )
5181 if err != nil {
52- log .Warnf ("failed to process URL %s: %v" , p , err )
82+ log .Warnf ("failed to open file %s: %v" , path , err )
5383 continue
5484 }
55- func () { // ensure cleanup per-iteration
56- defer func () {
57- _ = sbomFile .Close ()
58- _ = os .Remove (sbomFile .Name ())
59- }()
60- res , err := processSBOMInput (ctx , sbomFile , sig , config , p )
61- if err != nil {
62- log .Warnf ("failed to score SBOM from URL %s: %v" , p , err )
63- return
64- }
65- results = append (results , res )
66- anyProcessed = true
67- }()
68-
69- case IsDir (p ):
70- log .Debugf ("processing directory: %s" , p )
71- dirResults := processDirectory (ctx , p , config ) // []ScoreResult (skip bad files internally)
72- if len (dirResults ) > 0 {
73- results = append (results , dirResults ... )
74- anyProcessed = true
75- }
76-
77- default :
78- if _ , err := os .Stat (p ); err != nil {
79- log .Warnf ("cannot stat path %s: %v" , p , err )
80- continue
85+ defer file .Close ()
86+
87+ signature , err := getSignature (
88+ ctx ,
89+ path ,
90+ config .SignatureBundle .SigValue ,
91+ config .SignatureBundle .PublicKey ,
92+ )
93+ if err != nil {
94+ return nil , fmt .Errorf ("get signature for %q: %w" , path , err )
8195 }
82- log .Debugf ("processing file: %s" , p )
8396
84- f , err := getFileHandle (ctx , p ) // *os.File
97+ res , err := SBOMEvaluation (ctx , file , signature , config , path )
8598 if err != nil {
86- log .Warnf ("failed to open file %s: %v" , p , err )
87- continue
99+ log .Warnf ("failed to process SBOM %s: %v" , path , err )
100+ return nil , fmt . Errorf ( "process SBOM %q: %w" , path , err )
88101 }
89- func () {
90- defer f .Close ()
91-
92- sig , err := getSignature (ctx , p , config .SignatureBundle .SigValue , config .SignatureBundle .PublicKey )
93- if err != nil {
94- log .Warnf ("failed to get signature for %s: %v" , p , err )
95- return
96- }
97- res , err := processSBOMInput (ctx , f , sig , config , p )
98- if err != nil {
99- log .Warnf ("failed to process SBOM %s: %v" , p , err )
100- return
101- }
102- results = append (results , res )
103- anyProcessed = true
104- }()
102+
103+ results = append (results , res )
104+ anyProcessed = true
105105 }
106106 }
107107
0 commit comments