hashicorp / go-getter

Package for downloading things from a string URL using a variety of protocols.
Mozilla Public License 2.0
1.65k stars 232 forks source link

The `filename` magic param isn't always removed from the request #471

Open pkosiec opened 7 months ago

pkosiec commented 7 months ago

Description

The filename magic parameter sometimes isn't removed from the underlying request, which make some requests fail, e.g. when using signed URLs to GCS bucket.

Details

Based on the code, I believe all the "magic" parameters should be removed before making a request. This is not the case in case of an URL to tar.gz directory, like this:

https://storage.googleapis.com/bucket/v1.0.0/binary_darwin_amd64.tar.gz

and configuration:

    getterCli := &getter.Client{
        Ctx:  ctx,
        Src:  url, // url with `filename` magic param
        Dst:  tmpDestPath,
        Pwd:  pwd,
        Mode: getter.ClientModeAny,
    }

I tracked the code execution, and it falls in the if which changes the mode:

https://github.com/hashicorp/go-getter/blob/a2ebce998f8d4105bd4b78d6c99a12803ad97a45/client.go#L217

    if decompressor != nil {
        // ...
        mode = ClientModeFile
    }

Which is why the filename param is not removed, as the next if is skipped, which actually removes the filename param.

https://github.com/hashicorp/go-getter/blob/a2ebce998f8d4105bd4b78d6c99a12803ad97a45/client.go#L230-L249

Fix incoming

I fixed it locally and will prepare a pull request soon. Hope you'll like it!