@@ -112,10 +112,6 @@ func getDefinitions(ctx context.Context, client *http.Client, purls []string, co
112112 return nil , fmt .Errorf ("error unmarshalling JSON: %v" , err )
113113 }
114114
115- if len (purls ) != len (definitions ) {
116- return nil , fmt .Errorf ("failed to get expected responses back! Purl count: %d, returned definition count %d" , len (purls ), len (definitions ))
117- }
118-
119115 for coordinate , definition := range definitions {
120116 definitionMap [coordinateToPurl [coordinate ]] = definition
121117 }
@@ -124,7 +120,7 @@ func getDefinitions(ctx context.Context, client *http.Client, purls []string, co
124120}
125121
126122// EvaluateClearlyDefinedDefinition converts the purls into coordinates to query clearly defined
127- func EvaluateClearlyDefinedDefinition (ctx context.Context , client * http.Client , purls []string ) ([]* processor.Document , error ) {
123+ func EvaluateClearlyDefinedDefinition (ctx context.Context , client * http.Client , purls []string , docChannel chan <- * processor. Document ) ([]* processor.Document , error ) {
128124 logger := logging .FromContext (ctx )
129125 var batchCoordinates []string
130126 var queryPurls []string
@@ -147,7 +143,7 @@ func EvaluateClearlyDefinedDefinition(ctx context.Context, client *http.Client,
147143 batchCoordinates = append (batchCoordinates , coordinate .ToString ())
148144 }
149145 }
150- if genCDDocs , err := generateDefinitions (ctx , client , batchCoordinates , queryPurls ); err != nil {
146+ if genCDDocs , err := generateDefinitions (ctx , client , batchCoordinates , queryPurls , docChannel ); err != nil {
151147 return nil , fmt .Errorf ("generateDefinitions failed with error: %w" , err )
152148 } else {
153149 generatedCDDocs = append (generatedCDDocs , genCDDocs ... )
@@ -158,21 +154,21 @@ func EvaluateClearlyDefinedDefinition(ctx context.Context, client *http.Client,
158154
159155// generateDefinitions takes in the batched coordinated to retrieve the definition. It uses the definition to check if source
160156// information can be queried in clearly defined.
161- func generateDefinitions (ctx context.Context , client * http.Client , batchCoordinates , queryPurls []string ) ([]* processor.Document , error ) {
157+ func generateDefinitions (ctx context.Context , client * http.Client , batchCoordinates , queryPurls []string , docChannel chan <- * processor. Document ) ([]* processor.Document , error ) {
162158 var generatedCDDocs []* processor.Document
163159 if len (batchCoordinates ) > 0 {
164160 definitionMap , err := getDefinitions (ctx , client , queryPurls , batchCoordinates )
165161 if err != nil {
166162 return nil , fmt .Errorf ("failed get package definition from clearly defined with error: %w" , err )
167163 }
168164
169- if genCDPkgDocs , err := generateDocument (definitionMap ); err != nil {
165+ if genCDPkgDocs , err := generateDocument (definitionMap , docChannel ); err != nil {
170166 return nil , fmt .Errorf ("evaluateDefinitionForSource failed with error: %w" , err )
171167 } else {
172168 generatedCDDocs = append (generatedCDDocs , genCDPkgDocs ... )
173169 }
174170
175- if genCDSrcDocs , err := evaluateDefinitionForSource (ctx , client , definitionMap ); err != nil {
171+ if genCDSrcDocs , err := evaluateDefinitionForSource (ctx , client , definitionMap , docChannel ); err != nil {
176172 return nil , fmt .Errorf ("evaluateDefinitionForSource failed with error: %w" , err )
177173 } else {
178174 generatedCDDocs = append (generatedCDDocs , genCDSrcDocs ... )
@@ -194,20 +190,16 @@ func (c *cdCertifier) CertifyComponent(ctx context.Context, rootComponent interf
194190 purls = append (purls , node .Purl )
195191 }
196192
197- if genCDDocs , err := EvaluateClearlyDefinedDefinition (ctx , c .cdHTTPClient , purls ); err != nil {
193+ if _ , err := EvaluateClearlyDefinedDefinition (ctx , c .cdHTTPClient , purls , docChannel ); err != nil {
198194 return fmt .Errorf ("could not generate document from Clearly Defined results: %w" , err )
199- } else {
200- for _ , doc := range genCDDocs {
201- docChannel <- doc
202- }
203195 }
204196
205197 return nil
206198}
207199
208200// evaluateDefinitionForSource takes in the returned definitions from package coordinates to determine if
209201// source information can be obtained to re-query clearly defined for source related license information
210- func evaluateDefinitionForSource (ctx context.Context , client * http.Client , definitionMap map [string ]* attestation.Definition ) ([]* processor.Document , error ) {
202+ func evaluateDefinitionForSource (ctx context.Context , client * http.Client , definitionMap map [string ]* attestation.Definition , docChannel chan <- * processor. Document ) ([]* processor.Document , error ) {
211203 sourceMap := map [string ]bool {}
212204 var batchCoordinates []string
213205 var sourceInputs []string
@@ -238,13 +230,13 @@ func evaluateDefinitionForSource(ctx context.Context, client *http.Client, defin
238230 if err != nil {
239231 return nil , fmt .Errorf ("failed get source definition from clearly defined with error: %w" , err )
240232 }
241- return generateDocument (definitionMap )
233+ return generateDocument (definitionMap , docChannel )
242234 }
243235 return nil , nil
244236}
245237
246238// generateDocument generates the processor document for ingestion
247- func generateDocument (definitionMap map [string ]* attestation.Definition ) ([]* processor.Document , error ) {
239+ func generateDocument (definitionMap map [string ]* attestation.Definition , docChannel chan <- * processor. Document ) ([]* processor.Document , error ) {
248240 var generatedCDDocs []* processor.Document
249241 for purl , definition := range definitionMap {
250242 if definition .Described .ReleaseDate == "" {
@@ -265,6 +257,9 @@ func generateDocument(definitionMap map[string]*attestation.Definition) ([]*proc
265257 DocumentRef : events .GetDocRef (payload ),
266258 },
267259 }
260+ if docChannel != nil {
261+ docChannel <- doc
262+ }
268263 generatedCDDocs = append (generatedCDDocs , doc )
269264 }
270265 return generatedCDDocs , nil
0 commit comments