right_scraper 1.0.26 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/Gemfile +16 -0
  2. data/README.rdoc +9 -28
  3. data/Rakefile +51 -39
  4. data/lib/right_scraper/builders/base.rb +64 -0
  5. data/lib/right_scraper/builders/filesystem.rb +96 -0
  6. data/lib/right_scraper/builders/union.rb +57 -0
  7. data/lib/right_scraper/logger.rb +102 -0
  8. data/lib/right_scraper/loggers/noisy.rb +85 -0
  9. data/lib/right_scraper/processes/ssh.rb +188 -0
  10. data/lib/right_scraper/repositories/base.rb +299 -0
  11. data/lib/right_scraper/repositories/download.rb +90 -0
  12. data/lib/right_scraper/repositories/git.rb +92 -0
  13. data/lib/right_scraper/repositories/mock.rb +70 -0
  14. data/lib/right_scraper/repositories/svn.rb +96 -0
  15. data/lib/right_scraper/resources/base.rb +70 -0
  16. data/{spec/scraper_base_spec.rb → lib/right_scraper/resources/cookbook.rb} +9 -23
  17. data/lib/right_scraper/resources/workflow.rb +55 -0
  18. data/lib/right_scraper/retrievers/base.rb +114 -0
  19. data/lib/right_scraper/retrievers/checkout.rb +79 -0
  20. data/lib/right_scraper/retrievers/download.rb +97 -0
  21. data/lib/right_scraper/retrievers/git.rb +140 -0
  22. data/lib/right_scraper/retrievers/svn.rb +87 -0
  23. data/lib/right_scraper/scanners/base.rb +111 -0
  24. data/lib/right_scraper/scanners/cookbook_manifest.rb +59 -0
  25. data/lib/right_scraper/scanners/cookbook_metadata.rb +69 -0
  26. data/lib/right_scraper/scanners/cookbook_s3_upload.rb +84 -0
  27. data/lib/right_scraper/scanners/union.rb +89 -0
  28. data/lib/right_scraper/scanners/workflow_manifest.rb +86 -0
  29. data/lib/right_scraper/scanners/workflow_metadata.rb +70 -0
  30. data/lib/right_scraper/scanners/workflow_s3_upload.rb +85 -0
  31. data/lib/right_scraper/scraper.rb +81 -57
  32. data/lib/right_scraper/scraper_logger.rb +61 -0
  33. data/lib/right_scraper/scrapers/base.rb +262 -0
  34. data/lib/right_scraper/scrapers/cookbook.rb +73 -0
  35. data/lib/right_scraper/scrapers/workflow.rb +88 -0
  36. data/lib/right_scraper/svn_client.rb +101 -0
  37. data/lib/right_scraper/version.rb +28 -0
  38. data/lib/right_scraper.rb +35 -11
  39. data/right_scraper.gemspec +26 -13
  40. data/right_scraper.rconf +13 -0
  41. data/spec/builder_spec.rb +50 -0
  42. data/spec/cookbook_helper.rb +73 -0
  43. data/spec/cookbook_manifest_spec.rb +55 -0
  44. data/spec/cookbook_s3_upload_spec.rb +152 -0
  45. data/spec/download/download_retriever_spec.rb +118 -0
  46. data/spec/download/download_retriever_spec_helper.rb +72 -0
  47. data/spec/download/download_spec.rb +130 -0
  48. data/spec/download/multi_dir_spec.rb +106 -0
  49. data/spec/download/multi_dir_spec_helper.rb +40 -0
  50. data/spec/git/cookbook_spec.rb +166 -0
  51. data/spec/git/demokey +27 -0
  52. data/spec/git/demokey.pub +1 -0
  53. data/spec/git/password_key +30 -0
  54. data/spec/git/password_key.pub +1 -0
  55. data/spec/git/repository_spec.rb +110 -0
  56. data/spec/git/retriever_spec.rb +505 -0
  57. data/spec/git/retriever_spec_helper.rb +112 -0
  58. data/spec/git/scraper_spec.rb +136 -0
  59. data/spec/git/ssh_spec.rb +170 -0
  60. data/spec/git/url_spec.rb +103 -0
  61. data/spec/logger_spec.rb +185 -0
  62. data/spec/repository_spec.rb +89 -23
  63. data/spec/{scraper_spec_helper_base.rb → retriever_spec_helper.rb} +41 -27
  64. data/spec/scanner_spec.rb +61 -0
  65. data/spec/scraper_helper.rb +96 -0
  66. data/spec/scraper_spec.rb +123 -45
  67. data/spec/spec_helper.rb +87 -14
  68. data/spec/svn/cookbook_spec.rb +97 -0
  69. data/spec/svn/multi_svn_spec.rb +64 -0
  70. data/spec/svn/multi_svn_spec_helper.rb +40 -0
  71. data/spec/svn/repository_spec.rb +72 -0
  72. data/spec/svn/retriever_spec.rb +261 -0
  73. data/spec/svn/scraper_spec.rb +90 -0
  74. data/spec/svn/{svn_scraper_spec_helper.rb → svn_retriever_spec_helper.rb} +46 -27
  75. data/spec/svn/url_spec.rb +47 -0
  76. data/spec/url_spec.rb +164 -0
  77. metadata +203 -31
  78. data/lib/right_scraper/linux/process_monitor.rb +0 -84
  79. data/lib/right_scraper/repository.rb +0 -78
  80. data/lib/right_scraper/scraper_base.rb +0 -175
  81. data/lib/right_scraper/scrapers/download_scraper.rb +0 -67
  82. data/lib/right_scraper/scrapers/git_scraper.rb +0 -283
  83. data/lib/right_scraper/scrapers/svn_scraper.rb +0 -119
  84. data/lib/right_scraper/watcher.rb +0 -158
  85. data/lib/right_scraper/win32/process_monitor.rb +0 -98
  86. data/spec/download/download_scraper_spec.rb +0 -94
  87. data/spec/git/git_scraper_spec.rb +0 -165
  88. data/spec/git/git_scraper_spec_helper.rb +0 -72
  89. data/spec/rcov.opts +0 -1
  90. data/spec/spec.opts +0 -2
  91. data/spec/svn/svn_scraper_spec.rb +0 -148
  92. data/spec/watcher_spec.rb +0 -74
@@ -1,17 +1,18 @@
1
- # Copyright: Copyright (c) 2010 RightScale, Inc.
1
+ # -*-ruby-*-
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
2
3
  #
3
4
  # Permission is hereby granted, free of charge, to any person obtaining
4
5
  # a copy of this software and associated documentation files (the
5
6
  # 'Software'), to deal in the Software without restriction, including
6
7
  # without limitation the rights to use, copy, modify, merge, publish,
7
- # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
9
  # permit persons to whom the Software is furnished to do so, subject to
9
10
  # the following conditions:
10
11
  #
11
12
  # The above copyright notice and this permission notice shall be
12
13
  # included in all copies or substantial portions of the Software.
13
14
  #
14
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
16
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
17
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
18
  # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
@@ -21,10 +22,10 @@
21
22
 
22
23
  require 'rubygems'
23
24
 
24
- spec = Gem::Specification.new do |spec|
25
+ Gem::Specification.new do |spec|
25
26
  spec.name = 'right_scraper'
26
- spec.version = '1.0.26'
27
- spec.authors = ['Raphael Simon']
27
+ spec.version = '3.0.0'
28
+ spec.authors = ['Graham Hughes', 'Raphael Simon']
28
29
  spec.email = 'raphael@rightscale.com'
29
30
  spec.homepage = 'https://github.com/rightscale/right_scraper'
30
31
  spec.platform = Gem::Platform::RUBY
@@ -32,24 +33,36 @@ spec = Gem::Specification.new do |spec|
32
33
  spec.has_rdoc = true
33
34
  spec.rdoc_options = ["--main", "README.rdoc", "--title", "RightScraper"]
34
35
  spec.extra_rdoc_files = ["README.rdoc"]
35
- spec.required_ruby_version = '>= 1.8.6'
36
+ spec.required_ruby_version = '>= 1.8.7'
36
37
  spec.rubyforge_project = %q{right_scraper}
37
38
  spec.require_path = 'lib'
38
39
 
40
+ spec.add_dependency('json', '>= 1.4.5')
41
+ spec.add_dependency('git', '>= 1.2.5')
42
+ spec.add_dependency('libarchive', '>= 0.1.1')
43
+ spec.add_dependency('right_aws', '>= 2.0')
44
+ spec.add_dependency('process_watcher', '~> 0.3')
45
+
46
+ spec.requirements << 'libarchive, 2.8.4'
47
+ spec.requirements << 'curl command line client'
48
+ spec.requirements << 'Subversion command line client'
49
+
50
+ spec.add_development_dependency('rspec')
51
+ spec.add_development_dependency('flexmock')
52
+ spec.add_development_dependency('rtags')
53
+
39
54
  spec.description = <<-EOF
40
55
  RightScraper provides a simple interface to download and keep local copies of remote
41
56
  repositories up-to-date using the following protocols:
42
57
  * git: RightScraper will clone then pull repos from git
43
58
  * SVN: RightScraper will checkout then update SVN repositories
44
59
  * tarballs: RightScraper will download, optionally uncompress and expand a given tar file
60
+ On top of retrieving remote repositories, right_scraper also include "scrapers" that
61
+ will analyze the repository content and instantiate "resources" as a result. Currently
62
+ supported resources are Chef cookbooks and RightScale workflow definitions.
45
63
  EOF
46
64
 
47
65
  candidates = Dir.glob("{lib,spec}/**/*") +
48
- ["LICENSE", "README.rdoc", "Rakefile", "right_scraper.gemspec"]
66
+ ["LICENSE", "README.rdoc", "Rakefile", "right_scraper.gemspec", "Gemfile", "right_scraper.rconf"]
49
67
  spec.files = candidates.sort
50
68
  end
51
-
52
- if $PROGRAM_NAME == __FILE__
53
- Gem.manage_gems if Gem::RubyGemsVersion.to_f < 1.0
54
- Gem::Builder.new(spec).build
55
- end
@@ -0,0 +1,13 @@
1
+ # RConf configuration file, usage:
2
+ # gem install rconf
3
+ # rconf
4
+ #
5
+ ruby do
6
+ version 'ruby-1.9.2-p290'
7
+ rubygems '1.6.2'
8
+ gemset 'right_scraper'
9
+ end
10
+ bundler do
11
+ version '1.0.10'
12
+ bundle_path File.join(ENV["HOME"], '.rightscale', 'right_scraper')
13
+ end
@@ -0,0 +1,50 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), 'download', 'download_retriever_spec_helper'))
26
+
27
+ describe RightScraper::Builders::Builder do
28
+
29
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
30
+
31
+ before(:each) do
32
+ @helper = RightScraper::DownloadRetrieverSpecHelper.new
33
+ @repo_dir = @helper.download_repo_path
34
+ end
35
+
36
+ it 'should be called correctly' do
37
+ builder = flexmock("builder")
38
+ builder.should_receive(:new).with(Hash).once.and_return(builder)
39
+ builder.should_receive(:go).with(String, RightScraper::Resources::Cookbook).once
40
+ builder.should_receive(:finish).with().once
41
+
42
+ @scraper = RightScraper::Scrapers::Cookbook.new(:repository => @helper.repo,
43
+ :repo_dir => @repo_dir,
44
+ :builders => [builder])
45
+ @scraper.next_resource.should_not be_nil
46
+ @scraper.next_resource.should be_nil
47
+ @scraper.close
48
+ end
49
+
50
+ end
@@ -0,0 +1,73 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'retriever_spec_helper'))
25
+ require 'uri'
26
+ require 'cgi'
27
+
28
+ module RightScraper
29
+ module CookbookHelper
30
+
31
+ def example_cookbook(repository, position=nil)
32
+ @helper = RightScraper::RetrieverSpecHelper.new if @helper.nil?
33
+ RightScraper::Resources::Cookbook.new(@repository, position)
34
+ end
35
+
36
+ def parse_url(repository)
37
+ uri = URI.parse(repository.url)
38
+ userinfo, query, tag = uri.select(:userinfo, :query, :fragment)
39
+ unless userinfo.nil?
40
+ username, password = userinfo.split(":", 2).map {|str| URI.unescape str}
41
+ uri.user = nil
42
+ uri.password = nil
43
+ end
44
+ unless query.nil?
45
+ hash = CGI::parse(query)
46
+ position = hash["p"][0]
47
+ hash.delete("p")
48
+ result = hash.map do |key, values|
49
+ values.map {|value| CGI::escape(key) + "=" + CGI::escape(value)}.join(";")
50
+ end.join(';')
51
+
52
+ if result == ""
53
+ uri.query = nil
54
+ else
55
+ uri.query = result
56
+ end
57
+ end
58
+ uri.fragment = nil unless tag.nil?
59
+ { :url => uri.to_s,
60
+ :username => username,
61
+ :password => password,
62
+ :position => position,
63
+ :tag => tag}
64
+ end
65
+
66
+ shared_examples_for 'a generic repository' do
67
+ it 'should have the same url' do
68
+ parse_url(@repository)[:url].should == @repository.url
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,55 @@
1
+ #-- -*- mode: ruby; encoding: utf-8 -*-
2
+ # Copyright: Copyright (c) 2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'right_scraper'))
26
+
27
+
28
+ module RightScraper::Scanners
29
+ describe CookbookManifest do
30
+ it 'should accumulate files' do
31
+ resource = flexmock(:resource)
32
+ resource.should_receive(:manifest=).with({"foo" => Digest::SHA1.hexdigest("bar"),
33
+ "baz" => Digest::SHA1.hexdigest("quux")
34
+ }).once
35
+ manifest = CookbookManifest.new
36
+ manifest.notice("foo") { "bar" }
37
+ manifest.notice("baz") { "quux" }
38
+ manifest.end(resource)
39
+ end
40
+ it 'should keep different resources separated' do
41
+ resource = flexmock(:resource)
42
+ resource.should_receive(:manifest=).with({"foo" => Digest::SHA1.hexdigest("bar"),
43
+ "baz" => Digest::SHA1.hexdigest("quux")
44
+ }).once
45
+ resource.should_receive(:manifest=).with({"bar" => Digest::SHA1.hexdigest("fred")
46
+ }).once
47
+ manifest = CookbookManifest.new
48
+ manifest.notice("foo") { "bar" }
49
+ manifest.notice("baz") { "quux" }
50
+ manifest.end(resource)
51
+ manifest.notice("bar") { "fred" }
52
+ manifest.end(resource)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,152 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
25
+ require 'tmpdir'
26
+ require 'digest/sha1'
27
+
28
+ describe RightScraper::Scanners::CookbookS3Upload do
29
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
30
+
31
+ include RightScraper::SpecHelpers
32
+
33
+ # Create download repository following given layout
34
+ # Update @repo_path with path to repository
35
+ # Delete any previously created repo
36
+ def setup_download_repo
37
+ @tmpdir = Dir.mktmpdir
38
+ @download_repo_path = File.join(@tmpdir, "download")
39
+ @repo_path = File.join(@tmpdir, "repo")
40
+ @repo_content = [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => [ { 'folder3' => [ 'file4' ] } ] }, 'file1' ]
41
+ create_cookbook(@download_repo_path, @repo_content)
42
+ @download_file = File.join(@tmpdir, "file.tar")
43
+ Dir.chdir(@download_repo_path) do
44
+ res, status = exec("tar cf \"#{@download_file}\" *")
45
+ raise "Failed to create tarball: #{res}" unless status.success?
46
+ end
47
+ end
48
+
49
+ # Cleanup after ourselves
50
+ def delete_download_repo
51
+ FileUtils.remove_entry_secure @tmpdir unless @tmpdir.nil?
52
+ end
53
+
54
+ before(:all) do
55
+ @scraperclass = RightScraper::Scrapers::Cookbook
56
+ end
57
+
58
+ before(:each) do
59
+ pending "Not run unless AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY set" unless
60
+ ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY']
61
+ end
62
+
63
+ context "given a bucket that doesn't exist" do
64
+ before(:each) do
65
+ setup_download_repo
66
+ end
67
+
68
+ after(:each) do
69
+ delete_download_repo
70
+ end
71
+
72
+ before(:each) do
73
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
74
+ :repo_type => :download,
75
+ :url => "file:///#{@download_file}")
76
+ @s3 = RightAws::S3.new(aws_access_key_id=ENV['AMAZON_ACCESS_KEY_ID'],
77
+ aws_secret_access_key=ENV['AMAZON_SECRET_ACCESS_KEY'],
78
+ :logger => RightScraper::Logger.new)
79
+ FileUtils.rm_rf(RightScraper::Retrievers::Base.repo_dir(@repo_path, @repo))
80
+ end
81
+
82
+ it 'should raise an exception immediately' do
83
+ bucket_name = 'this-bucket-does-not-exist'
84
+ @s3.bucket(bucket_name).should be_nil
85
+ lambda {
86
+ @scraper = @scraperclass.new(:repo_dir => @download_repo_path,
87
+ :scanners => [RightScraper::Scanners::CookbookMetadata,
88
+ RightScraper::Scanners::CookbookManifest,
89
+ RightScraper::Scanners::S3Upload],
90
+ :s3_key => ENV['AMAZON_ACCESS_KEY_ID'],
91
+ :s3_secret => ENV['AMAZON_SECRET_ACCESS_KEY'],
92
+ :s3_bucket => bucket_name,
93
+ :max_bytes => 1024**2,
94
+ :max_seconds => 20)
95
+ }.should raise_exception(/Need an actual, existing S3 bucket!/)
96
+ end
97
+ end
98
+
99
+ context 'given a download repository with the S3UploadScanner' do
100
+ before(:each) do
101
+ setup_download_repo
102
+ end
103
+
104
+ before(:each) do
105
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
106
+ :repo_type => :download,
107
+ :url => "file:///#{@download_file}")
108
+ bucket_name = 'com.rightscale.test.20100823'
109
+ @scraper = @scraperclass.new(:repo_dir => @download_repo_path,
110
+ :scanners => [RightScraper::Scanners::CookbookMetadata,
111
+ RightScraper::Scanners::CookbookManifest,
112
+ RightScraper::Scanners::S3Upload],
113
+ :s3_key => ENV['AMAZON_ACCESS_KEY_ID'],
114
+ :s3_secret => ENV['AMAZON_SECRET_ACCESS_KEY'],
115
+ :s3_bucket => bucket_name,
116
+ :max_bytes => 1024**2,
117
+ :max_seconds => 20)
118
+ s3 = RightAws::S3.new(aws_access_key_id=ENV['AMAZON_ACCESS_KEY_ID'],
119
+ aws_secret_access_key=ENV['AMAZON_SECRET_ACCESS_KEY'],
120
+ :logger => RightScraper::Logger.new)
121
+ @bucket = s3.bucket(bucket_name, create=true)
122
+ FileUtils.rm_rf(RightScraper::Retrievers::Base.repo_dir(@repo_path, @repo))
123
+ end
124
+
125
+ after(:each) do
126
+ delete_download_repo
127
+ end
128
+
129
+ context 'that has scraped' do
130
+ before(:each) do
131
+ @cookbook = @scraper.next
132
+ @cookbook.should_not be_nil
133
+ end
134
+
135
+ it 'the cookbook should exist' do
136
+ s3cookbook = @bucket.get(File.join('Cooks', @cookbook.resource_hash))
137
+ s3cookbook.should_not be_nil
138
+ hash = JSON.parse(s3cookbook)
139
+ hash["metadata"].should == @cookbook.metadata
140
+ hash["manifest"].should == @cookbook.manifest
141
+ end
142
+
143
+ it 'every file in the manifest should exist' do
144
+ @cookbook.manifest.each do |key, value|
145
+ file = @bucket.get(File.join('Files', value))
146
+ file.should_not be_nil
147
+ Digest::SHA1.hexdigest(file).should == value
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,118 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'download_retriever_spec_helper'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'scraper_helper'))
26
+
27
+ describe RightScraper::Retrievers::Download do
28
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
29
+
30
+ include RightScraper::ScraperHelper
31
+ include RightScraper::SpecHelpers
32
+
33
+ before(:each) do
34
+ @helper = RightScraper::DownloadRetrieverSpecHelper.new
35
+ @repo = @helper.repo
36
+ @retriever = @repo.retriever(:max_bytes => 1024**2, :max_seconds => 20, :basedir => @helper.download_repo_path)
37
+ end
38
+
39
+ after(:each) do
40
+ @helper.close unless @helper.nil?
41
+ @helper = nil
42
+ end
43
+
44
+ it 'should not initially have a tag' do
45
+ @repo.tag.should be_nil
46
+ end
47
+
48
+ context 'given a password protected repository' do
49
+ before(:each) do
50
+ pending "Not run unless REMOTE_USER and REMOTE_PASSWORD set" unless ENV['REMOTE_USER'] && ENV['REMOTE_PASSWORD']
51
+ url = 'https://wush.net/svn/rightscale/cookbooks_test/cookbooks/app_rails.tar.gz'
52
+ @repo.url = url
53
+ @repo.display_name = 'wush'
54
+ end
55
+
56
+ it 'should scrape' do
57
+ @retriever.retrieve
58
+ scraper = RightScraper::Scrapers::Base.scraper(:kind => :cookbook,
59
+ :ignorable_paths => @retriever.ignorable_paths,
60
+ :repo_dir => @retriever.repo_dir,
61
+ :repository => @retriever.repository)
62
+ cookbook = scraper.next_resource
63
+ cookbook.should_not be_nil
64
+ cookbook.metadata.should_not be_nil
65
+ cookbook.metadata["name"].should == "app_rails"
66
+ cookbook.repository.tag.should_not be_nil
67
+ end
68
+ end
69
+
70
+ context 'given a download repository' do
71
+ before(:each) do
72
+ @download_file = @helper.download_file
73
+ end
74
+
75
+ def get_scraper
76
+ @retriever.retrieve
77
+ RightScraper::Scrapers::Base.scraper(:kind => :cookbook,
78
+ :ignorable_paths => @retriever.ignorable_paths,
79
+ :repo_dir => @retriever.repo_dir,
80
+ :repository => @retriever.repository)
81
+ end
82
+
83
+ it 'should only return one cookbook' do
84
+ scraper = get_scraper
85
+ scraper.next_resource
86
+ scraper.next_resource.should == nil
87
+ end
88
+
89
+ it 'should scrape' do
90
+ scraper = get_scraper
91
+ @helper.check_resource(scraper.next_resource, @download_file, @repo)
92
+ end
93
+
94
+ it 'should scrape a gzipped tarball' do
95
+ res, status = exec("gzip -c #{@download_file} > #{@download_file}.gz")
96
+ raise "Failed to gzip tarball: #{res}" unless status.success?
97
+ @repo.url += ".gz"
98
+ scraper = get_scraper
99
+ begin
100
+ @helper.check_resource(scraper.next_resource, @download_file + ".gz", @repo)
101
+ ensure
102
+ File.unlink(@download_file + ".gz")
103
+ end
104
+ end
105
+
106
+ it 'should scrape a bzipped tarball' do
107
+ res, status = exec("bzip2 -c #{@download_file} > #{@download_file}.bz2")
108
+ raise "Failed to bzip tarball: #{res}" unless status.success?
109
+ @repo.url += ".bz2"
110
+ scraper = get_scraper
111
+ begin
112
+ @helper.check_resource(scraper.next_resource, @download_file + ".bz2", @repo)
113
+ ensure
114
+ File.unlink(@download_file + ".bz2")
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,72 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'retriever_spec_helper'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'right_scraper'))
26
+
27
+ module RightScraper
28
+ class DownloadRetrieverSpecHelper < RetrieverSpecHelper
29
+ def download_repo_path
30
+ File.join(@tmpdir, "download")
31
+ end
32
+
33
+ attr_reader :download_file
34
+
35
+ def repo
36
+ RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
37
+ :repo_type => :download,
38
+ :url => "file://#{@download_file}",
39
+ :first_credential => ENV['REMOTE_USER'],
40
+ :second_credential => ENV['REMOTE_PASSWORD'])
41
+ end
42
+
43
+ # Create download repository following given layout
44
+ # Update @repo_path with path to repository
45
+ # Delete any previously created repo
46
+ def initialize
47
+ super
48
+ @download_repo_path = File.join(@tmpdir, "download")
49
+ make_cookbooks
50
+ @download_file = File.join(@tmpdir, "file.tar")
51
+ Dir.chdir(download_repo_path) do
52
+ res, status = exec("tar cf \"#{@download_file}\" *")
53
+ raise "Failed to create tarball: #{res}" unless status.success?
54
+ end
55
+ end
56
+
57
+ # Cookbook creation method. Meant to be extended by subclasses.
58
+ def make_cookbooks
59
+ create_cookbook(download_repo_path, repo_content)
60
+ end
61
+
62
+ def check_resource(resource, tarball, repository, position=".")
63
+ resource.should_not == nil
64
+ resource.repository.tag.should_not == nil
65
+ resource.repository.repository_hash.should == repository.repository_hash
66
+ resource.repository.checkout_hash.should_not == repository.checkout_hash
67
+ resource.pos.should == position
68
+ resource.metadata.should == repo_content
69
+ resource.manifest.should == manifest
70
+ end
71
+ end
72
+ end