ridley 4.0.0 → 4.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcfcaeea81633ef129ccef6ff8f1f2ffe02c3862
4
- data.tar.gz: 193f02dd4c48240a88730a325364f7a467a3377e
3
+ metadata.gz: a8f779adc3b49cb4e56e8c3ec7be31f9c9d4d578
4
+ data.tar.gz: 567f7dfd4825123df48ba3481b925de1d99e2dfc
5
5
  SHA512:
6
- metadata.gz: ff2323596b824efadefe1b9b6e795f07e81464f70a62a53271719662413ab6c195eedff29e499c63e8a6bb454db4235d2818b7fffa028baa1c2daec43522507a
7
- data.tar.gz: 7193d8513449c3cef68faaa95776519fcf819c1c17cdf9764ccb3889ca126afc4814a609a1616538bf87795a8ed67c6decf50daeb0151d1db5e3683b7b626938
6
+ metadata.gz: 19d7b37325d54cba04a0685999cdb753b2bec68c8361e83736049a62a3b99410dfff57ab42757943395ce3f66075725dd9b479f44d4930e08f9b9300c04de839
7
+ data.tar.gz: 15f13659355c879b27e1b5e5388f7b055baef746d5474e2478557f771f7d152727d4c609e540855a901b7d92d4360d0e3424e9fda3de542adfdfe3249682996a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 4.1.0
2
+
3
+ * Fix monkey patching issue with options#slice when running under Vagrant
4
+ * Bump required version of Celluloid `~> 0.16.0`
5
+ * Bump required version of Celluloid-IO `~> 0.16.1`
6
+
1
7
  # 4.0.0
2
8
 
3
9
  * Update many out of date dependencies
@@ -43,13 +43,13 @@ module Ridley::Chef
43
43
  set_assignment_mode :carefree
44
44
 
45
45
  attribute :node_name,
46
- default: Socket.gethostname
46
+ default: -> { Socket.gethostname }
47
47
  attribute :chef_server_url,
48
48
  default: 'http://localhost:4000'
49
49
  attribute :client_key,
50
- default: platform_specific_path('/etc/chef/client.pem')
50
+ default: -> { platform_specific_path('/etc/chef/client.pem') }
51
51
  attribute :validation_key,
52
- default: platform_specific_path('/etc/chef/validation.pem')
52
+ default: -> { platform_specific_path('/etc/chef/validation.pem') }
53
53
  attribute :validation_client_name,
54
54
  default: 'chef-validator'
55
55
 
@@ -70,9 +70,9 @@ module Ridley::Chef
70
70
  # deprecated in chef/config.rb but doesn't currently trigger a warning.
71
71
  # See also: CHEF-3715
72
72
  attribute :syntax_check_cache_path,
73
- default: Dir.mktmpdir
73
+ default: -> { Dir.mktmpdir }
74
74
  attribute :cache_options,
75
- default: { path: defined?(syntax_check_cache_path) ? syntax_check_cache_path : Dir.mktmpdir }
75
+ default: -> { { path: defined?(syntax_check_cache_path) ? syntax_check_cache_path : Dir.mktmpdir } }
76
76
 
77
77
  # Create a new Chef Config object.
78
78
  #
@@ -1,5 +1,4 @@
1
- require 'shellwords'
2
- require 'buff/shell_out'
1
+ require 'erubis'
3
2
 
4
3
  module Ridley::Chef
5
4
  class Cookbook
@@ -68,7 +67,6 @@ module Ridley::Chef
68
67
  end
69
68
  end
70
69
 
71
- include Buff::ShellOut
72
70
  include Ridley::Logging
73
71
  include Ridley::Mixin::Checksum
74
72
 
@@ -131,30 +129,55 @@ module Ridley::Chef
131
129
  true
132
130
  end
133
131
 
132
+ # Borrowed from: https://github.com/opscode/chef/blob/d111e82/lib/chef/cookbook/syntax_check.rb#L191-L215
134
133
  def validate_template(erb_file)
135
- result = shell_out("erubis -x #{erb_file.shellescape} | ruby -c")
134
+ old_stderr = $stderr
136
135
 
