This repository was archived by the owner on Oct 11, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,11 @@ func fetchAndSave(ds datasource.Datasource) error {
182182 log .Errorf ("Failed fetching user-data from datasource: %v" , err )
183183 return err
184184 }
185+ userDataBytes , err = decompressIfGzip (userDataBytes )
186+ if err != nil {
187+ log .Errorf ("Failed decompressing user-data from datasource: %v" , err )
188+ return err
189+ }
185190 log .Infof ("Fetching meta-data from datasource of type %v" , ds .Type ())
186191 metadata , err = ds .FetchMetadata ()
187192 if err != nil {
@@ -367,3 +372,13 @@ func composeToCloudConfig(bytes []byte) ([]byte, error) {
367372 },
368373 })
369374}
375+
376+ const gzipMagicBytes = "\x1f \x8b "
377+
378+ func decompressIfGzip (userdataBytes []byte ) ([]byte , error ) {
379+ if ! bytes .HasPrefix (userdataBytes , []byte (gzipMagicBytes )) {
380+ return userdataBytes , nil
381+ }
382+
383+ return config .DecompressGzip (userdataBytes )
384+ }
Original file line number Diff line number Diff line change @@ -18,7 +18,12 @@ func DecodeBase64Content(content string) ([]byte, error) {
1818}
1919
2020func DecodeGzipContent (content string ) ([]byte , error ) {
21- gzr , err := gzip .NewReader (bytes .NewReader ([]byte (content )))
21+ byteContent := []byte (content )
22+ return DecompressGzip (byteContent )
23+ }
24+
25+ func DecompressGzip (content []byte ) ([]byte , error ) {
26+ gzr , err := gzip .NewReader (bytes .NewReader (content ))
2227
2328 if err != nil {
2429 return nil , fmt .Errorf ("Unable to decode gzip: %q" , err )
You can’t perform that action at this time.
0 commit comments