chef-zero 14.0.13 → 14.0.17

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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -6
  3. data/Rakefile +9 -1
  4. data/chef-zero.gemspec +1 -4
  5. data/lib/chef_zero.rb +1 -1
  6. data/lib/chef_zero/chef_data/cookbook_data.rb +1 -1
  7. data/lib/chef_zero/chef_data/data_normalizer.rb +9 -7
  8. data/lib/chef_zero/chef_data/default_creator.rb +8 -5
  9. data/lib/chef_zero/data_store/data_already_exists_error.rb +1 -1
  10. data/lib/chef_zero/data_store/data_error.rb +1 -1
  11. data/lib/chef_zero/data_store/data_not_found_error.rb +1 -1
  12. data/lib/chef_zero/data_store/default_facade.rb +4 -4
  13. data/lib/chef_zero/data_store/interface_v2.rb +1 -1
  14. data/lib/chef_zero/data_store/memory_store.rb +3 -3
  15. data/lib/chef_zero/data_store/memory_store_v2.rb +22 -14
  16. data/lib/chef_zero/data_store/raw_file_store.rb +6 -4
  17. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +11 -1
  18. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +1 -1
  19. data/lib/chef_zero/endpoints/acl_endpoint.rb +3 -2
  20. data/lib/chef_zero/endpoints/acls_endpoint.rb +5 -4
  21. data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +2 -1
  22. data/lib/chef_zero/endpoints/actor_endpoint.rb +3 -3
  23. data/lib/chef_zero/endpoints/actor_key_endpoint.rb +1 -1
  24. data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +3 -2
  25. data/lib/chef_zero/endpoints/actors_endpoint.rb +1 -1
  26. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +2 -1
  27. data/lib/chef_zero/endpoints/container_endpoint.rb +2 -2
  28. data/lib/chef_zero/endpoints/containers_endpoint.rb +2 -2
  29. data/lib/chef_zero/endpoints/controls_endpoint.rb +1 -1
  30. data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +1 -1
  31. data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +3 -3
  32. data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +1 -1
  33. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +1 -1
  34. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +7 -5
  35. data/lib/chef_zero/endpoints/cookbooks_base.rb +4 -2
  36. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +1 -1
  37. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +3 -3
  38. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +3 -3
  39. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +2 -2
  40. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +1 -1
  41. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +13 -10
  42. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +1 -1
  43. data/lib/chef_zero/endpoints/environment_endpoint.rb +2 -2
  44. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +1 -1
  45. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +1 -1
  46. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +1 -1
  47. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +1 -1
  48. data/lib/chef_zero/endpoints/group_endpoint.rb +2 -2
  49. data/lib/chef_zero/endpoints/groups_endpoint.rb +1 -1
  50. data/lib/chef_zero/endpoints/license_endpoint.rb +1 -1
  51. data/lib/chef_zero/endpoints/node_endpoint.rb +2 -2
  52. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +1 -1
  53. data/lib/chef_zero/endpoints/nodes_endpoint.rb +2 -2
  54. data/lib/chef_zero/endpoints/not_found_endpoint.rb +1 -1
  55. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +2 -1
  56. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +1 -1
  57. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +1 -1
  58. data/lib/chef_zero/endpoints/organization_endpoint.rb +3 -2
  59. data/lib/chef_zero/endpoints/organization_user_base.rb +1 -1
  60. data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +1 -1
  61. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +1 -1
  62. data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +2 -2
  63. data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +1 -1
  64. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +2 -2
  65. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +1 -1
  66. data/lib/chef_zero/endpoints/organizations_endpoint.rb +1 -1
  67. data/lib/chef_zero/endpoints/policies_endpoint.rb +1 -1
  68. data/lib/chef_zero/endpoints/policy_endpoint.rb +1 -1
  69. data/lib/chef_zero/endpoints/policy_group_endpoint.rb +2 -2
  70. data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +3 -3
  71. data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +2 -2
  72. data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +1 -1
  73. data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +1 -1
  74. data/lib/chef_zero/endpoints/principal_endpoint.rb +2 -2
  75. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +2 -2
  76. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +3 -2
  77. data/lib/chef_zero/endpoints/role_endpoint.rb +2 -2
  78. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +1 -1
  79. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +3 -3
  80. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +1 -1
  81. data/lib/chef_zero/endpoints/search_endpoint.rb +8 -8
  82. data/lib/chef_zero/endpoints/searches_endpoint.rb +1 -1
  83. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +1 -1
  84. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +3 -3
  85. data/lib/chef_zero/endpoints/universe_endpoint.rb +2 -2
  86. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +2 -1
  87. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +1 -1
  88. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +1 -1
  89. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +1 -1
  90. data/lib/chef_zero/endpoints/version_endpoint.rb +2 -2
  91. data/lib/chef_zero/rest_base.rb +15 -15
  92. data/lib/chef_zero/rest_request.rb +4 -4
  93. data/lib/chef_zero/rest_router.rb +2 -2
  94. data/lib/chef_zero/rspec.rb +3 -2
  95. data/lib/chef_zero/server.rb +87 -83
  96. data/lib/chef_zero/socketless_server_map.rb +2 -1
  97. data/lib/chef_zero/solr/query/phrase.rb +2 -2
  98. data/lib/chef_zero/solr/query/range_query.rb +3 -3
  99. data/lib/chef_zero/solr/query/term.rb +1 -1
  100. data/lib/chef_zero/solr/solr_parser.rb +12 -10
  101. data/lib/chef_zero/version.rb +1 -1
  102. data/spec/run_oc_pedant.rb +5 -3
  103. data/spec/search_spec.rb +2 -2
  104. data/spec/socketless_server_map_spec.rb +1 -1
  105. data/spec/support/oc_pedant.rb +1 -1
  106. metadata +3 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f0e22b3dea494e8b561ec5f724f8854c0441f3b0695528f925737f4f9c9e768
