Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support xz-encoded images #3160

Merged
merged 2 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/gorilla/websocket v1.4.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.12.1 // indirect
github.com/h2non/filetype v1.0.12
github.com/hashicorp/go-azure-helpers v0.10.0
github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/go-retryablehttp v0.6.4 // indirect
Expand Down Expand Up @@ -98,6 +99,7 @@ require (
github.com/terraform-providers/terraform-provider-openstack v1.25.0
github.com/terraform-providers/terraform-provider-random v1.3.2-0.20190925210718-83518d96ae4f
github.com/terraform-providers/terraform-provider-vsphere v0.0.0
github.com/ulikunitz/xz v0.5.6
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50
github.com/vmware/govmomi v0.22.1
go.uber.org/atomic v1.5.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.4/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.12.1 h1:zCy2xE9ablevUOrUZc3Dl72Dt+ya2FNAvC2yLYMHzi4=
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/h2non/filetype v1.0.12 h1:yHCsIe0y2cvbDARtJhGBTD2ecvqMSTvlIcph9En/Zao=
github.com/h2non/filetype v1.0.12/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/hashicorp/aws-sdk-go-base v0.4.0 h1:zH9hNUdsS+2G0zJaU85ul8D59BGnZBaKM+KMNPAHGwk=
github.com/hashicorp/aws-sdk-go-base v0.4.0/go.mod h1:eRhlz3c4nhqxFZJAahJEFL7gh6Jyj5rQmQc7F9eHFyQ=
Expand Down
18 changes: 13 additions & 5 deletions pkg/tfvars/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (
"os"
"path/filepath"

"github.com/h2non/filetype/matchers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/ulikunitz/xz"

"golang.org/x/sys/unix"
)

const (
applicationName = "openshift-installer"
imageDataType = "image"
gzipFileType = "application/x-gzip"
)

// getCacheDir returns a local path of the cache, where the installer should put the data:
Expand Down Expand Up @@ -119,18 +120,25 @@ func cacheFile(reader io.Reader, filePath string, sha256Checksum string) (err er
}

reader = io.MultiReader(bytes.NewReader(buf), reader)
fileType := http.DetectContentType(buf)
logrus.Debugf("content type of %s is %s", filePath, fileType)
switch fileType {
case gzipFileType:
switch {
case matchers.Gz(buf):
logrus.Debug("decompressing the image archive as gz")
uncompressor, err := gzip.NewReader(reader)
if err != nil {
return err
}
defer uncompressor.Close()
reader = uncompressor
case matchers.Xz(buf):
logrus.Debug("decompressing the image archive as xz")
uncompressor, err := xz.NewReader(reader)
if err != nil {
return err
}
reader = uncompressor
default:
// No need for an interposer otherwise
logrus.Debug("no known archive format detected for image, assuming no decompression necessary")
}

// Wrap the reader in TeeReader to calculate sha256 checksum on the fly
Expand Down
24 changes: 24 additions & 0 deletions vendor/github.com/h2non/filetype/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/h2non/filetype/matchers/application.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

234 changes: 234 additions & 0 deletions vendor/github.com/h2non/filetype/matchers/archive.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.