Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion base/util/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import (
"github.com/vincent-petithory/dataurl"
)

func MakeDataURL(contents []byte, currentCompression *string, allowCompression bool) (uri string, compression *string, err error) {
func MakeDataURL(contents []byte, currentCompression *string, allowCompression bool, humanReadableEncoding bool) (uri string, compression *string, err error) {
if humanReadableEncoding {
compression = util.StrToPtr("")
uri = string(contents)
return
}

// try three different encodings, and select the smallest one

if util.NilOrEmpty(currentCompression) {
Expand Down
6 changes: 3 additions & 3 deletions base/v0_2/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
return
}
}
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand All @@ -148,7 +148,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
if from.Inline != nil {
c := path.New("yaml", "inline")

src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand Down Expand Up @@ -270,7 +270,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report
r.AddOnError(yamlPath, err)
return nil
}
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression)
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(yamlPath, err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions base/v0_3/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
return
}
}
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand All @@ -155,7 +155,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
if from.Inline != nil {
c := path.New("yaml", "inline")

src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand Down Expand Up @@ -277,7 +277,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report
r.AddOnError(yamlPath, err)
return nil
}
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression)
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(yamlPath, err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions base/v0_4/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
return
}
}
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand All @@ -170,7 +170,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
if from.Inline != nil {
c := path.New("yaml", "inline")

src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand Down Expand Up @@ -292,7 +292,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report
r.AddOnError(yamlPath, err)
return nil
}
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression)
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(yamlPath, err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions base/v0_5/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
return
}
}
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand All @@ -173,7 +173,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
if from.Inline != nil {
c := path.New("yaml", "inline")

src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand Down Expand Up @@ -382,7 +382,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report
r.AddOnError(yamlPath, err)
return nil
}
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression)
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(yamlPath, err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions base/v0_6/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
return
}
}
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand All @@ -173,7 +173,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
if from.Inline != nil {
c := path.New("yaml", "inline")

src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(c, err)
return
Expand Down Expand Up @@ -382,7 +382,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report
r.AddOnError(yamlPath, err)
return nil
}
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression)
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(yamlPath, err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions base/v0_7_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
}
}

src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(contents, to.Compression, !options.NoResourceAutoCompression, options.PlainTextEncoding)
if err != nil {
r.AddOnError(c, err)
return
Expand All @@ -174,7 +174,7 @@ func translateResource(from Resource, options common.TranslateOptions) (to types
if from.Inline != nil {
c := path.New("yaml", "inline")

src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL([]byte(*from.Inline), to.Compression, !options.NoResourceAutoCompression, options.PlainTextEncoding)
if err != nil {
r.AddOnError(c, err)
return
Expand Down Expand Up @@ -421,7 +421,7 @@ func walkTree(yamlPath path.ContextPath, ts *translate.TranslationSet, r *report
r.AddOnError(yamlPath, err)
return nil
}
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression)
url, compression, err := baseutil.MakeDataURL(contents, file.Contents.Compression, !options.NoResourceAutoCompression, options.PlainTextEncoding)
if err != nil {
r.AddOnError(yamlPath, err)
return nil
Expand Down
1 change: 1 addition & 0 deletions config/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package common
type TranslateOptions struct {
FilesDir string // allow embedding local files relative to this directory
NoResourceAutoCompression bool // skip automatic compression of inline/local resources
PlainTextEncoding bool // plain text, only for debugging
DebugPrintTranslations bool // report translations to stderr
}

Expand Down
2 changes: 1 addition & 1 deletion config/fcos/v1_5/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (c Config) handleUserGrubCfg(options common.TranslateOptions) (types.Config
})

userCfgContent := []byte(buildGrubConfig(c.Grub))
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(yamlPath, err)
return rendered, ts, r
Expand Down
2 changes: 1 addition & 1 deletion config/fcos/v1_6/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (c Config) handleUserGrubCfg(options common.TranslateOptions) (types.Config
})

userCfgContent := []byte(buildGrubConfig(c.Grub))
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression, false)
if err != nil {
r.AddOnError(yamlPath, err)
return rendered, ts, r
Expand Down
2 changes: 1 addition & 1 deletion config/fcos/v1_7_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (c Config) handleUserGrubCfg(options common.TranslateOptions) (types.Config
})

userCfgContent := []byte(buildGrubConfig(c.Grub))
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression)
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression, false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In this experimental spec, the plain-text option is not propagated to MakeDataURL for the user grub config. This is inconsistent with other experimental specs and the overall goal of the feature. To ensure consistent behavior for the --plain-text flag, options.PlainTextEncoding should be used here instead of hardcoding false.

Suggested change
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression, false)
src, compression, err := baseutil.MakeDataURL(userCfgContent, nil, !options.NoResourceAutoCompression, options.PlainTextEncoding)

if err != nil {
r.AddOnError(yamlPath, err)
return rendered, ts, r
Expand Down
9 changes: 6 additions & 3 deletions config/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ func Translate(cfg Config, translateMethod string, options common.TranslateOptio
dupsReport := validate.ValidateCustom(final, "json", ignvalidate.ValidateDups)
r.Merge(TranslateReportPaths(dupsReport, translations))

// Validate JSON semantics.
jsonReport := validate.Validate(final, "json")
r.Merge(TranslateReportPaths(jsonReport, translations))
// When user use --plain-text flag, we skip the JSON semantics validation because the resulting Ignition is invalid, and this is for debug only
if !options.PlainTextEncoding {
// Validate JSON semantics.
jsonReport := validate.Validate(final, "json")
r.Merge(TranslateReportPaths(jsonReport, translations))
}

if r.IsFatal() {
return zeroValue, r, common.ErrInvalidGeneratedConfig
Expand Down
2 changes: 2 additions & 0 deletions internal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func main() {
pflag.Lookup("input").Hidden = true
pflag.StringVarP(&output, "output", "o", "", "write to output file instead of stdout")
pflag.StringVarP(&options.FilesDir, "files-dir", "d", "", "allow embedding local files from this directory")
pflag.BoolVar(&options.PlainTextEncoding, "plain-text", false,
"use plain text only -- only for debugging, should not be used for configs!!!")

pflag.Usage = func() {
fmt.Fprintf(pflag.CommandLine.Output(), "Usage: %s [options] [input-file]\n", os.Args[0])
Expand Down