4
- data.tar.gz: d7e7e8b3d22f9d2ecea27799b04c40bc73c9765aabb353eac88442f7359da98b
3
+ metadata.gz: 51b6df8cfb1404572342f5012c1779ae1abf0f5dedfbe9bbe85f59f9d36830a3
4
+ data.tar.gz: 134c6eeab2b181816a7e7211392f5472d9dbf497fad9c5a3b424521f747fcda4
5
5
  SHA512:
6
- metadata.gz: f3ba2f87dfa20516459d5a17bde60a0dc7925f1fe245700707c328fe9c99f8dcbe110cb6daaeed70c92dcc85bda18f63eb1b8868e27e50a284443078abbe6d4b
7
- data.tar.gz: 405b1b2b070dd2b8c2d6537de6af2a029cd9cf05378b17e9ea10351b52b8230621acd3468ada349d2bafccccb4abbf448a62e62c9714f211f3af27df3f0dd785
6
+ metadata.gz: 28d830c27a14463aee454123475caee162ff31f62bc2c9bdda6ff7628e6b1fe24af883dbcf78c64071683a51eac4492367ff68f500eb2feaea45e7c5e8583a5e
7
+ data.tar.gz: 352b9c4184dc973953dde9322bdb71f9cd54dce7f2f56acb2acbcc47edda8dc29b94fb975d9f1f87b104b49004eb5dbe026287c420d1d58f8c139b3de6a184e9
data/Gemfile CHANGED
@@ -9,11 +9,13 @@ group :pedant do
9
9
  end
10
10
 
11
11
  group :development, :test do
12
- gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
12
+ gem "chefstyle"
13
+ gem "rake"
14
+ gem "rspec", "~> 3.0"
13
15
  end
14
16
 
15
17
  if ENV["GEMFILE_MOD"]
16
- puts "GEMFILE_MOD: #{ENV['GEMFILE_MOD']}"
18
+ puts "GEMFILE_MOD: #{ENV["GEMFILE_MOD"]}"
17
19
  instance_eval(ENV["GEMFILE_MOD"])
18
20
  else
19
21
  gem "chef", "~> 14.0"
@@ -25,7 +27,3 @@ group :debug do
25
27
  gem "pry-byebug"
26
28
  gem "pry-stack_explorer"
27
29
  end
28
-
29
- # If you want to load debugging tools into the bundle exec sandbox,
30
- # add these additional dependencies into Gemfile.local
31
- eval_gemfile(__FILE__ + ".local") if File.exist?(__FILE__ + ".local")
data/Rakefile CHANGED
@@ -52,9 +52,17 @@ end
52
52
  begin
53
53
  require "chefstyle"
54
54
  require "rubocop/rake_task"
55
+ desc "Run Chefstyle tests"
55
56
  RuboCop::RakeTask.new(:style) do |task|
56
57
  task.options += ["--display-cop-names", "--no-color"]
