feat(packages): add download command
Description
Adds glab packages download (alias dl): downloads a generic package file by
--name, --version, and --filename. By default the file is verified against
the checksum stored in the registry (looked up via the packages API, since the
download endpoint returns no metadata). --no-verify skips verification and
--force forcefully overwrites an existing file. Writes go through a temp file and
atomic rename like securefile donwload.
Related Issues
Related to #7421 (closed)
How has this been tested?
Automated:
go test ./internal/commands/packages/download/...golangci-lint run ./internal/commands/packages/...
Manual:
make to build package for this MR.
Download a package.
bin/glab packages download --name glab --version 1.102.0 --filename glab_1.102.0_linux_amd64.tar.gz
# Downloaded package file 'glab_1.102.0_linux_amd64.tar.gz' (Package: glab, Version: 1.102.0)Run it again to test the overwrite check.
bin/glab packages download --name glab --version 1.102.0 --filename glab_1.102.0_linux_amd64.tar.gz ERROR
File glab_1.102.0_linux_amd64.tar.gz already exists; use --force to overwrite current file.Verify it works with the force flag added.
bin/glab packages download --name glab --version 1.102.0 --filename glab_1.102.0_linux_amd64.tar.gz --force
# Downloaded package file 'glab_1.102.0_linux_amd64.tar.gz' (Package: glab, Version: 1.102.0)Verify it works with a custom output path as a file.
bin/glab packages download --name glab --version 1.102.0 --filename glab_1.102.0_linux_amd64.tar.gz --path tmp/bin/glab
# Downloaded package file 'glab_1.102.0_linux_amd64.tar.gz' (Package: glab, Version: 1.102.0)Verify it works with a custom output path correctly as a dir and path.
If the output is a dir that exists or if it doesn't but ends with a /
then we keep the original filename and output to that directory. Otherwise
we output it under a new name.
bin/glab packages download --name glab --version 1.102.0 --filename glab_1.102.0_linux_amd64.tar.gz --path tmp/bin/glab --force
# Downloaded package file to 'tmp/bin/glab' (Package: glab, Version: 1.102.0)
bin/glab packages download --name glab --version 1.102.0 --filename glab_1.102.0_linux_amd64.tar.gz --path tmp/bin --force
# Downloaded package file to 'tmp/bin/glab_1.102.0_linux_amd64.tar.gz' (Package: glab, Version: 1.102.0)It should also fail if a package file doesn't exist.
bin/glab packages download --name glab --version 1.102.0 --filename file.txt ERROR
Failed to download package file: 404 Not Found.