Skip to content

Commit

Permalink
Improve fatal error handling, add support for reading bios config fro…
Browse files Browse the repository at this point in the history
…m json file
  • Loading branch information
splaspood committed Apr 12, 2024
1 parent b6086b0 commit 1ac1d69
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions examples/bios/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"io"
"os"
"strings"
"time"

Expand All @@ -24,6 +26,8 @@ func main() {
pass := flag.String("password", "", "Username to login with")
host := flag.String("host", "", "BMC hostname to connect to")
mode := flag.String("mode", "get", "Mode [get,set,reset]")
dfile := flag.String("file", "", "Read data from file")

flag.Parse()

// Logger configuration
Expand All @@ -39,7 +43,7 @@ func main() {

err := client.Open(ctx)
if err != nil {
log.Fatal(err, "bmc login failed")
l.Fatal(err, "bmc login failed")
}

defer client.Close(ctx)
Expand All @@ -50,12 +54,31 @@ func main() {
// retrieve bios configuration
biosConfig, err := client.GetBiosConfiguration(ctx)
if err != nil {
l.Error(err)
l.Fatal(err)
}

fmt.Printf("biosConfig: %+v\n", biosConfig)
case "set":
exampleConfig := map[string]string{"TpmSecurity": "Off"}
exampleConfig := make(map[string]string)

if *dfile != "" {
jsonFile, err := os.Open(*dfile)
if err != nil {
l.Fatal(err)
}

defer jsonFile.Close()

jsonData, _ := io.ReadAll(jsonFile)

err = json.Unmarshal(jsonData, &exampleConfig)
if err != nil {
l.Fatal(err)
}
} else {
exampleConfig["TpmSecurity"] = "Off"
}

fmt.Println("Attempting to set BIOS configuration:")
fmt.Printf("exampleConfig: %+v\n", exampleConfig)

Expand Down

0 comments on commit 1ac1d69

Please sign in to comment.