Skip to content
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

Allow for yaml aliases to be loaded using YAML.safe_load #510

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## next

*Bug Fixes*
- Re-enable support for YAML aliases when using YAML.safe_load [#510](https://github.com/Shopify/kubernetes-deploy/pull/510)

## 0.26.5

*Bug Fixes*
Expand Down
2 changes: 1 addition & 1 deletion lib/kubernetes-deploy/bindings_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def parse_file(string)
when '.json'
bindings = parse_json(File.read(file_path))
when '.yaml', '.yml'
bindings = YAML.safe_load(File.read(file_path))
bindings = YAML.safe_load(File.read(file_path), [], [], true, file_path)
else
raise ArgumentError, "Supplied file does not appear to be JSON or YAML"
end
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/for_unit_tests/bindings-with-aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
alias: &alias
baz: bang
foo: a,b,c
bar:
<<: *alias
7 changes: 7 additions & 0 deletions test/unit/kubernetes-deploy/bindings_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def test_parse_nested_values
assert_equal(expected, bindings.parse)
end

def test_parses_yaml_file_with_aliases
expected = { "foo" => "a,b,c", "bar" => { "baz" => "bang" }, "alias" => { "baz" => "bang" } }
bindings = KubernetesDeploy::BindingsParser.new
bindings.add('@test/fixtures/for_unit_tests/bindings-with-aliases.yaml')
assert_equal(expected, bindings.parse)
end

private

def parse(string)
Expand Down