chef-zero 0.9.9 → 0.9.11
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.
- data/bin/chef-zero +6 -0
- data/lib/chef_zero/cookbook_data.rb +74 -2
- data/lib/chef_zero/rest_router.rb +18 -7
- data/lib/chef_zero/server.rb +1 -0
- data/lib/chef_zero/version.rb +1 -1
- metadata +2 -3
- data/lib/chef_zero/chef/cookbook/metadata.rb +0 -30
data/bin/chef-zero
CHANGED
@@ -18,13 +18,19 @@ OptionParser.new do |opts|
|
|
18
18
|
opts.on("-H", "--host HOST", "Host to bind to (default: 127.0.0.1)") do |value|
|
19
19
|
options[:host] = value
|
20
20
|
end
|
21
|
+
|
21
22
|
opts.on("-p", "--port PORT", Integer, "Port to listen on") do |value|
|
22
23
|
options[:port] = value
|
23
24
|
end
|
25
|
+
|
24
26
|
opts.on("--[no-]generate-keys", "Whether to generate actual keys or fake it (faster). Default: false.") do |value|
|
25
27
|
options[:generate_real_keys] = value
|
26
28
|
end
|
27
29
|
|
30
|
+
opts.on("-d", "--debug", "Show requests and debugging output") do |value|
|
31
|
+
options[:debug] = true
|
32
|
+
end
|
33
|
+
|
28
34
|
opts.on_tail("-h", "--help", "Show this message") do
|
29
35
|
puts opts
|
30
36
|
exit
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'digest/md5'
|
2
|
-
require '
|
2
|
+
require 'hashie/mash'
|
3
3
|
|
4
4
|
module ChefZero
|
5
5
|
module CookbookData
|
@@ -29,8 +29,80 @@ module ChefZero
|
|
29
29
|
attr_reader :name, :fully_qualified_recipe_names
|
30
30
|
end
|
31
31
|
|
32
|
+
# Handles loading configuration values from a Chef config file
|
33
|
+
#
|
34
|
+
# @author Justin Campbell <justin.campbell@riotgames.com>
|
35
|
+
class PretendCookbookMetadata < Hash
|
36
|
+
# @param [String] path
|
37
|
+
def initialize(cookbook)
|
38
|
+
self.name(cookbook.name)
|
39
|
+
self.recipes(cookbook.fully_qualified_recipe_names)
|
40
|
+
%w(dependencies supports recommendations suggestions conflicting providing replacing recipes).each do |cookbook_arg|
|
41
|
+
self[cookbook_arg.to_sym] = Hashie::Mash.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def from_json(filepath)
|
46
|
+
self.merge!(JSON.parse(File.read(filepath)))
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def depends(cookbook, *version_constraints)
|
52
|
+
cookbook_arg(:dependencies, cookbook, version_constraints)
|
53
|
+
end
|
54
|
+
|
55
|
+
def supports(cookbook, *version_constraints)
|
56
|
+
cookbook_arg(:supports, cookbook, version_constraints)
|
57
|
+
end
|
58
|
+
|
59
|
+
def recommends(cookbook, *version_constraints)
|
60
|
+
cookbook_arg(:recommendations, cookbook, version_constraints)
|
61
|
+
end
|
62
|
+
|
63
|
+
def suggests(cookbook, *version_constraints)
|
64
|
+
cookbook_arg(:suggestions, cookbook, version_constraints)
|
65
|
+
end
|
66
|
+
|
67
|
+
def conflicts(cookbook, *version_constraints)
|
68
|
+
cookbook_arg(:conflicting, cookbook, version_constraints)
|
69
|
+
end
|
70
|
+
|
71
|
+
def provides(cookbook, *version_constraints)
|
72
|
+
cookbook_arg(:providing, cookbook, version_constraints)
|
73
|
+
end
|
74
|
+
|
75
|
+
def replaces(cookbook, *version_constraints)
|
76
|
+
cookbook_arg(:replacing, cookbook, version_constraints)
|
77
|
+
end
|
78
|
+
|
79
|
+
def recipe(recipe, description)
|
80
|
+
self[:recipes][recipe] = description
|
81
|
+
end
|
82
|
+
|
83
|
+
def attribute(name, options)
|
84
|
+
self[:attributes][name] = options
|
85
|
+
end
|
86
|
+
|
87
|
+
def grouping(name, options)
|
88
|
+
self[:grouping][name] = options
|
89
|
+
end
|
90
|
+
|
91
|
+
def cookbook_arg(key, cookbook, version_constraints)
|
92
|
+
self[key][cookbook] = version_constraints.first || ">= 0.0.0"
|
93
|
+
end
|
94
|
+
|
95
|
+
def method_missing(key, value = nil)
|
96
|
+
if value.nil?
|
97
|
+
self[key.to_sym]
|
98
|
+
else
|
99
|
+
store key.to_sym, value
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
32
104
|
def self.metadata_from(directory, name, version, recipe_names)
|
33
|
-
metadata =
|
105
|
+
metadata = PretendCookbookMetadata.new(PretendCookbook.new(name, recipe_names))
|
34
106
|
# If both .rb and .json exist, read .rb
|
35
107
|
# TODO if recipes has 3 recipes in it, and the Ruby/JSON has only one, should
|
36
108
|
# the resulting recipe list have 1, or 3-4 recipes in it?
|
@@ -12,18 +12,29 @@ module ChefZero
|
|
12
12
|
|
13
13
|
def call(request)
|
14
14
|
begin
|
15
|
-
ChefZero::Log.debug
|
15
|
+
ChefZero::Log.debug(request)
|
16
|
+
|
16
17
|
clean_path = "/" + request.rest_path.join("/")
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
|
19
|
+
response = find_endpoint(clean_path).call(request)
|
20
|
+
ChefZero::Log.debug([
|
21
|
+
"",
|
22
|
+
"--- RESPONSE (#{response[0]}) ---",
|
23
|
+
response[2],
|
24
|
+
"--- END RESPONSE ---",
|
25
|
+
].join("\n"))
|
26
|
+
return response
|
23
27
|
rescue
|
24
28
|
ChefZero::Log.error("#{$!.inspect}\n#{$!.backtrace.join("\n")}")
|
25
29
|
[500, {"Content-Type" => "text/plain"}, "Exception raised! #{$!.inspect}\n#{$!.backtrace.join("\n")}"]
|
26
30
|
end
|
27
31
|
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def find_endpoint(clean_path)
|
36
|
+
_, endpoint = routes.find { |route, endpoint| route.match(clean_path) }
|
37
|
+
endpoint || not_found
|
38
|
+
end
|
28
39
|
end
|
29
40
|
end
|
data/lib/chef_zero/server.rb
CHANGED
@@ -59,6 +59,7 @@ module ChefZero
|
|
59
59
|
options[:host] ||= '127.0.0.1'
|
60
60
|
options[:port] ||= 80
|
61
61
|
options[:generate_real_keys] = true if !options.has_key?(:generate_real_keys)
|
62
|
+
ChefZero::Log.level = :debug if options.has_key?(:debug)
|
62
63
|
thin_options = {}
|
63
64
|
thin_options[:signals] = options[:signals] if options.has_key?(:signals)
|
64
65
|
@server = Thin::Server.new(options[:host], options[:port], make_app, thin_options)
|
data/lib/chef_zero/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|
@@ -88,7 +88,6 @@ files:
|
|
88
88
|
- LICENSE
|
89
89
|
- README.rdoc
|
90
90
|
- Rakefile
|
91
|
-
- lib/chef_zero/chef/cookbook/metadata.rb
|
92
91
|
- lib/chef_zero/cookbook_data.rb
|
93
92
|
- lib/chef_zero/core_ext/hash.rb
|
94
93
|
- lib/chef_zero/core_ext.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Chef
|
3
|
-
module Cookbook
|
4
|
-
# Handles loading configuration values from a Chef config file
|
5
|
-
#
|
6
|
-
# @author Justin Campbell <justin.campbell@riotgames.com>
|
7
|
-
class Metadata < Hash
|
8
|
-
# @param [String] path
|
9
|
-
def initialize(cookbook)
|
10
|
-
self.name(cookbook.name)
|
11
|
-
self.recipes(cookbook.fully_qualified_recipe_names)
|
12
|
-
end
|
13
|
-
|
14
|
-
def from_json(filepath)
|
15
|
-
self.merge!(JSON.parse(File.read(filepath)))
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def method_missing(key, value = nil)
|
21
|
-
if value.nil?
|
22
|
-
self[key.to_sym]
|
23
|
-
else
|
24
|
-
store key.to_sym, value
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|