chef-zero 4.7.1 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +78 -69
- data/bin/chef-zero +5 -1
- data/lib/chef_zero/chef_data/cookbook_data.rb +8 -4
- data/lib/chef_zero/chef_data/data_normalizer.rb +1 -1
- data/lib/chef_zero/endpoints/search_endpoint.rb +10 -0
- data/lib/chef_zero/rest_base.rb +3 -2
- data/lib/chef_zero/rest_request.rb +7 -1
- data/lib/chef_zero/server.rb +13 -0
- data/lib/chef_zero/solr/query/regexpable_query.rb +2 -2
- data/lib/chef_zero/solr/query/unary_operator.rb +2 -4
- data/lib/chef_zero/solr/solr_parser.rb +3 -1
- data/lib/chef_zero/version.rb +1 -1
- data/spec/run_oc_pedant.rb +9 -0
- data/spec/search_spec.rb +4 -0
- data/spec/server_spec.rb +4 -0
- 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: 0b1777b8332d31b59e467917da633172429a610f
|
4
|
+
data.tar.gz: 994c97845bc1a3cd6899f5effd61d5ffde45456e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d7cd1a182106317d3847068cc7f8db5bcc7f76a77734006ad884f31d4413b0c3c852cb6cf0d85b25f555fba1cc4526d04a40855446a62638080ce79b14fb17c
|
7
|
+
data.tar.gz: a55e55cca7fe1288808ce6a7ba6dc59f0d7cae8387a16ee9a61638caf9db9ec5b5a3c32a68ea40481f651614f967da95a8b3bce4808e30c6ffe624a62b921086
|
data/README.md
CHANGED
@@ -1,33 +1,20 @@
|
|
1
|
+
# Chef Zero
|
1
2
|
|
2
|
-
|
3
|
-
=========
|
3
|
+
[![Status](https://travis-ci.org/chef/chef-zero.svg?branch=master)](https://travis-ci.org/chef/chef-zero) [![Gem Version](https://badge.fury.io/rb/chef-zero.svg)](http://badge.fury.io/rb/chef-zero)
|
4
4
|
|
5
|
-
|
6
|
-
[![Gem Version](https://badge.fury.io/rb/chef-zero.svg)](http://badge.fury.io/rb/chef-zero)
|
7
|
-
[![Stories in Ready](https://badge.waffle.io/chef/chef-zero.png?label=ready&title=Ready)](https://waffle.io/chef/chef-zero)
|
8
|
-
[![Stories in Progress](https://badge.waffle.io/chef/chef-zero.png?label=in+progress&title=In+Progress)](https://waffle.io/chef/chef-zero)
|
5
|
+
## Description
|
9
6
|
|
7
|
+
Chef Zero is a simple, easy-install, in-memory Chef server that can be useful for Chef Client testing and chef-solo-like tasks that require a full Chef Server. It IS intended to be simple, Chef 11+ compliant, easy to run and fast to start. It is NOT intended to be secure, scalable, performant or persistent. It does NO input validation, authentication or authorization (it will not throw a 400, 401 or 403). It does not save data, and will start up empty each time you start it.
|
10
8
|
|
11
|
-
|
12
|
-
-----------
|
13
|
-
Chef Zero is a simple, easy-install, in-memory Chef server that can be useful
|
14
|
-
for Chef Client testing and chef-solo-like tasks that require a full Chef
|
15
|
-
Server. It IS intended to be simple, Chef 11 compliant, easy to run and fast
|
16
|
-
to start. It is NOT intended to be secure, scalable, performant or persistent.
|
17
|
-
It does NO input validation, authentication or authorization (it will not
|
18
|
-
throw a 400, 401 or 403). It does not save data, and will start up empty each
|
19
|
-
time you start it.
|
9
|
+
Because Chef Zero runs in memory, it's super fast and lightweight. This makes it perfect for testing against a "real" Chef Server without mocking the entire Internet.
|
20
10
|
|
21
|
-
|
22
|
-
it perfect for testing against a "real" Chef Server without mocking the
|
23
|
-
entire Internet.
|
11
|
+
## Installation
|
24
12
|
|
25
|
-
|
26
|
-
Installation
|
27
|
-
------------
|
28
13
|
This server can be installed as a Ruby Gem.
|
29
14
|
|
30
|
-
|
15
|
+
```bash
|
16
|
+
$ gem install chef-zero
|
17
|
+
```
|
31
18
|
|
32
19
|
If you're using bundler, add `chef-zero` as a development dependency:
|
33
20
|
|
@@ -45,10 +32,9 @@ s.add_development_dependency 'chef-zero'
|
|
45
32
|
|
46
33
|
You can also clone the source repository and install it using `rake install`.
|
47
34
|
|
48
|
-
Usage
|
49
|
-
|
50
|
-
One of chef-zero's primary uses is as a small test server for people writing and
|
51
|
-
testing clients. Here's a simple example of starting it up:
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
One of chef-zero's primary uses is as a small test server for people writing and testing clients. Here's a simple example of starting it up:
|
52
38
|
|
53
39
|
```ruby
|
54
40
|
require 'chef_zero/server'
|
@@ -62,8 +48,7 @@ This will create a server instance in the foreground. To stop the server:
|
|
62
48
|
server.stop
|
63
49
|
```
|
64
50
|
|
65
|
-
This is great for debugging and logging requests, but you'll probably want
|
66
|
-
to run this in the background so you have full control of your thread.
|
51
|
+
This is great for debugging and logging requests, but you'll probably want to run this in the background so you have full control of your thread.
|
67
52
|
|
68
53
|
To run Chef Zero in the background, simply issue the `start_background` command:
|
69
54
|
|
@@ -80,65 +65,65 @@ server.stop
|
|
80
65
|
```
|
81
66
|
|
82
67
|
### Valid Options
|
68
|
+
|
83
69
|
You may currently pass the following options to the initializer:
|
84
70
|
|
85
71
|
- `host` - the host to run on (Default: '127.0.0.1')
|
86
72
|
- `port` - the port to run on (Default: 8889)
|
87
73
|
- `debug` - run in debug mode to see all requests and responses (Default: false)
|
88
74
|
|
75
|
+
## CLI (Command Line)
|
89
76
|
|
90
|
-
|
91
|
-
-----------------
|
92
|
-
If you don't want to use Chef Zero as a library, you can simply start an instance
|
93
|
-
with the included `chef-zero` executable:
|
77
|
+
If you don't want to use Chef Zero as a library, you can simply start an instance with the included `chef-zero` executable:
|
94
78
|
|
95
|
-
|
79
|
+
```bash
|
80
|
+
$ chef-zero
|
81
|
+
```
|
96
82
|
|
97
83
|
Note, this will run in the foreground.
|
98
84
|
|
99
85
|
You now have a fully functional (empty) Chef Server running.
|
100
86
|
|
101
|
-
To try it out, go into the `chef-zero/playground` directory and run `knife`. It
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
staging
|
87
|
+
To try it out, go into the `chef-zero/playground` directory and run `knife`. It will behave the same as a normal Chef Server, and all normal knife commands will work (show, list, delete, from file, upload, download, diff ...). For example, with +knife-essentials+ (or Chef 11) you can upload everything in the repo:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
chef-zero/playground> knife upload .
|
91
|
+
Created nodes/desktop.json
|
92
|
+
Created data_bags/dns
|
93
|
+
Created environments/production.json
|
94
|
+
Created nodes/lb.json
|
95
|
+
Created nodes/dns.json
|
96
|
+
Created nodes/ldap.json
|
97
|
+
Created nodes/www.json
|
98
|
+
Created data_bags/dns/services.json
|
99
|
+
Created environments/staging.json
|
100
|
+
Created data_bags/passwords
|
101
|
+
Created data_bags/users
|
102
|
+
Created data_bags/users/jkeiser.json
|
103
|
+
Created data_bags/passwords/github.json
|
104
|
+
Created data_bags/passwords/twitter.json
|
105
|
+
Created data_bags/users/schisamo.json
|
106
|
+
Created data_bags/users/sethvargo.json
|
107
|
+
Created cookbooks/apache2
|
108
|
+
Created cookbooks/php
|
109
|
+
|
110
|
+
chef-zero/playground> knife environment list
|
111
|
+
_default
|
112
|
+
production
|
113
|
+
staging
|
114
|
+
```
|
130
115
|
|
131
116
|
To use it in your own repository, create a `knife.rb` like so:
|
132
117
|
|
133
|
-
|
134
|
-
|
135
|
-
|
118
|
+
```ruby
|
119
|
+
chef_server_url 'http://127.0.0.1:8889'
|
120
|
+
node_name 'stickywicket'
|
121
|
+
client_key 'path_to_any_pem_file.pem'
|
122
|
+
```
|
136
123
|
|
137
124
|
And use knife like you normally would.
|
138
125
|
|
139
|
-
Since Chef Zero does no authentication, any `.pem` file will do. The client just
|
140
|
-
needs something to sign requests with (which will be ignored on the server). Even
|
141
|
-
though it's ignored, the `.pem` must still be a valid format.
|
126
|
+
Since Chef Zero does no authentication, any `.pem` file will do. The client just needs something to sign requests with (which will be ignored on the server). Even though it's ignored, the `.pem` must still be a valid format.
|
142
127
|
|
143
128
|
Now, stop the Chef Zero server and all the data is gone!
|
144
129
|
|
@@ -147,9 +132,33 @@ Run `chef-zero --help` to see a list of the supported flags and options:
|
|
147
132
|
```text
|
148
133
|
Usage: chef-zero [ARGS]
|
149
134
|
-H, --host HOST Host to bind to (default: 127.0.0.1)
|
150
|
-
-p, --port PORT Port to listen on
|
135
|
+
-p, --port PORT Port to listen on (e.g. 8889, or 8500-8600 or 8885,8888)
|
151
136
|
--[no-]generate-keys Whether to generate actual keys or fake it (faster). Default: false.
|
137
|
+
-d, --daemon Run as a daemon process
|
152
138
|
-l, --log-level LEVEL Set the output log level
|
139
|
+
--log-file FILE Log to a file
|
140
|
+
--enterprise Whether to run in enterprise mode
|
141
|
+
--multi-org Whether to run in multi-org mode
|
142
|
+
--file-store PATH Persist data to files at the given path
|
143
|
+
--[no-]ssl Use SSL with self-signed certificate(Auto generate before every run). Default: false.
|
153
144
|
-h, --help Show this message
|
154
145
|
--version Show version
|
155
146
|
```
|
147
|
+
|
148
|
+
## License
|
149
|
+
|
150
|
+
Copyright 2012-2016, Chef Software, Inc.
|
151
|
+
|
152
|
+
```
|
153
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
154
|
+
you may not use this file except in compliance with the License.
|
155
|
+
You may obtain a copy of the License at
|
156
|
+
|
157
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
158
|
+
|
159
|
+
Unless required by applicable law or agreed to in writing, software
|
160
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
161
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
162
|
+
See the License for the specific language governing permissions and
|
163
|
+
limitations under the License.
|
164
|
+
```
|
data/bin/chef-zero
CHANGED
@@ -99,7 +99,11 @@ if options[:daemon]
|
|
99
99
|
Process.daemon(true)
|
100
100
|
server.start(true)
|
101
101
|
else
|
102
|
-
|
102
|
+
if ENV['OS'] == 'Windows_NT'
|
103
|
+
abort 'Daemonization is not supported on Windows. Running 'start chef-zero' will fork the process.'
|
104
|
+
else
|
105
|
+
abort 'Process.daemon requires Ruby >= 1.9'
|
106
|
+
end
|
103
107
|
end
|
104
108
|
else
|
105
109
|
server.start(true)
|
@@ -129,11 +129,15 @@ module ChefZero
|
|
129
129
|
self[key][cookbook] = version_constraints.first || ">= 0.0.0"
|
130
130
|
end
|
131
131
|
|
132
|
-
def method_missing(key,
|
133
|
-
if
|
132
|
+
def method_missing(key, *values)
|
133
|
+
if values.nil?
|
134
134
|
self[key.to_sym]
|
135
135
|
else
|
136
|
-
|
136
|
+
if values.length > 1
|
137
|
+
store key.to_sym, values
|
138
|
+
else
|
139
|
+
store key.to_sym, values.first
|
140
|
+
end
|
137
141
|
end
|
138
142
|
end
|
139
143
|
end
|
@@ -144,7 +148,7 @@ module ChefZero
|
|
144
148
|
:attributes => load_child_files(directory, 'attributes', false),
|
145
149
|
:definitions => load_child_files(directory, 'definitions', false),
|
146
150
|
:recipes => load_child_files(directory, 'recipes', false),
|
147
|
-
:libraries => load_child_files(directory, 'libraries',
|
151
|
+
:libraries => load_child_files(directory, 'libraries', true),
|
148
152
|
:templates => load_child_files(directory, 'templates', true),
|
149
153
|
:files => load_child_files(directory, 'files', true),
|
150
154
|
:resources => load_child_files(directory, 'resources', true),
|
@@ -163,7 +163,7 @@ module ChefZero
|
|
163
163
|
node['chef_type'] ||= 'node'
|
164
164
|
node['chef_environment'] ||= '_default'
|
165
165
|
node['override'] ||= {}
|
166
|
-
node['normal'] ||= {}
|
166
|
+
node['normal'] ||= {"tags" => []}
|
167
167
|
node['default'] ||= {}
|
168
168
|
node['automatic'] ||= {}
|
169
169
|
node['run_list'] ||= []
|
@@ -14,6 +14,8 @@ module ChefZero
|
|
14
14
|
results = search(request, orgname)
|
15
15
|
results['rows'] = results['rows'].map { |name,uri,value,search_value| value }
|
16
16
|
json_response(200, results)
|
17
|
+
rescue ChefZero::Solr::ParseError
|
18
|
+
bad_search_request(request)
|
17
19
|
end
|
18
20
|
|
19
21
|
def post(request)
|
@@ -43,10 +45,18 @@ module ChefZero
|
|
43
45
|
'start' => full_results['start'],
|
44
46
|
'total' => full_results['total']
|
45
47
|
})
|
48
|
+
rescue ChefZero::Solr::ParseError
|
49
|
+
bad_search_request(request)
|
46
50
|
end
|
47
51
|
|
48
52
|
private
|
49
53
|
|
54
|
+
def bad_search_request(request)
|
55
|
+
query_string = request.query_params['q']
|
56
|
+
resp = {"error" => ["invalid search query: '#{query_string}'"]}
|
57
|
+
json_response(400, resp)
|
58
|
+
end
|
59
|
+
|
50
60
|
def search_container(request, index, orgname)
|
51
61
|
relative_parts, normalize_proc = case index
|
52
62
|
when 'client'
|
data/lib/chef_zero/rest_base.rb
CHANGED
@@ -61,7 +61,7 @@ module ChefZero
|
|
61
61
|
begin
|
62
62
|
self.send(method, request)
|
63
63
|
rescue RestErrorResponse => e
|
64
|
-
ChefZero::Log.
|
64
|
+
ChefZero::Log.debug("#{e.inspect}\n#{e.backtrace.join("\n")}")
|
65
65
|
error(e.response_code, e.error)
|
66
66
|
end
|
67
67
|
end
|
@@ -80,6 +80,7 @@ module ChefZero
|
|
80
80
|
|
81
81
|
def get_data(request, rest_path=nil, *options)
|
82
82
|
rest_path ||= request.rest_path
|
83
|
+
rest_path = rest_path.map { |v| URI.decode(v) }
|
83
84
|
begin
|
84
85
|
data_store.get(rest_path, request)
|
85
86
|
rescue DataStore::DataNotFoundError
|
@@ -276,7 +277,7 @@ module ChefZero
|
|
276
277
|
end
|
277
278
|
|
278
279
|
def self.build_uri(base_uri, rest_path)
|
279
|
-
"#{base_uri}/#{rest_path.join('/')}"
|
280
|
+
"#{base_uri}/#{rest_path.map { |v| URI.escape(v) }.join('/')}"
|
280
281
|
end
|
281
282
|
|
282
283
|
def populate_defaults(request, response)
|
@@ -14,7 +14,13 @@ module ChefZero
|
|
14
14
|
attr_accessor :rest_base_prefix
|
15
15
|
|
16
16
|
def base_uri
|
17
|
-
|
17
|
+
# Load balancer awareness
|
18
|
+
if env['HTTP_X_FORWARDED_PROTO']
|
19
|
+
scheme = env['HTTP_X_FORWARDED_PROTO']
|
20
|
+
else
|
21
|
+
scheme = env['rack.url_scheme']
|
22
|
+
end
|
23
|
+
@base_uri ||= "#{scheme}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}"
|
18
24
|
end
|
19
25
|
|
20
26
|
def base_uri=(value)
|
data/lib/chef_zero/server.rb
CHANGED
@@ -284,7 +284,9 @@ module ChefZero
|
|
284
284
|
:DoNotListen => true,
|
285
285
|
:AccessLog => [],
|
286
286
|
:Logger => WEBrick::Log.new(StringIO.new, 7),
|
287
|
+
:RequestTimeout => 300,
|
287
288
|
:SSLEnable => options[:ssl],
|
289
|
+
:SSLOptions => ssl_opts,
|
288
290
|
:SSLCertName => [ [ 'CN', WEBrick::Utils::getservername ] ],
|
289
291
|
:StartCallback => proc {
|
290
292
|
@running = true
|
@@ -708,5 +710,16 @@ module ChefZero
|
|
708
710
|
end
|
709
711
|
value
|
710
712
|
end
|
713
|
+
|
714
|
+
## Disable unsecure ssl
|
715
|
+
## Ref: https://www.ruby-lang.org/en/news/2014/10/27/changing-default-settings-of-ext-openssl/
|
716
|
+
def ssl_opts
|
717
|
+
ssl_opts = OpenSSL::SSL::OP_ALL
|
718
|
+
ssl_opts &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS if defined?(OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS)
|
719
|
+
ssl_opts |= OpenSSL::SSL::OP_NO_COMPRESSION if defined?(OpenSSL::SSL::OP_NO_COMPRESSION)
|
720
|
+
ssl_opts |= OpenSSL::SSL::OP_NO_SSLv2 if defined?(OpenSSL::SSL::OP_NO_SSLv2)
|
721
|
+
ssl_opts |= OpenSSL::SSL::OP_NO_SSLv3 if defined?(OpenSSL::SSL::OP_NO_SSLv3)
|
722
|
+
ssl_opts
|
723
|
+
end
|
711
724
|
end
|
712
725
|
end
|
@@ -16,8 +16,7 @@ module ChefZero
|
|
16
16
|
|
17
17
|
def matches_doc?(doc)
|
18
18
|
case @operator
|
19
|
-
when '-'
|
20
|
-
when 'NOT'
|
19
|
+
when '-', 'NOT'
|
21
20
|
!operand.matches_doc?(doc)
|
22
21
|
when '+'
|
23
22
|
# TODO This operator uses relevance to eliminate other, unrelated
|
@@ -28,8 +27,7 @@ module ChefZero
|
|
28
27
|
|
29
28
|
def matches_values?(values)
|
30
29
|
case @operator
|
31
|
-
when '-'
|
32
|
-
when 'NOT'
|
30
|
+
when '-', 'NOT'
|
33
31
|
!operand.matches_values?(values)
|
34
32
|
when '+'
|
35
33
|
# TODO This operator uses relevance to eliminate other, unrelated
|
@@ -7,6 +7,8 @@ require 'chef_zero/solr/query/subquery'
|
|
7
7
|
|
8
8
|
module ChefZero
|
9
9
|
module Solr
|
10
|
+
class ParseError < RuntimeError; end
|
11
|
+
|
10
12
|
class SolrParser
|
11
13
|
def initialize(query_string)
|
12
14
|
@query_string = query_string
|
@@ -114,7 +116,7 @@ module ChefZero
|
|
114
116
|
end
|
115
117
|
|
116
118
|
def parse_error(token, str)
|
117
|
-
raise "Error on token '#{token}' at #{@index} of '#{@query_string}': #{str}"
|
119
|
+
raise ChefZero::Solr::ParseError, "Error on token '#{token}' at #{@index} of '#{@query_string}': #{str}"
|
118
120
|
end
|
119
121
|
|
120
122
|
def read_single_expression
|
data/lib/chef_zero/version.rb
CHANGED
data/spec/run_oc_pedant.rb
CHANGED
@@ -191,6 +191,15 @@ begin
|
|
191
191
|
Pedant.setup(pedant_args + pedant_args_from_env)
|
192
192
|
|
193
193
|
rspec_args = Pedant.config.rspec_args + rspec_args_from_env
|
194
|
+
|
195
|
+
if defined? Chef::ChefFS::FileSystemCache
|
196
|
+
RSpec.configure do |c|
|
197
|
+
c.before(:each) do
|
198
|
+
Chef::ChefFS::FileSystemCache.instance.reset!
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
194
203
|
result = RSpec::Core::Runner.run(rspec_args)
|
195
204
|
|
196
205
|
server.stop if server.running?
|
data/spec/search_spec.rb
CHANGED
@@ -24,6 +24,10 @@ describe ChefZero::Solr::SolrParser do
|
|
24
24
|
search_for('foo:[a TO c]').size.should eq(1)
|
25
25
|
end
|
26
26
|
|
27
|
+
it "handles -" do
|
28
|
+
search_for('-foo:a').size.should eq(1)
|
29
|
+
end
|
30
|
+
|
27
31
|
it "handles wildcard ranges" do
|
28
32
|
search_for('foo:[* TO c]').size.should eq(1)
|
29
33
|
search_for('foo:[c TO *]').size.should eq(1)
|
data/spec/server_spec.rb
CHANGED
@@ -27,6 +27,10 @@ describe ChefZero::Server do
|
|
27
27
|
expect { ChefZero::Server.new(:port => 8889.upto(8889)).start_background }.to raise_error Errno::EADDRINUSE
|
28
28
|
end
|
29
29
|
|
30
|
+
it 'has a very patient request timeout' do
|
31
|
+
expect(@server.server.config[:RequestTimeout]).to eq 300
|
32
|
+
end
|
33
|
+
|
30
34
|
context 'accept headers' do
|
31
35
|
def get_nodes(accepts)
|
32
36
|
uri = URI(@server.url)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-log
|