feat: add --insecure flag to allow insecure connections for firmware updates

This commit is contained in:
Alex Lovell-Troy 2025-02-07 09:56:36 -05:00
parent 7bdad54ed5
commit 01f811dc07
No known key found for this signature in database
2 changed files with 12 additions and 6 deletions

View file

@ -17,6 +17,7 @@ var (
component string component string
transferProtocol string transferProtocol string
showStatus bool showStatus bool
Insecure bool
) )
// The `update` command provides an interface to easily update firmware // The `update` command provides an interface to easily update firmware
@ -27,8 +28,8 @@ var updateCmd = &cobra.Command{
Short: "Update BMC node firmware", Short: "Update BMC node firmware",
Long: "Perform an firmware update using Redfish by providing a remote firmware URL and component.\n\n" + Long: "Perform an firmware update using Redfish by providing a remote firmware URL and component.\n\n" +
"Examples:\n" + "Examples:\n" +
" magellan update 172.16.0.108:443 --username bmc_username --password bmc_password --firmware-url http://172.16.0.200:8005/firmware/bios/image.RBU --component BIOS\n" + " magellan update 172.16.0.108:443 --insecure --username bmc_username --password bmc_password --firmware-url http://172.16.0.200:8005/firmware/bios/image.RBU --component BIOS\n" +
" magellan update 172.16.0.108:443 --status --username bmc_username --password bmc_password", " magellan update 172.16.0.108:443 --insecure --status --username bmc_username --password bmc_password",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// check that we have at least one host // check that we have at least one host
if len(args) <= 0 { if len(args) <= 0 {
@ -44,6 +45,7 @@ var updateCmd = &cobra.Command{
FirmwareVersion: firmwareVersion, FirmwareVersion: firmwareVersion,
Component: component, Component: component,
TransferProtocol: transferProtocol, TransferProtocol: transferProtocol,
Insecure: Insecure,
CollectParams: magellan.CollectParams{ CollectParams: magellan.CollectParams{
URI: arg, URI: arg,
Username: username, Username: username,
@ -63,6 +65,7 @@ var updateCmd = &cobra.Command{
FirmwareVersion: firmwareVersion, FirmwareVersion: firmwareVersion,
Component: component, Component: component,
TransferProtocol: strings.ToUpper(transferProtocol), TransferProtocol: strings.ToUpper(transferProtocol),
Insecure: Insecure,
CollectParams: magellan.CollectParams{ CollectParams: magellan.CollectParams{
URI: host, URI: host,
Username: username, Username: username,
@ -85,6 +88,7 @@ func init() {
updateCmd.Flags().StringVar(&firmwareVersion, "firmware-version", "", "Set the version of firmware to be installed") 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().StringVar(&component, "component", "", "Set the component to upgrade (BMC|BIOS)")
updateCmd.Flags().BoolVar(&showStatus, "status", false, "Get the status of the update") updateCmd.Flags().BoolVar(&showStatus, "status", false, "Get the status of the update")
updateCmd.Flags().BoolVar(&Insecure, "insecure", false, "Allow insecure connections to the server")
checkBindFlagError(viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username"))) checkBindFlagError(viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username")))
checkBindFlagError(viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password"))) checkBindFlagError(viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password")))
@ -93,6 +97,7 @@ func init() {
checkBindFlagError(viper.BindPFlag("update.firmware-version", updateCmd.Flags().Lookup("firmware-version"))) checkBindFlagError(viper.BindPFlag("update.firmware-version", updateCmd.Flags().Lookup("firmware-version")))
checkBindFlagError(viper.BindPFlag("update.component", updateCmd.Flags().Lookup("component"))) checkBindFlagError(viper.BindPFlag("update.component", updateCmd.Flags().Lookup("component")))
checkBindFlagError(viper.BindPFlag("update.status", updateCmd.Flags().Lookup("status"))) checkBindFlagError(viper.BindPFlag("update.status", updateCmd.Flags().Lookup("status")))
checkBindFlagError(viper.BindPFlag("update.insecure", updateCmd.Flags().Lookup("insecure")))
rootCmd.AddCommand(updateCmd) rootCmd.AddCommand(updateCmd)
} }

View file

@ -14,6 +14,7 @@ type UpdateParams struct {
FirmwareVersion string FirmwareVersion string
Component string Component string
TransferProtocol string TransferProtocol string
Insecure bool
} }
// UpdateFirmwareRemote() uses 'gofish' to update the firmware of a BMC node. // UpdateFirmwareRemote() uses 'gofish' to update the firmware of a BMC node.
@ -35,8 +36,8 @@ func UpdateFirmwareRemote(q *UpdateParams) error {
return fmt.Errorf("failed to parse URI: %w", err) return fmt.Errorf("failed to parse URI: %w", err)
} }
// Connect to the Redfish service using gofish (using insecure connection for this) // Connect to the Redfish service using gofish
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: true}) client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure})
if err != nil { if err != nil {
return fmt.Errorf("failed to connect to Redfish service: %w", err) return fmt.Errorf("failed to connect to Redfish service: %w", err)
} }
@ -70,8 +71,8 @@ func GetUpdateStatus(q *UpdateParams) error {
return fmt.Errorf("failed to parse URI: %w", err) return fmt.Errorf("failed to parse URI: %w", err)
} }
// Connect to the Redfish service using gofish (using insecure connection for this) // Connect to the Redfish service using gofish
client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: true}) client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure})
if err != nil { if err != nil {
return fmt.Errorf("failed to connect to Redfish service: %w", err) return fmt.Errorf("failed to connect to Redfish service: %w", err)
} }