ridley 0.10.1 → 0.10.2

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/lib/ridley/chef.rb CHANGED
@@ -5,6 +5,7 @@ module Ridley
5
5
  # site, and Chef Cookbooks
6
6
  module Chef
7
7
  autoload :Cookbook, 'ridley/chef/cookbook'
8
+ autoload :Chefignore, 'ridley/chef/chefignore'
8
9
  autoload :Digester, 'ridley/chef/digester'
9
10
  end
10
11
  end
@@ -0,0 +1,76 @@
1
+ module Ridley::Chef
2
+ # Borrowed and modified from:
3
+ # {https://raw.github.com/opscode/chef/62f9b0e3be8e22eef092163c331b7d3f8d350f94/lib/chef/cookbook/chefignore.rb}
4
+ #
5
+ # Copyright:: Copyright (c) 2011 Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ class Chefignore
19
+ class << self
20
+ # Traverse a path in relative context to find a Chefignore file
21
+ #
22
+ # @param [String] path
23
+ # path to traverse
24
+ #
25
+ # @return [String, nil]
26
+ def find_relative_to(path)
27
+ [
28
+ File.join(path, FILENAME),
29
+ File.join(path, 'cookbooks', FILENAME)
30
+ ].find { |f| File.exists?(f) }
31
+ end
32
+ end
33
+
34
+ FILENAME = "chefignore".freeze
35
+ COMMENTS_AND_WHITESPACE = /^\s*(?:#.*)?$/
36
+
37
+ attr_reader :ignores
38
+
39
+ def initialize(ignore_file_or_repo)
40
+ @ignore_file = find_ignore_file(ignore_file_or_repo)
41
+ @ignores = parse_ignore_file
42
+ end
43
+
44
+ def remove_ignores_from(file_list)
45
+ Array(file_list).inject([]) do |unignored, file|
46
+ ignored?(file) ? unignored : unignored << file
47
+ end
48
+ end
49
+
50
+ def ignored?(file_name)
51
+ @ignores.any? { |glob| File.fnmatch?(glob, file_name) }
52
+ end
53
+
54
+ private
55
+
56
+ def parse_ignore_file
57
+ ignore_globs = []
58
+
59
+ if File.exist?(@ignore_file) && File.readable?(@ignore_file)
60
+ File.foreach(@ignore_file) do |line|
61
+ ignore_globs << line.strip unless line =~ COMMENTS_AND_WHITESPACE
62
+ end
63
+ end
64
+
65
+ ignore_globs
66
+ end
67
+
68
+ def find_ignore_file(path)
69
+ if File.basename(path) =~ /#{FILENAME}/
70
+ path
71
+ else
72
+ File.join(path, FILENAME)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -96,6 +96,7 @@ module Ridley::Chef
96
96
  root_files: Array.new
97
97
  )
98
98
  @frozen = false
99
+ @chefignore = Ridley::Chef::Chefignore.new(@path)
99
100
 
100
101
  load_files
101
102
  end
@@ -207,7 +208,12 @@ module Ridley::Chef
207
208
 
208
209
  private
209
210
 
211
+ # @return [Array]
210
212
  attr_reader :files
213
+ # @return [Ridley::Chef::Chefignore]
214
+ attr_reader :chefignore
215
+
216
+ def_delegator :chefignore, :ignored?
211
217
 
212
218
  def load_files
213
219
  load_shallow(:recipes, 'recipes', '*.rb')
@@ -225,6 +231,7 @@ module Ridley::Chef
225
231
  [].tap do |files|
226
232
  Dir.glob(path.join('*'), File::FNM_DOTMATCH).each do |file|
227
233
  next if File.directory?(file)
234
+ next if ignored?(file)
228
235
  @files << file
229
236
  @manifest[:root_files] << file_metadata(:root_files, file)
230
237
  end
@@ -236,6 +243,7 @@ module Ridley::Chef
236
243
  file_spec = path.join(category_dir, '**', glob)
237
244
  Dir.glob(file_spec, File::FNM_DOTMATCH).each do |file|
238
245
  next if File.directory?(file)
246
+ next if ignored?(file)
239
247
  @files << file
240
248
  @manifest[category] << file_metadata(category, file)
241
249
  end
@@ -245,6 +253,7 @@ module Ridley::Chef
245
253
  def load_shallow(category, *path_glob)
246
254
  [].tap do |files|
247
255
  Dir[path.join(*path_glob)].each do |file|
256
+ next if ignored?(file)
248
257
  @files << file
249
258
  @manifest[category] << file_metadata(category, file)
250
259
  end
@@ -94,7 +94,7 @@ module Ridley
94
94
  # @return [Hash, nil]
95
95
  def upload(chk_id, path)
96
96
  checksum = self.checksum(chk_id)
97
-
97
+
98
98
  unless checksum[:needs_upload]
99
99
  return nil
100
100
  end
@@ -109,6 +109,12 @@ module Ridley
109
109
  upload_path = url.path
110
110
  url.path = ""
111
111
 
112
+ # versions prior to OSS Chef 11 will strip the port to upload the file to in the checksum
113
+ # url returned. This will ensure we are uploading to the proper location.
114
+ if client.connection.foss?
115
+ url.port = URI(client.connection.server_url).port
116
+ end
117
+
112
118
  begin
113
119
  Faraday.new(url, client.options.slice(*Connection::VALID_OPTIONS)) do |c|
114
120
  c.response :chef_response
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "0.10.1"
2
+ VERSION = "0.10.2"
3
3
  end
@@ -0,0 +1,8 @@
1
+ #
2
+ # The ignore file allows you to skip files in cookbooks with the same name that appear
3
+ # later in the search path.
4
+ #
5
+
6
+ recipes/ignoreme.rb
7
+ # comments can be indented
8
+ ignored
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::Chef::Chefignore do
4
+ describe "ClassMethods" do
5
+ subject { described_class }
6
+
7
+ describe "::find_relative_to" do
8
+ let(:path) { tmp_path.join('chefignore-test') }
9
+ before(:each) { FileUtils.mkdir_p(path) }
10
+
11
+ it "finds a chefignore file in a 'cookbooks' directory relative to the given path" do
12
+ FileUtils.touch(path.join('chefignore'))
13
+ subject.find_relative_to(path)
14
+ end
15
+
16
+ it "finds a chefignore file relative to the given path" do
17
+ FileUtils.mkdir_p(path.join('cookbooks'))
18
+ FileUtils.touch(path.join('cookbooks', 'chefignore'))
19
+ subject.find_relative_to(path)
20
+ end
21
+ end
22
+ end
23
+
24
+ subject { described_class.new(File.join(fixtures_path)) }
25
+
26
+ it "loads the globs in the chefignore file" do
27
+ subject.ignores.should =~ %w[recipes/ignoreme.rb ignored]
28
+ end
29
+
30
+ it "removes items from an array that match the ignores" do
31
+ file_list = %w[ recipes/ignoreme.rb recipes/dontignoreme.rb ]
32
+ subject.remove_ignores_from(file_list).should == %w[recipes/dontignoreme.rb]
33
+ end
34
+
35
+ it "determines if a file is ignored" do
36
+ subject.ignored?('ignored').should be_true
37
+ subject.ignored?('recipes/ignoreme.rb').should be_true
38
+ subject.ignored?('recipes/dontignoreme.rb').should be_false
39
+ end
40
+ end
@@ -1,11 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ridley::SandboxUploader do
4
+ let(:connection) { double('chef-conn') }
4
5
  let(:client) do
5
6
  double('client',
6
7
  client_name: 'reset',
7
8
  client_key: fixtures_path.join('reset.pem'),
8
- options: {}
9
+ options: {},
10
+ connection: connection
9
11
  )
10
12
  end
11
13
 
@@ -66,6 +68,10 @@ describe Ridley::SandboxUploader do
66
68
  let(:chk_id) { "oGCPHrQ+5MylEL+V+NIJ9w==" }
67
69
  let(:path) { fixtures_path.join('reset.pem').to_s }
68
70
 
71
+ before do
72
+ connection.stub(foss?: false)
73
+ end
74
+
69
75
  context "when the checksum needs uploading" do
70
76
  let(:checksums) do
71
77
  {
@@ -100,5 +106,26 @@ describe Ridley::SandboxUploader do
100
106
  subject.upload(chk_id, path).should be_nil
101
107
  end
102
108
  end
109
+
110
+ context "when the connection is an open source server connection with a non-80 port" do
111
+ before do
112
+ connection.stub(foss?: true, server_url: "http://localhost:8889")
113
+ end
114
+
115
+ let(:checksums) do
116
+ {
117
+ chk_id => {
118
+ url: "http://localhost/sandboxes/bd091b150b0a4578b97771af6abf3e05",
119
+ needs_upload: true
120
+ }
121
+ }
122
+ end
123
+
124
+ it "does not strip the port from the target to upload to" do
125
+ stub_request(:put, "http://localhost:8889/sandboxes/bd091b150b0a4578b97771af6abf3e05")
126
+
127
+ subject.upload(chk_id, path)
128
+ end
129
+ end
103
130
  end
104
131
  end
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: 0.10.1
4
+ version: 0.10.2
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-04-27 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -308,6 +308,7 @@ files:
308
308
  - lib/ridley/bootstrapper/context.rb
309
309
  - lib/ridley/chain_link.rb
310
310
  - lib/ridley/chef.rb
311
+ - lib/ridley/chef/chefignore.rb
311
312
  - lib/ridley/chef/cookbook.rb
312
313
  - lib/ridley/chef/cookbook/metadata.rb
313
314
  - lib/ridley/chef/cookbook/syntax_check.rb
@@ -359,6 +360,7 @@ files:
359
360
  - spec/acceptance/role_resource_spec.rb
360
361
  - spec/acceptance/sandbox_resource_spec.rb
361
362
  - spec/acceptance/search_resource_spec.rb
363
+ - spec/fixtures/chefignore
362
364
  - spec/fixtures/encrypted_data_bag_secret
363
365
  - spec/fixtures/example_cookbook/README.md
364
366
  - spec/fixtures/example_cookbook/attributes/default.rb
@@ -384,6 +386,7 @@ files:
384
386
  - spec/unit/ridley/bootstrap_bindings/windows_template_binding_spec.rb
385
387
  - spec/unit/ridley/bootstrapper/context_spec.rb
386
388
  - spec/unit/ridley/bootstrapper_spec.rb
389
+ - spec/unit/ridley/chef/chefignore_spec.rb
387
390
  - spec/unit/ridley/chef/cookbook_spec.rb
388
391
  - spec/unit/ridley/chef/digester_spec.rb
389
392
  - spec/unit/ridley/client_spec.rb
@@ -433,7 +436,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
433
436
  version: '0'
434
437
  segments:
435
438
  - 0
436
- hash: -1173467066893192737
439
+ hash: -2279939140045068051
437
440
  requirements: []
438
441
  rubyforge_project:
439
442
  rubygems_version: 1.8.23
@@ -450,6 +453,7 @@ test_files:
450
453
  - spec/acceptance/role_resource_spec.rb
451
454
  - spec/acceptance/sandbox_resource_spec.rb
452
455
  - spec/acceptance/search_resource_spec.rb
456
+ - spec/fixtures/chefignore
453
457
  - spec/fixtures/encrypted_data_bag_secret
454
458
  - spec/fixtures/example_cookbook/README.md
455
459
  - spec/fixtures/example_cookbook/attributes/default.rb
@@ -475,6 +479,7 @@ test_files:
475
479
  - spec/unit/ridley/bootstrap_bindings/windows_template_binding_spec.rb
476
480
  - spec/unit/ridley/bootstrapper/context_spec.rb
477
481
  - spec/unit/ridley/bootstrapper_spec.rb
482
+ - spec/unit/ridley/chef/chefignore_spec.rb
478
483
  - spec/unit/ridley/chef/cookbook_spec.rb
479
484
  - spec/unit/ridley/chef/digester_spec.rb
480
485
  - spec/unit/ridley/client_spec.rb