diff --git a/cmd/update.go b/cmd/update.go index d0b050c..b8fe150 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -17,18 +17,19 @@ var ( component string transferProtocol string showStatus bool + Insecure bool ) // The `update` command provides an interface to easily update firmware // using Redfish. It also provides a simple way to check the status of // an update in-progress. -var UpdateCmd = &cobra.Command{ +var updateCmd = &cobra.Command{ Use: "update hosts...", 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, @@ -78,21 +81,23 @@ 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, "scheme", "https", "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") + updateCmd.Flags().StringVar(&username, "username", "", "Set the BMC user") + updateCmd.Flags().StringVar(&password, "password", "", "Set the BMC password") + updateCmd.Flags().StringVar(&transferProtocol, "scheme", "https", "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") + 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"))) - checkBindFlagError(viper.BindPFlag("update.scheme", UpdateCmd.Flags().Lookup("scheme"))) - 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"))) + checkBindFlagError(viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username"))) + checkBindFlagError(viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password"))) + checkBindFlagError(viper.BindPFlag("update.scheme", updateCmd.Flags().Lookup("scheme"))) + 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"))) + 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) }