go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/updates/suse_updates.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package updates 5 6 import ( 7 "fmt" 8 "io" 9 10 "go.mondoo.com/cnquery/providers/os/connection/shared" 11 "go.mondoo.com/cnquery/providers/os/resources/packages" 12 ) 13 14 const ( 15 SuseOSUpdateFormat = "suse" 16 ) 17 18 type SuseUpdateManager struct { 19 conn shared.Connection 20 } 21 22 func (sum *SuseUpdateManager) Name() string { 23 return "Suse Update Manager" 24 } 25 26 func (sum *SuseUpdateManager) Format() string { 27 return SuseOSUpdateFormat 28 } 29 30 func (sum *SuseUpdateManager) List() ([]OperatingSystemUpdate, error) { 31 cmd, err := sum.conn.RunCommand("zypper -n --xmlout list-updates -t patch") 32 if err != nil { 33 return nil, fmt.Errorf("could not read package list") 34 } 35 return ParseZypperPatches(cmd.Stdout) 36 } 37 38 // ParseZypperPatches reads the operating system patches for Suse 39 func ParseZypperPatches(input io.Reader) ([]OperatingSystemUpdate, error) { 40 zypper, err := packages.ParseZypper(input) 41 if err != nil { 42 return nil, err 43 } 44 45 var updates []OperatingSystemUpdate 46 // filter for kind patch 47 for _, u := range zypper.Updates { 48 if u.Kind != "patch" { 49 continue 50 } 51 52 restart := false 53 if u.Restart == "true" { 54 restart = true 55 } 56 57 updates = append(updates, OperatingSystemUpdate{ 58 ID: u.Edition, 59 Name: u.Name, 60 Severity: u.Severity, 61 Restart: restart, 62 Category: u.Category, 63 Description: u.Description, 64 Format: SuseOSUpdateFormat, 65 }) 66 } 67 68 return updates, nil 69 }