57
58
  end
58
59
  rescue LoadError
59
- puts "chefstyle/rubocop is not available. bundle install first to make sure all dependencies are installed."
60
+ puts "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed."
61
+ end
62
+
63
+ begin
64
+ require "yard"
65
+ YARD::Rake::YardocTask.new(:docs)
66
+ rescue LoadError
67
+ puts "yard is not available. bundle install first to make sure all dependencies are installed."
60
68
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "https://github.com/chef/chef-zero"
12
12
  s.license = "Apache-2.0"
13
13
 
14
- s.required_ruby_version = ">= 2.4.0"
14
+ s.required_ruby_version = ">= 2.4"
15
15
 
16
16
  s.add_dependency "mixlib-log", ">= 2.0", "< 4.0"
17
17
  s.add_dependency "hashie", ">= 2.0", "< 4.0"
@@ -19,9 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "ffi-yajl", "~> 2.2"
20
20
  s.add_dependency "rack", "~> 2.0", ">= 2.0.6"
21
21
 
22
- s.add_development_dependency "rake"
23
- s.add_development_dependency "rspec"
24
-
25
22
  s.bindir = "bin"
26
23
  s.executables = ["chef-zero"]
27
24
  s.require_path = "lib"
@@ -1,5 +1,5 @@
1
1
  module ChefZero
2
- require "chef_zero/log"
2
+ require_relative "chef_zero/log"
3
3
 
4
4
  MIN_API_VERSION = 0
5
5
  MAX_API_VERSION = 2
@@ -107,7 +107,7 @@ module ChefZero
107
107
  if directory.is_a?(Hash)
108
108
  directory.keys
109
109
  else
110
- directory.children.map { |c| c.name }
110
+ directory.children.map(&:name)
111
111
  end
112
112
  end
113
113
 
@@ -1,6 +1,6 @@
1
- require "chef_zero"
2
- require "chef_zero/rest_base"
3
- require "chef_zero/chef_data/default_creator"
1
+ require_relative "../../chef_zero"
2
+ require_relative "../rest_base"
3
+ require_relative "default_creator"
4
4
 
5
5
  module ChefZero
6
6
  module ChefData
@@ -53,7 +53,7 @@ module ChefZero
53
53
  user["admin"] ||= false
54
54
  user["admin"] = !!user["admin"]
55
55
  user["openid"] ||= nil
56
- if !osc_compat
56
+ unless osc_compat
57
57
  if method == "GET"
58
58
  user.delete("admin")
59
59
  user.delete("password")
@@ -69,7 +69,7 @@ module ChefZero
69
69
  def self.normalize_data_bag_item(data_bag_item, data_bag_name, id, method)
70
70
  if method == "DELETE"
71
71
  # TODO SERIOUSLY, WHO DOES THIS MANY EXCEPTIONS IN THEIR INTERFACE
72
- if !(data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"])
72
+ unless data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"]
73
73
  data_bag_item["id"] ||= id
74
74
  data_bag_item = { "raw_data" => data_bag_item }
75
75
  data_bag_item["chef_type"] ||= "data_bag_item"
@@ -93,14 +93,15 @@ module ChefZero
93
93
  end
94
94
 
95
95
  def self.normalize_cookbook(endpoint, org_prefix, cookbook, name, version, base_uri, method,
96
- is_cookbook_artifact = false, api_version: 2)
96
+ is_cookbook_artifact = false, api_version: 2)
97
97
  # TODO I feel dirty
98
98
  if method == "PUT" && api_version < 2
99
99
  cookbook["all_files"] = cookbook.delete(["root_files"]) { [] }
100
100
  COOKBOOK_SEGMENTS.each do |segment|
101
101
  next unless cookbook.key? segment
102
+
102
103
  cookbook[segment].each do |file|
103
- file["name"] = "#{segment}/#{file['name']}"
104
+ file["name"] = "#{segment}/#{file["name"]}"
104
105
  cookbook["all_files"] << file
105
106
  end
106
107
  cookbook.delete(segment)
@@ -131,6 +132,7 @@ module ChefZero
131
132
 
132
133
  file.delete("full_path")
133
134
  next unless COOKBOOK_SEGMENTS.include? segment
135
+
134
136
  file["name"] = name
135
137
  cookbook[segment] << file
136
138
  end
@@ -1,4 +1,4 @@
1
- require "chef_zero/chef_data/acl_path"
1
+ require_relative "acl_path"
2
2
 
