@@ -33,7 +33,7 @@ import (
33
33
)
34
34
35
35
func TransferRun (ctx context.Context , cmd * cobra.Command , config types.Config ) error {
36
- logger .LogDebug (ctx , "Starting SBOM transfer process" )
36
+ logger .LogDebug (ctx , "Starting SBOM transfer process.... " )
37
37
38
38
// Initialize shared context with metadata support
39
39
transferCtx := tcontext .NewTransferMetadata (ctx )
@@ -59,14 +59,14 @@ func TransferRun(ctx context.Context, cmd *cobra.Command, config types.Config) e
59
59
return fmt .Errorf ("input adapter error: %w" , err )
60
60
}
61
61
62
- logger .LogDebug (transferCtx .Context , "input adapter instance config" , "value" , inputAdapterInstance )
62
+ logger .LogDebug (transferCtx .Context , "Input adapter instance config" , "value" , inputAdapterInstance )
63
63
64
64
// Parse and validate output adapter parameters
65
65
if err := outputAdapterInstance .ParseAndValidateParams (cmd ); err != nil {
66
66
return fmt .Errorf ("output adapter error: %w" , err )
67
67
}
68
68
69
- logger .LogDebug (transferCtx .Context , "output adapter instance config" , "value" , outputAdapterInstance )
69
+ logger .LogDebug (transferCtx .Context , "Output adapter instance config" , "value" , outputAdapterInstance )
70
70
71
71
// Fetch SBOMs lazily using the iterator
72
72
sbomIterator , err := inputAdapterInstance .FetchSBOMs (transferCtx )
@@ -127,7 +127,8 @@ func sbomConversion(sbomIterator iterator.SBOMIterator, transferCtx tcontext.Tra
127
127
logger .LogDebug (transferCtx .Context , "Processing SBOM conversion" )
128
128
129
129
var convertedSBOMs []* iterator.SBOM
130
-
130
+ var totalMinifiedSBOM int
131
+ var totalSBOM int
131
132
for {
132
133
sbom , err := sbomIterator .Next (transferCtx .Context )
133
134
if err == io .EOF {
@@ -146,7 +147,7 @@ func sbomConversion(sbomIterator iterator.SBOMIterator, transferCtx tcontext.Tra
146
147
}
147
148
148
149
// let's check minimfied SBOM
149
- sbom .Data , err = convertMinifiedJSON (transferCtx , convertedData )
150
+ sbom .Data , totalMinifiedSBOM , err = convertMinifiedJSON (transferCtx , convertedData , totalMinifiedSBOM )
150
151
151
152
// Update SBOM data with converted content
152
153
sbom .Data = convertedData
@@ -156,31 +157,29 @@ func sbomConversion(sbomIterator iterator.SBOMIterator, transferCtx tcontext.Tra
156
157
// transferCtx.FilePath = sbom.Path // Sync FilePath for logging
157
158
}
158
159
159
- // err = os.WriteFile(sbom.Path, sbom.Data, 0o644)
160
- // if err != nil {
161
- // fmt.Println("Error writing formatted JSON:", err)
162
- // }
163
-
160
+ totalSBOM ++
164
161
convertedSBOMs = append (convertedSBOMs , sbom )
165
162
}
163
+
164
+ logger .LogDebug (transferCtx .Context , "Out of total SBOM" , "value" , totalSBOM , "total minifiedJSONSBOM converted to preety JSON" , totalMinifiedSBOM )
166
165
logger .LogDebug (transferCtx .Context , "Successfully SBOM conversion" )
167
166
168
167
return convertedSBOMs
169
168
}
170
169
171
170
func sbomProcessing (transferCtx * tcontext.TransferMetadata , config types.Config , sbomIterator iterator.SBOMIterator ) iterator.SBOMIterator {
172
- logger .LogDebug (transferCtx .Context , "Checking adapter eligibility for undergoing conversion layer" , "adapter type" , config .DestinationType )
171
+ logger .LogDebug (transferCtx .Context , "Checking adapter eligibility for undergoing conversion layer" , "adapter type" , config .DestinationAdapter )
173
172
174
173
// convert sbom to cdx for DTrack adapter only
175
- if types .AdapterType (config .DestinationType ) == types .DtrackAdapterType {
176
- logger .LogDebug (transferCtx .Context , "Adapter eligible for conversion layer" , "adapter type" , config .DestinationType )
174
+ if types .AdapterType (config .DestinationAdapter ) == types .DtrackAdapterType {
175
+ logger .LogDebug (transferCtx .Context , "Adapter eligible for conversion layer" , "adapter type" , config .DestinationAdapter )
177
176
178
177
logger .LogDebug (transferCtx .Context , "SBOM conversion will take place" )
179
178
convertedSBOMs := sbomConversion (sbomIterator , * transferCtx )
180
179
181
180
return iterator .NewMemoryIterator (convertedSBOMs )
182
181
} else {
183
- logger .LogDebug (transferCtx .Context , "Adapter not eligible for conversion layer" , "adapter type" , config .DestinationType )
182
+ logger .LogDebug (transferCtx .Context , "Adapter not eligible for conversion layer" , "adapter type" , config .DestinationAdapter )
184
183
logger .LogDebug (transferCtx .Context , "SBOM conversion will not take place" )
185
184
return sbomIterator
186
185
}
@@ -208,19 +207,16 @@ func isMinifiedJSON(data []byte) (bool, []byte, []byte, error) {
208
207
return true , data , prettyJSON , nil // Minified JSON detected
209
208
}
210
209
211
- func convertMinifiedJSON (transferCtx tcontext.TransferMetadata , data []byte ) ([]byte , error ) {
210
+ func convertMinifiedJSON (transferCtx tcontext.TransferMetadata , data []byte , totalMinifiedSBOM int ) ([]byte , int , error ) {
212
211
minified , original , formatted , err := isMinifiedJSON (data )
213
212
if err != nil {
214
213
logger .LogError (transferCtx .Context , err , "Error while isMinifiedJSON" )
215
- return original , nil
214
+ return original , totalMinifiedSBOM , nil
216
215
}
217
216
218
217
if minified {
219
- logger .LogDebug (transferCtx .Context , "Minified JSON detected! Converting to pretty format." )
220
- logger .LogDebug (transferCtx .Context , "Minified JSON converted to preety JSON!" )
221
-
222
- return formatted , nil
223
-
218
+ totalMinifiedSBOM ++
219
+ return formatted , totalMinifiedSBOM , nil
224
220
}
225
- return original , nil
221
+ return original , totalMinifiedSBOM , nil
226
222
}
0 commit comments