chef-zero 4.8.0 → 4.9.0
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.
- checksums.yaml +4 -4
- data/Gemfile +8 -4
- data/Rakefile +20 -10
- data/bin/chef-zero +12 -12
- data/chef-zero.gemspec +24 -24
- data/lib/chef_zero.rb +1 -1
- data/lib/chef_zero/chef_data/acl_path.rb +16 -16
- data/lib/chef_zero/chef_data/cookbook_data.rb +24 -24
- data/lib/chef_zero/chef_data/data_normalizer.rb +120 -120
- data/lib/chef_zero/chef_data/default_creator.rb +145 -145
- data/lib/chef_zero/data_store/data_already_exists_error.rb +1 -1
- data/lib/chef_zero/data_store/data_not_found_error.rb +2 -2
- data/lib/chef_zero/data_store/default_facade.rb +5 -5
- data/lib/chef_zero/data_store/interface_v1.rb +1 -1
- data/lib/chef_zero/data_store/interface_v2.rb +1 -1
- data/lib/chef_zero/data_store/memory_store.rb +4 -4
- data/lib/chef_zero/data_store/memory_store_v2.rb +8 -8
- data/lib/chef_zero/data_store/raw_file_store.rb +10 -10
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +9 -9
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +5 -5
- data/lib/chef_zero/endpoints/acl_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/acls_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/actor_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/actor_key_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +5 -6
- data/lib/chef_zero/endpoints/actors_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +10 -10
- data/lib/chef_zero/endpoints/container_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/containers_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +20 -16
- data/lib/chef_zero/endpoints/cookbooks_base.rb +13 -13
- data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/dummy_endpoint.rb +0 -2
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/environment_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/group_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/groups_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/license_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/node_endpoint.rb +3 -4
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +7 -7
- data/lib/chef_zero/endpoints/nodes_endpoint.rb +3 -4
- data/lib/chef_zero/endpoints/not_found_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/organization_endpoint.rb +10 -10
- data/lib/chef_zero/endpoints/organization_user_base.rb +2 -2
- data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/organization_users_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +12 -13
- data/lib/chef_zero/endpoints/policies_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/policy_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/policy_group_endpoint.rb +6 -6
- data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +3 -4
- data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +1 -1
- data/lib/chef_zero/endpoints/principal_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/role_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +3 -3
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +9 -9
- data/lib/chef_zero/endpoints/search_endpoint.rb +51 -49
- data/lib/chef_zero/endpoints/searches_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +2 -2
- data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +8 -8
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +12 -12
- data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +4 -4
- data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +5 -5
- data/lib/chef_zero/endpoints/version_endpoint.rb +1 -1
- data/lib/chef_zero/log.rb +1 -1
- data/lib/chef_zero/rest_base.rb +25 -25
- data/lib/chef_zero/rest_request.rb +11 -11
- data/lib/chef_zero/rest_router.rb +30 -30
- data/lib/chef_zero/rspec.rb +33 -33
- data/lib/chef_zero/server.rb +188 -189
- data/lib/chef_zero/socketless_server_map.rb +2 -3
- data/lib/chef_zero/solr/query/binary_operator.rb +8 -8
- data/lib/chef_zero/solr/query/phrase.rb +1 -1
- data/lib/chef_zero/solr/query/range_query.rb +2 -2
- data/lib/chef_zero/solr/query/regexpable_query.rb +1 -0
- data/lib/chef_zero/solr/query/term.rb +5 -5
- data/lib/chef_zero/solr/query/unary_operator.rb +4 -4
- data/lib/chef_zero/solr/solr_doc.rb +4 -4
- data/lib/chef_zero/solr/solr_parser.rb +34 -33
- data/lib/chef_zero/version.rb +1 -1
- data/spec/run_oc_pedant.rb +61 -60
- data/spec/search_spec.rb +11 -11
- data/spec/server_spec.rb +35 -35
- data/spec/socketless_server_map_spec.rb +1 -3
- data/spec/support/oc_pedant.rb +20 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c7f3a055202722134203eea195e863199ebe127
|
4
|
+
data.tar.gz: e9840b8dcffaac05370d37bb63a9ea3181026700
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b856efb3361afc894f457b253fd1b682a39fee7e4e5f924273052e546b932cbd35b575792280821427ba29a3406af93bfa098cb331d38d15e421a8d6952e9391
|
7
|
+
data.tar.gz: 272ae46e85c90e99f8d1cecffad2f2ef4017b1c7d4dce079f14dcc6dfb6ddf54747dfe07298b5baf812dfa11ead7aae6ad500ee47804d07f7a69261451a84bbf
|
data/Gemfile
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
# gem 'rest-client', :github => 'chef/rest-client'
|
5
5
|
|
6
|
-
gem
|
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[
|
21
|
+
if ENV["GEMFILE_MOD"]
|
18
22
|
puts "GEMFILE_MOD: #{ENV['GEMFILE_MOD']}"
|
19
|
-
instance_eval(ENV[
|
23
|
+
instance_eval(ENV["GEMFILE_MOD"])
|
20
24
|
end
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "bundler"
|
2
|
+
require "bundler/gem_tasks"
|
3
3
|
|
4
|
-
require
|
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(
|
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(
|
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(
|
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(
|
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[
|
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[
|
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
|
|
data/bin/chef-zero
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# Trap interrupts to quit cleanly.
|
4
|
-
Signal.trap(
|
4
|
+
Signal.trap("INT") { exit 1 }
|
5
5
|
|
6
|
-
require
|
6
|
+
require "rubygems"
|
7
7
|
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
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(
|
18
|
-
a,b = part.split(
|
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[
|
103
|
-
abort
|
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
|
105
|
+
abort "Process.daemon requires Ruby >= 1.9"
|
106
106
|
end
|
107
107
|
end
|
108
108
|
else
|
data/chef-zero.gemspec
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) +
|
2
|
-
require
|
1
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
2
|
+
require "chef_zero/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name =
|
5
|
+
s.name = "chef-zero"
|
6
6
|
s.version = ChefZero::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.summary =
|
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 =
|
11
|
-
s.email =
|
12
|
-
s.homepage =
|
13
|
-
s.license =
|
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
|
18
|
-
s.add_dependency
|
19
|
-
s.add_dependency
|
20
|
-
s.add_dependency
|
21
|
-
s.add_dependency
|
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
|
24
|
-
s.add_development_dependency
|
25
|
-
s.add_development_dependency
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_development_dependency
|
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 =
|
31
|
-
s.executables = [
|
32
|
-
s.require_path =
|
33
|
-
s.files = %w
|
34
|
-
|
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
|
data/lib/chef_zero.rb
CHANGED
@@ -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
|
17
|
-
nodes policies policy_groups roles sandboxes
|
18
|
-
TOP_DATA_TYPES = %w
|
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] ==
|
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] ==
|
67
|
-
if acl_data_path[1] ==
|
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] ==
|
73
|
-
if acl_data_path[3] ==
|
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] ==
|
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
|
-
|
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
|
118
|
-
|
117
|
+
if acl_data_path == %w{acls containers containers}
|
118
|
+
%w{acls root}
|
119
119
|
else
|
120
|
-
[
|
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
|
-
|
129
|
+
%w{acls root}
|
130
130
|
elsif data_types.include?(path[0])
|
131
131
|
if path.size == 0
|
132
|
-
[
|
132
|
+
[ "acls", "containers", path[0] ]
|
133
133
|
elsif path.size == 2
|
134
|
-
[
|
134
|
+
[ "acls", path[0], path[1] ]
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
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 ==
|
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] =
|
22
|
+
result[:json_class] = "Chef::CookbookVersion"
|
23
23
|
result[:cookbook_name] = name
|
24
24
|
result[:version] = result[:metadata][:version]
|
25
|
-
result[:chef_type] =
|
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,
|
35
|
+
if has_child(directory, "metadata.rb")
|
36
36
|
begin
|
37
|
-
file = filename(directory,
|
38
|
-
metadata.instance_eval(read_file(directory,
|
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,
|
43
|
-
metadata.from_json(read_file(directory,
|
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
|
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,
|
149
|
-
:definitions => load_child_files(directory,
|
150
|
-
:recipes => load_child_files(directory,
|
151
|
-
:libraries => load_child_files(directory,
|
152
|
-
:templates => load_child_files(directory,
|
153
|
-
:files => load_child_files(directory,
|
154
|
-
:resources => load_child_files(directory,
|
155
|
-
:providers => load_child_files(directory,
|
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 =>
|
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
|
2
|
-
require
|
3
|
-
require
|
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][
|
12
|
-
acls[perm][
|
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[
|
19
|
-
client[
|
20
|
-
client[
|
21
|
-
client[
|
22
|
-
client[
|
23
|
-
client[
|
24
|
-
client[
|
25
|
-
client[
|
26
|
-
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(
|
32
|
-
container[
|
33
|
-
container[
|
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[
|
40
|
-
user[
|
41
|
-
user[
|
42
|
-
user[
|
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 ==
|
45
|
-
user.delete(
|
46
|
-
user.delete(
|
47
|
-
user.delete(
|
44
|
+
if method == "GET"
|
45
|
+
user.delete("admin")
|
46
|
+
user.delete("password")
|
47
|
+
user.delete("openid")
|
48
48
|
end
|
49
|
-
user[
|
50
|
-
user[
|
51
|
-
user[
|
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 ==
|
57
|
+
if method == "DELETE"
|
58
58
|
# TODO SERIOUSLY, WHO DOES THIS MANY EXCEPTIONS IN THEIR INTERFACE
|
59
|
-
if !(data_bag_item[
|
60
|
-
data_bag_item[
|
61
|
-
data_bag_item = {
|
62
|
-
data_bag_item[
|
63
|
-
data_bag_item[
|
64
|
-
data_bag_item[
|
65
|
-
data_bag_item[
|
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[
|
70
|
-
data_bag_item = data_bag_item[
|
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
|
74
|
-
data_bag_item[
|
75
|
-
data_bag_item[
|
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[
|
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 !=
|
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?(
|
90
|
-
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"]])
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
|
-
cookbook[
|
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[
|
99
|
-
cookbook[
|
100
|
-
cookbook[
|
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[
|
106
|
-
cookbook[
|
107
|
-
cookbook[
|
108
|
-
cookbook[
|
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(
|
112
|
+
cookbook.delete("json_class")
|
113
113
|
else
|
114
|
-
cookbook[
|
115
|
-
cookbook[
|
114
|
+
cookbook["cookbook_name"] ||= name
|
115
|
+
cookbook["json_class"] ||= "Chef::CookbookVersion"
|
116
116
|
end
|
117
117
|
|
118
|
-
cookbook[
|
119
|
-
if method ==
|
120
|
-
cookbook[
|
121
|
-
cookbook[
|
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[
|
128
|
-
environment[
|
129
|
-
environment[
|
130
|
-
environment[
|
131
|
-
environment[
|
132
|
-
environment[
|
133
|
-
environment[
|
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(
|
139
|
-
if group[
|
140
|
-
group[
|
141
|
-
group[
|
142
|
-
group[
|
143
|
-
group[
|
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[
|
146
|
-
group[
|
147
|
-
group[
|
148
|
-
group[
|
149
|
-
group[
|
150
|
-
group[
|
151
|
-
group[
|
152
|
-
|
153
|
-
group[
|
154
|
-
group[
|
155
|
-
group[
|
156
|
-
group[
|
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[
|
162
|
-
node[
|
163
|
-
node[
|
164
|
-
node[
|
165
|
-
node[
|
166
|
-
node[
|
167
|
-
node[
|
168
|
-
node[
|
169
|
-
node[
|
170
|
-
node[
|
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[
|
176
|
-
policy[
|
177
|
-
policy[
|
178
|
-
policy[
|
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] ||=
|
184
|
-
policy_group[
|
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[
|
190
|
-
org[
|
191
|
-
org[
|
192
|
-
org[
|
193
|
-
org[
|
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[
|
199
|
-
role[
|
200
|
-
role[
|
201
|
-
role[
|
202
|
-
role[
|
203
|
-
role[
|
204
|
-
role[
|
205
|
-
role[
|
206
|
-
role[
|
207
|
-
role[
|
208
|
-
role[
|
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
|