3
3
  module ChefZero
4
4
  module ChefData
@@ -140,6 +140,7 @@ module ChefZero
140
140
 
141
141
  def exists?(path)
142
142
  return true if path.size == 0
143
+
143
144
  parent_list = list(path[0..-2])
144
145
  parent_list && parent_list.include?(path[-1])
145
146
  end
@@ -184,7 +185,8 @@ module ChefZero
184
185
  value = DEFAULT_ORG_SPINE
185
186
  2.upto(path.size - 1) do |index|
186
187
  value = nil if @deleted[path[0..index]]
187
- break if !value
188
+ break unless value
189
+
188
190
  value = value[path[index]]
189
191
  end
190
192
 
@@ -272,7 +274,8 @@ module ChefZero
272
274
  object_path = AclPath.get_object_path(path)
273
275
  # The actual things containers correspond to don't have to exist, as
274
276
  # long as the container does
275
- return nil if !data_exists?(object_path)
277
+ return nil unless data_exists?(object_path)
278
+
276
279
  basic_acl =
277
280
  case path[3..-1].join("/")
278
281
  when "root", "containers/containers", "containers/groups"
@@ -350,7 +353,7 @@ module ChefZero
350
353
  if path.size == 4 && path[0] == "organizations" && path[2] == "clients"
351
354
  begin
352
355
  client = FFI_Yajl::Parser.parse(data.get(path))
353
- if !client["validator"]
356
+ unless client["validator"]
354
357
  unknown_owners |= [ path[3] ]
355
358
  end
356
359
  rescue
@@ -453,7 +456,7 @@ module ChefZero
453
456
  def is_dir?(path)
454
457
  case path.size
455
458
  when 0, 1
456
- return true
459
+ true
457
460
  when 2
458
461
  path[0] == "organizations" || (path[0] == "acls" && path[1] != "root")
459
462
  when 3
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_error"
19
+ require_relative "data_error"
20
20
 
21
21
  module ChefZero
22
22
  module DataStore
@@ -24,7 +24,7 @@ module ChefZero
24
24
  def initialize(path, cause = nil)
25
25
  @path = path
26
26
  @cause = cause
27
- path_for_msg = path.nil? ? "nil" : "/#{path.join('/')}"
27
+ path_for_msg = path.nil? ? "nil" : "/#{path.join("/")}"
28
28
  super "Data path: #{path_for_msg}"
29
29
  end
30
30
  end
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_error"
19
+ require_relative "data_error"
20
20
 
21
21
  module ChefZero
22
22
  module DataStore
@@ -1,5 +1,5 @@
1
- require "chef_zero/data_store/interface_v2"
2
- require "chef_zero/chef_data/default_creator"
1
+ require_relative "interface_v2"
2
+ require_relative "../chef_data/default_creator"
3
3
 
4
4
  module ChefZero
5
5
  module DataStore
@@ -100,7 +100,7 @@ module ChefZero
100
100
  begin
101
101
  real_store.delete(path)
102
102
  rescue DataNotFoundError
103
- if !deleted
103
+ unless deleted
104
104
  raise
105
105
  end
106
106
  end
@@ -111,7 +111,7 @@ module ChefZero
111
111
  begin
112
112
  real_store.delete_dir(path, *options)
113
113
  rescue DataNotFoundError
114
- if !deleted
114
+ unless deleted
115
115
  raise
116
116
  end
117
117
  end
@@ -1,4 +1,4 @@
1
- require "chef_zero/data_store/interface_v1"
1
+ require_relative "interface_v1"
2
2
 
3
3
  module ChefZero
4
4
  module DataStore
@@ -16,9 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/v2_to_v1_adapter"
20
- require "chef_zero/data_store/memory_store_v2"
21
- require "chef_zero/data_store/default_facade"
19
+ require_relative "v2_to_v1_adapter"
20
+ require_relative "memory_store_v2"
21
+ require_relative "default_facade"
22
22
 
23
23
  module ChefZero
24
24
  module DataStore
@@ -16,9 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_already_exists_error"
20
- require "chef_zero/data_store/data_not_found_error"
21
- require "chef_zero/data_store/interface_v2"
19
+ require_relative "data_already_exists_error"
20
+ require_relative "data_not_found_error"
21
+ require_relative "interface_v2"
22
22
 
23
23
  module ChefZero
24
24
  module DataStore
