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

Use json instead of yaml #22

Merged
merged 1 commit into from
Aug 1, 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
26 changes: 7 additions & 19 deletions cmd/create/firmware.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package create

import (
"encoding/json"
"log"
"os"

mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
"github.com/metal-toolbox/mctl/pkg/model"
"github.com/spf13/cobra"
ss "go.hollow.sh/serverservice/pkg/api/v1"
"gopkg.in/yaml.v2"
serverservice "go.hollow.sh/serverservice/pkg/api/v1"
)

// Create
Expand All @@ -33,29 +32,18 @@ var createFirmware = &cobra.Command{
log.Fatal(err)
}

firmwareConfig := &model.FirmwareConfig{}
var firmwares []*serverservice.ComponentFirmwareVersion
fbytes, err := os.ReadFile(flagsDefinedCreateFirmware.firmwareConfigFile)
if err != nil {
log.Fatal(err)
}

if err = yaml.Unmarshal(fbytes, firmwareConfig); err != nil {
if err = json.Unmarshal(fbytes, &firmwares); err != nil {
log.Fatal(err)
}

for _, config := range firmwareConfig.Firmwares {
c := ss.ComponentFirmwareVersion{
Vendor: config.Vendor,
RepositoryURL: config.RepositoryURL,
Model: config.Model,
UpstreamURL: config.UpstreamURL,
Version: config.Version,
Filename: config.FileName,
Checksum: config.Checksum,
Component: config.Component,
}

id, _, err := client.CreateServerComponentFirmware(cmd.Context(), c)
for _, fw := range firmwares {
id, _, err := client.CreateServerComponentFirmware(cmd.Context(), *fw)
if err != nil {
log.Fatal(err)
}
Expand All @@ -70,7 +58,7 @@ func init() {

createFirmware.PersistentFlags().StringVar(
&flagsDefinedCreateFirmware.firmwareConfigFile,
"from-file", "", "YAML file with firmware configuration data")
"from-file", "", "JSON file with firmware configuration data")
if err := createFirmware.MarkPersistentFlagRequired("from-file"); err != nil {
log.Fatal(err)
}
Expand Down
18 changes: 0 additions & 18 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,3 @@ type ConfigOIDC struct {
Scopes []string `mapstructure:"oidc_scopes"`
PkceCallbackURL string `mapstructure:"oidc_pkce_callback_url"`
}

// Firmware includes a firmware version attributes and is part of FirmwareConfig
type Firmware struct {
Vendor string `yaml:"vendor"`
Version string `yaml:"version"`
UpstreamURL string `yaml:"upstreamURL"`
RepositoryURL string `yaml:"repositoryURL"`
FileName string `yaml:"filename"`
Utility string `yaml:"utility"`
Component string `yaml:"component"`
Checksum string `yaml:"checksum"`
Model []string `yaml:"model"`
}

// FirmwareConfig struct holds firmware configuration data
type FirmwareConfig struct {
Firmwares []*Firmware `yaml:"firmwares"`
}
Loading