chef-zero 14.0.11 → 15.0.1

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -6
  3. data/Rakefile +9 -1
  4. data/bin/chef-zero +3 -2
  5. data/chef-zero.gemspec +5 -8
  6. data/lib/chef_zero.rb +1 -1
  7. data/lib/chef_zero/chef_data/cookbook_data.rb +1 -1
  8. data/lib/chef_zero/chef_data/data_normalizer.rb +9 -7
  9. data/lib/chef_zero/chef_data/default_creator.rb +22 -19
  10. data/lib/chef_zero/data_store/data_already_exists_error.rb +1 -1
  11. data/lib/chef_zero/data_store/data_error.rb +1 -1
  12. data/lib/chef_zero/data_store/data_not_found_error.rb +1 -1
  13. data/lib/chef_zero/data_store/default_facade.rb +4 -4
  14. data/lib/chef_zero/data_store/interface_v2.rb +1 -1
  15. data/lib/chef_zero/data_store/memory_store.rb +3 -3
  16. data/lib/chef_zero/data_store/memory_store_v2.rb +22 -14
  17. data/lib/chef_zero/data_store/raw_file_store.rb +7 -5
  18. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +11 -1
  19. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +1 -1
  20. data/lib/chef_zero/dist.rb +9 -0
  21. data/lib/chef_zero/endpoints/acl_endpoint.rb +4 -3
  22. data/lib/chef_zero/endpoints/acls_endpoint.rb +6 -5
  23. data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +2 -1
  24. data/lib/chef_zero/endpoints/actor_endpoint.rb +4 -4
  25. data/lib/chef_zero/endpoints/actor_key_endpoint.rb +1 -1
  26. data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +3 -2
  27. data/lib/chef_zero/endpoints/actors_endpoint.rb +2 -2
  28. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +3 -2
  29. data/lib/chef_zero/endpoints/container_endpoint.rb +3 -3
  30. data/lib/chef_zero/endpoints/containers_endpoint.rb +3 -3
  31. data/lib/chef_zero/endpoints/controls_endpoint.rb +3 -2
  32. data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +1 -1
  33. data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +3 -3
  34. data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +7 -7
  35. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +1 -1
  36. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +8 -6
  37. data/lib/chef_zero/endpoints/cookbooks_base.rb +6 -4
  38. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +1 -1
  39. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +4 -4
  40. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +4 -4
  41. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +3 -3
  42. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +2 -2
  43. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +14 -11
  44. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +2 -2
  45. data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
  46. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +2 -2
  47. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +2 -2
  48. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +2 -2
  49. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +1 -1
  50. data/lib/chef_zero/endpoints/group_endpoint.rb +3 -3
  51. data/lib/chef_zero/endpoints/groups_endpoint.rb +2 -2
  52. data/lib/chef_zero/endpoints/license_endpoint.rb +2 -2
  53. data/lib/chef_zero/endpoints/node_endpoint.rb +3 -3
  54. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +2 -2
  55. data/lib/chef_zero/endpoints/nodes_endpoint.rb +3 -3
  56. data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
  57. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +3 -2
  58. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +2 -2
  59. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +2 -2
  60. data/lib/chef_zero/endpoints/organization_endpoint.rb +4 -3
  61. data/lib/chef_zero/endpoints/organization_user_base.rb +2 -2
  62. data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +1 -1
  63. data/lib/chef_zero/endpoints/organization_user_endpoint.rb +2 -2
  64. data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +2 -2
  65. data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +1 -1
  66. data/lib/chef_zero/endpoints/organization_users_endpoint.rb +3 -3
  67. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +2 -2
  68. data/lib/chef_zero/endpoints/organizations_endpoint.rb +2 -2
  69. data/lib/chef_zero/endpoints/policies_endpoint.rb +1 -1
  70. data/lib/chef_zero/endpoints/policy_endpoint.rb +1 -1
  71. data/lib/chef_zero/endpoints/policy_group_endpoint.rb +3 -3
  72. data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +4 -4
  73. data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +3 -3
  74. data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +1 -1
  75. data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +1 -1
  76. data/lib/chef_zero/endpoints/principal_endpoint.rb +3 -3
  77. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +3 -3
  78. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +4 -3
  79. data/lib/chef_zero/endpoints/role_endpoint.rb +3 -3
  80. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +2 -2
  81. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +4 -4
  82. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +2 -2
  83. data/lib/chef_zero/endpoints/search_endpoint.rb +9 -9
  84. data/lib/chef_zero/endpoints/searches_endpoint.rb +1 -1
  85. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +1 -1
  86. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +4 -4
  87. data/lib/chef_zero/endpoints/universe_endpoint.rb +3 -3
  88. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +3 -2
  89. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +2 -2
  90. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +2 -2
  91. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +2 -2
  92. data/lib/chef_zero/endpoints/version_endpoint.rb +3 -2
  93. data/lib/chef_zero/rest_base.rb +20 -16
  94. data/lib/chef_zero/rest_request.rb +10 -6
  95. data/lib/chef_zero/rest_router.rb +3 -3
  96. data/lib/chef_zero/rspec.rb +6 -5
  97. data/lib/chef_zero/server.rb +98 -93
  98. data/lib/chef_zero/socketless_server_map.rb +4 -2
  99. data/lib/chef_zero/solr/query/phrase.rb +2 -2
  100. data/lib/chef_zero/solr/query/range_query.rb +3 -3
  101. data/lib/chef_zero/solr/query/term.rb +1 -1
  102. data/lib/chef_zero/solr/solr_parser.rb +12 -10
  103. data/lib/chef_zero/version.rb +1 -1
  104. data/spec/run_oc_pedant.rb +5 -3
  105. data/spec/search_spec.rb +2 -2
  106. data/spec/socketless_server_map_spec.rb +1 -1
  107. data/spec/support/oc_pedant.rb +1 -1
  108. metadata +17 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81a886b9fb926d3f1f355c4de530c96f2d65d7a3565c39415ad4a5d257689493
