chef-zero 0.9.11 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +145 -0
- data/Rakefile +4 -15
- data/bin/chef-zero +5 -8
- data/lib/chef_zero.rb +2 -3
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +1 -2
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +1 -2
- data/lib/chef_zero/endpoints/cookbooks_base.rb +3 -4
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +3 -4
- data/lib/chef_zero/rspec.rb +0 -1
- data/lib/chef_zero/server.rb +68 -39
- data/lib/chef_zero/version.rb +1 -1
- data/spec/run.rb +25 -0
- data/spec/support/pedant.rb +117 -0
- data/spec/support/stickywicket.pem +27 -0
- metadata +26 -25
- data/README.rdoc +0 -79
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
Chef Zero
|
2
|
+
=========
|
3
|
+
|
4
|
+
Description
|
5
|
+
-----------
|
6
|
+
Chef Zero is a simple, easy-install, in-memory Chef server that can be useful
|
7
|
+
for Chef Client testing and chef-solo-like tasks that require a full Chef
|
8
|
+
Cerver. It IS intended to be simple, Chef 11 compliant, easy to run and fast
|
9
|
+
to start. It is NOT intended to be secure, scalable, performant or persistent.
|
10
|
+
It does NO input validation, authentication or authorization (it will not
|
11
|
+
throw a 400, 401 or 403). It does not save data, and will start up empty each
|
12
|
+
time you start it.
|
13
|
+
|
14
|
+
Because Chef Zero runs in memory, it's super fast and lightweight. This makes
|
15
|
+
it perfect for testing against a "real" Chef Server without mocking the
|
16
|
+
entire Internet.
|
17
|
+
|
18
|
+
|
19
|
+
Installation
|
20
|
+
------------
|
21
|
+
This server can be installed as a Ruby Gem.
|
22
|
+
|
23
|
+
$ gem install chef-zero
|
24
|
+
|
25
|
+
If you're using bundler, add `chef-zero` as a development dependency:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
group :development do
|
29
|
+
gem 'chef-zero'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Or in a `.gemspec`
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
s.add_development_dependency 'chef-zero'
|
37
|
+
```
|
38
|
+
|
39
|
+
You can also clone the source repository and install it using `rake install`.
|
40
|
+
|
41
|
+
Usage
|
42
|
+
-----
|
43
|
+
One of chef-zero's primary uses is as a small test server for people writing and
|
44
|
+
testing clients. Here's a simple example of starting it up:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
require 'chef_zero/server'
|
48
|
+
server = ChefZero::Server.new(port: 4000)
|
49
|
+
server.start
|
50
|
+
```
|
51
|
+
|
52
|
+
This will create a server instance in the foreground. To stop the server:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
server.stop
|
56
|
+
```
|
57
|
+
|
58
|
+
This is great for debugging and logging requests, but you'll probably want
|
59
|
+
to run this in the background so you have full control of your thread.
|
60
|
+
|
61
|
+
To run Chef Zero in the background, simply issue the `start_background` command:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
require 'chef_zero/server'
|
65
|
+
server = ChefZero::Server.new(port: 4000)
|
66
|
+
server.start_background
|
67
|
+
```
|
68
|
+
|
69
|
+
You can stop the server the same way:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
server.stop
|
73
|
+
```
|
74
|
+
|
75
|
+
### Valid Options
|
76
|
+
You may currently pass the following options to the initializer:
|
77
|
+
|
78
|
+
- `host` - the host to run on (Default: '127.0.0.1')
|
79
|
+
- `port` - the port to run on (Default: 8889)
|
80
|
+
- `debug` - run in debug mode to see all requests and responses (Default: false)
|
81
|
+
|
82
|
+
|
83
|
+
CLI (Comand Line)
|
84
|
+
-----------------
|
85
|
+
If you don't want to use Chef Zero as a library, you can simply start an instance
|
86
|
+
with the included `chef-zero` executable:
|
87
|
+
|
88
|
+
$ chef-zero
|
89
|
+
|
90
|
+
Note, this will run in the foreground.
|
91
|
+
|
92
|
+
You now have a fully functional (empty) Chef Server running.
|
93
|
+
|
94
|
+
To try it out, go into the `chef-zero/playground` directory and run `knife`. It
|
95
|
+
will behave the same as a normal Chef Server, and all normal knife commands will
|
96
|
+
work (show, list, delete, from file, upload, download, diff ...). For example,
|
97
|
+
with +knife-essentials+ (or Chef 11) you can upload everything in the repo:
|
98
|
+
|
99
|
+
chef-zero/playground> knife upload .
|
100
|
+
Created remote/cookbooks/blah
|
101
|
+
Created remote/cookbooks/blork
|
102
|
+
Created remote/data_bags/foo/
|
103
|
+
Created remote/data_bags/foo/bar.json
|
104
|
+
Created remote/data_bags/foo/baz.json
|
105
|
+
Created remote/data_bags/foo/blarghle.json
|
106
|
+
Created remote/data_bags/foom/
|
107
|
+
Created remote/data_bags/foom/x.json
|
108
|
+
Created remote/data_bags/widdle/
|
109
|
+
Created remote/data_bags/widdle/blank.json
|
110
|
+
Created remote/data_bags/widdle/wow.json
|
111
|
+
Created remote/environments/desert.json
|
112
|
+
Created remote/environments/rainforest.json
|
113
|
+
Created remote/environments/semi_arid_plains.json
|
114
|
+
|
115
|
+
chef-zero/playground> knife environment list
|
116
|
+
_default
|
117
|
+
desert
|
118
|
+
rainforest
|
119
|
+
semi_arid_plains
|
120
|
+
|
121
|
+
To use it in your own repository, create a `knife.rb` like so:
|
122
|
+
|
123
|
+
chef_server_url 'http://127.0.0.1:8889'
|
124
|
+
node_name 'stickywicket'
|
125
|
+
client_key 'path_to_any_pem_file.pem'
|
126
|
+
|
127
|
+
And use knife like you normally would.
|
128
|
+
|
129
|
+
Since Chef Zero does no authentication, any `.pem` file will do. The client just
|
130
|
+
needs something to sign requests with (which will be ignored on the server). Even
|
131
|
+
though it's ignored, the `.pem` must still be a valid format.
|
132
|
+
|
133
|
+
Now, stop the Chef Zero server and all the data is gone!
|
134
|
+
|
135
|
+
Run `chef-zero --help` to see a list of the supported flags and options:
|
136
|
+
|
137
|
+
```text
|
138
|
+
Usage: chef-zero [ARGS]
|
139
|
+
-H, --host HOST Host to bind to (default: 127.0.0.1)
|
140
|
+
-p, --port PORT Port to listen on
|
141
|
+
--[no-]generate-keys Whether to generate actual keys or fake it (faster). Default: false.
|
142
|
+
-d, --debug Show requests and debugging output
|
143
|
+
-h, --help Show this message
|
144
|
+
--version Show version
|
145
|
+
```
|
data/Rakefile
CHANGED
@@ -1,19 +1,8 @@
|
|
1
1
|
require 'bundler'
|
2
|
-
require '
|
3
|
-
require 'rubygems/package_task'
|
4
|
-
require 'rdoc/task'
|
2
|
+
require 'bundler/gem_tasks'
|
5
3
|
|
6
|
-
|
4
|
+
require 'chef_zero/version'
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
RDoc::Task.new do |rdoc|
|
11
|
-
rdoc.rdoc_dir = 'rdoc'
|
12
|
-
rdoc.title = "chef-zero #{gem_spec.version}"
|
13
|
-
rdoc.rdoc_files.include('README*')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
|
-
|
17
|
-
task :test do
|
18
|
-
sh "cd test && ruby run-pedant.rb"
|
6
|
+
task :spec do
|
7
|
+
sh 'ruby spec/run.rb'
|
19
8
|
end
|
data/bin/chef-zero
CHANGED
@@ -7,11 +7,8 @@ require 'chef_zero/version'
|
|
7
7
|
require 'chef_zero/server'
|
8
8
|
require 'optparse'
|
9
9
|
|
10
|
-
options = {
|
11
|
-
|
12
|
-
:port => 8889,
|
13
|
-
:generate_real_keys => false
|
14
|
-
}
|
10
|
+
options = {}
|
11
|
+
|
15
12
|
OptionParser.new do |opts|
|
16
13
|
opts.banner = "Usage: chef-zero [ARGS]"
|
17
14
|
|
@@ -27,8 +24,8 @@ OptionParser.new do |opts|
|
|
27
24
|
options[:generate_real_keys] = value
|
28
25
|
end
|
29
26
|
|
30
|
-
opts.on("-
|
31
|
-
options[:
|
27
|
+
opts.on("-l", "--log-level LEVEL", "Set the output log level") do |value|
|
28
|
+
options[:log_level] = value
|
32
29
|
end
|
33
30
|
|
34
31
|
opts.on_tail("-h", "--help", "Show this message") do
|
@@ -43,4 +40,4 @@ OptionParser.new do |opts|
|
|
43
40
|
end.parse!
|
44
41
|
|
45
42
|
server = ChefZero::Server.new(options)
|
46
|
-
server.start
|
43
|
+
server.start(:publish => true)
|
data/lib/chef_zero.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require 'chef_zero/core_ext'
|
2
|
-
|
3
1
|
module ChefZero
|
4
|
-
|
2
|
+
require 'chef_zero/core_ext'
|
3
|
+
require 'chef_zero/log'
|
5
4
|
|
6
5
|
CERTIFICATE = "-----BEGIN CERTIFICATE-----\nMIIDMzCCApygAwIBAgIBATANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMCVVMx\nEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxFjAUBgNVBAoM\nDU9wc2NvZGUsIEluYy4xHDAaBgNVBAsME0NlcnRpZmljYXRlIFNlcnZpY2UxMjAw\nBgNVBAMMKW9wc2NvZGUuY29tL2VtYWlsQWRkcmVzcz1hdXRoQG9wc2NvZGUuY29t\nMB4XDTEyMTEyMTAwMzQyMVoXDTIyMTExOTAwMzQyMVowgZsxEDAOBgNVBAcTB1Nl\nYXR0bGUxEzARBgNVBAgTCldhc2hpbmd0b24xCzAJBgNVBAYTAlVTMRwwGgYDVQQL\nExNDZXJ0aWZpY2F0ZSBTZXJ2aWNlMRYwFAYDVQQKEw1PcHNjb2RlLCBJbmMuMS8w\nLQYDVQQDFCZVUkk6aHR0cDovL29wc2NvZGUuY29tL0dVSURTL3VzZXJfZ3VpZDCC\nASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANLDmPbR71bS2esZlZh/HfC6\n0azXFjl2677wq2ovk9xrUb0Ui4ZLC66TqQ9C/RBzOjXU4TRf3hgPTqvlCgHusl0d\nIcLCrsSl6kPEhJpYWWfRoroIAwf82A9yLQekhqXZEXu5EKkwoUMqyF6m0ZCasaE1\ny8niQxdLAsk3ady/CGQlFqHTPKFfU5UASR2LRtYC1MCIvJHDFRKAp9kPJbQo9P37\nZ8IU7cDudkZFgNLmDixlWsh7C0ghX8fgAlj1P6FgsFufygam973k79GhIP54dELB\nc0S6E8ekkRSOXU9jX/IoiXuFglBvFihAdhvED58bMXzj2AwXUyeAlxItnvs+NVUC\nAwEAATANBgkqhkiG9w0BAQUFAAOBgQBkFZRbMoywK3hb0/X7MXmPYa7nlfnd5UXq\nr2n32ettzZNmEPaI2d1j+//nL5qqhOlrWPS88eKEPnBOX/jZpUWOuAAddnrvFzgw\nrp/C2H7oMT+29F+5ezeViLKbzoFYb4yECHBoi66IFXNae13yj7taMboBeUmE664G\nTB/MZpRr8g==\n-----END CERTIFICATE-----\n"
|
7
6
|
PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0sOY9tHvVtLZ6xmVmH8d\n8LrRrNcWOXbrvvCrai+T3GtRvRSLhksLrpOpD0L9EHM6NdThNF/eGA9Oq+UKAe6y\nXR0hwsKuxKXqQ8SEmlhZZ9GiuggDB/zYD3ItB6SGpdkRe7kQqTChQyrIXqbRkJqx\noTXLyeJDF0sCyTdp3L8IZCUWodM8oV9TlQBJHYtG1gLUwIi8kcMVEoCn2Q8ltCj0\n/ftnwhTtwO52RkWA0uYOLGVayHsLSCFfx+ACWPU/oWCwW5/KBqb3veTv0aEg/nh0\nQsFzRLoTx6SRFI5dT2Nf8iiJe4WCUG8WKEB2G8QPnxsxfOPYDBdTJ4CXEi2e+z41\nVQIDAQAB\n-----END PUBLIC KEY-----\n"
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'chef_zero/endpoints/cookbooks_base'
|
2
|
-
require 'solve'
|
3
2
|
|
4
3
|
module ChefZero
|
5
4
|
module Endpoints
|
@@ -32,7 +31,7 @@ module ChefZero
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def latest_version(versions)
|
35
|
-
sorted = versions.sort_by { |version|
|
34
|
+
sorted = versions.sort_by { |version| Gem::Version.new(version.dup) }
|
36
35
|
sorted[-1]
|
37
36
|
end
|
38
37
|
end
|
@@ -2,7 +2,6 @@ require 'json'
|
|
2
2
|
require 'chef_zero/endpoints/rest_object_endpoint'
|
3
3
|
require 'chef_zero/rest_error_response'
|
4
4
|
require 'chef_zero/data_normalizer'
|
5
|
-
require 'solve'
|
6
5
|
|
7
6
|
module ChefZero
|
8
7
|
module Endpoints
|
@@ -99,7 +98,7 @@ module ChefZero
|
|
99
98
|
end
|
100
99
|
|
101
100
|
def latest_version(versions)
|
102
|
-
sorted = versions.sort_by { |version|
|
101
|
+
sorted = versions.sort_by { |version| Gem::Version.new(version.dup) }
|
103
102
|
sorted[-1]
|
104
103
|
end
|
105
104
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'chef_zero/rest_base'
|
3
3
|
require 'chef_zero/data_normalizer'
|
4
|
-
require 'solve'
|
5
4
|
|
6
5
|
module ChefZero
|
7
6
|
module Endpoints
|
@@ -26,11 +25,11 @@ module ChefZero
|
|
26
25
|
|
27
26
|
def filter_cookbooks(cookbooks_list, constraints = {}, num_versions = nil)
|
28
27
|
cookbooks_list.keys.sort.each do |name|
|
29
|
-
constraint =
|
28
|
+
constraint = Gem::Requirement.new(constraints[name])
|
30
29
|
versions = []
|
31
|
-
cookbooks_list[name].keys.sort_by { |version|
|
30
|
+
cookbooks_list[name].keys.sort_by { |version| Gem::Version.new(version.dup) }.reverse.each do |version|
|
32
31
|
break if num_versions && versions.size >= num_versions
|
33
|
-
if constraint.
|
32
|
+
if constraint.satisfied_by?(Gem::Version.new(version.dup))
|
34
33
|
versions << version
|
35
34
|
end
|
36
35
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'chef_zero/rest_base'
|
3
3
|
require 'chef_zero/rest_error_response'
|
4
|
-
require 'solve'
|
5
4
|
|
6
5
|
module ChefZero
|
7
6
|
module Endpoints
|
@@ -98,15 +97,15 @@ module ChefZero
|
|
98
97
|
end
|
99
98
|
|
100
99
|
def sort_versions(versions)
|
101
|
-
result = versions.sort_by { |version|
|
100
|
+
result = versions.sort_by { |version| Gem::Version.new(version.dup) }
|
102
101
|
result.reverse
|
103
102
|
end
|
104
103
|
|
105
104
|
def filter_by_constraint(versions, cookbook_name, constraint)
|
106
105
|
return versions if !constraint
|
107
|
-
constraint =
|
106
|
+
constraint = Gem::Requirement.new(constraint)
|
108
107
|
new_versions = versions[cookbook_name]
|
109
|
-
new_versions = new_versions.select { |version| constraint.
|
108
|
+
new_versions = new_versions.select { |version| constraint.satisfied_by?(Gem::Version.new(version)) }
|
110
109
|
result = versions.clone
|
111
110
|
result[cookbook_name] = new_versions
|
112
111
|
result
|
data/lib/chef_zero/rspec.rb
CHANGED
@@ -29,7 +29,6 @@ module ChefZero
|
|
29
29
|
before :each do
|
30
30
|
unless ChefZero::RSpec.server
|
31
31
|
# Set up configuration so that clients will point to the server
|
32
|
-
Thin::Logging.silent = true
|
33
32
|
ChefZero::RSpec.server = ChefZero::Server.new(:port => 8889, :signals => false, :log_requests => true)
|
34
33
|
ChefZero::RSpec.client_key = Tempfile.new(['chef_zero_client_key', '.pem'])
|
35
34
|
ChefZero::RSpec.client_key.write(ChefZero::PRIVATE_KEY)
|
data/lib/chef_zero/server.rb
CHANGED
@@ -16,13 +16,15 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require 'rubygems'
|
20
|
-
require 'thin'
|
21
19
|
require 'openssl'
|
22
|
-
require '
|
23
|
-
require '
|
20
|
+
require 'puma'
|
21
|
+
require 'rubygems'
|
24
22
|
require 'timeout'
|
23
|
+
|
24
|
+
require 'chef_zero'
|
25
25
|
require 'chef_zero/cookbook_data'
|
26
|
+
require 'chef_zero/rest_router'
|
27
|
+
require 'chef_zero/version'
|
26
28
|
|
27
29
|
require 'chef_zero/endpoints/authenticate_user_endpoint'
|
28
30
|
require 'chef_zero/endpoints/actors_endpoint'
|
@@ -54,69 +56,86 @@ require 'chef_zero/endpoints/not_found_endpoint'
|
|
54
56
|
|
55
57
|
module ChefZero
|
56
58
|
class Server
|
59
|
+
DEFAULT_OPTIONS = {
|
60
|
+
:host => '127.0.0.1',
|
61
|
+
:port => 8889,
|
62
|
+
:log_level => :info,
|
63
|
+
:generate_real_keys => true
|
64
|
+
}.freeze
|
65
|
+
|
57
66
|
def initialize(options = {})
|
58
|
-
|
59
|
-
options[:host]
|
60
|
-
options[:port] ||= 80
|
61
|
-
options[:generate_real_keys] = true if !options.has_key?(:generate_real_keys)
|
62
|
-
ChefZero::Log.level = :debug if options.has_key?(:debug)
|
63
|
-
thin_options = {}
|
64
|
-
thin_options[:signals] = options[:signals] if options.has_key?(:signals)
|
65
|
-
@server = Thin::Server.new(options[:host], options[:port], make_app, thin_options)
|
67
|
+
options = DEFAULT_OPTIONS.merge(options)
|
68
|
+
@url = "http://#{options[:host]}:#{options[:port]}"
|
66
69
|
@generate_real_keys = options[:generate_real_keys]
|
70
|
+
|
71
|
+
ChefZero::Log.level = options[:log_level].to_sym
|
72
|
+
|
73
|
+
@server = Puma::Server.new(make_app, Puma::Events.new(STDERR, STDOUT))
|
74
|
+
@server.add_tcp_listener(options[:host], options[:port])
|
75
|
+
|
67
76
|
clear_data
|
68
77
|
end
|
69
78
|
|
70
79
|
attr_reader :server
|
71
80
|
attr_reader :data
|
72
|
-
attr_reader :
|
73
|
-
attr_reader :generate_real_keys
|
81
|
+
attr_reader :url
|
74
82
|
|
75
83
|
include ChefZero::Endpoints
|
76
84
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
85
|
+
def start(options = {})
|
86
|
+
if options[:publish]
|
87
|
+
puts ">> Starting Chef Zero (v#{ChefZero::VERSION})..."
|
88
|
+
puts ">> Puma (v#{Puma::Const::PUMA_VERSION}) is listening at #{url}"
|
89
|
+
puts ">> Press CTRL+C to stop"
|
90
|
+
end
|
80
91
|
|
81
|
-
|
82
|
-
|
92
|
+
begin
|
93
|
+
thread = server.run.join
|
94
|
+
rescue Object, Interrupt
|
95
|
+
puts "\n>> Stopping Puma..."
|
96
|
+
server.stop(true) if running?
|
97
|
+
end
|
83
98
|
end
|
84
99
|
|
85
|
-
def start_background(
|
86
|
-
@thread = Thread.new
|
100
|
+
def start_background(wait = 5)
|
101
|
+
@thread = Thread.new {
|
87
102
|
begin
|
88
|
-
|
103
|
+
start
|
89
104
|
rescue
|
90
105
|
@server_error = $!
|
91
106
|
ChefZero::Log.error("#{$!.message}\n#{$!.backtrace.join("\n")}")
|
92
107
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
108
|
+
}
|
109
|
+
|
110
|
+
# Wait x seconds to make sure the server actually started
|
111
|
+
Timeout::timeout(wait) {
|
112
|
+
sleep(0.01) until running? || @server_error
|
98
113
|
raise @server_error if @server_error
|
99
|
-
|
114
|
+
}
|
115
|
+
|
116
|
+
# Give the user the thread, just in case they want it
|
117
|
+
@thread
|
100
118
|
end
|
101
119
|
|
102
120
|
def running?
|
103
|
-
server.running
|
121
|
+
!!server.running
|
104
122
|
end
|
105
123
|
|
106
|
-
def stop(
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
rescue
|
112
|
-
ChefZero::Log.error("Server did not stop within #{timeout}s. Killing.")
|
113
|
-
@thread.kill if @thread
|
114
|
-
@thread = nil
|
124
|
+
def stop(wait = 5)
|
125
|
+
if @thread
|
126
|
+
@thread.join(wait)
|
127
|
+
else
|
128
|
+
server.stop(true)
|
115
129
|
end
|
130
|
+
rescue
|
131
|
+
ChefZero::Log.error "Server did not stop within #{wait} seconds. Killing..."
|
132
|
+
@thread.kill if @thread
|
133
|
+
ensure
|
134
|
+
@thread = nil
|
116
135
|
end
|
117
136
|
|
118
137
|
def gen_key_pair
|
119
|
-
if generate_real_keys
|
138
|
+
if generate_real_keys?
|
120
139
|
private_key = OpenSSL::PKey::RSA.new(2048)
|
121
140
|
public_key = private_key.public_key.to_s
|
122
141
|
public_key.sub!(/^-----BEGIN RSA PUBLIC KEY-----/, '-----BEGIN PUBLIC KEY-----')
|
@@ -270,6 +289,12 @@ module ChefZero
|
|
270
289
|
if @on_response_proc
|
271
290
|
@on_response_proc.call(request, response)
|
272
291
|
end
|
292
|
+
|
293
|
+
# Puma expects the response to be an array (chunked responses). Since
|
294
|
+
# we are statically generating data, we won't ever have said chunked
|
295
|
+
# response, so fake it.
|
296
|
+
response[-1] = Array(response[-1])
|
297
|
+
|
273
298
|
response
|
274
299
|
end
|
275
300
|
end
|
@@ -289,5 +314,9 @@ module ChefZero
|
|
289
314
|
end
|
290
315
|
value
|
291
316
|
end
|
317
|
+
|
318
|
+
def generate_real_keys?
|
319
|
+
!!@generate_real_keys
|
320
|
+
end
|
292
321
|
end
|
293
322
|
end
|
data/lib/chef_zero/version.rb
CHANGED
data/spec/run.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'bundler'
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
require 'chef_zero/server'
|
6
|
+
require 'rspec/core'
|
7
|
+
|
8
|
+
require 'pedant'
|
9
|
+
require 'pedant/opensource'
|
10
|
+
|
11
|
+
server = ChefZero::Server.new(:port => 8889)
|
12
|
+
server.start_background
|
13
|
+
|
14
|
+
Pedant.config.suite = 'api'
|
15
|
+
Pedant.config[:config_file] = 'spec/support/pedant.rb'
|
16
|
+
Pedant.setup([
|
17
|
+
'--skip-validation',
|
18
|
+
'--skip-authentication',
|
19
|
+
'--skip-authorization'
|
20
|
+
])
|
21
|
+
|
22
|
+
result = RSpec::Core::Runner.run(Pedant.config.rspec_args)
|
23
|
+
|
24
|
+
server.stop
|
25
|
+
exit(result)
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Copyright: Copyright (c) 2012 Opscode, Inc.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# This annotated Pedant configuration file details the various
|
17
|
+
# configuration settings available to you. It is separate from the
|
18
|
+
# actual Pedant::Config class because not all settings have sane
|
19
|
+
# defaults, and not all settings are appropriate in all settings.
|
20
|
+
|
21
|
+
################################################################################
|
22
|
+
# You MUST specify the address of the server the API requests will be
|
23
|
+
# sent to. Only specify protocol, hostname, and port.
|
24
|
+
chef_server 'http://127.0.0.1:8889'
|
25
|
+
|
26
|
+
# If you are doing development testing, you can specify the address of
|
27
|
+
# the Solr server. The presence of this parameter will enable tests
|
28
|
+
# to force commits to Solr, greatly decreasing the amout of time
|
29
|
+
# needed for testing the search endpoint. This is only an
|
30
|
+
# optimization for development! If you are testing a "live" Chef
|
31
|
+
# Server, or otherwise do not have access to the Solr server from your
|
32
|
+
# testing location, you should not specify a value for this parameter.
|
33
|
+
# The tests will still run, albeit slower, as they will now need to
|
34
|
+
# poll for a period to ensure they are querying committed results.
|
35
|
+
#search_server "http://localhost:8983"
|
36
|
+
|
37
|
+
# Related to the 'search_server' parameter, this specifies the maximum
|
38
|
+
# amout of time (in seconds) that search endpoint requests should be
|
39
|
+
# retried before giving up. If not explicitly set, it will default to
|
40
|
+
# 65 seconds; only set it if you know that your Solr commit interval
|
41
|
+
# differs significantly from this.
|
42
|
+
maximum_search_time 0
|
43
|
+
|
44
|
+
# We're starting to break tests up into groups based on different
|
45
|
+
# criteria. The proper API tests (the results of which are viewable
|
46
|
+
# to OPC customers) should be the only ones run by Pedant embedded in
|
47
|
+
# OPC installs. There are other specs that help us keep track of API
|
48
|
+
# cruft that we want to come back and fix later; these shouldn't be
|
49
|
+
# viewable to customers, but we should be able to run them in
|
50
|
+
# development and CI environments. If this parameter is missing or
|
51
|
+
# explicitly `false` only the customer-friendly tests will be run.
|
52
|
+
#
|
53
|
+
# This is mainly here for documentation purposes, since the
|
54
|
+
# command-line `opscode-pedant` utility ultimately determines this
|
55
|
+
# value.
|
56
|
+
include_internal false
|
57
|
+
|
58
|
+
# Test users. The five users specified below are required; their
|
59
|
+
# names (:user, :non_org_user, etc.) are indicative of their role
|
60
|
+
# within the tests. All users must have a ':name' key. If they have
|
61
|
+
# a ':create_me' key, Pedant will create these users for you. If you
|
62
|
+
# are using pre-existing users, you must supply a ':key_file' key,
|
63
|
+
# which should be the fully-qualified path /on the machine Pedant is
|
64
|
+
# running on/ to a private key for that user.
|
65
|
+
key = 'spec/support/stickywicket.pem'
|
66
|
+
superuser_name 'admin'
|
67
|
+
superuser_key key
|
68
|
+
webui_key key
|
69
|
+
|
70
|
+
# Set the platform_class
|
71
|
+
platform_class Pedant::OpenSourcePlatform
|
72
|
+
|
73
|
+
requestors({
|
74
|
+
:clients => {
|
75
|
+
# The the admin user, for the purposes of getting things rolling
|
76
|
+
:admin => {
|
77
|
+
:name => "pedant_admin_client",
|
78
|
+
:create_me => true,
|
79
|
+
:create_knife => true,
|
80
|
+
:admin => true
|
81
|
+
},
|
82
|
+
:non_admin => {
|
83
|
+
:name => 'pedant_client',
|
84
|
+
:create_me => true,
|
85
|
+
:create_knife => true
|
86
|
+
},
|
87
|
+
:bad => {
|
88
|
+
:name => 'bad_client',
|
89
|
+
:bogus => true
|
90
|
+
}
|
91
|
+
},
|
92
|
+
:users => {
|
93
|
+
:admin => {
|
94
|
+
:name => "admin",
|
95
|
+
:key_file => key,
|
96
|
+
:create_me => false,
|
97
|
+
:create_knife => false,
|
98
|
+
:admin => true
|
99
|
+
},
|
100
|
+
:non_admin => {
|
101
|
+
:name => "pedant_non_admin_user",
|
102
|
+
:create_me => true,
|
103
|
+
:create_knife => true,
|
104
|
+
:admin => false
|
105
|
+
},
|
106
|
+
# A user for Knife tests. A knife.rb and key files will be set up
|
107
|
+
# for this user
|
108
|
+
:knife_user => {
|
109
|
+
:name => "knifey",
|
110
|
+
:create_me => true,
|
111
|
+
:create_knife => true
|
112
|
+
}
|
113
|
+
}
|
114
|
+
})
|
115
|
+
|
116
|
+
self[:tags] = [:validation, :authentication, :authorization]
|
117
|
+
verify_error_messages false
|
@@ -0,0 +1,27 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIEpQIBAAKCAQEApNCkX2k+lFGDWRVhX4uClaVQrumG9XXvk6X7M2izrIg7RzMP
|
3
|
+
Dk4thhZkpx5gr22By7PZQdMEjWC/Zo8MBjtoJ0GV0jw8npefbU1MGKs2dtpYgo0N
|
4
|
+
Fq8fX8MdFPu4h2W3g0dMEdhT8icc2H4EjhZmdeUhUn3RIEt2duCgp3YDYnUUZx3j
|
5
|
+
N7MHcTIdzD58ikr6zQrZzHOv+OOI86Xk9EpyEEQizOLoQxkICNrhqN7ElQDuvXaX
|
6
|
+
BSBrYDRKH2umBMMcXzvsR/SvkmqxoEESSpIlW8zeKAWQ+znNjDC0tmTg7jZmgSP7
|
7
|
+
siKrwo4t4ebjcmjpIoi/JKww/nGN3Uhz1ZOZuwIDAQABAoIBAQCaJQD2s0nyEeKU
|
8
|
+
uKhfYe155Cl3zbWJcQnmv4AXbr9MiAVY6+oS6Q8ur1bn7kNjDzoruENjiuZhC7E3
|
9
|
+
TGZklb8tp+tluyy+7vQOmBKpp8fClSfewekR5CultqhGbb8B8yIVR+NfdUHd4rLZ
|
10
|
+
z9KWyWB+txPZQQ8L80gSmrfmpzs3IuT7oPvmtBU1Wq9QapC4n/rUohHUpUV1du4G
|
11
|
+
0wCIF4zQTg6cbYW2YXozwVQvw+P7P3RVEqZt+aZlbVcy0fNr6jNao0hi1KFC9OH2
|
12
|
+
VjjU+PioreoA/NU3aZPIUzmJpWtsu31yuOZxXmytAkYooCZgiEQNEHnJlNPv0RmC
|
13
|
+
6BPMzVoBAoGBAM7yZoSNJpzdP/q1/4+H3zyy7o4I0VTW9u/GqUzhnbjm5poK30X9
|
14
|
+
YXh/7WOVV0OoVqdO6ljRKygP3Oggf41ZEbi1C6bbsO57pksBWgx9bD9V35XscZ0J
|
15
|
+
F1ERe//kMHwVQy74R8/cIuRwm75haLSBj5/fwGbLeeVDglJkCVqPjtuBAoGBAMvh
|
16
|
+
qsAGG5k9u6voTcXlFwS+B5YjULhK4NSxdJ2BnOxzYzxQ3IYQZMlb2xt8yZYx/ZZK
|
17
|
+
wjkr9rcAPEQIQZ2A6NUbGq6qCD7sSmg6UAi0CgiqTokQ/Wtag0UDvFMzwerdg/On
|
18
|
+
37uxffpxpte8z1jYi/MxRaoTYueuc1UVnqofVIM7AoGBALZJzwPzUY/bVAADUJmd
|
19
|
+
lYZiFsAGBF42/E05MOgH1GaK/ZWy/fkouDLsfK67XaK7JZk6ajLSDLG9R1kxRym6
|
20
|
+
y2FoGFtiKPfo8xIenrNhx3gCrG/jVjB9UYyXWiKNXifukr9M8/SkdBfFGWsZYqGd
|
21
|
+
fmXVMiVaFoVcce8hLxwWWEABAoGBAKcyhKX/HEj6YFqlIoqkydDAylXs1jicZ27l
|
22
|
+
rF2yum8KXZpMMdzbutuKsdAD8Ql0K6NB4a+jByuiTMn5/11cJxUEqkgM9sArZQW+
|
23
|
+
tH2+r+/VQpyTS0/rpXVGj/2nl2K1kI2T4R36e/aTl6CanWweAf9JK/lC9rxKyxg+
|
24
|
+
p6SaFuObAoGACP6TKCkp2oymXlKgdUUgPrnsaz2VAw8jD5QHtx10U4wty0C8gxsk
|
25
|
+
MLe00h09iLPyFmvJpD+MgbxV/r6RrZeVdsKdU/5LG52YgiVSTaizyy+ciEfW7xoQ
|
26
|
+
CL5EtZd8Cn5OKinBEzzFpELqunlqepIKCIDOcLKz/cjR+3a+E6Zx5Wo=
|
27
|
+
-----END RSA PRIVATE KEY-----
|
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.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,84 +9,82 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: puma
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
21
|
+
version: '2.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
29
|
+
version: '2.0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: mixlib-log
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.3
|
37
|
+
version: '1.3'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.3
|
45
|
+
version: '1.3'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: hashie
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0
|
53
|
+
version: '2.0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '2.0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rake
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
70
|
-
type: :
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: '0'
|
78
78
|
description: Self-contained, easy-setup, fast-start in-memory Chef server for testing
|
79
79
|
and solo setup purposes
|
80
80
|
email: jkeiser@opscode.com
|
81
81
|
executables:
|
82
82
|
- chef-zero
|
83
83
|
extensions: []
|
84
|
-
extra_rdoc_files:
|
85
|
-
- README.rdoc
|
86
|
-
- LICENSE
|
84
|
+
extra_rdoc_files: []
|
87
85
|
files:
|
88
86
|
- LICENSE
|
89
|
-
- README.
|
87
|
+
- README.md
|
90
88
|
- Rakefile
|
91
89
|
- lib/chef_zero/cookbook_data.rb
|
92
90
|
- lib/chef_zero/core_ext/hash.rb
|
@@ -139,6 +137,9 @@ files:
|
|
139
137
|
- lib/chef_zero/solr/solr_parser.rb
|
140
138
|
- lib/chef_zero/version.rb
|
141
139
|
- lib/chef_zero.rb
|
140
|
+
- spec/run.rb
|
141
|
+
- spec/support/pedant.rb
|
142
|
+
- spec/support/stickywicket.pem
|
142
143
|
- !binary |-
|
143
144
|
YmluL2NoZWYtemVybw==
|
144
145
|
homepage: http://www.opscode.com
|
@@ -167,4 +168,4 @@ specification_version: 3
|
|
167
168
|
summary: Self-contained, easy-setup, fast-start in-memory Chef server for testing
|
168
169
|
and solo setup purposes
|
169
170
|
test_files: []
|
170
|
-
has_rdoc:
|
171
|
+
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
== Chef Zero
|
2
|
-
|
3
|
-
= DESCRIPTION:
|
4
|
-
|
5
|
-
chef-zero is a simple, easy-install, in-memory Chef server that can be useful
|
6
|
-
for Chef client testing and chef-solo-like tasks that require a full Chef
|
7
|
-
server. It IS intended to be simple, Chef 11 compliant, easy to run and fast
|
8
|
-
to start. It is NOT intended to be secure, scalable, performant or persistent.
|
9
|
-
It does NO input validation, authentication or authorization (it will not
|
10
|
-
throw a 400, 401 or 403). It does not save data, and will start up empty each
|
11
|
-
time you start it.
|
12
|
-
|
13
|
-
= INSTALLATION:
|
14
|
-
|
15
|
-
This server can be installed as a Ruby Gem.
|
16
|
-
|
17
|
-
gem install chef-zero
|
18
|
-
|
19
|
-
You can also copy the source repository and install it using +rake install+.
|
20
|
-
|
21
|
-
= TEST SERVER USAGE:
|
22
|
-
|
23
|
-
One of chef-zero's primary uses is as a small test server for people writing and
|
24
|
-
testing clients. To bring it up, simply do:
|
25
|
-
|
26
|
-
require 'chef_zero/server'
|
27
|
-
server = ChefZero::Server.new(:port => 8889)
|
28
|
-
server.start
|
29
|
-
|
30
|
-
To bring it up in the background, do:
|
31
|
-
|
32
|
-
thread = Thread.new { server.start }
|
33
|
-
|
34
|
-
To kill the background server, do:
|
35
|
-
|
36
|
-
thread.stop
|
37
|
-
|
38
|
-
= COMMAND LINE USAGE:
|
39
|
-
|
40
|
-
To simply run the server, you can just type +chef-zero+ after installing and you
|
41
|
-
will have a fully functional (empty) Chef Server running.
|
42
|
-
|
43
|
-
To try it out, go into the +chef-zero/playground+ directory and run knife. It
|
44
|
-
will behave the same as a normal Chef server, and all normal knife commands will
|
45
|
-
work (show, list, delete, from file, upload, download, diff ...). For example,
|
46
|
-
with +knife-essentials+ (or Chef 11) you can upload everything in the repo:
|
47
|
-
|
48
|
-
chef-zero/playground> knife upload .
|
49
|
-
Created remote/cookbooks/blah
|
50
|
-
Created remote/cookbooks/blork
|
51
|
-
Created remote/data_bags/foo/
|
52
|
-
Created remote/data_bags/foo/bar.json
|
53
|
-
Created remote/data_bags/foo/baz.json
|
54
|
-
Created remote/data_bags/foo/blarghle.json
|
55
|
-
Created remote/data_bags/foom/
|
56
|
-
Created remote/data_bags/foom/x.json
|
57
|
-
Created remote/data_bags/widdle/
|
58
|
-
Created remote/data_bags/widdle/blank.json
|
59
|
-
Created remote/data_bags/widdle/wow.json
|
60
|
-
Created remote/environments/desert.json
|
61
|
-
Created remote/environments/rainforest.json
|
62
|
-
Created remote/environments/semi_arid_plains.json
|
63
|
-
|
64
|
-
chef-zero/playground> knife environment list
|
65
|
-
_default
|
66
|
-
desert
|
67
|
-
rainforest
|
68
|
-
semi_arid_plains
|
69
|
-
|
70
|
-
To use it in your own repository, create a +knife.rb+ like so:
|
71
|
-
|
72
|
-
chef_server_url "http://127.0.0.1:8889"
|
73
|
-
node_name "stickywicket"
|
74
|
-
client_key "path_to_any_pem_file.pem"
|
75
|
-
|
76
|
-
And use knife like you normally would.
|
77
|
-
|
78
|
-
Since Chef Zero does no authentication, any .pem file will do. The client just
|
79
|
-
needs something to sign requests with (which will be ignored on the server).
|