mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-12 08:01:11 +02:00
feat: detect gzipped machine configs
This PR will add the ability for talos to detect if the machine config that it downloads from the platform is a gzipped file. If so, it will unzip it and overwrite the byte slice that gets written to disk. Signed-off-by: Spencer Smith <robertspencersmith@gmail.com>
This commit is contained in:
parent
bccaa36b44
commit
d8db2bc65b
@ -5,7 +5,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/talos-systems/talos/internal/app/machined/internal/phase"
|
||||
"github.com/talos-systems/talos/internal/pkg/runtime"
|
||||
@ -32,5 +36,24 @@ func (task *Task) standard(r runtime.Runtime) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Detect if config is a gzip archive and unzip it if so
|
||||
contentType := http.DetectContentType(b)
|
||||
if contentType == "application/x-gzip" {
|
||||
gzipReader, err := gzip.NewReader(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating gzip reader: %w", err)
|
||||
}
|
||||
|
||||
// nolint: errcheck
|
||||
defer gzipReader.Close()
|
||||
|
||||
unzippedData, err := ioutil.ReadAll(gzipReader)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unzipping machine config: %w", err)
|
||||
}
|
||||
|
||||
b = unzippedData
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(constants.ConfigPath, b, 0600)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user