@@ -37,7 +37,7 @@ module ChefZero
37
37
  parent = _get(path, options.include?(:recursive))
38
38
 
39
39
  if parent.key?(name)
40
- if !options.include?(:recursive)
40
+ unless options.include?(:recursive)
41
41
  raise DataAlreadyExistsError.new(path + [name])
42
42
  end
43
43
  else
@@ -46,7 +46,7 @@ module ChefZero
46
46
  end
47
47
 
48
48
  def create(path, name, data, *options)
49
- if !data.is_a?(String)
49
+ unless data.is_a?(String)
50
50
  raise "set only works with strings (given data: #{data.inspect})"
51
51
  end
52
52
 
@@ -55,19 +55,21 @@ module ChefZero
55
55
  if parent.key?(name)
56
56
  raise DataAlreadyExistsError.new(path + [name])
57
57
  end
58
+
58
59
  parent[name] = data
59
60
  end
60
61
 
61
62
  def get(path, request = nil)
62
63
  value = _get(path)
63
64
  if value.is_a?(Hash)
64
- raise "get() called on directory #{path.join('/')}"
65
+ raise "get() called on directory #{path.join("/")}"
65
66
  end
67
+
66
68
  value
67
69
  end
68
70
 
69
71
  def set(path, data, *options)
70
- if !data.is_a?(String)
72
+ unless data.is_a?(String)
71
73
  raise "set only works with strings: #{path} = #{data.inspect}"
72
74
  end
73
75
 
@@ -77,36 +79,40 @@ module ChefZero
77
79
  if !options.include?(:create) && !parent[path[-1]]
78
80
  raise DataNotFoundError.new(path)
79
81
  end
82
+
80
83
  parent[path[-1]] = data
81
84
  end
82
85
 
83
86
  def delete(path)
84
87
  parent = _get(path[0, path.length - 1])
85
- if !parent.key?(path[-1])
88
+ unless parent.key?(path[-1])
86
89
  raise DataNotFoundError.new(path)
87
90
  end
88
- if !parent[path[-1]].is_a?(String)
91
+ unless parent[path[-1]].is_a?(String)
89
92
  raise "delete only works with strings: #{path}"
90
93
  end
94
+
91
95
  parent.delete(path[-1])
92
96
  end
93
97
 
94
98
  def delete_dir(path, *options)
95
99
  parent = _get(path[0, path.length - 1])
96
- if !parent.key?(path[-1])
100
+ unless parent.key?(path[-1])
97
101
  raise DataNotFoundError.new(path)
98
102
  end
99
- if !parent[path[-1]].is_a?(Hash)
103
+ unless parent[path[-1]].is_a?(Hash)
100
104
  raise "delete_dir only works with directories: #{path}"
101
105
  end
106
+
102
107
  parent.delete(path[-1])
103
108
  end
104
109
 
105
110
  def list(path)
106
111
  dir = _get(path)
107
- if !dir.is_a? Hash
112
+ unless dir.is_a? Hash
108
113
  raise "list only works with directories (#{path} = #{dir.class})"
109
114
  end
115
+
110
116
  dir.keys.sort
111
117
  end
112
118
 
@@ -115,6 +121,7 @@ module ChefZero
115
121
  if value.is_a?(Hash) && !options[:allow_dirs]
116
122
  raise "exists? does not work with directories (#{path} = #{value.class})"
117
123
  end
124
+
118
125
  true
119
126
  rescue DataNotFoundError
120
127
  false
@@ -122,9 +129,10 @@ module ChefZero
122
129
 
123
130
  def exists_dir?(path)
124
131
  dir = _get(path)
125
- if !dir.is_a? Hash
132
+ unless dir.is_a? Hash
126
133
  raise "exists_dir? only works with directories (#{path} = #{dir.class})"
127
134
  end
135
+
128
136
  true
129
137
  rescue DataNotFoundError
130
138
  false
@@ -135,7 +143,7 @@ module ChefZero
135
143
  def _get(path, create_dir = false)
136
144
  value = @data
137
145
  path.each_with_index do |path_part, index|
138
- if !value.key?(path_part)
146
+ unless value.key?(path_part)
139
147
  if create_dir
140
148
  value[path_part] = {}
141
149
  else
