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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afe555937b43ccbb7feafd348d292c8d3fc0efc8
4
- data.tar.gz: 3fbcb48f8503b03cb5a6231bd69e931d23d05870
3
+ metadata.gz: 0b1777b8332d31b59e467917da633172429a610f
4
+ data.tar.gz: 994c97845bc1a3cd6899f5effd61d5ffde45456e
5
5
  SHA512:
6
- metadata.gz: 175cf74bbe8e73781b1b82ff7f22581b7665c3a13a07feb6f852246fd0c2401003f05622b53eeabd7acba6a478386172c897102149ffdec41713acad05b01a34
7
- data.tar.gz: e0877b8047f093166e56ba5486167e4525e950266a1b6310046b27aa325b164c325c954373988c37196d13930818ac3d617593989b4461a0296838e8ec4d37e8
6
+ metadata.gz: 7d7cd1a182106317d3847068cc7f8db5bcc7f76a77734006ad884f31d4413b0c3c852cb6cf0d85b25f555fba1cc4526d04a40855446a62638080ce79b14fb17c
7
+ data.tar.gz: a55e55cca7fe1288808ce6a7ba6dc59f0d7cae8387a16ee9a61638caf9db9ec5b5a3c32a68ea40481f651614f967da95a8b3bce4808e30c6ffe624a62b921086
data/README.md CHANGED
@@ -1,33 +1,20 @@
1
+ # Chef Zero
1
2
 
2
- Chef Zero
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
- [![Status](https://travis-ci.org/chef/chef-zero.svg?branch=master)](https://travis-ci.org/chef/chef-zero)
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
- Description
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
- Because Chef Zero runs in memory, it's super fast and lightweight. This makes
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
- $ gem install chef-zero
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
- CLI (Command Line)
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
- $ chef-zero
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
- will behave the same as a normal Chef Server, and all normal knife commands will
103
- work (show, list, delete, from file, upload, download, diff ...). For example,
104
- with +knife-essentials+ (or Chef 11) you can upload everything in the repo:
105
-
106
- chef-zero/playground> knife upload .
107
- Created nodes/desktop.json
108
- Created data_bags/dns
109
- Created environments/production.json
110
- Created nodes/lb.json
111
- Created nodes/dns.json
112
- Created nodes/ldap.json
113
- Created nodes/www.json
114
- Created data_bags/dns/services.json
115
- Created environments/staging.json
116
- Created data_bags/passwords
117
- Created data_bags/users
118
- Created data_bags/users/jkeiser.json
119
- Created data_bags/passwords/github.json
120
- Created data_bags/passwords/twitter.json
121
- Created data_bags/users/schisamo.json
122
- Created data_bags/users/sethvargo.json
123
- Created cookbooks/apache2
124
- Created cookbooks/php
125
-
126
- chef-zero/playground> knife environment list
127
- _default
128
- production
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
- chef_server_url 'http://127.0.0.1:8889'
134
- node_name 'stickywicket'
135
- client_key 'path_to_any_pem_file.pem'
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
+ ```
@@ -99,7 +99,11 @@ if options[:daemon]
99
99
  Process.daemon(true)
100
100
  server.start(true)
101
101
  else
102
- abort 'Process.daemon requires Ruby >= 1.9'
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, value = nil)
133
- if value.nil?
132
+ def method_missing(key, *values)
133
+ if values.nil?
134
134
  self[key.to_sym]
135
135
  else
136
- store key.to_sym, value
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', false),
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'
@@ -61,7 +61,7 @@ module ChefZero
61
61
  begin
62
62
  self.send(method, request)
63
63
  rescue RestErrorResponse => e
64
- ChefZero::Log.info("#{e.inspect}\n#{e.backtrace.join("\n")}")
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
- @base_uri ||= "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}"
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)
@@ -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
@@ -21,8 +21,8 @@ module ChefZero
21
21
  end
22
22
 
23
23
  DEFAULT_FIELD = "text"
24
- WORD_CHARACTER = "[A-Za-z0-9@._':]"
25
- NON_WORD_CHARACTER = "[^A-Za-z0-9@._':]"
24
+ WORD_CHARACTER = "[A-Za-z0-9@._':\-]"
25
+ NON_WORD_CHARACTER = "[^A-Za-z0-9@._':\-]"
26
26
  end
27
27
  end
28
28
  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
@@ -1,3 +1,3 @@
1
1
  module ChefZero
2
- VERSION = '4.7.1'
2
+ VERSION = '4.8.0'
3
3
  end
@@ -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?
@@ -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)
@@ -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.7.1
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-07 00:00:00.000000000 Z
11
+ date: 2016-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-log