137
- if result.error?
138
- file_relative_path = erb_file[/^#{Regexp.escape(cookbook_path+File::Separator)}(.*)/, 1]
139
- log.error { "Erb template #{file_relative_path} has a syntax error:" }
140
- result.stderr.each_line { |l| Ridley.log.fatal(l.chomp) }
141
- return false
142
- end
136
+ engine = Erubis::Eruby.new
137
+ engine.convert!(IO.read(erb_file))
138
+
139
+ ruby_code = engine.src
140
+
141
+ # Even when we're compiling the code w/ RubyVM, syntax errors just
142
+ # print to $stderr. We want to capture this and handle the printing
143
+ # ourselves, so we must temporarily swap $stderr to capture the output.
144
+ tmp_stderr = $stderr = StringIO.new
145
+
146
+ abs_path = File.expand_path(erb_file)
147
+ RubyVM::InstructionSequence.new(ruby_code, erb_file, abs_path, 0)
143
148
 
144
149
  true
150
+ rescue SyntaxError
151
+ $stderr = old_stderr
152
+ invalid_erb_file(erb_file, tmp_stderr.string)
153
+ false
154
+ ensure
155
+ $stderr = old_stderr if defined?(old_stderr) && old_stderr
145
156
  end
146
157
 
158
+ # Borrowed from: https://github.com/opscode/chef/blob/d111e82/lib/chef/cookbook/syntax_check.rb#L242-L264
147
159
  def validate_ruby_file(ruby_file)
148
- result = shell_out("ruby -c #{ruby_file.shellescape}")
149
-
150
- if result.error?
151
- file_relative_path = ruby_file[/^#{Regexp.escape(cookbook_path+File::Separator)}(.*)/, 1]
152
- log.error { "Cookbook file #{file_relative_path} has a ruby syntax error:" }
153
- result.stderr.each_line { |l| Ridley.log.error(l.chomp) }
154
- return false
155
- end
156
-
160
+ # Even when we're compiling the code w/ RubyVM, syntax errors just
161
+ # print to $stderr. We want to capture this and handle the printing
162
+ # ourselves, so we must temporarily swap $stderr to capture the output.
163
+ old_stderr = $stderr
164
+ tmp_stderr = $stderr = StringIO.new
165
+ abs_path = File.expand_path(ruby_file)
166
+ file_content = IO.read(abs_path)
167
+
168
+ # We have to wrap this in a block so the user code evaluates in a
169
+ # similar context as what Chef does normally. Otherwise RubyVM
170
+ # will reject some common idioms, like using `return` to end evaluation
171
+ # of a recipe. See also CHEF-5199
172
+ wrapped_content = "Object.new.instance_eval do\n#{file_content}\nend\n"
173
+ RubyVM::InstructionSequence.new(wrapped_content, ruby_file, abs_path, 0)
157
174
  true
175
+ rescue SyntaxError
176
+ $stderr = old_stderr
177
+ invalid_ruby_file(ruby_file, tmp_stderr.string)
178
+ false
179
+ ensure
180
+ $stderr = old_stderr if defined?(old_stderr) && old_stderr
158
181
  end
159
182
 
160
183
  private
@@ -165,6 +188,21 @@ module Ridley::Chef
165
188
  def ignored?(file)
166
189
  !!chefignore && chefignore.ignored?(file)
167
190
  end
191
+
192
+ # Debug a syntax error in a template.
193
+ def invalid_erb_file(erb_file, error_message)
194
+ log.error("Erb template #{erb_file} has a syntax error:")
195
+ error_message.each_line { |l| log.error(l.chomp) }
196
+ nil
197
+ end
198
+
199
+ # Debugs ruby syntax errors by printing the path to the file and any
200
+ # diagnostic info given in +error_message+
201
+ def invalid_ruby_file(ruby_file, error_message)
202
+ log.error("Cookbook file #{ruby_file} has a ruby syntax error:")
203
+ error_message.each_line { |l| log.error(l.chomp) }
204
+ false
205
+ end
168
206
  end
169
207
  end
170
208
  end
@@ -40,7 +40,9 @@ module Ridley::Chef
40
40
  private
41
41
 
42
42
  def checksum_file(file, digest)
43
- File.open(file, 'rb') { |f| checksum_io(f, digest) }
43
+ File.open(file, 'rb') do |f|
44
+ checksum_io(f, digest)
45
+ end
44
46
  end
45
47
 
46
48
  def checksum_io(io, digest)
data/lib/ridley/client.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'ridley/helpers'
2
+
1
3
  module Ridley
2
4
  class Client
3
5
  class ConnectionSupervisor < ::Celluloid::SupervisionGroup
@@ -7,7 +9,7 @@ module Ridley
7
9
  options[:server_url],
8
10
  options[:client_name],
9
11
  options[:client_key],
10
- options.slice(*Ridley::Connection::VALID_OPTIONS)
12
+ Ridley::Helpers.options_slice(options, *Ridley::Connection::VALID_OPTIONS)
11
13
  ], as: :connection_pool)
12
14
  end
13
15
  end
@@ -17,14 +19,14 @@ module Ridley
17
19
  super(registry)
18
20
  supervise_as :client_resource, Ridley::ClientResource, connection_registry
19
21
  supervise_as :cookbook_resource, Ridley::CookbookResource, connection_registry,
