1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

cache: Support artifacts compressed with xz

Switches to "github.com/h2non/filetype/matchers" for MIME type matching
and uses "github.com/ulikunitz/xz" for xz decompression.
This commit is contained in:
Christian Glombek
2020-02-27 22:56:18 +01:00
parent 29beee5f01
commit 3748d216b4
3 changed files with 17 additions and 5 deletions

2
go.mod
View File

@@ -40,6 +40,7 @@ require (
github.com/gorilla/websocket v1.4.1 // indirect github.com/gorilla/websocket v1.4.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.12.1 // 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-azure-helpers v0.10.0
github.com/hashicorp/go-plugin v1.0.1 github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/go-retryablehttp v0.6.4 // indirect github.com/hashicorp/go-retryablehttp v0.6.4 // indirect
@@ -98,6 +99,7 @@ require (
github.com/terraform-providers/terraform-provider-openstack v1.25.0 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-random v1.3.2-0.20190925210718-83518d96ae4f
github.com/terraform-providers/terraform-provider-vsphere v0.0.0 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/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50
github.com/vmware/govmomi v0.22.1 github.com/vmware/govmomi v0.22.1
go.uber.org/atomic v1.5.1 // indirect go.uber.org/atomic v1.5.1 // indirect

2
go.sum
View File

@@ -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.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 h1:zCy2xE9ablevUOrUZc3Dl72Dt+ya2FNAvC2yLYMHzi4=
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= 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/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 h1:zH9hNUdsS+2G0zJaU85ul8D59BGnZBaKM+KMNPAHGwk=
github.com/hashicorp/aws-sdk-go-base v0.4.0/go.mod h1:eRhlz3c4nhqxFZJAahJEFL7gh6Jyj5rQmQc7F9eHFyQ= github.com/hashicorp/aws-sdk-go-base v0.4.0/go.mod h1:eRhlz3c4nhqxFZJAahJEFL7gh6Jyj5rQmQc7F9eHFyQ=

View File

@@ -12,8 +12,10 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/h2non/filetype/matchers"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/ulikunitz/xz"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@@ -21,7 +23,6 @@ import (
const ( const (
applicationName = "openshift-installer" applicationName = "openshift-installer"
imageDataType = "image" imageDataType = "image"
gzipFileType = "application/x-gzip"
) )
// getCacheDir returns a local path of the cache, where the installer should put the data: // getCacheDir returns a local path of the cache, where the installer should put the data:
@@ -119,18 +120,25 @@ func cacheFile(reader io.Reader, filePath string, sha256Checksum string) (err er
} }
reader = io.MultiReader(bytes.NewReader(buf), reader) reader = io.MultiReader(bytes.NewReader(buf), reader)
fileType := http.DetectContentType(buf) switch {
logrus.Debugf("content type of %s is %s", filePath, fileType) case matchers.Gz(buf):
switch fileType { logrus.Debug("decompressing the image archive as gz")
case gzipFileType:
uncompressor, err := gzip.NewReader(reader) uncompressor, err := gzip.NewReader(reader)
if err != nil { if err != nil {
return err return err
} }
defer uncompressor.Close() defer uncompressor.Close()
reader = uncompressor 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: default:
// No need for an interposer otherwise // 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 // Wrap the reader in TeeReader to calculate sha256 checksum on the fly