diff options
author | Thom May <thom@chef.io> | 2016-02-09 11:20:56 -0800 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-02-15 12:32:06 +0000 |
commit | 8eae0cc429b1ad2f569e611202051a1bddbe142a (patch) | |
tree | 9f3ec8fc4331a69825e8acb8d298a3cd74fdea65 /lib/chef/knife/core | |
parent | a030711a57e126f58b2e897c915d430e67cb7d13 (diff) | |
download | chef-8eae0cc429b1ad2f569e611202051a1bddbe142a.tar.gz |
Be way more explicit about how we're handling datatm/missed_migration
This just codifies the behaviour we're actually using - that we're
passing a json string and expecting a hash back.
Also adds a deprecation warning to the use of Chef::JSONCompat.from_json
Diffstat (limited to 'lib/chef/knife/core')
-rw-r--r-- | lib/chef/knife/core/node_editor.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/core/ui.rb | 17 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/chef/knife/core/node_editor.rb b/lib/chef/knife/core/node_editor.rb index 9b5f0a435f..0f7e51cdf3 100644 --- a/lib/chef/knife/core/node_editor.rb +++ b/lib/chef/knife/core/node_editor.rb @@ -41,7 +41,7 @@ class Chef abort "You specified the --disable_editing option, nothing to edit" if config[:disable_editing] assert_editor_set! - updated_node_data = ui.edit_data(view) + updated_node_data = ui.edit_hash(view) apply_updates(updated_node_data) @updated_node end diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index d6c21ee411..938942c173 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -165,13 +165,13 @@ class Chef # Hash -> Hash # Works the same as edit_data but - # returns a hash rather than a JSON string/Fully infated object + # returns a hash rather than a JSON string/Fully inflated object def edit_hash(hash) raw = edit_data(hash, false) Chef::JSONCompat.parse(raw) end - def edit_data(data, parse_output = true) + def edit_data(data, parse_output = true, object_class: nil) output = Chef::JSONCompat.to_json_pretty(data) if !config[:disable_editing] Tempfile.open([ "knife-edit-", ".json" ]) do |tf| @@ -184,13 +184,22 @@ class Chef end end - parse_output ? Chef::JSONCompat.from_json(output) : output + if parse_output + if object_class.nil? + Chef.log_deprecation("Auto inflation of JSON data is deprecated. Please pass in the class to inflate or use #edit_hash") + Chef::JSONCompat.from_json(output) + else + object_class.from_hash(Chef::JSONCompat.parse(output)) + end + else + output + end end def edit_object(klass, name) object = klass.load(name) - output = edit_data(object) + output = edit_data(object, object_class: klass) # Only make the save if the user changed the object. # |