-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle errors #1311
Handle errors #1311
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,10 @@ func (store Store) appendYamlNodeToTreeBranch(node *yaml.Node, branch sops.TreeB | |
return nil, fmt.Errorf("YAML documents that are values are not supported") | ||
case yaml.AliasNode: | ||
branch, err = store.appendYamlNodeToTreeBranch(node.Alias, branch, false) | ||
if err != nil { | ||
// This should never happen since node.Alias was already successfully decoded before | ||
return nil, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure this should never happen, but it definitely won't hurt to still pass on the error if it actually does. |
||
} | ||
} | ||
if !commentsWereHandled { | ||
branch = store.appendCommentToMap(node.FootComment, branch) | ||
|
@@ -204,9 +208,9 @@ func (store *Store) appendSequence(in []interface{}, sequence *yaml.Node) { | |
} | ||
if len(comments) > 0 { | ||
if beginning { | ||
comments = store.addCommentsHead(sequence, comments) | ||
store.addCommentsHead(sequence, comments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value is always |
||
} else { | ||
comments = store.addCommentsFoot(sequence.Content[len(sequence.Content)-1], comments) | ||
store.addCommentsFoot(sequence.Content[len(sequence.Content)-1], comments) | ||
} | ||
} | ||
} | ||
|
@@ -231,9 +235,9 @@ func (store *Store) appendTreeBranch(branch sops.TreeBranch, mapping *yaml.Node) | |
} | ||
if len(comments) > 0 { | ||
if beginning { | ||
comments = store.addCommentsHead(mapping, comments) | ||
store.addCommentsHead(mapping, comments) | ||
} else { | ||
comments = store.addCommentsFoot(mapping.Content[len(mapping.Content)-2], comments) | ||
store.addCommentsFoot(mapping.Content[len(mapping.Content)-2], comments) | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,59 @@ var BRANCHES = sops.TreeBranches{ | |
}, | ||
} | ||
|
||
var ALIASES = []byte(`--- | ||
key1: &foo | ||
- foo | ||
key2: *foo | ||
key3: &bar | ||
foo: bar | ||
baz: bam | ||
key4: *bar | ||
`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a test with anchors and aliases surely doesn't hurt. |
||
|
||
var ALIASES_BRANCHES = sops.TreeBranches{ | ||
sops.TreeBranch{ | ||
sops.TreeItem{ | ||
Key: "key1", | ||
Value: []interface{}{ | ||
"foo", | ||
}, | ||
}, | ||
sops.TreeItem{ | ||
Key: "key2", | ||
Value: []interface{}{ | ||
"foo", | ||
}, | ||
}, | ||
sops.TreeItem{ | ||
Key: "key3", | ||
Value: sops.TreeBranch{ | ||
sops.TreeItem{ | ||
Key: "foo", | ||
Value: "bar", | ||
}, | ||
sops.TreeItem{ | ||
Key: "baz", | ||
Value: "bam", | ||
}, | ||
}, | ||
}, | ||
sops.TreeItem{ | ||
Key: "key4", | ||
Value: sops.TreeBranch{ | ||
sops.TreeItem{ | ||
Key: "foo", | ||
Value: "bar", | ||
}, | ||
sops.TreeItem{ | ||
Key: "baz", | ||
Value: "bam", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var COMMENT_1 = []byte(`# test | ||
a: | ||
b: null | ||
|
@@ -170,6 +223,12 @@ func TestLoadPlainFile(t *testing.T) { | |
assert.Equal(t, BRANCHES, branches) | ||
} | ||
|
||
func TestLoadAliasesPlainFile(t *testing.T) { | ||
branches, err := (&Store{}).LoadPlainFile(ALIASES) | ||
assert.Nil(t, err) | ||
assert.Equal(t, ALIASES_BRANCHES, branches) | ||
} | ||
|
||
func TestComment1(t *testing.T) { | ||
// First iteration: load and store | ||
branches, err := (&Store{}).LoadPlainFile(COMMENT_1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
err != nil
, then decryption failed for some reason we should tell the user, instead of just saying that there was a MAC mismatch, with the file having a MAC ofnil
.