diff --git a/cmd/driver/install/install.go b/cmd/driver/install/install.go index f43c43d2..389e75ee 100644 --- a/cmd/driver/install/install.go +++ b/cmd/driver/install/install.go @@ -36,6 +36,7 @@ import ( type driverDownloadOptions struct { InsecureDownload bool HTTPTimeout time.Duration + HTTPHeaders string } type driverInstallOptions struct { @@ -92,6 +93,10 @@ func NewDriverInstallCmd(ctx context.Context, opt *options.Common, driver *optio "(e.g. '#1 SMP PREEMPT_DYNAMIC Debian 6.1.38-2 (2023-07-27)')") cmd.Flags().BoolVar(&o.InsecureDownload, "http-insecure", false, "Whether you want to allow insecure downloads or not") cmd.Flags().DurationVar(&o.HTTPTimeout, "http-timeout", 60*time.Second, "Timeout for each http try") + cmd.Flags().StringVar(&o.HTTPHeaders, "http-headers", + "", + "Optional comma-separated list of headers for the http GET request "+ + "(e.g. --http-headers='x-emc-namespace: default,Proxy-Authenticate: Basic'). Not necessary if default repo is used") return cmd } @@ -173,7 +178,8 @@ func (o *driverInstallOptions) RunDriverInstall(ctx context.Context) (string, er if !o.Printer.DisableStyling { o.Printer.Spinner, _ = o.Printer.Spinner.Start("Trying to download the driver") } - dest, err = driverdistro.Download(ctx, d, o.Printer.WithWriter(&buf), kr, o.Driver.Name, o.Driver.Type, o.Driver.Version, o.Driver.Repos) + dest, err = driverdistro.Download(ctx, d, o.Printer.WithWriter(&buf), kr, o.Driver.Name, + o.Driver.Type, o.Driver.Version, o.Driver.Repos, o.HTTPHeaders) if o.Printer.Spinner != nil { _ = o.Printer.Spinner.Stop() } diff --git a/cmd/driver/install/install_test.go b/cmd/driver/install/install_test.go index a3591dc1..f16153ed 100644 --- a/cmd/driver/install/install_test.go +++ b/cmd/driver/install/install_test.go @@ -36,6 +36,7 @@ Flags: --compile Whether to enable local compilation of drivers (default true) --download Whether to enable download of prebuilt drivers (default true) -h, --help help for install + --http-headers string Optional comma-separated list of headers for the http GET request (e.g. --http-headers='x-emc-namespace: default,Proxy-Authenticate: Basic'). Not necessary if default repo is used --http-insecure Whether you want to allow insecure downloads or not --http-timeout duration Timeout for each http try (default 1m0s) --kernelrelease string Specify the kernel release for which to download/build the driver in the same format used by 'uname -r' (e.g. '6.1.0-10-cloud-amd64') diff --git a/pkg/driver/distro/distro.go b/pkg/driver/distro/distro.go index 2fb348c0..89a94644 100644 --- a/pkg/driver/distro/distro.go +++ b/pkg/driver/distro/distro.go @@ -203,6 +203,7 @@ func Download(ctx context.Context, driverName string, driverType drivertype.DriverType, driverVer string, repos []string, + httpHeaders string, ) (string, error) { driverFileName := toFilename(d, &kr, driverName, driverType) // Skip if existent @@ -222,6 +223,17 @@ func Download(ctx context.Context, printer.Logger.Warn("Error creating http request.", printer.Logger.Args("err", err)) continue } + if httpHeaders != "" { + header := http.Header{} + for _, h := range strings.Split(httpHeaders, ",") { + key, value := func() (string, string) { + x := strings.Split(h, ":") + return x[0], x[1] + }() + header.Add(key, value) + } + req.Header = header + } resp, err := http.DefaultClient.Do(req) if err != nil || resp.StatusCode != 200 { if err == nil {