ridley 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1 @@
1
1
  1.9.3-p327
2
-
@@ -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.9.0"
2
+ VERSION = "0.9.1"
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.9.0
4
+ version: 0.9.1
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-03-22 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
@@ -288,6 +288,7 @@ files:
288
288
  - lib/ridley/bootstrapper/context.rb
289
289
  - lib/ridley/chain_link.rb
290
290
  - lib/ridley/chef.rb
291
+ - lib/ridley/chef/chefignore.rb
291
292
  - lib/ridley/chef/cookbook.rb
292
293
  - lib/ridley/chef/cookbook/metadata.rb
293
294
  - lib/ridley/chef/cookbook/syntax_check.rb
@@ -334,6 +335,7 @@ files:
334
335
  - spec/acceptance/role_resource_spec.rb
335
336
  - spec/acceptance/sandbox_resource_spec.rb
336
337
  - spec/acceptance/search_resource_spec.rb
338
+ - spec/fixtures/chefignore
337
339
  - spec/fixtures/encrypted_data_bag_secret
338
340
  - spec/fixtures/example_cookbook/README.md
339
341
  - spec/fixtures/example_cookbook/attributes/default.rb
@@ -357,6 +359,7 @@ files:
357
359
  - spec/support/spec_helpers.rb
358
360
  - spec/unit/ridley/bootstrapper/context_spec.rb
359
361
  - spec/unit/ridley/bootstrapper_spec.rb
362
+ - spec/unit/ridley/chef/chefignore_spec.rb
360
363
  - spec/unit/ridley/chef/cookbook_spec.rb
361
364
  - spec/unit/ridley/chef/digester_spec.rb
362
365
  - spec/unit/ridley/client_spec.rb
@@ -401,10 +404,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
401
404
  version: '0'
402
405
  segments:
403
406
  - 0
404
- hash: 141649622166830890
407
+ hash: -3927256690615298092
405
408
  requirements: []
406
409
  rubyforge_project:
407
- rubygems_version: 1.8.24
410
+ rubygems_version: 1.8.23
408
411
  signing_key:
409
412
  specification_version: 3
410
413
  summary: A reliable Chef API client with a clean syntax
@@ -418,6 +421,7 @@ test_files:
418
421
  - spec/acceptance/role_resource_spec.rb
419
422
  - spec/acceptance/sandbox_resource_spec.rb
420
423
  - spec/acceptance/search_resource_spec.rb
424
+ - spec/fixtures/chefignore
421
425
  - spec/fixtures/encrypted_data_bag_secret
422
426
  - spec/fixtures/example_cookbook/README.md
423
427
  - spec/fixtures/example_cookbook/attributes/default.rb
@@ -441,6 +445,7 @@ test_files:
441
445
  - spec/support/spec_helpers.rb
442
446
  - spec/unit/ridley/bootstrapper/context_spec.rb
443
447
  - spec/unit/ridley/bootstrapper_spec.rb
448
+ - spec/unit/ridley/chef/chefignore_spec.rb
444
449
  - spec/unit/ridley/chef/cookbook_spec.rb
445
450
  - spec/unit/ridley/chef/digester_spec.rb
446
451
  - spec/unit/ridley/client_spec.rb