knife-essentials 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -124,8 +124,6 @@ module ChefFS
124
124
 
125
125
  def self.canonicalize_json(json_text)
126
126
  parsed_json = JSON.parse(json_text, :create_additions => false)
127
- parsed_json.delete('requesting_actor_type')
128
- parsed_json.delete('requesting_user')
129
127
  sorted_json = sort_keys(parsed_json)
130
128
  JSON.pretty_generate(sorted_json)
131
129
  end
@@ -1,5 +1,5 @@
1
- require 'chef_fs/file_system/base_fs_dir'
2
- require 'chef_fs/file_system/rest_list_entry'
1
+ require 'chef_fs/file_system/rest_list_dir'
2
+ require 'chef_fs/file_system/data_bag_item'
3
3
  require 'chef_fs/file_system/not_found_error'
4
4
 
5
5
  module ChefFS
@@ -25,6 +25,11 @@ module ChefFS
25
25
  end
26
26
  @exists
27
27
  end
28
+
29
+ def _make_child_entry(name, exists = nil)
30
+ DataBagItem.new(name, self, exists)
31
+ end
32
+
28
33
  end
29
34
  end
30
35
  end
@@ -0,0 +1,39 @@
1
+ require 'chef_fs/file_system/rest_list_entry'
2
+
3
+ module ChefFS
4
+ module FileSystem
5
+ class DataBagItem < RestListEntry
6
+ def initialize(name, parent, exists = nil)
7
+ super(name, parent, exists)
8
+ end
9
+
10
+ def write(file_contents)
11
+ # Write is just a little tiny bit different for data bags:
12
+ # you set raw_data in the JSON instead of putting the items
13
+ # in the top level.
14
+ json = Chef::JSONCompat.from_json(file_contents).to_hash
15
+ id = name[0,name.length-5] # Strip off the .json from the end
16
+ if json['id'] != id
17
+ raise "Id in #{path_for_printing}/#{name} must be '#{id}' (is '#{json['id']}')"
18
+ end
19
+ begin
20
+ data_bag = parent.name
21
+ json = {
22
+ "name" => "data_bag_item_#{data_bag}_#{id}",
23
+ "json_class" => "Chef::DataBagItem",
24
+ "chef_type" => "data_bag_item",
25
+ "data_bag" => data_bag,
26
+ "raw_data" => json
27
+ }
28
+ rest.put_rest(api_path, json)
29
+ rescue Net::HTTPServerException
30
+ if $!.response.code == "404"
31
+ raise ChefFS::FileSystem::NotFoundError.new($!), "#{path_for_printing} not found"
32
+ else
33
+ raise
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -14,7 +14,17 @@ module ChefFS
14
14
  end
15
15
 
16
16
  def children
17
- @children ||= rest.get_rest(api_path).keys.map { |entry| DataBagDir.new(entry, self, true) }
17
+ begin
18
+ @children ||= rest.get_rest(api_path).keys.map do |entry|
19
+ DataBagDir.new(entry, self, true)
20
+ end
21
+ rescue Net::HTTPServerException
22
+ if $!.response.code == "404"
23
+ raise ChefFS::FileSystem::NotFoundError.new($!), "#{path_for_printing} not found"
24
+ else
25
+ raise
26
+ end
27
+ end
18
28
  end
19
29
 
20
30
  def can_have_child?(name, is_dir)
@@ -14,7 +14,8 @@ module ChefFS
14
14
 
15
15
  def child(name)
16
16
  result = @children.select { |child| child.name == name }.first if @children
17
- result ||= can_have_child?(name, false) ? RestListEntry.new(name, self) : NonexistentFSObject.new(name, self)
17
+ result ||= can_have_child?(name, false) ?
18
+ _make_child_entry(name) : NonexistentFSObject.new(name, self)
18
19
  end
19
20
 
20
21
  def can_have_child?(name, is_dir)
@@ -23,7 +24,9 @@ module ChefFS
23
24
 
24
25
  def children
25
26
  begin
26
- @children ||= rest.get_rest(api_path).keys.map { |key| RestListEntry.new("#{key}.json", self, true) }
27
+ @children ||= rest.get_rest(api_path).keys.map do |key|
28
+ _make_child_entry("#{key}.json", true)
29
+ end
27
30
  rescue Net::HTTPServerException
28
31
  if $!.response.code == "404"
29
32
  raise ChefFS::FileSystem::NotFoundError.new($!), "#{path_for_printing} not found"
@@ -42,7 +45,7 @@ module ChefFS
42
45
  raise "Name in #{path_for_printing}/#{name} must be '#{base_name}' (is '#{json['id']}')"
43
46
  end
44
47
  rest.post_rest(api_path, json)
45
- RestListEntry.new(name, self, true)
48
+ _make_child_entry(name, true)
46
49
  end
47
50
 
48
51
  def environment
@@ -52,6 +55,11 @@ module ChefFS
52
55
  def rest
53
56
  parent.rest
54
57
  end
58
+
59
+ def _make_child_entry(name, exists = nil)
60
+ RestListEntry.new(name, self, exists)
61
+ end
62
+
55
63
  end
56
64
  end
57
65
  end
@@ -65,10 +65,8 @@ module ChefFS
65
65
  def write(file_contents)
66
66
  json = Chef::JSONCompat.from_json(file_contents).to_hash
67
67
  base_name = name[0,name.length-5]
68
- if json.include?('name') && json['name'] != base_name
68
+ if json['name'] != base_name
69
69
  raise "Name in #{path_for_printing}/#{name} must be '#{base_name}' (is '#{json['name']}')"
70
- elsif json.include?('id') && json['id'] != base_name
71
- raise "Name in #{path_for_printing}/#{name} must be '#{base_name}' (is '#{json['id']}')"
72
70
  end
73
71
  begin
74
72
  rest.put_rest(api_path, json)
@@ -1,4 +1,4 @@
1
1
  module ChefFS
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-essentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-17 00:00:00.000000000Z
12
+ date: 2012-05-18 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Universal knife verbs that work with your Chef repository
15
15
  email: jkeiser@opscode.com
@@ -41,6 +41,7 @@ files:
41
41
  - lib/chef_fs/file_system/cookbook_subdir.rb
42
42
  - lib/chef_fs/file_system/cookbooks_dir.rb
43
43
  - lib/chef_fs/file_system/data_bag_dir.rb
44
+ - lib/chef_fs/file_system/data_bag_item.rb
44
45
  - lib/chef_fs/file_system/data_bags_dir.rb
45
46
  - lib/chef_fs/file_system/file_system_entry.rb
46
47
  - lib/chef_fs/file_system/file_system_root_dir.rb