4
- data.tar.gz: 7575b3e658f703ef7f9e3ea4d04a3a263ae4fe1318ac40af36ba6d235d8b1faf
3
+ metadata.gz: b6cb6a13dc0d9c49fb124d0e766ed7e6d74e2901111549f4fa7225d58a5adfc5
4
+ data.tar.gz: 1843abd469e2e1ee5264a1b55e45a214fcc5641f6fe5f8498cd88fee3ad9f6e9
5
5
  SHA512:
6
- metadata.gz: 7dd8837c30d93b11a012bd1dfcd335938ee42e91a0e0e0b46a20d89cd4acfd0101220185c209f77f99cc9e5d6f68c6f1ca79db9d76d760e83c925986438d7669
7
- data.tar.gz: d4bd90dd779dbdcec494219f9a08c8f1402c349b9b1985f39c836724c0ee235a7e1a49feeaf8c640381a8fb4297259a91314f9659cb1757ef834dbce85c74143
6
+ metadata.gz: 9ec9537e222596c0ed1117f2fce21e4d59e558b9d51f7e316e760c65726661f2e94760b67091bb66a34570353ae65b997daedcddb95dce2b7a40f390cf3660c2
7
+ data.tar.gz: 1b24b9210093cf5da5118563a2664afe276a8bb769864e1ae4143e2a3fa7090e3b03bb94ae523edd675dba570e0a70acfda49394291fb02e5372f15d64ae0965
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
@@ -7,6 +7,7 @@ require "rubygems"
7
7
  $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
8
8
 
9
9
  require "chef_zero/log"
10
+ require "chef_zero/dist"
10
11
  require "chef_zero/version"
11
12
  require "chef_zero/server"
12
13
  require "chef_zero/data_store/raw_file_store"
@@ -28,7 +29,7 @@ end
28
29
  options = {}
29
30
 
30
31
  OptionParser.new do |opts|
31
- opts.banner = "Usage: chef-zero [ARGS]"
32
+ opts.banner = "Usage: #{ChefZero::Dist::CLIENT} [ARGS]"
32
33
 
33
34
  opts.on("-H", "--host HOST", "Host to bind to (default: 127.0.0.1)") do |value|
34
35
  options[:host] ||= []
@@ -100,7 +101,7 @@ if options[:daemon]
100
101
  server.start(true)
101
102
  else
102
103
  if ENV["OS"] == "Windows_NT"
103
- abort "Daemonization is not supported on Windows. Running 'start chef-zero' will fork the process."
104
+ abort "Daemonization is not supported on Windows. Running 'start #{ChefZero::Dist::CLIENT}' will fork the process."
104
105
  else
105
106
  abort "Process.daemon requires Ruby >= 1.9"
106
107
  end
@@ -6,22 +6,19 @@ Gem::Specification.new do |s|
6
6
  s.version = ChefZero::VERSION
