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

utility MustBytes methods #14

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.*.swp
.*.swo
30 changes: 21 additions & 9 deletions condition/firmware_install.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package condition

import "github.com/google/uuid"
import (
"encoding/json"

"github.com/google/uuid"
)

const (
FirmwareInstall Kind = "firmwareInstall"
Expand Down Expand Up @@ -41,14 +45,22 @@ type FirmwareInstallTaskParameters struct {
FirmwareSetID uuid.UUID `json:"firmware_set_id,omitempty"`
}

func (p *FirmwareInstallTaskParameters) MustJSON() []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious where the MustJSON function being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to use it in ConditionAPI (and likely orchestrator). But it really belongs here where it's defined.

byt, err := json.Marshal(p)
if err != nil {
panic(err)
}
return byt
}

// Firmware holds attributes for a firmware object
type Firmware struct {
ID string `yaml:"id"`
Vendor string `yaml:"vendor"`
FileName string `yaml:"filename"`
Version string `yaml:"version"`
URL string `yaml:"URL"`
Component string `yaml:"component"`
Checksum string `yaml:"checksum"`
Models []string `yaml:"models"`
ID string `yaml:"id" json:"id"`
Vendor string `yaml:"vendor" json:"vendor"`
FileName string `yaml:"filename" json:"filename"`
Version string `yaml:"version" json:"version"`
URL string `yaml:"URL" json:"URL"`
Component string `yaml:"component" json:"component"`
Checksum string `yaml:"checksum" json:"checksum"`
Models []string `yaml:"models" json:"models"`
}
20 changes: 20 additions & 0 deletions condition/inventory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package condition

import (
"encoding/json"

"github.com/google/uuid"
)

Expand Down Expand Up @@ -40,3 +42,21 @@ func NewInventoryTaskParameters(assetID uuid.UUID, method InventoryMethod, colle
Method: method,
}
}

func MustInventoryJSON(assetID uuid.UUID, method InventoryMethod, collectFirmwareStatus, collectBiosCfg bool) []byte {
p := &InventoryTaskParameters{
AssetID: assetID,
CollectBiosCfg: collectBiosCfg,
CollectFirwmareStatus: collectFirmwareStatus,
Method: method,
}
byt, err := json.Marshal(p)
if err != nil {
panic(err)
}
return byt
}

func MustDefaultInventoryJSON(assetID uuid.UUID) []byte {
return MustInventoryJSON(assetID, OutofbandInventory, true, true)
}
Loading