20
- options[:client_name], options[:client_key], options.slice(*Ridley::Connection::VALID_OPTIONS)
22
+ options[:client_name], options[:client_key], Ridley::Helpers.options_slice(options, *Ridley::Connection::VALID_OPTIONS)
21
23
  supervise_as :data_bag_resource, Ridley::DataBagResource, connection_registry,
22
24
  options[:encrypted_data_bag_secret]
23
25
  supervise_as :environment_resource, Ridley::EnvironmentResource, connection_registry
24
26
  supervise_as :node_resource, Ridley::NodeResource, connection_registry, options
25
27
  supervise_as :role_resource, Ridley::RoleResource, connection_registry
26
28
  supervise_as :sandbox_resource, Ridley::SandboxResource, connection_registry,
27
- options[:client_name], options[:client_key], options.slice(*Ridley::Connection::VALID_OPTIONS)
29
+ options[:client_name], options[:client_key], Ridley::Helpers.options_slice(options, *Ridley::Connection::VALID_OPTIONS)
28
30
  supervise_as :search_resource, Ridley::SearchResource, connection_registry
29
31
  supervise_as :user_resource, Ridley::UserResource, connection_registry
30
32
  end
@@ -3,6 +3,8 @@ require 'retryable'
3
3
  require 'tempfile'
4
4
  require 'zlib'
5
5
 
6
+ require 'ridley/helpers'
7
+
6
8
  module Ridley
7
9
  class Connection < Faraday::Connection
8
10
  include Celluloid
@@ -65,7 +67,7 @@ module Ridley
65
67
  b.adapter :net_http_persistent
66
68
  end
67
69
 
68
- uri_hash = Addressable::URI.parse(server_url).to_hash.slice(:scheme, :host, :port)
70
+ uri_hash = Ridley::Helpers.options_slice(Addressable::URI.parse(server_url).to_hash, :scheme, :host, :port)
69
71
 
70
72
  unless uri_hash[:port]
71
73
  uri_hash[:port] = (uri_hash[:scheme] == "https" ? 443 : 80)
@@ -0,0 +1,10 @@
1
+ module Ridley
2
+ module Helpers
3
+ def self.options_slice(options, *keys)
4
+ keys.inject({}) do |memo, key|
5
+ memo[key] = options[key] if options.include?(key)
6
+ memo
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ require 'ridley/helpers'
2
+
1
3
  module Ridley
2
4
  class CookbookResource < Ridley::Resource
3
5
  task_class TaskThread
@@ -225,7 +227,7 @@ module Ridley
225
227
 
226
228
  sandbox.upload(checksums)
227
229
  sandbox.commit
228
- update(cookbook, options.slice(:force, :freeze))
230
+ update(cookbook, Ridley::Helpers.options_slice(options, :force, :freeze))
229
231
  ensure
230
232
  # Destroy the compiled metadata only if it was created
231
233
  File.delete(compiled_metadata) unless compiled_metadata.nil?
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "4.0.0"
2
+ VERSION = "4.1.0"
3
3
  end
data/ridley.gemspec CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'buff-extensions', '~> 1.0'
24
24
  s.add_dependency 'buff-ignore', '~> 1.1'
25
25
  s.add_dependency 'buff-shell_out', '~> 0.1'
26
- s.add_dependency 'celluloid', '~> 0.16.0.pre'
27
- s.add_dependency 'celluloid-io', '~> 0.16.0.pre'
26
+ s.add_dependency 'celluloid', '~> 0.16.0'
27
+ s.add_dependency 'celluloid-io', '~> 0.16.1'
28
28
  s.add_dependency 'erubis'
29
29
  s.add_dependency 'faraday', '~> 0.9.0'
30
30
  s.add_dependency 'hashie', '>= 2.0.2', '< 3.0.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridley
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-03 00:00:00.000000000 Z
12
+ date: 2014-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -101,28 +101,28 @@ dependencies:
101
101
  requirements:
102
102
  - - ~>
103
103
  - !ruby/object:Gem::Version
104
- version: 0.16.0.pre
104
+ version: 0.16.0
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ~>
110
110
  - !ruby/object:Gem::Version
111
- version: 0.16.0.pre
111
+ version: 0.16.0
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: celluloid-io
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ~>
117
117
  - !ruby/object:Gem::Version
118
- version: 0.16.0.pre
118
+ version: 0.16.1
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 0.16.0.pre
125
+ version: 0.16.1
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: erubis
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -294,6 +294,7 @@ files:
294
294
  - lib/ridley/client.rb
295
295
  - lib/ridley/connection.rb
296
296
  - lib/ridley/errors.rb
297
+ - lib/ridley/helpers.rb
297
298
  - lib/ridley/logger.rb
298
299
  - lib/ridley/logging.rb
299
300
  - lib/ridley/middleware.rb