mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Minor changes to fix lint errors
This commit is contained in:
parent
128f9ad42d
commit
81ec43a923
11 changed files with 90 additions and 78 deletions
|
|
@ -14,10 +14,6 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
forceUpdate bool
|
||||
)
|
||||
|
||||
// The `collect` command fetches data from a collection of BMC nodes.
|
||||
// This command should be ran after the `scan` to find available hosts
|
||||
// on a subnet.
|
||||
|
|
@ -82,7 +78,7 @@ func init() {
|
|||
collectCmd.PersistentFlags().StringVar(&password, "password", "", "Set the BMC password")
|
||||
collectCmd.PersistentFlags().StringVar(&scheme, "scheme", "https", "Set the scheme used to query")
|
||||
collectCmd.PersistentFlags().StringVar(&protocol, "protocol", "tcp", "Set the protocol used to query")
|
||||
collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", fmt.Sprintf("/tmp/%smagellan/inventory/", currentUser.Username+"/"), "set the path to store collection data")
|
||||
collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", fmt.Sprintf("/tmp/%smagellan/inventory/", currentUser.Username+"/"), "Set the path to store collection data")
|
||||
collectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", false, "Set flag to force update data sent to SMD")
|
||||
collectCmd.PersistentFlags().StringVar(&cacertPath, "cacert", "", "Path to CA cert. (defaults to system CAs)")
|
||||
|
||||
|
|
@ -90,16 +86,15 @@ func init() {
|
|||
collectCmd.MarkFlagsRequiredTogether("username", "password")
|
||||
|
||||
// bind flags to config properties
|
||||
viper.BindPFlag("collect.driver", collectCmd.Flags().Lookup("driver"))
|
||||
viper.BindPFlag("collect.host", collectCmd.Flags().Lookup("host"))
|
||||
viper.BindPFlag("collect.port", collectCmd.Flags().Lookup("port"))
|
||||
viper.BindPFlag("collect.username", collectCmd.Flags().Lookup("username"))
|
||||
viper.BindPFlag("collect.password", collectCmd.Flags().Lookup("password"))
|
||||
viper.BindPFlag("collect.protocol", collectCmd.Flags().Lookup("protocol"))
|
||||
viper.BindPFlag("collect.output", collectCmd.Flags().Lookup("output"))
|
||||
viper.BindPFlag("collect.force-update", collectCmd.Flags().Lookup("force-update"))
|
||||
viper.BindPFlag("collect.cacert", collectCmd.Flags().Lookup("secure-tls"))
|
||||
viper.BindPFlags(collectCmd.Flags())
|
||||
checkBindFlagError(viper.BindPFlag("collect.host", collectCmd.Flags().Lookup("collect.host")))
|
||||
checkBindFlagError(viper.BindPFlag("collect.username", collectCmd.Flags().Lookup("collect.username")))
|
||||
checkBindFlagError(viper.BindPFlag("collect.password", collectCmd.Flags().Lookup("collect.password")))
|
||||
checkBindFlagError(viper.BindPFlag("collect.scheme", collectCmd.Flags().Lookup("collect.scheme")))
|
||||
checkBindFlagError(viper.BindPFlag("collect.protocol", collectCmd.Flags().Lookup("collect.protocol")))
|
||||
checkBindFlagError(viper.BindPFlag("collect.output", collectCmd.Flags().Lookup("collect.output")))
|
||||
checkBindFlagError(viper.BindPFlag("collect.force-update", collectCmd.Flags().Lookup("collect.force-update")))
|
||||
checkBindFlagError(viper.BindPFlag("collect.cacert", collectCmd.Flags().Lookup("collect.cacert")))
|
||||
checkBindFlagError(viper.BindPFlags(collectCmd.Flags()))
|
||||
|
||||
rootCmd.AddCommand(collectCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ var crawlCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
crawlCmd.Flags().StringP("username", "u", "", "Username for the BMC")
|
||||
crawlCmd.Flags().StringP("password", "p", "", "Password for the BMC")
|
||||
crawlCmd.Flags().StringP("username", "u", "", "Set the username for the BMC")
|
||||
crawlCmd.Flags().StringP("password", "p", "", "Set the password for the BMC")
|
||||
crawlCmd.Flags().BoolP("insecure", "i", false, "Ignore SSL errors")
|
||||
|
||||
rootCmd.AddCommand(crawlCmd)
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ var listCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
listCmd.Flags().StringVar(&format, "format", "", "set the output format (json|default)")
|
||||
listCmd.Flags().BoolVar(&showCache, "cache-info", false, "show cache information and exit")
|
||||
listCmd.Flags().StringVar(&format, "format", "", "Set the output format (json|default)")
|
||||
listCmd.Flags().BoolVar(&showCache, "cache-info", false, "Show cache information and exit")
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
|
|
|
|||
12
cmd/login.go
12
cmd/login.go
|
|
@ -77,11 +77,11 @@ var loginCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
loginCmd.Flags().StringVar(&loginUrl, "url", "http://127.0.0.1:3333/login", "set the login URL")
|
||||
loginCmd.Flags().StringVar(&targetHost, "target-host", "127.0.0.1", "set the target host to return the access code")
|
||||
loginCmd.Flags().IntVar(&targetPort, "target-port", 5000, "set the target host to return the access code")
|
||||
loginCmd.Flags().BoolVarP(&forceLogin, "force", "f", false, "start the login process even with a valid token")
|
||||
loginCmd.Flags().StringVar(&tokenPath, "token-path", ".ochami-token", "set the path the load/save the access token")
|
||||
loginCmd.Flags().BoolVar(&noBrowser, "no-browser", false, "prevent the default browser from being opened automatically")
|
||||
loginCmd.Flags().StringVar(&loginUrl, "url", "http://127.0.0.1:3333/login", "Set the login URL")
|
||||
loginCmd.Flags().StringVar(&targetHost, "target-host", "127.0.0.1", "Set the target host to return the access code")
|
||||
loginCmd.Flags().IntVar(&targetPort, "target-port", 5000, "Set the target host to return the access code")
|
||||
loginCmd.Flags().BoolVarP(&forceLogin, "force", "f", false, "Start the login process even with a valid token")
|
||||
loginCmd.Flags().StringVar(&tokenPath, "token-path", ".ochami-token", "Set the path to load/save the access token")
|
||||
loginCmd.Flags().BoolVar(&noBrowser, "no-browser", false, "Prevent the default browser from being opened automatically")
|
||||
rootCmd.AddCommand(loginCmd)
|
||||
}
|
||||
|
|
|
|||
51
cmd/root.go
51
cmd/root.go
|
|
@ -43,6 +43,7 @@ var (
|
|||
configPath string
|
||||
verbose bool
|
||||
debug bool
|
||||
forceUpdate bool
|
||||
)
|
||||
|
||||
// The `root` command doesn't do anything on it's own except display
|
||||
|
|
@ -53,7 +54,10 @@ var rootCmd = &cobra.Command{
|
|||
Long: "",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 0 {
|
||||
cmd.Help()
|
||||
err := cmd.Help()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to print help")
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
},
|
||||
|
|
@ -79,11 +83,19 @@ func init() {
|
|||
rootCmd.PersistentFlags().StringVar(&cachePath, "cache", fmt.Sprintf("/tmp/%s/magellan/assets.db", currentUser.Username), "set the scanning result cache path")
|
||||
|
||||
// bind viper config flags with cobra
|
||||
viper.BindPFlag("concurrency", rootCmd.Flags().Lookup("concurrency"))
|
||||
viper.BindPFlag("timeout", rootCmd.Flags().Lookup("timeout"))
|
||||
viper.BindPFlag("verbose", rootCmd.Flags().Lookup("verbose"))
|
||||
viper.BindPFlag("cache", rootCmd.Flags().Lookup("cache"))
|
||||
viper.BindPFlags(rootCmd.Flags())
|
||||
checkBindFlagError(viper.BindPFlag("concurrency", rootCmd.Flags().Lookup("concurrency")))
|
||||
checkBindFlagError(viper.BindPFlag("timeout", rootCmd.Flags().Lookup("timeout")))
|
||||
checkBindFlagError(viper.BindPFlag("verbose", rootCmd.Flags().Lookup("verbose")))
|
||||
checkBindFlagError(viper.BindPFlag("debug", rootCmd.Flags().Lookup("debug")))
|
||||
checkBindFlagError(viper.BindPFlag("access-token", rootCmd.Flags().Lookup("verbose")))
|
||||
checkBindFlagError(viper.BindPFlag("cache", rootCmd.Flags().Lookup("cache")))
|
||||
checkBindFlagError(viper.BindPFlags(rootCmd.Flags()))
|
||||
}
|
||||
|
||||
func checkBindFlagError(err error) {
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to bind flag")
|
||||
}
|
||||
}
|
||||
|
||||
// InitializeConfig() initializes a new config object by loading it
|
||||
|
|
@ -117,24 +129,21 @@ func SetDefaults() {
|
|||
viper.SetDefault("scan.subnets", []string{})
|
||||
viper.SetDefault("scan.subnet-masks", []net.IP{})
|
||||
viper.SetDefault("scan.disable-probing", false)
|
||||
viper.SetDefault("collect.driver", []string{"redfish"})
|
||||
viper.SetDefault("scan.disable-cache", false)
|
||||
viper.SetDefault("collect.host", host)
|
||||
viper.SetDefault("collect.user", "")
|
||||
viper.SetDefault("collect.pass", "")
|
||||
viper.SetDefault("collect.username", "")
|
||||
viper.SetDefault("collect.password", "")
|
||||
viper.SetDefault("collect.protocol", "tcp")
|
||||
viper.SetDefault("collect.output", "/tmp/magellan/data/")
|
||||
viper.SetDefault("collect.force-update", false)
|
||||
viper.SetDefault("collect.ca-cert", "")
|
||||
viper.SetDefault("bmc-host", "")
|
||||
viper.SetDefault("bmc-port", 443)
|
||||
viper.SetDefault("user", "")
|
||||
viper.SetDefault("pass", "")
|
||||
viper.SetDefault("transfer-protocol", "HTTP")
|
||||
viper.SetDefault("protocol", "tcp")
|
||||
viper.SetDefault("firmware-url", "")
|
||||
viper.SetDefault("firmware-version", "")
|
||||
viper.SetDefault("component", "")
|
||||
viper.SetDefault("secure-tls", false)
|
||||
viper.SetDefault("status", false)
|
||||
viper.SetDefault("collect.cacert", "")
|
||||
viper.SetDefault("update.username", "")
|
||||
viper.SetDefault("update.password", "")
|
||||
viper.SetDefault("update.transfer-protocol", "https")
|
||||
viper.SetDefault("update.protocol", "tcp")
|
||||
viper.SetDefault("update.firmware.url", "")
|
||||
viper.SetDefault("update.firmware.version", "")
|
||||
viper.SetDefault("update.component", "")
|
||||
viper.SetDefault("update.status", false)
|
||||
|
||||
}
|
||||
|
|
|
|||
13
cmd/scan.go
13
cmd/scan.go
|
|
@ -184,11 +184,14 @@ func init() {
|
|||
scanCmd.Flags().BoolVar(&disableProbing, "disable-probing", false, "Disable probing found assets for Redfish service(s) running on BMC nodes")
|
||||
scanCmd.Flags().BoolVar(&disableCache, "disable-cache", false, "Disable saving found assets to a cache database specified with 'cache' flag")
|
||||
|
||||
viper.BindPFlag("scan.hosts", scanCmd.Flags().Lookup("host"))
|
||||
viper.BindPFlag("scan.ports", scanCmd.Flags().Lookup("port"))
|
||||
viper.BindPFlag("scan.subnets", scanCmd.Flags().Lookup("subnet"))
|
||||
viper.BindPFlag("scan.subnet-masks", scanCmd.Flags().Lookup("subnet-mask"))
|
||||
viper.BindPFlag("scan.disable-probing", scanCmd.Flags().Lookup("disable-probing"))
|
||||
checkBindFlagError(viper.BindPFlag("scan.hosts", scanCmd.Flags().Lookup("host")))
|
||||
checkBindFlagError(viper.BindPFlag("scan.ports", scanCmd.Flags().Lookup("port")))
|
||||
checkBindFlagError(viper.BindPFlag("scan.scheme", scanCmd.Flags().Lookup("scheme")))
|
||||
checkBindFlagError(viper.BindPFlag("scan.protocol", scanCmd.Flags().Lookup("protocol")))
|
||||
checkBindFlagError(viper.BindPFlag("scan.subnets", scanCmd.Flags().Lookup("subnet")))
|
||||
checkBindFlagError(viper.BindPFlag("scan.subnet-masks", scanCmd.Flags().Lookup("subnet-mask")))
|
||||
checkBindFlagError(viper.BindPFlag("scan.disable-probing", scanCmd.Flags().Lookup("disable-probing")))
|
||||
checkBindFlagError(viper.BindPFlag("scan.disable-cache", scanCmd.Flags().Lookup("disable-cache")))
|
||||
|
||||
rootCmd.AddCommand(scanCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
var (
|
||||
host string
|
||||
port int
|
||||
firmwareUrl string
|
||||
firmwareVersion string
|
||||
component string
|
||||
|
|
@ -79,25 +78,22 @@ var updateCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
updateCmd.Flags().StringVar(&username, "username", "", "set the BMC user")
|
||||
updateCmd.Flags().StringVar(&password, "password", "", "set the BMC password")
|
||||
updateCmd.Flags().StringVar(&transferProtocol, "transfer-protocol", "HTTP", "set the transfer protocol")
|
||||
updateCmd.Flags().StringVar(&firmwareUrl, "firmware.url", "", "set the path to the firmware")
|
||||
updateCmd.Flags().StringVar(&firmwareVersion, "firmware.version", "", "set the version of firmware to be installed")
|
||||
updateCmd.Flags().StringVar(&component, "component", "", "set the component to upgrade")
|
||||
updateCmd.Flags().BoolVar(&showStatus, "status", false, "get the status of the update")
|
||||
updateCmd.Flags().StringVar(&username, "username", "", "Set the BMC user")
|
||||
updateCmd.Flags().StringVar(&password, "password", "", "Set the BMC password")
|
||||
updateCmd.Flags().StringVar(&transferProtocol, "transfer-protocol", "HTTP", "Set the transfer protocol")
|
||||
updateCmd.Flags().StringVar(&firmwareUrl, "firmware.url", "", "Set the path to the firmware")
|
||||
updateCmd.Flags().StringVar(&firmwareVersion, "firmware.version", "", "Set the version of firmware to be installed")
|
||||
updateCmd.Flags().StringVar(&component, "component", "", "Set the component to upgrade (BMC|BIOS)")
|
||||
updateCmd.Flags().BoolVar(&showStatus, "status", false, "Get the status of the update")
|
||||
|
||||
viper.BindPFlag("update.bmc.host", updateCmd.Flags().Lookup("bmc.host"))
|
||||
viper.BindPFlag("update.bmc.port", updateCmd.Flags().Lookup("bmc.port"))
|
||||
viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username"))
|
||||
viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password"))
|
||||
viper.BindPFlag("update.transfer-protocol", updateCmd.Flags().Lookup("transfer-protocol"))
|
||||
viper.BindPFlag("update.protocol", updateCmd.Flags().Lookup("protocol"))
|
||||
viper.BindPFlag("update.firmware.url", updateCmd.Flags().Lookup("firmware.url"))
|
||||
viper.BindPFlag("update.firmware.version", updateCmd.Flags().Lookup("firmware.version"))
|
||||
viper.BindPFlag("update.component", updateCmd.Flags().Lookup("component"))
|
||||
viper.BindPFlag("update.secure-tls", updateCmd.Flags().Lookup("secure-tls"))
|
||||
viper.BindPFlag("update.status", updateCmd.Flags().Lookup("status"))
|
||||
checkBindFlagError(viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username")))
|
||||
checkBindFlagError(viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password")))
|
||||
checkBindFlagError(viper.BindPFlag("update.transfer-protocol", updateCmd.Flags().Lookup("transfer-protocol")))
|
||||
checkBindFlagError(viper.BindPFlag("update.protocol", updateCmd.Flags().Lookup("protocol")))
|
||||
checkBindFlagError(viper.BindPFlag("update.firmware.url", updateCmd.Flags().Lookup("firmware.url")))
|
||||
checkBindFlagError(viper.BindPFlag("update.firmware.version", updateCmd.Flags().Lookup("firmware.version")))
|
||||
checkBindFlagError(viper.BindPFlag("update.component", updateCmd.Flags().Lookup("component")))
|
||||
checkBindFlagError(viper.BindPFlag("update.status", updateCmd.Flags().Lookup("status")))
|
||||
|
||||
rootCmd.AddCommand(updateCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import "fmt"
|
|||
func FormatErrorList(errList []error) error {
|
||||
var err error
|
||||
for i, e := range errList {
|
||||
// NOTE: for multi-error formating, we want to include \n here
|
||||
err = fmt.Errorf("\t[%d] %v\n", i, e)
|
||||
i += 1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ func (c SmdClient) Update(data HTTPBody, headers HTTPHeader) error {
|
|||
// Update redfish endpoint via PUT `/hsm/v2/Inventory/RedfishEndpoints` endpoint
|
||||
url := c.RootEndpoint("/Inventory/RedfishEndpoints/" + c.Xname)
|
||||
res, body, err := MakeRequest(c.Client, url, http.MethodPut, data, headers)
|
||||
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
|
||||
if res != nil {
|
||||
statusOk := res.StatusCode >= 200 && res.StatusCode < 300
|
||||
if !statusOk {
|
||||
return fmt.Errorf("failed to update redfish endpoint (returned %s)", res.Status)
|
||||
}
|
||||
fmt.Printf("%v (%v)\n%s\n", url, res.Status, string(body))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"testing"
|
||||
|
||||
magellan "github.com/OpenCHAMI/magellan/internal"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -43,7 +44,10 @@ func TestScanAndCollect(t *testing.T) {
|
|||
}
|
||||
|
||||
// do a collect on the emulator cluster to collect Redfish info
|
||||
magellan.CollectInventory(&results, &magellan.CollectParams{})
|
||||
err := magellan.CollectInventory(&results, &magellan.CollectParams{})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to collect inventory")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrawlCommand(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/OpenCHAMI/magellan/pkg/client"
|
||||
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -26,7 +27,7 @@ var (
|
|||
// Simple test to fetch the base Redfish URL and assert a 200 OK response.
|
||||
func TestRedfishV1Availability(t *testing.T) {
|
||||
var (
|
||||
url = fmt.Sprintf("%s/redfish/v1", host)
|
||||
url = fmt.Sprintf("%s/redfish/v1", *host)
|
||||
body = []byte{}
|
||||
headers = map[string]string{}
|
||||
)
|
||||
|
|
@ -55,12 +56,16 @@ func TestRedfishV1Availability(t *testing.T) {
|
|||
// Simple test to ensure an expected Redfish version minimum requirement.
|
||||
func TestRedfishVersion(t *testing.T) {
|
||||
var (
|
||||
url = fmt.Sprintf("%s/redfish/v1", host)
|
||||
body = []byte{}
|
||||
headers = map[string]string{}
|
||||
url string = fmt.Sprintf("%s/redfish/v1", *host)
|
||||
body client.HTTPBody = []byte{}
|
||||
headers client.HTTPHeader = map[string]string{}
|
||||
err error
|
||||
)
|
||||
|
||||
client.MakeRequest(nil, url, http.MethodGet, body, headers)
|
||||
_, _, err = client.MakeRequest(nil, url, http.MethodGet, body, headers)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to make request")
|
||||
}
|
||||
}
|
||||
|
||||
// Crawls a BMC node and checks that we're able to query certain properties
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue