chef-zero 4.8.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -4
  3. data/Rakefile +20 -10
  4. data/bin/chef-zero +12 -12
  5. data/chef-zero.gemspec +24 -24
  6. data/lib/chef_zero.rb +1 -1
  7. data/lib/chef_zero/chef_data/acl_path.rb +16 -16
  8. data/lib/chef_zero/chef_data/cookbook_data.rb +24 -24
  9. data/lib/chef_zero/chef_data/data_normalizer.rb +120 -120
  10. data/lib/chef_zero/chef_data/default_creator.rb +145 -145
  11. data/lib/chef_zero/data_store/data_already_exists_error.rb +1 -1
  12. data/lib/chef_zero/data_store/data_not_found_error.rb +2 -2
  13. data/lib/chef_zero/data_store/default_facade.rb +5 -5
  14. data/lib/chef_zero/data_store/interface_v1.rb +1 -1
  15. data/lib/chef_zero/data_store/interface_v2.rb +1 -1
  16. data/lib/chef_zero/data_store/memory_store.rb +4 -4
  17. data/lib/chef_zero/data_store/memory_store_v2.rb +8 -8
  18. data/lib/chef_zero/data_store/raw_file_store.rb +10 -10
  19. data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +9 -9
  20. data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +5 -5
  21. data/lib/chef_zero/endpoints/acl_endpoint.rb +6 -6
  22. data/lib/chef_zero/endpoints/acls_endpoint.rb +5 -5
  23. data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +1 -1
  24. data/lib/chef_zero/endpoints/actor_endpoint.rb +20 -20
  25. data/lib/chef_zero/endpoints/actor_key_endpoint.rb +1 -1
  26. data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +5 -6
  27. data/lib/chef_zero/endpoints/actors_endpoint.rb +12 -12
  28. data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +10 -10
  29. data/lib/chef_zero/endpoints/container_endpoint.rb +4 -4
  30. data/lib/chef_zero/endpoints/containers_endpoint.rb +3 -3
  31. data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +1 -1
  32. data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +1 -1
  33. data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +1 -1
  34. data/lib/chef_zero/endpoints/cookbook_endpoint.rb +5 -5
  35. data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +20 -16
  36. data/lib/chef_zero/endpoints/cookbooks_base.rb +13 -13
  37. data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +4 -4
  38. data/lib/chef_zero/endpoints/data_bag_endpoint.rb +12 -12
  39. data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +6 -6
  40. data/lib/chef_zero/endpoints/data_bags_endpoint.rb +5 -5
  41. data/lib/chef_zero/endpoints/dummy_endpoint.rb +0 -2
  42. data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +6 -6
  43. data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +16 -16
  44. data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +6 -6
  45. data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
  46. data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +6 -6
  47. data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +4 -4
  48. data/lib/chef_zero/endpoints/environment_role_endpoint.rb +8 -8
  49. data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +2 -2
  50. data/lib/chef_zero/endpoints/group_endpoint.rb +4 -4
  51. data/lib/chef_zero/endpoints/groups_endpoint.rb +3 -3
  52. data/lib/chef_zero/endpoints/license_endpoint.rb +5 -5
  53. data/lib/chef_zero/endpoints/node_endpoint.rb +3 -4
  54. data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +7 -7
  55. data/lib/chef_zero/endpoints/nodes_endpoint.rb +3 -4
  56. data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
  57. data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +2 -2
  58. data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +6 -6
  59. data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +8 -8
  60. data/lib/chef_zero/endpoints/organization_endpoint.rb +10 -10
  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 +5 -5
  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 +12 -12
  67. data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +6 -6
  68. data/lib/chef_zero/endpoints/organizations_endpoint.rb +12 -13
  69. data/lib/chef_zero/endpoints/policies_endpoint.rb +2 -2
  70. data/lib/chef_zero/endpoints/policy_endpoint.rb +1 -1
  71. data/lib/chef_zero/endpoints/policy_group_endpoint.rb +6 -6
  72. data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +3 -4
  73. data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +4 -4
  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 +15 -15
  77. data/lib/chef_zero/endpoints/rest_list_endpoint.rb +4 -4
  78. data/lib/chef_zero/endpoints/rest_object_endpoint.rb +4 -4
  79. data/lib/chef_zero/endpoints/role_endpoint.rb +3 -3
  80. data/lib/chef_zero/endpoints/role_environments_endpoint.rb +3 -3
  81. data/lib/chef_zero/endpoints/sandbox_endpoint.rb +8 -8
  82. data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +9 -9
  83. data/lib/chef_zero/endpoints/search_endpoint.rb +51 -49
  84. data/lib/chef_zero/endpoints/searches_endpoint.rb +2 -2
  85. data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +2 -2
  86. data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +8 -8
  87. data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +12 -12
  88. data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +4 -4
  89. data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +4 -4
  90. data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +5 -5
  91. data/lib/chef_zero/endpoints/version_endpoint.rb +1 -1
  92. data/lib/chef_zero/log.rb +1 -1
  93. data/lib/chef_zero/rest_base.rb +25 -25
  94. data/lib/chef_zero/rest_request.rb +11 -11
  95. data/lib/chef_zero/rest_router.rb +30 -30
  96. data/lib/chef_zero/rspec.rb +33 -33
  97. data/lib/chef_zero/server.rb +188 -189
  98. data/lib/chef_zero/socketless_server_map.rb +2 -3
  99. data/lib/chef_zero/solr/query/binary_operator.rb +8 -8
  100. data/lib/chef_zero/solr/query/phrase.rb +1 -1
  101. data/lib/chef_zero/solr/query/range_query.rb +2 -2
  102. data/lib/chef_zero/solr/query/regexpable_query.rb +1 -0
  103. data/lib/chef_zero/solr/query/term.rb +5 -5
  104. data/lib/chef_zero/solr/query/unary_operator.rb +4 -4
  105. data/lib/chef_zero/solr/solr_doc.rb +4 -4
  106. data/lib/chef_zero/solr/solr_parser.rb +34 -33
  107. data/lib/chef_zero/version.rb +1 -1
  108. data/spec/run_oc_pedant.rb +61 -60
  109. data/spec/search_spec.rb +11 -11
  110. data/spec/server_spec.rb +35 -35
  111. data/spec/socketless_server_map_spec.rb +1 -3
  112. data/spec/support/oc_pedant.rb +20 -21
  113. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b1777b8332d31b59e467917da633172429a610f
4
- data.tar.gz: 994c97845bc1a3cd6899f5effd61d5ffde45456e
3
+ metadata.gz: 8c7f3a055202722134203eea195e863199ebe127
4
+ data.tar.gz: e9840b8dcffaac05370d37bb63a9ea3181026700
5
5
  SHA512:
6
- metadata.gz: 7d7cd1a182106317d3847068cc7f8db5bcc7f76a77734006ad884f31d4413b0c3c852cb6cf0d85b25f555fba1cc4526d04a40855446a62638080ce79b14fb17c
7
- data.tar.gz: a55e55cca7fe1288808ce6a7ba6dc59f0d7cae8387a16ee9a61638caf9db9ec5b5a3c32a68ea40481f651614f967da95a8b3bce4808e30c6ffe624a62b921086
6
+ metadata.gz: b856efb3361afc894f457b253fd1b682a39fee7e4e5f924273052e546b932cbd35b575792280821427ba29a3406af93bfa098cb331d38d15e421a8d6952e9391
7
+ data.tar.gz: 272ae46e85c90e99f8d1cecffad2f2ef4017b1c7d4dce079f14dcc6dfb6ddf54747dfe07298b5baf812dfa11ead7aae6ad500ee47804d07f7a69261451a84bbf
data/Gemfile CHANGED
@@ -1,20 +1,24 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  # gem 'rest-client', :github => 'chef/rest-client'
5
5
 
6
- gem 'oc-chef-pedant', :github => 'chef/chef-server'
6
+ gem "oc-chef-pedant", :github => "chef/chef-server"
7
7
 
8
8
  group :changelog do
9
9
  gem "github_changelog_generator"
10
10
  end
11
11
 
12
+ group :development, :test do
13
+ gem "chefstyle", "= 0.3.1"
14
+ end
15
+
12
16
  # bundler resolve failure on "rspec_junit_formatter"
13
17
  # gem 'chef-pedant', :github => 'opscode/chef-pedant', :ref => "server-cli-option"
14
18
 
15
19
  # gem 'chef', :github => 'chef/chef', :branch => 'jk/policies-acls'
16
20
 
17
- if ENV['GEMFILE_MOD']
21
+ if ENV["GEMFILE_MOD"]
18
22
  puts "GEMFILE_MOD: #{ENV['GEMFILE_MOD']}"
19
- instance_eval(ENV['GEMFILE_MOD'])
23
+ instance_eval(ENV["GEMFILE_MOD"])
20
24
  end
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- require 'bundler'
2
- require 'bundler/gem_tasks'
1
+ require "bundler"
2
+ require "bundler/gem_tasks"
3
3
 
4
- require 'chef_zero/version'
4
+ require "chef_zero/version"
5
5
 
6
- def run_oc_pedant(env={})
6
+ def run_oc_pedant(env = {})
7
7
  ENV.update(env)
8
- require File.expand_path('spec/run_oc_pedant')
8
+ require File.expand_path("spec/run_oc_pedant")
9
9
  end
10
10
 
11
11
  ENV_DOCS = <<END
@@ -22,7 +22,7 @@ task :default => :pedant
22
22
 
23
23
  desc "Run specs"
24
24
  task :spec do
25
- system('rspec spec/*_spec.rb')
25
+ system("rspec spec/*_spec.rb")
26
26
  end
27
27
 
28
28
  desc "Run oc-chef-pedant\n\n#{ENV_DOCS}"
@@ -30,12 +30,12 @@ task :pedant => :oc_pedant
30
30
 
31
31
  desc "Run oc-chef-pedant with CHEF_FS set\n\n#{ENV_DOCS}"
32
32
  task :cheffs do
33
- run_oc_pedant('CHEF_FS' => 'yes')
33
+ run_oc_pedant("CHEF_FS" => "yes")
34
34
  end
35
35
 
36
36
  desc "Run oc-chef-pedant with FILE_STORE set\n\n#{ENV_DOCS}"
37
37
  task :filestore do
38
- run_oc_pedant('FILE_STORE' => 'yes')
38
+ run_oc_pedant("FILE_STORE" => "yes")
39
39
  end
40
40
 
41
41
  task :oc_pedant do
@@ -43,15 +43,25 @@ task :oc_pedant do
43
43
  end
44
44
 
45
45
  task :chef_spec do
46
- gem_path = Bundler.environment.specs['chef'].first.full_gem_path
46
+ gem_path = Bundler.environment.specs["chef"].first.full_gem_path
47
47
  system("cd #{gem_path} && rspec spec/integration")
48
48
  end
49
49
 
50
50
  task :berkshelf_spec do
51
- gem_path = Bundler.environment.specs['berkshelf'].first.full_gem_path
51
+ gem_path = Bundler.environment.specs["berkshelf"].first.full_gem_path
52
52
  system("cd #{gem_path} && thor spec:ci")
53
53
  end
54
54
 
55
+ begin
56
+ require "chefstyle"
57
+ require "rubocop/rake_task"
58
+ RuboCop::RakeTask.new(:style) do |task|
59
+ task.options += ["--display-cop-names", "--no-color"]
60
+ end
61
+ rescue LoadError
62
+ puts "chefstyle/rubocop is not available. gem install chefstyle to do style checking."
63
+ end
64
+
55
65
  begin
56
66
  require "github_changelog_generator/task"
57
67
 
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # Trap interrupts to quit cleanly.
4
- Signal.trap('INT') { exit 1 }
4
+ Signal.trap("INT") { exit 1 }
5
5
 
6
- require 'rubygems'
6
+ require "rubygems"
7
7
  $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
8
8
 
9
- require 'chef_zero/log'
10
- require 'chef_zero/version'
11
- require 'chef_zero/server'
12
- require 'chef_zero/data_store/raw_file_store'
13
- require 'optparse'
9
+ require "chef_zero/log"
10
+ require "chef_zero/version"
11
+ require "chef_zero/server"
12
+ require "chef_zero/data_store/raw_file_store"
13
+ require "optparse"
14
14
 
15
15
  def parse_port(port)
16
16
  array = []
17
- port.split(',').each do |part|
18
- a,b = part.split('-',2)
17
+ port.split(",").each do |part|
18
+ a, b = part.split("-", 2)
19
19
  if b
20
20
  array = array.concat(a.to_i.upto(b.to_i).to_a)
21
21
  else
@@ -99,10 +99,10 @@ if options[:daemon]
99
99
  Process.daemon(true)
100
100
  server.start(true)
101
101
  else
102
- if ENV['OS'] == 'Windows_NT'
103
- abort 'Daemonization is not supported on Windows. Running 'start chef-zero' will fork the process.'
102
+ if ENV["OS"] == "Windows_NT"
103
+ abort "Daemonization is not supported on Windows. Running 'start chef-zero' will fork the process."
104
104
  else
105
- abort 'Process.daemon requires Ruby >= 1.9'
105
+ abort "Process.daemon requires Ruby >= 1.9"
106
106
  end
107
107
  end
108
108
  else
@@ -1,35 +1,35 @@
1
- $:.unshift(File.dirname(__FILE__) + '/lib')
2
- require 'chef_zero/version'
1
+ $:.unshift(File.dirname(__FILE__) + "/lib")
2
+ require "chef_zero/version"
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = 'chef-zero'
5
+ s.name = "chef-zero"
6
6
  s.version = ChefZero::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.summary = 'Self-contained, easy-setup, fast-start in-memory Chef server for testing and solo setup purposes'
8
+ s.summary = "Self-contained, easy-setup, fast-start in-memory Chef server for testing and solo setup purposes"
9
9
  s.description = s.summary
10
- s.author = 'John Keiser'
11
- s.email = 'jkeiser@chef.io'
12
- s.homepage = 'http://www.chef.io'
13
- s.license = 'Apache 2.0'
10
+ s.author = "John Keiser"
11
+ s.email = "jkeiser@chef.io"
12
+ s.homepage = "http://www.chef.io"
13
+ s.license = "Apache 2.0"
14
14
 
15
15
  s.required_ruby_version = ">= 2.1.0"
16
16
 
17
- s.add_dependency 'mixlib-log', '~> 1.3'
18
- s.add_dependency 'hashie', '>= 2.0', '< 4.0'
19
- s.add_dependency 'uuidtools', '~> 2.1'
20
- s.add_dependency 'ffi-yajl', '~> 2.2'
21
- s.add_dependency 'rack', '< 2' # 2.0 requires Ruby 2.2+
17
+ s.add_dependency "mixlib-log", "~> 1.3"
18
+ s.add_dependency "hashie", ">= 2.0", "< 4.0"
19
+ s.add_dependency "uuidtools", "~> 2.1"
20
+ s.add_dependency "ffi-yajl", "~> 2.2"
21
+ s.add_dependency "rack", "< 2" # 2.0 requires Ruby 2.2+
22
22
 
23
- s.add_development_dependency 'pry'
24
- s.add_development_dependency 'pry-byebug'
25
- s.add_development_dependency 'pry-stack_explorer'
26
- s.add_development_dependency 'rake'
27
- s.add_development_dependency 'rspec'
28
- s.add_development_dependency 'chef'
23
+ s.add_development_dependency "pry"
24
+ s.add_development_dependency "pry-byebug"
25
+ s.add_development_dependency "pry-stack_explorer"
26
+ s.add_development_dependency "rake"
27
+ s.add_development_dependency "rspec"
28
+ s.add_development_dependency "chef"
29
29
 
30
- s.bindir = 'bin'
31
- s.executables = ['chef-zero']
32
- s.require_path = 'lib'
33
- s.files = %w(LICENSE README.md Gemfile Rakefile) + Dir.glob('*.gemspec') +
34
- Dir.glob('{lib,spec}/**/*', File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
30
+ s.bindir = "bin"
31
+ s.executables = ["chef-zero"]
32
+ s.require_path = "lib"
33
+ s.files = %w{LICENSE README.md Gemfile Rakefile} + Dir.glob("*.gemspec") +
34
+ Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
35
35
  end
@@ -1,5 +1,5 @@
1
1
  module ChefZero
2
- require 'chef_zero/log'
2
+ require "chef_zero/log"
3
3
 
4
4
  MIN_API_VERSION = 0
5
5
  MAX_API_VERSION = 1
@@ -13,9 +13,9 @@ module ChefZero
13
13
  # specified on X, they are not inherited from X's parent
14
14
  # - stop adding pivotal to acls (he already has access to what he needs)
15
15
  module AclPath
16
- ORG_DATA_TYPES = %w(clients cookbook_artifacts cookbooks containers data environments groups
17
- nodes policies policy_groups roles sandboxes)
18
- TOP_DATA_TYPES = %w(containers organizations users)
16
+ ORG_DATA_TYPES = %w{clients cookbook_artifacts cookbooks containers data environments groups
17
+ nodes policies policy_groups roles sandboxes}
18
+ TOP_DATA_TYPES = %w{containers organizations users}
19
19
 
20
20
  # ACL data paths for a partition are:
21
21
  # / -> /acls/root
@@ -42,7 +42,7 @@ module ChefZero
42
42
  # return nil, because it is the parent path (data/bag) that has an ACL.
43
43
  def self.get_acl_data_path(path)
44
44
  # Things under organizations have their own acls hierarchy
45
- if path[0] == 'organizations' && path.size >= 2
45
+ if path[0] == "organizations" && path.size >= 2
46
46
  under_org = partition_acl_data_path(path[2..-1], ORG_DATA_TYPES)
47
47
  if under_org
48
48
  path[0..1] + under_org
@@ -63,14 +63,14 @@ module ChefZero
63
63
  # /containers/nodes, not /nodes.
64
64
  #
65
65
  def self.get_object_path(acl_data_path)
66
- if acl_data_path[0] == 'acls'
67
- if acl_data_path[1] == 'root'
66
+ if acl_data_path[0] == "acls"
67
+ if acl_data_path[1] == "root"
68
68
  []
69
69
  else
70
70
  acl_data_path[1..-1]
71
71
  end
72
- elsif acl_data_path[0] == 'organizations' && acl_data_path[2] == 'acls'
73
- if acl_data_path[3] == 'root'
72
+ elsif acl_data_path[0] == "organizations" && acl_data_path[2] == "acls"
73
+ if acl_data_path[3] == "root"
74
74
  acl_data_path[0..1]
75
75
  else
76
76
  acl_data_path[0..1] + acl_data_path[3..-1]
@@ -91,13 +91,13 @@ module ChefZero
91
91
  # /acls/root ->
92
92
  # nil
93
93
  def self.parent_acl_data_path(acl_data_path)
94
- if acl_data_path[0] == 'organizations'
94
+ if acl_data_path[0] == "organizations"
95
95
  under_org = partition_parent_acl_data_path(acl_data_path[2..-1])
96
96
  if under_org
97
97
  acl_data_path[0..1] + under_org
98
98
  else
99
99
  # ACL data path is /organizations/X/acls/root; therefore parent is "/organizations"
100
- [ 'acls', 'containers', 'organizations' ]
100
+ %w{acls containers organizations}
101
101
  end
102
102
  else
103
103
  partition_parent_acl_data_path(acl_data_path)
@@ -114,10 +114,10 @@ module ChefZero
114
114
  # Returns nil if the path is /acls/root
115
115
  def self.partition_parent_acl_data_path(acl_data_path)
116
116
  if acl_data_path.size == 3
117
- if acl_data_path == %w(acls containers containers)
118
- [ 'acls', 'root' ]
117
+ if acl_data_path == %w{acls containers containers}
118
+ %w{acls root}
119
119
  else
120
- [ 'acls', 'containers', acl_data_path[1]]
120
+ [ "acls", "containers", acl_data_path[1]]
121
121
  end
122
122
  else
123
123
  nil
@@ -126,12 +126,12 @@ module ChefZero
126
126
 
127
127
  def self.partition_acl_data_path(path, data_types)
128
128
  if path.size == 0
129
- [ 'acls', 'root']
129
+ %w{acls root}
130
130
  elsif data_types.include?(path[0])
131
131
  if path.size == 0
132
- [ 'acls', 'containers', path[0] ]
132
+ [ "acls", "containers", path[0] ]
133
133
  elsif path.size == 2
134
- [ 'acls', path[0], path[1] ]
134
+ [ "acls", path[0], path[1] ]
135
135
  end
136
136
  end
137
137
  end
@@ -1,10 +1,10 @@
1
- require 'digest/md5'
2
- require 'hashie/mash'
1
+ require "digest/md5"
2
+ require "hashie/mash"
3
3
 
4
4
  module ChefZero
5
5
  module ChefData
6
6
  module CookbookData
7
- def self.to_hash(cookbook, name, version=nil)
7
+ def self.to_hash(cookbook, name, version = nil)
8
8
  frozen = false
9
9
  if cookbook.has_key?(:frozen)
10
10
  frozen = cookbook[:frozen]
@@ -15,14 +15,14 @@ module ChefZero
15
15
  result = files_from(cookbook)
16
16
  recipe_names = result[:recipes].map do |recipe|
17
17
  recipe_name = recipe[:name][0..-2]
18
- recipe_name == 'default' ? name : "#{name}::#{recipe_name}"
18
+ recipe_name == "default" ? name : "#{name}::#{recipe_name}"
19
19
  end
20
20
  result[:metadata] = metadata_from(cookbook, name, version, recipe_names)
21
21
  result[:name] = "#{name}-#{result[:metadata][:version]}"
22
- result[:json_class] = 'Chef::CookbookVersion'
22
+ result[:json_class] = "Chef::CookbookVersion"
23
23
  result[:cookbook_name] = name
24
24
  result[:version] = result[:metadata][:version]
25
- result[:chef_type] = 'cookbook_version'
25
+ result[:chef_type] = "cookbook_version"
26
26
  result[:frozen?] = true if frozen
27
27
  result
28
28
  end
@@ -32,18 +32,18 @@ module ChefZero
32
32
  # If both .rb and .json exist, read .rb
33
33
  # TODO if recipes has 3 recipes in it, and the Ruby/JSON has only one, should
34
34
  # the resulting recipe list have 1, or 3-4 recipes in it?
35
- if has_child(directory, 'metadata.rb')
35
+ if has_child(directory, "metadata.rb")
36
36
  begin
37
- file = filename(directory, 'metadata.rb') || "(#{name}/metadata.rb)"
38
- metadata.instance_eval(read_file(directory, 'metadata.rb'), file)
37
+ file = filename(directory, "metadata.rb") || "(#{name}/metadata.rb)"
38
+ metadata.instance_eval(read_file(directory, "metadata.rb"), file)
39
39
  rescue
40
40
  ChefZero::Log.error("Error loading cookbook #{name}: #{$!}\n #{$!.backtrace.join("\n ")}")
41
41
  end
42
- elsif has_child(directory, 'metadata.json')
43
- metadata.from_json(read_file(directory, 'metadata.json'))
42
+ elsif has_child(directory, "metadata.json")
43
+ metadata.from_json(read_file(directory, "metadata.json"))
44
44
  end
45
45
  result = {}
46
- metadata.to_hash.each_pair do |key,value|
46
+ metadata.to_hash.each_pair do |key, value|
47
47
  result[key.to_sym] = value
48
48
  end
49
49
  result[:version] = version if version
@@ -69,7 +69,7 @@ module ChefZero
69
69
  def initialize(cookbook)
70
70
  self.name(cookbook.name)
71
71
  self.recipes(cookbook.fully_qualified_recipe_names)
72
- %w(attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes).each do |hash_arg|
72
+ %w{attributes grouping dependencies supports recommendations suggestions conflicting providing replacing recipes}.each do |hash_arg|
73
73
  self[hash_arg.to_sym] = Hashie::Mash.new
74
74
  end
75
75
  end
@@ -145,15 +145,15 @@ module ChefZero
145
145
  def self.files_from(directory)
146
146
  # TODO some support .rb only
147
147
  result = {
148
- :attributes => load_child_files(directory, 'attributes', false),
149
- :definitions => load_child_files(directory, 'definitions', false),
150
- :recipes => load_child_files(directory, 'recipes', false),
151
- :libraries => load_child_files(directory, 'libraries', true),
152
- :templates => load_child_files(directory, 'templates', true),
153
- :files => load_child_files(directory, 'files', true),
154
- :resources => load_child_files(directory, 'resources', true),
155
- :providers => load_child_files(directory, 'providers', true),
156
- :root_files => load_files(directory, false)
148
+ :attributes => load_child_files(directory, "attributes", false),
149
+ :definitions => load_child_files(directory, "definitions", false),
150
+ :recipes => load_child_files(directory, "recipes", false),
151
+ :libraries => load_child_files(directory, "libraries", true),
152
+ :templates => load_child_files(directory, "templates", true),
153
+ :files => load_child_files(directory, "files", true),
154
+ :resources => load_child_files(directory, "resources", true),
155
+ :providers => load_child_files(directory, "providers", true),
156
+ :root_files => load_files(directory, false),
157
157
  }
158
158
  set_specificity(result[:templates])
159
159
  set_specificity(result[:files])
@@ -231,13 +231,13 @@ module ChefZero
231
231
  :name => name,
232
232
  :path => name,
233
233
  :checksum => Digest::MD5.hexdigest(value),
234
- :specificity => 'default'
234
+ :specificity => "default",
235
235
  }]
236
236
  end
237
237
 
238
238
  def self.set_specificity(files)
239
239
  files.each do |file|
240
- parts = file[:path].split('/')
240
+ parts = file[:path].split("/")
241
241
  raise "Only directories are allowed directly under templates or files: #{file[:path]}" if parts.size == 2
242
242
  file[:specificity] = parts[1]
243
243
  end
@@ -1,6 +1,6 @@
1
- require 'chef_zero'
2
- require 'chef_zero/rest_base'
3
- require 'chef_zero/chef_data/default_creator'
1
+ require "chef_zero"
2
+ require "chef_zero/rest_base"
3
+ require "chef_zero/chef_data/default_creator"
4
4
 
5
5
  module ChefZero
6
6
  module ChefData
@@ -8,210 +8,210 @@ module ChefZero
8
8
  def self.normalize_acls(acls)
9
9
  ChefData::DefaultCreator::PERMISSIONS.each do |perm|
10
10
  acls[perm] ||= {}
11
- (acls[perm]['actors'] ||= []).uniq! # this gets doubled sometimes, for reasons.
12
- acls[perm]['groups'] ||= []
11
+ (acls[perm]["actors"] ||= []).uniq! # this gets doubled sometimes, for reasons.
12
+ acls[perm]["groups"] ||= []
13
13
  end
