go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/windows/features.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package windows
     5  
     6  import (
     7  	"encoding/json"
     8  	"io"
     9  )
    10  
    11  const QUERY_FEATURES = "Get-WindowsFeature | Select-Object -Property Path,Name,DisplayName,Description,Installed,InstallState,FeatureType,DependsOn,Parent,SubFeatures | ConvertTo-Json"
    12  
    13  type WindowsFeature struct {
    14  	Name         string   `json:"Name"`
    15  	DisplayName  string   `json:"DisplayName"`
    16  	Description  string   `json:"Description"`
    17  	Installed    bool     `json:"Installed"`
    18  	InstallState int64    `json:"InstallState"`
    19  	FeatureType  string   `json:"FeatureType"`
    20  	Path         string   `json:"Path"`
    21  	DependsOn    []string `json:"DependsOn"`
    22  	Parent       *string  `json:"Parent"`
    23  	SubFeatures  []string `json:"SubFeatures"`
    24  }
    25  
    26  func ParseWindowsFeatures(input io.Reader) ([]WindowsFeature, error) {
    27  	data, err := io.ReadAll(input)
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  
    32  	// for empty result set do not get the '{}', therefore lets abort here
    33  	if len(data) == 0 {
    34  		return []WindowsFeature{}, nil
    35  	}
    36  
    37  	var winFeatures []WindowsFeature
    38  	err = json.Unmarshal(data, &winFeatures)
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	return winFeatures, nil
    44  }