Skip to content

Commit

Permalink
WIP: spec: unify resource fetching type
Browse files Browse the repository at this point in the history
Dedupe the "remote resource" type from the spec. This came up too during
review of the new HTTP headers. They all had more or less the same
fields in common ("source", "verification", "compression", and more
recently "httpHeaders").

One noticeable spec level change from this is that some places now
support compression where they didn't before. Might seem odd to support
compression for e.g. certificate authorities, though it does make the
spec more consistent throughout.

It's a nice cleanup, though my goal with doing this is the ability to
inspect more easily whether a config contains any resources which
require some form of networking.
  • Loading branch information
jlebon committed Mar 30, 2020
1 parent 7d77071 commit 6e69536
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 270 deletions.
44 changes: 22 additions & 22 deletions config/merge/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestMerge(t *testing.T) {
Path: "/foo",
},
FileEmbedded1: types.FileEmbedded1{
Append: []types.FileContents{
Append: []types.Resource{
{
Source: util.StrToPtr("source1"),
},
Expand All @@ -94,7 +94,7 @@ func TestMerge(t *testing.T) {
Path: "/bar",
},
FileEmbedded1: types.FileEmbedded1{
Contents: types.FileContents{
Contents: types.Resource{
Compression: util.StrToPtr("gzip"),
},
},
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestMerge(t *testing.T) {
Path: "/foo",
},
FileEmbedded1: types.FileEmbedded1{
Append: []types.FileContents{
Append: []types.Resource{
{
Source: util.StrToPtr("source1"),
},
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestMerge(t *testing.T) {
Path: "/foo",
},
FileEmbedded1: types.FileEmbedded1{
Append: []types.FileContents{
Append: []types.Resource{
{
Source: util.StrToPtr("source1"),
},
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestMerge(t *testing.T) {
in1: types.Config{
Ignition: types.Ignition{
Config: types.IgnitionConfig{
Merge: []types.ConfigReference{
Merge: []types.Resource{
{
Source: &configURL,
HTTPHeaders: []types.HTTPHeader{
Expand All @@ -255,7 +255,7 @@ func TestMerge(t *testing.T) {
in2: types.Config{
Ignition: types.Ignition{
Config: types.IgnitionConfig{
Merge: []types.ConfigReference{
Merge: []types.Resource{
{
Source: &configURL,
HTTPHeaders: []types.HTTPHeader{
Expand All @@ -279,7 +279,7 @@ func TestMerge(t *testing.T) {
out: types.Config{
Ignition: types.Ignition{
Config: types.IgnitionConfig{
Merge: []types.ConfigReference{
Merge: []types.Resource{
{
Source: &configURL,
HTTPHeaders: []types.HTTPHeader{
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestMerge(t *testing.T) {
in1: types.Config{
Ignition: types.Ignition{
Config: types.IgnitionConfig{
Replace: types.ConfigReference{
Replace: types.Resource{
Source: &configURL,
HTTPHeaders: []types.HTTPHeader{
{
Expand All @@ -331,7 +331,7 @@ func TestMerge(t *testing.T) {
in2: types.Config{
Ignition: types.Ignition{
Config: types.IgnitionConfig{
Replace: types.ConfigReference{
Replace: types.Resource{
Source: &configURL,
HTTPHeaders: []types.HTTPHeader{
{
Expand All @@ -353,7 +353,7 @@ func TestMerge(t *testing.T) {
out: types.Config{
Ignition: types.Ignition{
Config: types.IgnitionConfig{
Replace: types.ConfigReference{
Replace: types.Resource{
Source: &configURL,
HTTPHeaders: []types.HTTPHeader{
{
Expand Down Expand Up @@ -381,9 +381,9 @@ func TestMerge(t *testing.T) {
Ignition: types.Ignition{
Security: types.Security{
TLS: types.TLS{
CertificateAuthorities: []types.CaReference{
CertificateAuthorities: []types.Resource{
{
Source: caURL,
Source: util.StrToPtr(caURL),
HTTPHeaders: []types.HTTPHeader{
{
Name: "old-header",
Expand All @@ -408,9 +408,9 @@ func TestMerge(t *testing.T) {
Ignition: types.Ignition{
Security: types.Security{
TLS: types.TLS{
CertificateAuthorities: []types.CaReference{
CertificateAuthorities: []types.Resource{
{
Source: caURL,
Source: util.StrToPtr(caURL),
HTTPHeaders: []types.HTTPHeader{
{
Name: "to-remove-header",
Expand All @@ -434,9 +434,9 @@ func TestMerge(t *testing.T) {
Ignition: types.Ignition{
Security: types.Security{
TLS: types.TLS{
CertificateAuthorities: []types.CaReference{
CertificateAuthorities: []types.Resource{
{
Source: caURL,
Source: util.StrToPtr(caURL),
HTTPHeaders: []types.HTTPHeader{
{
Name: "old-header",
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestMerge(t *testing.T) {
Files: []types.File{
{
FileEmbedded1: types.FileEmbedded1{
Contents: types.FileContents{
Contents: types.Resource{
Source: &fileURL,
HTTPHeaders: []types.HTTPHeader{
{
Expand All @@ -493,7 +493,7 @@ func TestMerge(t *testing.T) {
Files: []types.File{
{
FileEmbedded1: types.FileEmbedded1{
Contents: types.FileContents{
Contents: types.Resource{
Source: &fileURL,
HTTPHeaders: []types.HTTPHeader{
{
Expand All @@ -519,7 +519,7 @@ func TestMerge(t *testing.T) {
Files: []types.File{
{
FileEmbedded1: types.FileEmbedded1{
Contents: types.FileContents{
Contents: types.Resource{
Source: &fileURL,
HTTPHeaders: []types.HTTPHeader{
{
Expand Down Expand Up @@ -550,7 +550,7 @@ func TestMerge(t *testing.T) {
Files: []types.File{
{
FileEmbedded1: types.FileEmbedded1{
Append: []types.FileContents{
Append: []types.Resource{
{
Source: &fileURL,
HTTPHeaders: []types.HTTPHeader{
Expand All @@ -575,7 +575,7 @@ func TestMerge(t *testing.T) {
Files: []types.File{
{
FileEmbedded1: types.FileEmbedded1{
Append: []types.FileContents{
Append: []types.Resource{
{
Source: &fileURL,
HTTPHeaders: []types.HTTPHeader{
Expand All @@ -600,7 +600,7 @@ func TestMerge(t *testing.T) {
Files: []types.File{
{
FileEmbedded1: types.FileEmbedded1{
Append: []types.FileContents{
Append: []types.Resource{
{
Source: &fileURL,
HTTPHeaders: []types.HTTPHeader{
Expand Down
1 change: 1 addition & 0 deletions config/shared/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var (
ErrInvalidInstantiatedUnit = errors.New("invalid systemd instantiated unit")

// Misc errors
ErrSourceRequired = errors.New("source is required")
ErrInvalidScheme = errors.New("invalid url scheme")
ErrInvalidUrl = errors.New("unable to parse url")
ErrInvalidHTTPHeader = errors.New("unable to parse HTTP header")
Expand Down
78 changes: 22 additions & 56 deletions config/v3_1_experimental/schema/ignition.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
"ignition"
],
"definitions": {
"resource": {
"type": "object",
"properties": {
"source": {
"type": ["string", "null"]
},
"compression": {
"type": ["string", "null"]
},
"httpHeaders": {
"$ref": "#/definitions/httpHeaders"
},
"verification": {
"$ref": "#/definitions/verification"
}
}
},
"verification": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -69,11 +86,11 @@
"merge": {
"type": "array",
"items": {
"$ref": "#/definitions/ignition/definitions/config-reference"
"$ref": "#/definitions/resource"
}
},
"replace": {
"$ref": "#/definitions/ignition/definitions/config-reference"
"$ref": "#/definitions/resource"
}
}
},
Expand All @@ -86,7 +103,7 @@
"certificateAuthorities": {
"type": "array",
"items": {
"$ref": "#/definitions/ignition/definitions/ca-reference"
"$ref": "#/definitions/resource"
}
}
}
Expand All @@ -110,40 +127,6 @@
}
}
},
"config-reference": {
"type": "object",
"properties": {
"source": {
"type": ["string", "null"]
},
"httpHeaders": {
"$ref": "#/definitions/httpHeaders"
},
"verification": {
"$ref": "#/definitions/verification"
}
},
"required": [
"source"
]
},
"ca-reference": {
"type": ["object", "null"],
"properties": {
"source": {
"type": "string"
},
"httpHeaders": {
"$ref": "#/definitions/httpHeaders"
},
"verification": {
"$ref": "#/definitions/verification"
}
},
"required": [
"source"
]
},
"timeouts": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -299,12 +282,12 @@
"type": ["integer", "null"]
},
"contents": {
"$ref": "#/definitions/storage/definitions/file-contents"
"$ref": "#/definitions/resource"
},
"append": {
"type": "array",
"items": {
"$ref": "#/definitions/storage/definitions/file-contents"
"$ref": "#/definitions/resource"
}
}
}
Expand Down Expand Up @@ -376,23 +359,6 @@
}
}
},
"file-contents": {
"type": "object",
"properties": {
"compression": {
"type": ["string", "null"]
},
"source": {
"type": ["string", "null"]
},
"httpHeaders": {
"$ref": "#/definitions/httpHeaders"
},
"verification": {
"$ref": "#/definitions/verification"
}
}
},
"node": {
"type": "object",
"properties": {
Expand Down
6 changes: 3 additions & 3 deletions config/v3_1_experimental/translate/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ func translateFilesystem(old old_types.Filesystem) (ret types.Filesystem) {
return
}

func translateConfigReference(old old_types.ConfigReference) (ret types.ConfigReference) {
func translateConfigReference(old old_types.ConfigReference) (ret types.Resource) {
// use a new translator so we don't recurse infinitely
tr := translate.NewTranslator()
tr.Translate(&old.Source, &ret.Source)
tr.Translate(&old.Verification, &ret.Verification)
return
}

func translateCAReference(old old_types.CaReference) (ret types.CaReference) {
func translateCAReference(old old_types.CaReference) (ret types.Resource) {
// use a new translator so we don't recurse infinitely
tr := translate.NewTranslator()
tr.Translate(&old.Source, &ret.Source)
tr.Translate(&old.Verification, &ret.Verification)
return
}

func translateFileContents(old old_types.FileContents) (ret types.FileContents) {
func translateFileContents(old old_types.FileContents) (ret types.Resource) {
// use a new translator so we don't recurse infinitely
tr := translate.NewTranslator()
tr.Translate(&old.Compression, &ret.Compression)
Expand Down
56 changes: 0 additions & 56 deletions config/v3_1_experimental/types/ca.go

This file was deleted.

Loading

0 comments on commit 6e69536

Please sign in to comment.