From efbd60e6a87e7502e445e34e39a37e2c962de04d Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Thu, 21 Apr 2022 16:52:48 -0400 Subject: [PATCH 1/2] *: drop some unnecessary StrToPtr() calls --- base/v0_2/translate.go | 2 +- base/v0_3/translate.go | 2 +- base/v0_4/translate.go | 2 +- base/v0_5_exp/translate.go | 2 +- config/fcos/v1_5_exp/translate.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/base/v0_2/translate.go b/base/v0_2/translate.go index 9e8f18f4..49ac2bb3 100644 --- a/base/v0_2/translate.go +++ b/base/v0_2/translate.go @@ -283,7 +283,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - file.Contents.Source = util.StrToPtr(url) + file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) if gzipped { file.Contents.Compression = util.StrToPtr("gzip") diff --git a/base/v0_3/translate.go b/base/v0_3/translate.go index 6c692c1c..ee19e5da 100644 --- a/base/v0_3/translate.go +++ b/base/v0_3/translate.go @@ -294,7 +294,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - file.Contents.Source = util.StrToPtr(url) + file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) if gzipped { file.Contents.Compression = util.StrToPtr("gzip") diff --git a/base/v0_4/translate.go b/base/v0_4/translate.go index 686668e9..4e1bf2b2 100644 --- a/base/v0_4/translate.go +++ b/base/v0_4/translate.go @@ -309,7 +309,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - file.Contents.Source = util.StrToPtr(url) + file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) if gzipped { file.Contents.Compression = util.StrToPtr("gzip") diff --git a/base/v0_5_exp/translate.go b/base/v0_5_exp/translate.go index f057b579..fbf2af48 100644 --- a/base/v0_5_exp/translate.go +++ b/base/v0_5_exp/translate.go @@ -309,7 +309,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - file.Contents.Source = util.StrToPtr(url) + file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) if gzipped { file.Contents.Compression = util.StrToPtr("gzip") diff --git a/config/fcos/v1_5_exp/translate.go b/config/fcos/v1_5_exp/translate.go index c941af28..7b59841f 100644 --- a/config/fcos/v1_5_exp/translate.go +++ b/config/fcos/v1_5_exp/translate.go @@ -337,7 +337,7 @@ func (c Config) processPackages(options common.TranslateOptions) (types.Config, }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr(src), + Source: &src, }, Mode: util.IntToPtr(0644), }, From 5996fbe48c89da11d97dc0aee56ce00cd7d47c33 Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Thu, 21 Apr 2022 17:30:58 -0400 Subject: [PATCH 2/2] base/*: fix uncompressed inline child resource with compressed parent When desugaring inline/local resource contents, the current rules are: 1. If the input config specifies compression: gzip, we pass through the compression field unchanged and refuse to compress again. This is useful for local resources that are stored precompressed alongside the config. 2. If we decide to compress, we set the compression field to gzip. 3. If we decide not to compress, we do not set the compression field, ostensibly so precompressed resources in child configs can inherit the compression field from the parent. But case 3 doesn't really work. Butane doesn't know that the child resource is precompressed, so is allowed to compress it again, and only the compressibility heuristics (which technically are not contractual) prevent it from doing so and producing invalid output. (There's no way to represent nested compression, so the file would be written to the provisioned system compressed.) And if the parent resource is not formally precompressed, but is actually just auto-compressed by Butane, a change to the parent's contents or to the Butane heuristics could cause the parent to become uncompressed in the future and break the merged config. And case 3 creates a problem for an inline/local child resource overriding an inline/local parent. If Butane opts to compress the parent but not the child, the merged config will have uncompressed contents but inherit "compression: gzip" from the parent, causing a provisioning failure. And if the parent/child contents change over time, this problem may suddenly appear in the future. Fix this by changing rule 3. When desugaring a non-precompressed inline/local resource, always set the compression field to either "" or "gzip". This intuitively makes sense: only we know whether we decided to compress the resource, so we need to say so. This involves an API change to MakeDataURL(). We now return a pointer to the selected compression value, or nil if we're passing through the compression value from the input (case 1). In the latter case, the caller should record a 1:1 translation for the compression field, rather than attributing its value to the inline/local input field. Fixes https://github.com/coreos/butane/issues/332. --- base/util/url.go | 23 +++++-- base/v0_2/translate.go | 18 +++--- base/v0_2/translate_test.go | 82 +++++++++++++++++++------ base/v0_3/translate.go | 18 +++--- base/v0_3/translate_test.go | 82 +++++++++++++++++++------ base/v0_4/translate.go | 18 +++--- base/v0_4/translate_test.go | 82 +++++++++++++++++++------ base/v0_5_exp/translate.go | 18 +++--- base/v0_5_exp/translate_test.go | 82 +++++++++++++++++++------ config/fcos/v1_5_exp/translate.go | 8 +-- config/fcos/v1_5_exp/translate_test.go | 4 +- config/openshift/v4_8/translate_test.go | 4 +- config/openshift/v4_9/translate_test.go | 4 +- 13 files changed, 323 insertions(+), 120 deletions(-) diff --git a/base/util/url.go b/base/util/url.go index 2cf3bef0..b7bc0359 100644 --- a/base/util/url.go +++ b/base/util/url.go @@ -24,9 +24,24 @@ import ( "github.com/vincent-petithory/dataurl" ) -func MakeDataURL(contents []byte, currentCompression *string, allowCompression bool) (uri string, gzipped bool, err error) { +func MakeDataURL(contents []byte, currentCompression *string, allowCompression bool) (uri string, compression *string, err error) { // try three different encodings, and select the smallest one + if util.NilOrEmpty(currentCompression) { + // The config does not specify compression. We need to + // explicitly set the compression field to avoid a child + // config inheriting a compression setting from the parent, + // which may not have used the same compression algorithm. + compression = util.StrToPtr("") + } else { + // The config specifies compression, meaning that the + // contents were compressed by the user, so we can pick a + // data URL encoding but we can't compress again. Return a + // nil compression value so the caller knows not to record a + // translation from input contents to output compression. + compression = nil + } + // URL-escaped, useful for ASCII text opaque := "," + dataurl.Escape(contents) @@ -53,10 +68,10 @@ func MakeDataURL(contents []byte, currentCompression *string, allowCompression b return } gz := ";base64," + base64.StdEncoding.EncodeToString(buf.Bytes()) - // Account for space needed by "compression": "gzip". - if len(gz)+25 < len(opaque) { + // Account for space needed by the compression value + if len(gz)+len("gzip") < len(opaque) { opaque = gz - gzipped = true + compression = util.StrToPtr("gzip") } } diff --git a/base/v0_2/translate.go b/base/v0_2/translate.go index 49ac2bb3..976f4f92 100644 --- a/base/v0_2/translate.go +++ b/base/v0_2/translate.go @@ -140,15 +140,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types return } - src, gzipped, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -156,15 +156,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types if from.Inline != nil { c := path.New("yaml", "inline") - src, gzipped, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -278,15 +278,15 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - url, gzipped, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) + url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(yamlPath, err) return nil } file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) - if gzipped { - file.Contents.Compression = util.StrToPtr("gzip") + if compression != nil { + file.Contents.Compression = compression ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "compression")) } ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents")) diff --git a/base/v0_2/translate_test.go b/base/v0_2/translate_test.go index 35b28062..844b7f62 100644 --- a/base/v0_2/translate_test.go +++ b/base/v0_2/translate_test.go @@ -196,7 +196,8 @@ func TestTranslateFile(t *testing.T) { }, }, { - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, Contents: types.Resource{ @@ -223,6 +224,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, }, "", common.TranslateOptions{ @@ -244,7 +249,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -253,6 +259,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{}, @@ -271,7 +281,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -280,6 +291,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -300,7 +315,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -309,6 +325,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -418,10 +438,12 @@ func TestTranslateFile(t *testing.T) { Compression: util.StrToPtr("gzip"), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { Source: util.StrToPtr("data:," + zzz), @@ -455,10 +477,18 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 1, "inline"), To: path.New("json", "append", 1, "source"), }, + { + From: path.New("yaml", "append", 1, "inline"), + To: path.New("json", "append", 1, "compression"), + }, { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, { From: path.New("yaml", "append", 3, "inline"), To: path.New("json", "append", 3, "source"), @@ -487,7 +517,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:," + zzz), + Source: util.StrToPtr("data:," + zzz), + Compression: util.StrToPtr(""), }, }, }, @@ -496,6 +527,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -948,7 +983,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden"), + Source: util.StrToPtr("data:,tree%2Foverridden"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -962,7 +998,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -973,7 +1010,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fexecutable"), + Source: util.StrToPtr("data:,tree%2Fexecutable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(func() int { if runtime.GOOS != "windows" { @@ -991,7 +1029,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1002,7 +1041,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1025,7 +1065,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree2%2Ffile"), + Source: util.StrToPtr("data:,tree2%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1085,7 +1126,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1096,7 +1138,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1425,11 +1468,13 @@ func TestTranslateIgnition(t *testing.T) { Config: types.IgnitionConfig{ Merge: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, Replace: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -1467,7 +1512,8 @@ func TestTranslateIgnition(t *testing.T) { TLS: types.TLS{ CertificateAuthorities: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, diff --git a/base/v0_3/translate.go b/base/v0_3/translate.go index ee19e5da..ab2f0449 100644 --- a/base/v0_3/translate.go +++ b/base/v0_3/translate.go @@ -151,15 +151,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types return } - src, gzipped, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -167,15 +167,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types if from.Inline != nil { c := path.New("yaml", "inline") - src, gzipped, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -289,15 +289,15 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - url, gzipped, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) + url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(yamlPath, err) return nil } file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) - if gzipped { - file.Contents.Compression = util.StrToPtr("gzip") + if compression != nil { + file.Contents.Compression = compression ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "compression")) } ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents")) diff --git a/base/v0_3/translate_test.go b/base/v0_3/translate_test.go index 47158656..29d51b6b 100644 --- a/base/v0_3/translate_test.go +++ b/base/v0_3/translate_test.go @@ -196,7 +196,8 @@ func TestTranslateFile(t *testing.T) { }, }, { - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, Contents: types.Resource{ @@ -223,6 +224,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, }, "", common.TranslateOptions{ @@ -244,7 +249,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -253,6 +259,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{}, @@ -271,7 +281,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -280,6 +291,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -300,7 +315,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -309,6 +325,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -418,10 +438,12 @@ func TestTranslateFile(t *testing.T) { Compression: util.StrToPtr("gzip"), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { Source: util.StrToPtr("data:," + zzz), @@ -455,10 +477,18 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 1, "inline"), To: path.New("json", "append", 1, "source"), }, + { + From: path.New("yaml", "append", 1, "inline"), + To: path.New("json", "append", 1, "compression"), + }, { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, { From: path.New("yaml", "append", 3, "inline"), To: path.New("json", "append", 3, "source"), @@ -487,7 +517,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:," + zzz), + Source: util.StrToPtr("data:," + zzz), + Compression: util.StrToPtr(""), }, }, }, @@ -496,6 +527,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -1028,7 +1063,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden"), + Source: util.StrToPtr("data:,tree%2Foverridden"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -1042,7 +1078,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -1053,7 +1090,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fexecutable"), + Source: util.StrToPtr("data:,tree%2Fexecutable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(func() int { if runtime.GOOS != "windows" { @@ -1071,7 +1109,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1082,7 +1121,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1105,7 +1145,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree2%2Ffile"), + Source: util.StrToPtr("data:,tree2%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1165,7 +1206,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1176,7 +1218,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1505,11 +1548,13 @@ func TestTranslateIgnition(t *testing.T) { Config: types.IgnitionConfig{ Merge: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, Replace: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -1547,7 +1592,8 @@ func TestTranslateIgnition(t *testing.T) { TLS: types.TLS{ CertificateAuthorities: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, diff --git a/base/v0_4/translate.go b/base/v0_4/translate.go index 4e1bf2b2..ee9116a4 100644 --- a/base/v0_4/translate.go +++ b/base/v0_4/translate.go @@ -166,15 +166,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types return } - src, gzipped, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -182,15 +182,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types if from.Inline != nil { c := path.New("yaml", "inline") - src, gzipped, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -304,15 +304,15 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - url, gzipped, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) + url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(yamlPath, err) return nil } file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) - if gzipped { - file.Contents.Compression = util.StrToPtr("gzip") + if compression != nil { + file.Contents.Compression = compression ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "compression")) } ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents")) diff --git a/base/v0_4/translate_test.go b/base/v0_4/translate_test.go index 3abc7820..9e5339d2 100644 --- a/base/v0_4/translate_test.go +++ b/base/v0_4/translate_test.go @@ -196,7 +196,8 @@ func TestTranslateFile(t *testing.T) { }, }, { - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, Contents: types.Resource{ @@ -223,6 +224,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, }, "", common.TranslateOptions{ @@ -244,7 +249,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -253,6 +259,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{}, @@ -271,7 +281,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -280,6 +291,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -300,7 +315,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -309,6 +325,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -418,10 +438,12 @@ func TestTranslateFile(t *testing.T) { Compression: util.StrToPtr("gzip"), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { Source: util.StrToPtr("data:," + zzz), @@ -455,10 +477,18 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 1, "inline"), To: path.New("json", "append", 1, "source"), }, + { + From: path.New("yaml", "append", 1, "inline"), + To: path.New("json", "append", 1, "compression"), + }, { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, { From: path.New("yaml", "append", 3, "inline"), To: path.New("json", "append", 3, "source"), @@ -487,7 +517,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:," + zzz), + Source: util.StrToPtr("data:," + zzz), + Compression: util.StrToPtr(""), }, }, }, @@ -496,6 +527,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -1113,7 +1148,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden"), + Source: util.StrToPtr("data:,tree%2Foverridden"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -1127,7 +1163,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -1138,7 +1175,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fexecutable"), + Source: util.StrToPtr("data:,tree%2Fexecutable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(func() int { if runtime.GOOS != "windows" { @@ -1156,7 +1194,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1167,7 +1206,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1190,7 +1230,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree2%2Ffile"), + Source: util.StrToPtr("data:,tree2%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1250,7 +1291,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1261,7 +1303,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1590,11 +1633,13 @@ func TestTranslateIgnition(t *testing.T) { Config: types.IgnitionConfig{ Merge: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, Replace: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -1632,7 +1677,8 @@ func TestTranslateIgnition(t *testing.T) { TLS: types.TLS{ CertificateAuthorities: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, diff --git a/base/v0_5_exp/translate.go b/base/v0_5_exp/translate.go index fbf2af48..bfe63cf1 100644 --- a/base/v0_5_exp/translate.go +++ b/base/v0_5_exp/translate.go @@ -166,15 +166,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types return } - src, gzipped, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -182,15 +182,15 @@ func translateResource(from Resource, options common.TranslateOptions) (to types if from.Inline != nil { c := path.New("yaml", "inline") - src, gzipped, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(c, err) return } to.Source = &src tm.AddTranslation(c, path.New("json", "source")) - if gzipped { - to.Compression = util.StrToPtr("gzip") + if compression != nil { + to.Compression = compression tm.AddTranslation(c, path.New("json", "compression")) } } @@ -304,15 +304,15 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report r.AddOnError(yamlPath, err) return nil } - url, gzipped, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) + url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(yamlPath, err) return nil } file.Contents.Source = &url ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "source")) - if gzipped { - file.Contents.Compression = util.StrToPtr("gzip") + if compression != nil { + file.Contents.Compression = compression ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents", "compression")) } ts.AddTranslation(yamlPath, path.New("json", "storage", "files", i, "contents")) diff --git a/base/v0_5_exp/translate_test.go b/base/v0_5_exp/translate_test.go index 86b5c219..da0b8c02 100644 --- a/base/v0_5_exp/translate_test.go +++ b/base/v0_5_exp/translate_test.go @@ -196,7 +196,8 @@ func TestTranslateFile(t *testing.T) { }, }, { - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, Contents: types.Resource{ @@ -223,6 +224,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, }, "", common.TranslateOptions{ @@ -244,7 +249,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -253,6 +259,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{}, @@ -271,7 +281,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,file%20contents%0A"), + Source: util.StrToPtr("data:,file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -280,6 +291,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -300,7 +315,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Source: util.StrToPtr("data:,subdir%20file%20contents%0A"), + Compression: util.StrToPtr(""), }, }, }, @@ -309,6 +325,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "local"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "local"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -418,10 +438,12 @@ func TestTranslateFile(t *testing.T) { Compression: util.StrToPtr("gzip"), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { - Source: util.StrToPtr(random_b64), + Source: util.StrToPtr(random_b64), + Compression: util.StrToPtr(""), }, { Source: util.StrToPtr("data:," + zzz), @@ -455,10 +477,18 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "append", 1, "inline"), To: path.New("json", "append", 1, "source"), }, + { + From: path.New("yaml", "append", 1, "inline"), + To: path.New("json", "append", 1, "compression"), + }, { From: path.New("yaml", "append", 2, "local"), To: path.New("json", "append", 2, "source"), }, + { + From: path.New("yaml", "append", 2, "local"), + To: path.New("json", "append", 2, "compression"), + }, { From: path.New("yaml", "append", 3, "inline"), To: path.New("json", "append", 3, "source"), @@ -487,7 +517,8 @@ func TestTranslateFile(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:," + zzz), + Source: util.StrToPtr("data:," + zzz), + Compression: util.StrToPtr(""), }, }, }, @@ -496,6 +527,10 @@ func TestTranslateFile(t *testing.T) { From: path.New("yaml", "contents", "inline"), To: path.New("json", "contents", "source"), }, + { + From: path.New("yaml", "contents", "inline"), + To: path.New("json", "contents", "compression"), + }, }, "", common.TranslateOptions{ @@ -1113,7 +1148,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden"), + Source: util.StrToPtr("data:,tree%2Foverridden"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -1127,7 +1163,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Source: util.StrToPtr("data:,tree%2Foverridden-executable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0600), }, @@ -1138,7 +1175,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fexecutable"), + Source: util.StrToPtr("data:,tree%2Fexecutable"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(func() int { if runtime.GOOS != "windows" { @@ -1156,7 +1194,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1167,7 +1206,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1190,7 +1230,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree2%2Ffile"), + Source: util.StrToPtr("data:,tree2%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1250,7 +1291,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Ffile"), + Source: util.StrToPtr("data:,tree%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1261,7 +1303,8 @@ func TestTranslateTree(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Source: util.StrToPtr("data:,tree%2Fsubdir%2Ffile"), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(0644), }, @@ -1590,11 +1633,13 @@ func TestTranslateIgnition(t *testing.T) { Config: types.IgnitionConfig{ Merge: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, Replace: types.Resource{ - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, @@ -1632,7 +1677,8 @@ func TestTranslateIgnition(t *testing.T) { TLS: types.TLS{ CertificateAuthorities: []types.Resource{ { - Source: util.StrToPtr("data:,xyzzy"), + Source: util.StrToPtr("data:,xyzzy"), + Compression: util.StrToPtr(""), }, }, }, diff --git a/config/fcos/v1_5_exp/translate.go b/config/fcos/v1_5_exp/translate.go index 7b59841f..e3fdbbae 100644 --- a/config/fcos/v1_5_exp/translate.go +++ b/config/fcos/v1_5_exp/translate.go @@ -323,7 +323,7 @@ func (c Config) processPackages(options common.TranslateOptions) (types.Config, return ret, ts, r } fullYamlContents := append([]byte("# Generated by Butane\n\n"), treeFileContents...) - src, gzipped, err := baseutil.MakeDataURL(fullYamlContents, nil, !options.NoResourceAutoCompression) + src, compression, err := baseutil.MakeDataURL(fullYamlContents, nil, !options.NoResourceAutoCompression) if err != nil { r.AddOnError(yamlPath, err) return ret, ts, r @@ -337,14 +337,12 @@ func (c Config) processPackages(options common.TranslateOptions) (types.Config, }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: &src, + Source: &src, + Compression: compression, }, Mode: util.IntToPtr(0644), }, } - if gzipped { - file.Contents.Compression = util.StrToPtr("gzip") - } ret.Storage.Files = append(ret.Storage.Files, file) ts.AddFromCommonSource(yamlPath, path.New("json", "storage"), ret.Storage) diff --git a/config/fcos/v1_5_exp/translate_test.go b/config/fcos/v1_5_exp/translate_test.go index 9e910059..fa0f2577 100644 --- a/config/fcos/v1_5_exp/translate_test.go +++ b/config/fcos/v1_5_exp/translate_test.go @@ -1453,7 +1453,8 @@ func TestTranslateExtensions(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:;base64,IyBHZW5lcmF0ZWQgYnkgQnV0YW5lCgpwYWNrYWdlczoKICAgIC0gc3RyYWNlCiAgICAtIHpzaAo="), + Source: util.StrToPtr("data:;base64,IyBHZW5lcmF0ZWQgYnkgQnV0YW5lCgpwYWNrYWdlczoKICAgIC0gc3RyYWNlCiAgICAtIHpzaAo="), + Compression: util.StrToPtr(""), }, Mode: util.IntToPtr(420), }, @@ -1470,6 +1471,7 @@ func TestTranslateExtensions(t *testing.T) { {path.New("yaml", "extensions"), path.New("json", "storage", "files", 0, "mode")}, {path.New("yaml", "extensions"), path.New("json", "storage", "files", 0, "contents")}, {path.New("yaml", "extensions"), path.New("json", "storage", "files", 0, "contents", "source")}, + {path.New("yaml", "extensions"), path.New("json", "storage", "files", 0, "contents", "compression")}, }, report.Report{}, }, diff --git a/config/openshift/v4_8/translate_test.go b/config/openshift/v4_8/translate_test.go index 97137fc6..c84289d7 100644 --- a/config/openshift/v4_8/translate_test.go +++ b/config/openshift/v4_8/translate_test.go @@ -144,7 +144,8 @@ func TestTranslateConfig(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:," + zzz), + Source: util.StrToPtr("data:," + zzz), + Compression: util.StrToPtr(""), }, }, }, @@ -166,6 +167,7 @@ func TestTranslateConfig(t *testing.T) { {path.New("yaml", "storage", "files", 0, "path"), path.New("json", "spec", "config", "storage", "files", 0, "path")}, {path.New("yaml", "storage", "files", 0, "contents"), path.New("json", "spec", "config", "storage", "files", 0, "contents")}, {path.New("yaml", "storage", "files", 0, "contents", "inline"), path.New("json", "spec", "config", "storage", "files", 0, "contents", "source")}, + {path.New("yaml", "storage", "files", 0, "contents", "inline"), path.New("json", "spec", "config", "storage", "files", 0, "contents", "compression")}, }, }, // FIPS diff --git a/config/openshift/v4_9/translate_test.go b/config/openshift/v4_9/translate_test.go index ed3b46ec..468356c3 100644 --- a/config/openshift/v4_9/translate_test.go +++ b/config/openshift/v4_9/translate_test.go @@ -144,7 +144,8 @@ func TestTranslateConfig(t *testing.T) { }, FileEmbedded1: types.FileEmbedded1{ Contents: types.Resource{ - Source: util.StrToPtr("data:," + zzz), + Source: util.StrToPtr("data:," + zzz), + Compression: util.StrToPtr(""), }, }, }, @@ -166,6 +167,7 @@ func TestTranslateConfig(t *testing.T) { {path.New("yaml", "storage", "files", 0, "path"), path.New("json", "spec", "config", "storage", "files", 0, "path")}, {path.New("yaml", "storage", "files", 0, "contents"), path.New("json", "spec", "config", "storage", "files", 0, "contents")}, {path.New("yaml", "storage", "files", 0, "contents", "inline"), path.New("json", "spec", "config", "storage", "files", 0, "contents", "source")}, + {path.New("yaml", "storage", "files", 0, "contents", "inline"), path.New("json", "spec", "config", "storage", "files", 0, "contents", "compression")}, }, }, // FIPS