From 01f811dc077ddb897b3ed2a20b5dcfe7948e6abe Mon Sep 17 00:00:00 2001 From: Alex Lovell-Troy Date: Fri, 7 Feb 2025 09:56:36 -0500 Subject: [PATCH] feat: add --insecure flag to allow insecure connections for firmware updates --- cmd/update.go | 9 +++++++-- internal/update.go | 9 +++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/update.go b/cmd/update.go index d5f9a50..7f7d3b3 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -17,6 +17,7 @@ var ( component string transferProtocol string showStatus bool + Insecure bool ) // The `update` command provides an interface to easily update firmware @@ -27,8 +28,8 @@ var updateCmd = &cobra.Command{ Short: "Update BMC node firmware", Long: "Perform an firmware update using Redfish by providing a remote firmware URL and component.\n\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 --status --username bmc_username --password bmc_password", + " 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 --insecure --status --username bmc_username --password bmc_password", Run: func(cmd *cobra.Command, args []string) { // check that we have at least one host if len(args) <= 0 { @@ -44,6 +45,7 @@ var updateCmd = &cobra.Command{ FirmwareVersion: firmwareVersion, Component: component, TransferProtocol: transferProtocol, + Insecure: Insecure, CollectParams: magellan.CollectParams{ URI: arg, Username: username, @@ -63,6 +65,7 @@ var updateCmd = &cobra.Command{ FirmwareVersion: firmwareVersion, Component: component, TransferProtocol: strings.ToUpper(transferProtocol), + Insecure: Insecure, CollectParams: magellan.CollectParams{ URI: host, 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(&component, "component", "", "Set the component to upgrade (BMC|BIOS)") 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.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.component", updateCmd.Flags().Lookup("component"))) checkBindFlagError(viper.BindPFlag("update.status", updateCmd.Flags().Lookup("status"))) + checkBindFlagError(viper.BindPFlag("update.insecure", updateCmd.Flags().Lookup("insecure"))) rootCmd.AddCommand(updateCmd) } diff --git a/internal/update.go b/internal/update.go index 183980b..ccbed6b 100644 --- a/internal/update.go +++ b/internal/update.go @@ -14,6 +14,7 @@ type UpdateParams struct { FirmwareVersion string Component string TransferProtocol string + Insecure bool } // 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) } - // Connect to the Redfish service using gofish (using insecure connection for this) - client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: true}) + // Connect to the Redfish service using gofish + client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure}) if err != nil { 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) } - // Connect to the Redfish service using gofish (using insecure connection for this) - client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: true}) + // Connect to the Redfish service using gofish + client, err := gofish.Connect(gofish.ClientConfig{Endpoint: uri.String(), Username: q.Username, Password: q.Password, Insecure: q.Insecure}) if err != nil { return fmt.Errorf("failed to connect to Redfish service: %w", err) }