14
14
  acls
15
15
  end
16
16
 
17
17
  def self.normalize_client(client, name, orgname = nil)
18
- client['name'] ||= name
19
- client['clientname'] ||= name
20
- client['admin'] = !!client['admin'] if client.key?('admin')
21
- client['public_key'] = PUBLIC_KEY unless client.key?('public_key')
22
- client['orgname'] ||= orgname
23
- client['validator'] ||= false
24
- client['validator'] = !!client['validator']
25
- client['json_class'] ||= "Chef::ApiClient"
26
- client['chef_type'] ||= "client"
18
+ client["name"] ||= name
19
+ client["clientname"] ||= name
20
+ client["admin"] = !!client["admin"] if client.key?("admin")
21
+ client["public_key"] = PUBLIC_KEY unless client.key?("public_key")
22
+ client["orgname"] ||= orgname
23
+ client["validator"] ||= false
24
+ client["validator"] = !!client["validator"]
25
+ client["json_class"] ||= "Chef::ApiClient"
26
+ client["chef_type"] ||= "client"
27
27
  client
28
28
  end
29
29
 
30
30
  def self.normalize_container(container, name)
31
- container.delete('id')
32
- container['containername'] = name
33
- container['containerpath'] = name
31
+ container.delete("id")
32
+ container["containername"] = name
33
+ container["containerpath"] = name
34
34
  container
35
35
  end
36
36
 
37
- def self.normalize_user(user, name, identity_keys, osc_compat, method=nil)
37
+ def self.normalize_user(user, name, identity_keys, osc_compat, method = nil)
38
38
  user[identity_keys.first] ||= name
39
- user['public_key'] = PUBLIC_KEY unless user.key?('public_key')
40
- user['admin'] ||= false
41
- user['admin'] = !!user['admin']
42
- user['openid'] ||= nil
39
+ user["public_key"] = PUBLIC_KEY unless user.key?("public_key")
40
+ user["admin"] ||= false
41
+ user["admin"] = !!user["admin"]
42
+ user["openid"] ||= nil
43
43
  if !osc_compat
44
- if method == 'GET'
45
- user.delete('admin')
46
- user.delete('password')
47
- user.delete('openid')
44
+ if method == "GET"
45
+ user.delete("admin")
46
+ user.delete("password")
47
+ user.delete("openid")
48
48
  end
49
- user['email'] ||= nil
50
- user['first_name'] ||= nil
51
- user['last_name'] ||= nil
49
+ user["email"] ||= nil
50
+ user["first_name"] ||= nil
51
+ user["last_name"] ||= nil
52
52
  end
53
53
  user
54
54
  end
55
55
 
56
56
  def self.normalize_data_bag_item(data_bag_item, data_bag_name, id, method)
57
- if method == 'DELETE'
57
+ if method == "DELETE"
58
58
  # TODO SERIOUSLY, WHO DOES THIS MANY EXCEPTIONS IN THEIR INTERFACE
