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

Commit 7d6ce4d

Browse files
committed
config/types: allow compression on all file srcs
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: compression: gzip inline: !binary | H4sIAB/jFlsAA/NIzcnJ11Eozy/KSdHjAgDXu838DgAAAA== The CT transpiler would transform the above configuration snippet into the JSON below: { "filesystem": "root", "path": "/etc/helloworld.txt", "contents": { "compression": "gzip", "source": "data:,H4sIAB%2FjFlsAA%2FNIzcnJ11Eozy%2FKSdHjAgDXu838DgAAAA%3D%3D", "verification": {} }, "mode": 420 }, The following command may be used to verify the URL encoded data matches the original "Hello, world." string: $ echo H4sIAB%2FjFlsAA%2FNIzcnJ11Eozy%2FKSdHjAgDXu838DgAAAA%3D%3D | \ perl -pe 's/\%(\w\w)/chr hex $1/ge' | \ base64 -D | \ gzip -d Hello, world.
1 parent 5b24575 commit 7d6ce4d

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

config/config_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ storage:
295295
- path: /opt/file2
296296
filesystem: filesystem1
297297
contents:
298+
compression: gzip
298299
remote:
299300
url: http://example.com/file2
300-
compression: gzip
301301
verification:
302302
hash:
303303
function: sha512
@@ -311,9 +311,9 @@ storage:
311311
- path: /opt/file3
312312
filesystem: filesystem2
313313
contents:
314+
compression: gzip
314315
remote:
315316
url: http://example.com/file3
316-
compression: gzip
317317
mode: 0400
318318
user:
319319
id: 1000
@@ -503,9 +503,9 @@ storage:
503503
User: &types.FileUser{Id: util.IntToPtr(502)},
504504
Group: &types.FileGroup{Id: util.IntToPtr(503)},
505505
Contents: types.FileContents{
506+
Compression: "gzip",
506507
Remote: types.Remote{
507-
Url: "http://example.com/file2",
508-
Compression: "gzip",
508+
Url: "http://example.com/file2",
509509
Verification: types.Verification{
510510
Hash: types.Hash{
511511
Function: "sha512",
@@ -523,9 +523,9 @@ storage:
523523
User: &types.FileUser{Id: util.IntToPtr(1000)},
524524
Group: &types.FileGroup{Id: util.IntToPtr(1001)},
525525
Contents: types.FileContents{
526+
Compression: "gzip",
526527
Remote: types.Remote{
527-
Url: "http://example.com/file3",
528-
Compression: "gzip",
528+
Url: "http://example.com/file3",
529529
},
530530
},
531531
Mode: util.IntToPtr(0400),
@@ -1197,9 +1197,9 @@ func TestConvert(t *testing.T) {
11971197
User: &types.FileUser{Id: util.IntToPtr(502)},
11981198
Group: &types.FileGroup{Id: util.IntToPtr(503)},
11991199
Contents: types.FileContents{
1200+
Compression: "gzip",
12001201
Remote: types.Remote{
1201-
Url: "http://example.com/file2",
1202-
Compression: "gzip",
1202+
Url: "http://example.com/file2",
12031203
Verification: types.Verification{
12041204
Hash: types.Hash{
12051205
Function: "sha512",
@@ -1217,9 +1217,9 @@ func TestConvert(t *testing.T) {
12171217
User: &types.FileUser{Id: util.IntToPtr(1000)},
12181218
Group: &types.FileGroup{Id: util.IntToPtr(1001)},
12191219
Contents: types.FileContents{
1220+
Compression: "gzip",
12201221
Remote: types.Remote{
1221-
Url: "http://example.com/file3",
1222-
Compression: "gzip",
1222+
Url: "http://example.com/file3",
12231223
},
12241224
},
12251225
Mode: util.IntToPtr(0400),
@@ -1424,12 +1424,12 @@ func TestConvert(t *testing.T) {
14241424
},
14251425
FileEmbedded1: ignTypes.FileEmbedded1{
14261426
Contents: ignTypes.FileContents{
1427+
Compression: "gzip",
14271428
Source: (&url.URL{
14281429
Scheme: "http",
14291430
Host: "example.com",
14301431
Path: "/file2",
14311432
}).String(),
1432-
Compression: "gzip",
14331433
Verification: ignTypes.Verification{
14341434
Hash: util.StringToPtr("sha512-00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
14351435
},
@@ -1930,9 +1930,9 @@ storage:
19301930
- path: /opt/file2
19311931
filesystem: root
19321932
contents:
1933+
compression: gzip
19331934
remote:
19341935
url: httpz://example.com/file2
1935-
compression: gzip
19361936
verification:
19371937
hash:
19381938
function: sha512
@@ -2017,9 +2017,9 @@ storage:
20172017
- path: /opt/file2
20182018
filesystem: root
20192019
contents:
2020+
compression: gzip
20202021
remote:
20212022
url: http://example.com/file2
2022-
compression: gzip
20232023
verification:
20242024
hash:
20252025
function: sha512
@@ -2060,12 +2060,12 @@ storage:
20602060
},
20612061
FileEmbedded1: ignTypes.FileEmbedded1{
20622062
Contents: ignTypes.FileContents{
2063+
Compression: "gzip",
20632064
Source: (&url.URL{
20642065
Scheme: "http",
20652066
Host: "example.com",
20662067
Path: "/file2",
20672068
}).String(),
2068-
Compression: "gzip",
20692069
Verification: ignTypes.Verification{
20702070
Hash: util.StringToPtr("sha512-00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
20712071
},

config/types/files.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ 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+
Compression string `yaml:"compression"`
67+
Remote Remote `yaml:"remote"`
68+
Inline string `yaml:"inline"`
69+
Local string `yaml:"local"`
6970
}
7071

7172
type Remote struct {
7273
Url string `yaml:"url"`
73-
Compression string `yaml:"compression"`
7474
Verification Verification `yaml:"verification"`
7575
}
7676

@@ -237,7 +237,7 @@ func init() {
237237
}
238238
}
239239

240-
newFile.Contents.Compression = file.Contents.Remote.Compression
240+
newFile.Contents.Compression = file.Contents.Compression
241241
newFile.Contents.Verification = convertVerification(file.Contents.Remote.Verification)
242242

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

doc/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ _Note: all fields are optional unless otherwise marked_
6363
* **overwrite** (boolean): whether to delete preexisting nodes at the path. Defaults to true.
6464
* **append** (boolean): whether to append to the specified file. Creates a new file if nothing exists at the path. Cannot be set if overwrite is set to true.
6565
* **contents** (object): options related to the contents of the file.
66+
* **compression** (string): the type of compression used on the contents (null or gzip)
6667
* **inline** (string): the contents of the file.
6768
* **local** (string): the path to a local file, relative to the `--files-dir` directory. When using local files, the `--files-dir` flag must be passed to `ct`. The file contents are included in the generated config.
6869
* **remote** (object): options related to the fetching of remote file contents. Remote files are fetched by Ignition when Ignition runs, the contents are not included in the generated config.
69-
* **compression** (string): the type of compression used on the contents (null or gzip)
7070
* **url** (string): the URL of the file contents. Supported schemes are http, https, tftp, s3, and [data][rfc2397]. Note: When using http, it is advisable to use the verification option to ensure the contents haven't been modified.
7171
* **verification** (object): options related to the verification of the file contents.
7272
* **hash** (object): the hash of the config

0 commit comments

Comments
 (0)