Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Handle Chassis returned as slice #4629

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions providers/os/resources/smbios/win.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const smbiosWindowsScript = `
$bios = Get-WmiObject -class Win32_Bios
$baseboard = Get-WmiObject Win32_BaseBoard
$chassis = Get-WmiObject Win32_SystemEnclosure
$chassis = @(Get-WmiObject Win32_SystemEnclosure)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note on PowerShell syntax:

  • The @() syntax is used to (force) create an array in PowerShell.

$sys = Get-WmiObject Win32_ComputerSystem
$sysProduct = Get-WmiObject Win32_ComputerSystemProduct

Expand All @@ -31,7 +31,7 @@ $smbios | ConvertTo-Json
type smbiosWindows struct {
Bios smbiosWinBios `json:"Bios"`
BaseBoard smbiosBaseBoard `json:"BaseBoard"`
Chassis smbiosChassis `json:"Chassis"`
Chassis []smbiosChassis `json:"Chassis"`
System smbiosSystem `json:"System"`
SystemProduct smbiosSystemProduct `json:"SystemProduct"`
}
Expand Down Expand Up @@ -112,11 +112,11 @@ func (s *WindowsSmbiosManager) Info() (*SmBiosInfo, error) {
SerialNumber: winBios.BaseBoard.SerialNumber,
Version: winBios.BaseBoard.Version,
},
ChassisInfo: ChassisInfo{
Vendor: winBios.Chassis.Manufacturer,
Model: toString(winBios.Chassis.Model),
Version: winBios.Chassis.Version,
SerialNumber: winBios.Chassis.SerialNumber,
ChassisInfo: ChassisInfo{ // TODO: Might want to make this a slice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be nil? if winBios.Chassis is 0, we may as well jst set this to nil. we're currently filling in an empty struct that holds no value. if this cannot be nil, then thats ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't technically be, since it's not a pointer
Changing the type at this point would be even more breaking than making it slice, which would've been better solution imo

Vendor: winBios.Chassis[0].Manufacturer,
slntopp marked this conversation as resolved.
Show resolved Hide resolved
Model: toString(winBios.Chassis[0].Model),
Version: winBios.Chassis[0].Version,
SerialNumber: winBios.Chassis[0].SerialNumber,
},
}

Expand Down
Loading