github.com/google/osv-scalibr@v0.4.1/extractor/standalone/windows/dismpatch/dismpatch.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package dismpatch
    16  
    17  import (
    18  	"strings"
    19  
    20  	"github.com/google/osv-scalibr/extractor"
    21  	"github.com/google/osv-scalibr/extractor/standalone/windows/common/metadata"
    22  	"github.com/google/osv-scalibr/extractor/standalone/windows/common/winproducts"
    23  	"github.com/google/osv-scalibr/extractor/standalone/windows/dismpatch/dismparser"
    24  	"github.com/google/osv-scalibr/inventory"
    25  )
    26  
    27  // inventoryFromOutput parses the output of DISM and produces package entries from it.
    28  func inventoryFromOutput(flavor, output string) (inventory.Inventory, error) {
    29  	packages, imgVersion, err := dismparser.Parse(output)
    30  	if err != nil {
    31  		return inventory.Inventory{}, err
    32  	}
    33  
    34  	imgVersion = strings.TrimSpace(imgVersion)
    35  	windowsProduct := winproducts.WindowsProductFromVersion(flavor, imgVersion)
    36  	result := []*extractor.Package{
    37  		{
    38  			Name:     windowsProduct,
    39  			Version:  imgVersion,
    40  			PURLType: "windows",
    41  			Metadata: &metadata.OSVersion{
    42  				Product:     windowsProduct,
    43  				FullVersion: imgVersion,
    44  			},
    45  		},
    46  	}
    47  
    48  	// extract KB informations
    49  	for _, pkg := range packages {
    50  		result = append(result, &extractor.Package{
    51  			Name:     pkg.PackageIdentity,
    52  			Version:  pkg.PackageVersion,
    53  			PURLType: "windows",
    54  		})
    55  	}
    56  
    57  	return inventory.Inventory{Packages: result}, nil
    58  }