@@ -16,9 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "chef_zero/data_store/data_already_exists_error"
20
- require "chef_zero/data_store/data_not_found_error"
21
- require "chef_zero/data_store/interface_v2"
19
+ require_relative "data_already_exists_error"
20
+ require_relative "data_not_found_error"
21
+ require_relative "interface_v2"
22
22
  require "fileutils"
23
23
 
24
24
  module ChefZero
@@ -44,6 +44,7 @@ module ChefZero
44
44
  if destructible
45
45
  Dir.entries(root).each do |entry|
46
46
  next if entry == "." || entry == ".."
47
+
47
48
  FileUtils.rm_rf(Path.join(root, entry))
48
49
  end
49
50
  end
@@ -110,9 +111,10 @@ module ChefZero
110
111
 
111
112
  def delete_dir(path, *options)
112
113
  if options.include?(:recursive)
113
- if !File.exist?(path_to(path))
114
+ unless File.exist?(path_to(path))
114
115
  raise DataNotFoundError.new(path)
115
116
  end
117
+
116
118
  FileUtils.rm_rf(path_to(path))
117
119
  else
118
120
  begin
@@ -1,4 +1,4 @@
1
- require "chef_zero/data_store/interface_v2"
1
+ require_relative "interface_v2"
2
2
 
3
3
  module ChefZero
4
4
  module DataStore
@@ -21,6 +21,7 @@ module ChefZero
21
21
  raise DataNotFoundError.new(path) if skip_organizations?(path)
22
22
  raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name)
23
23
  raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2
24
+
24
25
  fix_exceptions do
25
26
  real_store.create_dir(path[2..-1], name, *options)
26
27
  end
@@ -30,6 +31,7 @@ module ChefZero
30
31
  raise DataNotFoundError.new(path) if skip_organizations?(path)
31
32
  raise "Cannot create #{name} at #{path} with V1ToV2Adapter: only handles a single org named #{single_org}." if skip_organizations?(path, name)
32
33
  raise DataAlreadyExistsError.new(path + [ name ]) if path.size < 2
34
+
33
35
  fix_exceptions do
34
36
  real_store.create(path[2..-1], name, data, *options)
35
37
  end
@@ -37,6 +39,7 @@ module ChefZero
37
39
 
38
40
  def get(path, request = nil)
39
41
  raise DataNotFoundError.new(path) if skip_organizations?(path)
42
+
40
43
  fix_exceptions do
41
44
  # Make it so build_uri will include /organizations/ORG inside the V1 data store
42
45
  if request && request.rest_base_prefix.size == 0
@@ -53,6 +56,7 @@ module ChefZero
53
56
 
54
57
  def set(path, data, *options)
55
58
  raise DataNotFoundError.new(path) if skip_organizations?(path)
59
+
56
60
  fix_exceptions do
57
61
  real_store.set(path[2..-1], data, *options)
58
62
  end
@@ -60,6 +64,7 @@ module ChefZero
60
64
 
61
65
  def delete(path, *options)
62
66
  raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
67
+
63
68
  fix_exceptions do
64
69
  real_store.delete(path[2..-1])
65
70
  end
@@ -67,6 +72,7 @@ module ChefZero
67
72
 
68
73
  def delete_dir(path, *options)
69
74
  raise DataNotFoundError.new(path) if skip_organizations?(path) && !options.include?(:recursive)
75
+
70
76
  fix_exceptions do
71
77
  real_store.delete_dir(path[2..-1], *options)
72
78
  end
@@ -74,6 +80,7 @@ module ChefZero
74
80
 
75
81
  def list(path)
76
82
  raise DataNotFoundError.new(path) if skip_organizations?(path)
83
+
77
84
  if path == []
78
85
  [ "organizations" ]
79
86
  elsif path == [ "organizations" ]
@@ -87,6 +94,7 @@ module ChefZero
87
94
 
88
95
  def exists?(path)
89
96
  return false if skip_organizations?(path)
97
+
90
98
  fix_exceptions do
91
99
  real_store.exists?(path[2..-1])
92
100
  end
@@ -94,12 +102,14 @@ module ChefZero
94
102
 
95
103
  def exists_dir?(path)
96
104
  return false if skip_organizations?(path)
105
+
97
106
  if path == []
98
107
  true
99
108
  elsif path == [ "organizations" ] || path == [ "users" ]
100
109
  true
101
110
  else
102
111
  return false if skip_organizations?(path)
112
+
103
113
  fix_exceptions do
104
114
  real_store.exists_dir?(path[2..-1])
105
115
  end