7
7
  s.summary = "Self-contained, easy-setup, fast-start in-memory Chef server for testing and solo setup purposes"
8
8
  s.description = s.summary
9
- s.author = "John Keiser"
10
- s.email = "jkeiser@chef.io"
9
+ s.author = "Chef Software, Inc."
10
+ s.email = "oss@chef.io"
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.6"
15
15
 
16
- s.add_dependency "mixlib-log", "~> 2.0"
17
- s.add_dependency "hashie", ">= 2.0", "< 4.0"
16
+ s.add_dependency "mixlib-log", ">= 2.0", "< 4.0"
17
+ s.add_dependency "hashie", ">= 2.0", "< 5.0"
18
18
  s.add_dependency "uuidtools", "~> 2.1"
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,16 +274,17 @@ 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"
279
282
  {
280
283
  "create" => { "groups" => %w{admins} },
281
- "read" => { "groups" => %w{admins users} },
284
+ "read" => { "groups" => %w{admins users} },
282
285
  "update" => { "groups" => %w{admins} },
283
286
  "delete" => { "groups" => %w{admins} },
284
- "grant" => { "groups" => %w{admins} },
287
+ "grant" => { "groups" => %w{admins} },
285
288
  }
286
289
  when "containers/environments", "containers/roles",
287
290
  "containers/policy_groups", "containers/policies",
@@ -289,50 +292,50 @@ module ChefZero
289
292
  "containers/data"
290
293
  {
291
294
  "create" => { "groups" => %w{admins users} },
292
- "read" => { "groups" => %w{admins users clients} },
295
+ "read" => { "groups" => %w{admins users clients} },
293
296
  "update" => { "groups" => %w{admins users} },
294
297
  "delete" => { "groups" => %w{admins users} },
295
- "grant" => { "groups" => %w{admins} },
298
+ "grant" => { "groups" => %w{admins} },
296
299
  }
297
300
  when "containers/nodes"
298
301
  {
299
302
  "create" => { "groups" => %w{admins users clients} },
300
- "read" => { "groups" => %w{admins users clients} },
303
+ "read" => { "groups" => %w{admins users clients} },
301
304
  "update" => { "groups" => %w{admins users} },
302
305
  "delete" => { "groups" => %w{admins users} },
303
- "grant" => { "groups" => %w{admins} },
306
+ "grant" => { "groups" => %w{admins} },
304
307
  }
305
308
  when "containers/clients"
306
309
  {
307
310
  "create" => { "groups" => %w{admins} },
308
- "read" => { "groups" => %w{admins users} },
311
+ "read" => { "groups" => %w{admins users} },
309
312
  "update" => { "groups" => %w{admins} },
310
313
  "delete" => { "groups" => %w{admins users} },
311
- "grant" => { "groups" => %w{admins} },
314
+ "grant" => { "groups" => %w{admins} },
312
315
  }
313
316
  when "containers/sandboxes"
314
317
  {
315
318
  "create" => { "groups" => %w{admins users} },
316
- "read" => { "groups" => %w{admins} },
319
+ "read" => { "groups" => %w{admins} },
317
320
  "update" => { "groups" => %w{admins} },
318
321
  "delete" => { "groups" => %w{admins} },
319
- "grant" => { "groups" => %w{admins} },
322
+ "grant" => { "groups" => %w{admins} },
320
323
  }
321
324
  when "groups/admins", "groups/clients", "groups/users"
322
325
  {
323
326
  "create" => { "groups" => %w{admins} },
324
- "read" => { "groups" => %w{admins} },
327
+ "read" => { "groups" => %w{admins} },
325
328
  "update" => { "groups" => %w{admins} },
326
329
  "delete" => { "groups" => %w{admins} },
327
- "grant" => { "groups" => %w{admins} },
330
+ "grant" => { "groups" => %w{admins} },
328
331
  }
329
332
  when "groups/billing-admins"
330
333
  {
331
334
  "create" => { "groups" => %w{} },
332
- "read" => { "groups" => %w{billing-admins} },
335
+ "read" => { "groups" => %w{billing-admins} },
333
336
  "update" => { "groups" => %w{billing-admins} },
334
337
  "delete" => { "groups" => %w{} },
335
- "grant" => { "groups" => %w{} },
338
+ "grant" => { "groups" => %w{} },
336
339
  }
337
340
  else
338
341
  {}
@@ -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