Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit e2730b5

Browse files
committed
Support for Compressed, Base64-Enc, Inline Content
This patch adds support for local, inline content as compressed, base64 encoded values. For example, the string "Hello, world." can be compressed with gzip and base64 encoded with the following command: $ echo Hello, world. | gzip | base64 H4sIAG/kFlsAA/NIzcnJ11Eozy/KSdHjAgDXu838DgAAAA== A Container Linux Config could use the above contents and write them to the file "/etc/helloworld.txt": storage: files: - path: /etc/helloworld.txt filesystem: root mode: 0644 contents: base64: true compression: gzip inline: | H4sIAB/jFlsAA/NIzcnJ11Eozy/KSdHjAgDXu838DgAAAA== The CT transpiler would transform the above configuration snippet into the JSON below: { "filesystem": "root", "path": "/etc/srv/kubernetes/pki/apiserver.key", "contents": { "compression": "gzip", "source": "data:;base64,H4sIAB/jFlsAA/NIzcnJ11Eozy/KSdHjAgDXu838DgAAAA==", "verification": {} }, "mode": 420 }, Please note the value of the "source" field -- it uses the data URL scheme (https://tools.ietf.org/html/rfc2397) to indicate the content is base64 encoded. The "compression" field indicates the content is also compressed using gzip. In fact, the following command may be used to verify the data matches the original "Hello, world." string: $ echo H4sIAB/jFlsAA/NIzcnJ11Eozy/KSdHjAgDXu838DgAAAA== | \ base64 -D | \ gzip -d Hello, world.
1 parent 5b24575 commit e2730b5

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

config/types/files.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ type File struct {
6363
}
6464

6565
type FileContents struct {
66-
Remote Remote `yaml:"remote"`
67-
Inline string `yaml:"inline"`
68-
Local string `yaml:"local"`
66+
Base64 *bool `yaml:"base64"`
67+
Compression string `yaml:"compression"`
68+
Remote Remote `yaml:"remote"`
69+
Inline string `yaml:"inline"`
70+
Local string `yaml:"local"`
6971
}
7072

7173
type Remote struct {
@@ -158,11 +160,20 @@ func init() {
158160
}
159161

160162
if file.Contents.Inline != "" {
161-
newFile.Contents = ignTypes.FileContents{
162-
Source: (&url.URL{
163-
Scheme: "data",
164-
Opaque: "," + dataurl.EscapeString(file.Contents.Inline),
165-
}).String(),
163+
if file.Contents.Base64 != nil && *file.Contents.Base64 {
164+
newFile.Contents = ignTypes.FileContents{
165+
Source: (&url.URL{
166+
Scheme: "data",
167+
Opaque: ";base64," + file.Contents.Inline,
168+
}).String(),
169+
}
170+
} else {
171+
newFile.Contents = ignTypes.FileContents{
172+
Source: (&url.URL{
173+
Scheme: "data",
174+
Opaque: "," + dataurl.EscapeString(file.Contents.Inline),
175+
}).String(),
176+
}
166177
}
167178
}
168179

@@ -237,7 +248,10 @@ func init() {
237248
}
238249
}
239250

240-
newFile.Contents.Compression = file.Contents.Remote.Compression
251+
if file.Contents.Compression == "" {
252+
file.Contents.Compression = file.Contents.Remote.Compression
253+
}
254+
newFile.Contents.Compression = file.Contents.Compression
241255
newFile.Contents.Verification = convertVerification(file.Contents.Remote.Verification)
242256

243257
out.Storage.Files = append(out.Storage.Files, newFile)

0 commit comments

Comments
 (0)