59
- if !(data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data'])
60
- data_bag_item['id'] ||= id
61
- data_bag_item = { 'raw_data' => data_bag_item }
62
- data_bag_item['chef_type'] ||= 'data_bag_item'
63
- data_bag_item['json_class'] ||= 'Chef::DataBagItem'
64
- data_bag_item['data_bag'] ||= data_bag_name
65
- data_bag_item['name'] ||= "data_bag_item_#{data_bag_name}_#{id}"
59
+ if !(data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"])
60
+ data_bag_item["id"] ||= id
61
+ data_bag_item = { "raw_data" => data_bag_item }
62
+ data_bag_item["chef_type"] ||= "data_bag_item"
63
+ data_bag_item["json_class"] ||= "Chef::DataBagItem"
64
+ data_bag_item["data_bag"] ||= data_bag_name
65
+ data_bag_item["name"] ||= "data_bag_item_#{data_bag_name}_#{id}"
66
66
  end
67
67
  else
68
68
  # If it's not already wrapped with raw_data, wrap it.
69
- if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
70
- data_bag_item = data_bag_item['raw_data']
69
+ if data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"]
70
+ data_bag_item = data_bag_item["raw_data"]
71
71
  end
72
72
  # Argh. We don't do this on GET, but we do on PUT and POST????
73
- if %w(PUT POST).include?(method)
74
- data_bag_item['chef_type'] ||= 'data_bag_item'
75
- data_bag_item['data_bag'] ||= data_bag_name
73
+ if %w{PUT POST}.include?(method)
74
+ data_bag_item["chef_type"] ||= "data_bag_item"
75
+ data_bag_item["data_bag"] ||= data_bag_name
76
76
  end
77
- data_bag_item['id'] ||= id
77
+ data_bag_item["id"] ||= id
78
78
  end
79
79
  data_bag_item
80
80
  end
81
81
 
82
82
  def self.normalize_cookbook(endpoint, org_prefix, cookbook, name, version, base_uri, method,
83
- is_cookbook_artifact=false)
83
+ is_cookbook_artifact = false)
84
84
  # TODO I feel dirty
85
- if method != 'PUT'
85
+ if method != "PUT"
86
86
  cookbook.each_pair do |key, value|
87
87
  if value.is_a?(Array)
88
88
  value.each do |file|
89
- if file.is_a?(Hash) && file.has_key?('checksum')
90
- file['url'] ||= endpoint.build_uri(base_uri, org_prefix + ['file_store', 'checksums', file['checksum']])
89
+ if file.is_a?(Hash) && file.has_key?("checksum")
90
+ file["url"] ||= endpoint.build_uri(base_uri, org_prefix + ["file_store", "checksums", file["checksum"]])
91
91
  end
92
92
  end
93
93
  end
94
94
  end
95
- cookbook['name'] ||= "#{name}-#{version}"
95
+ cookbook["name"] ||= "#{name}-#{version}"
96
96
  # TODO it feels wrong, but the real chef server doesn't expand 'version', so we don't either.
97
97
 
98
- cookbook['frozen?'] ||= false
99
- cookbook['metadata'] ||= {}
100
- cookbook['metadata']['version'] ||= version
98
+ cookbook["frozen?"] ||= false
99
+ cookbook["metadata"] ||= {}
100
+ cookbook["metadata"]["version"] ||= version
101
101
 
102
102
  # defaults set by the client and not the Server:
103
103
  # metadata[name, description, maintainer, maintainer_email, license]
104
104
 
105
- cookbook['metadata']['long_description'] ||= ""
106
- cookbook['metadata']['dependencies'] ||= {}
107
- cookbook['metadata']['attributes'] ||= {}
108
- cookbook['metadata']['recipes'] ||= {}
105
+ cookbook["metadata"]["long_description"] ||= ""
106
+ cookbook["metadata"]["dependencies"] ||= {}
107
+ cookbook["metadata"]["attributes"] ||= {}
108
+ cookbook["metadata"]["recipes"] ||= {}
109
109
  end
110
110
 
111
111
  if is_cookbook_artifact
112
- cookbook.delete('json_class')
112
+ cookbook.delete("json_class")
113
113
  else
114
- cookbook['cookbook_name'] ||= name
115
- cookbook['json_class'] ||= 'Chef::CookbookVersion'
114
+ cookbook["cookbook_name"] ||= name
115
+ cookbook["json_class"] ||= "Chef::CookbookVersion"
116
116
  end
117
117
 
118
- cookbook['chef_type'] ||= 'cookbook_version'
119
- if method == 'MIN'
120
- cookbook['metadata'].delete('attributes')
121
- cookbook['metadata'].delete('long_description')
118
+ cookbook["chef_type"] ||= "cookbook_version"
119
+ if method == "MIN"
120
+ cookbook["metadata"].delete("attributes")
121
+ cookbook["metadata"].delete("long_description")
122
122
  end
123
123
  cookbook
124
124
  end
125
125
 
126
126
  def self.normalize_environment(environment, name)
127
- environment['name'] ||= name
128
- environment['description'] ||= ''
129
- environment['cookbook_versions'] ||= {}
130
- environment['json_class'] ||= "Chef::Environment"
131
- environment['chef_type'] ||= "environment"
132
- environment['default_attributes'] ||= {}
133
- environment['override_attributes'] ||= {}
127
+ environment["name"] ||= name
128
+ environment["description"] ||= ""
129
+ environment["cookbook_versions"] ||= {}
130
+ environment["json_class"] ||= "Chef::Environment"
131
+ environment["chef_type"] ||= "environment"
132
+ environment["default_attributes"] ||= {}
133
+ environment["override_attributes"] ||= {}
134
134
  environment
135
135
  end
136
136
 
137
137
  def self.normalize_group(group, name, orgname)
138
- group.delete('id')
139
- if group['actors'].is_a?(Hash)
140
- group['users'] ||= group['actors']['users']
141
- group['clients'] ||= group['actors']['clients']
142
- group['groups'] ||= group['actors']['groups']
143
- group['actors'] = nil
138
+ group.delete("id")
139
+ if group["actors"].is_a?(Hash)
140
+ group["users"] ||= group["actors"]["users"]
141
+ group["clients"] ||= group["actors"]["clients"]
142
+ group["groups"] ||= group["actors"]["groups"]
143
+ group["actors"] = nil
144
144
  end
145
- group['users'] ||= []
146
- group['clients'] ||= []
147
- group['actors'] ||= (group['clients'] + group['users'])
148
- group['groups'] ||= []
149
- group['orgname'] ||= orgname if orgname
150
- group['name'] ||= name
151
- group['groupname'] ||= name
152
-
153
- group['users'].uniq!
154
- group['clients'].uniq!
155
- group['actors'].uniq!
156
- group['groups'].uniq!
145
+ group["users"] ||= []
146
+ group["clients"] ||= []
147
+ group["actors"] ||= (group["clients"] + group["users"])
148
+ group["groups"] ||= []
149
+ group["orgname"] ||= orgname if orgname
150
+ group["name"] ||= name
151
+ group["groupname"] ||= name
152
+
153
+ group["users"].uniq!
154
+ group["clients"].uniq!
155
+ group["actors"].uniq!
156
+ group["groups"].uniq!
157
157
  group
158
158
  end
159
159
 
160
160
  def self.normalize_node(node, name)
161
- node['name'] ||= name
162
- node['json_class'] ||= 'Chef::Node'
163
- node['chef_type'] ||= 'node'
164
- node['chef_environment'] ||= '_default'
165
- node['override'] ||= {}
166
- node['normal'] ||= {"tags" => []}
167
- node['default'] ||= {}
168
- node['automatic'] ||= {}
169
- node['run_list'] ||= []
170
- node['run_list'] = normalize_run_list(node['run_list'])
161
+ node["name"] ||= name
162
+ node["json_class"] ||= "Chef::Node"
163
+ node["chef_type"] ||= "node"
164
+ node["chef_environment"] ||= "_default"
165
+ node["override"] ||= {}
166
+ node["normal"] ||= { "tags" => [] }
167
+ node["default"] ||= {}
168
+ node["automatic"] ||= {}
169
+ node["run_list"] ||= []
170
+ node["run_list"] = normalize_run_list(node["run_list"])
171
171
  node
172
172
  end
173
173
 
174
174
  def self.normalize_policy(policy, name, revision)
175
- policy['name'] ||= name
176
- policy['revision_id'] ||= revision
177
- policy['run_list'] ||= []
178
- policy['cookbook_locks'] ||= {}
175
+ policy["name"] ||= name
176
+ policy["revision_id"] ||= revision
177
+ policy["run_list"] ||= []
178
+ policy["cookbook_locks"] ||= {}
179
179
  policy
180
180
  end
181
181
 
182
182
  def self.normalize_policy_group(policy_group, name)
183
- policy_group[name] ||= 'name'
184
- policy_group['policies'] ||= {}
183
+ policy_group[name] ||= "name"
184
+ policy_group["policies"] ||= {}
185
185
  policy_group
186
186
  end
187
187
 
188
188
  def self.normalize_organization(org, name)
189
- org['name'] ||= name
190
- org['full_name'] ||= name
191
- org['org_type'] ||= 'Business'
192
- org['clientname'] ||= "#{name}-validator"
193
- org['billing_plan'] ||= 'platform-free'
189
+ org["name"] ||= name
190
+ org["full_name"] ||= name
191
+ org["org_type"] ||= "Business"
192
+ org["clientname"] ||= "#{name}-validator"
193
+ org["billing_plan"] ||= "platform-free"
194
194
  org
195
195
  end
196
196
 
197
197
  def self.normalize_role(role, name)
198
- role['name'] ||= name
199
- role['description'] ||= ''
200
- role['json_class'] ||= 'Chef::Role'
201
- role['chef_type'] ||= 'role'
202
- role['default_attributes'] ||= {}
203
- role['override_attributes'] ||= {}
204
- role['run_list'] ||= []
205
- role['run_list'] = normalize_run_list(role['run_list'])
206
- role['env_run_lists'] ||= {}
207
- role['env_run_lists'].each_pair do |env, run_list|
208
- role['env_run_lists'][env] = normalize_run_list(run_list)
198
+ role["name"] ||= name
199
+ role["description"] ||= ""
200
+ role["json_class"] ||= "Chef::Role"
201
+ role["chef_type"] ||= "role"
202
+ role["default_attributes"] ||= {}
203
+ role["override_attributes"] ||= {}
204
+ role["run_list"] ||= []
205
+ role["run_list"] = normalize_run_list(role["run_list"])
206
+ role["env_run_lists"] ||= {}
207
+ role["env_run_lists"].each_pair do |env, run_list|
208
+ role["env_run_lists"][env] = normalize_run_list(run_list)
209
209
  end
210
210
  role
211
211
  end
212
212
 
213
213
  def self.normalize_run_list(run_list)
214
- run_list.map{|item|
214
+ run_list.map {|item|
215
215
  case item
216
216
  when /^recipe\[.*\]$/
217
217
  item # explicit recipe