Skip to content

Commit

Permalink
Merge pull request #953 from jlebon/pr/unify-source
Browse files Browse the repository at this point in the history
spec: unify resource fetching type
  • Loading branch information
bgilbert committed Apr 15, 2020
2 parents 110130e + 3660e8c commit 6708d9a
Show file tree
Hide file tree
Showing 21 changed files with 537 additions and 275 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
8 changes: 4 additions & 4 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)
ret.Source = &old.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 6708d9a

Please sign in to comment.