cookbook-omnifetch 0.2.3 → 0.4.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: 7459f59b8c61c06a07c01ddb3fa3170c08a2ed5e
4
- data.tar.gz: 171dfdf291c9cbb46ce391b2db87683698bd213e
3
+ metadata.gz: ed71a5a2de183598b020865f4c09f5442e15ee13
4
+ data.tar.gz: 05911931abea5ef8742300be91f55bdffff9bd73
5
5
  SHA512:
6
- metadata.gz: b5888ab46937874163e0d0d87e3ee97892dd3c6ad0ba6c7ee14ee1575f79c5c649016632a601986cf932c5a474e9dc86f31cc919624ba91a2e7efe74a558975e
7
- data.tar.gz: c7df3c93349506a07207c4c79806f9cb54a7977d1073c8609e1c6ae2991fb154c12eac1dc0e2cf08a86c286bb7b39a17de23fb018485ff70b89928ca837a4115
6
+ metadata.gz: ae1de192ff0125bfd70e08addaf18e14fe081e92cc85e13a0c07b6e3c9f0cc4aa25b390c3bececf72177a74dc4076a8b0d145c07c15cf8716f7ae156b875e02d
7
+ data.tar.gz: 8624065514fa015f4d2e292ebea63215715848a1c188e8dd00e46291cbd4bb68e0e512430575b8844a65cd26fb9d9ecde5a189bee6219eeb439a5808365dd0b2
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ branches:
2
+ only:
3
+ master
4
+
5
+ language: ruby
6
+ rvm:
7
+ - 2.1
8
+ - 2.2
9
+ - 2.3.1
10
+ before_install: gem install bundler -v 1.11.2
11
+ script: bundle exec rake ci
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ group :development, :test do
6
+ gem "minitar"
7
+ gem "chefstyle"
8
+ end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # CookbookOmnifetch
2
2
 
3
3
  `CookbookOmnifetch` provides library code for fetching Chef cookbooks
4
- from an artifact server (usually http://supermarket.getchef.com),
4
+ from an artifact server (usually https://supermarket.chef.io),
5
5
  git/github, a local path, or a chef-server to a local cache for
6
6
  developement.
7
7
 
@@ -73,14 +73,13 @@ CookbookOmnifetch.init(dependency, path: "~/chef-cookbooks/apache2")
73
73
 
74
74
  ## Contributing
75
75
 
76
- As with other Chef Software projects, in order to contribute you need to
77
- [agree to the contributor license agreement.](https://supermarket.getchef.com/become-a-contributor)
76
+ For information on contributing to this project, see https://github.com/chef/chef/blob/master/CONTRIBUTING.md
78
77
 
79
78
  After that:
80
79
 
81
80
  1. Fork it
82
81
  2. Create your feature branch (`git checkout -b my-new-feature`)
83
- 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 3. Commit your changes (`git commit -asm 'Add some feature'`)
84
83
  4. Push to the branch (`git push origin my-new-feature`)
85
84
  5. Create a new Pull Request
86
85
 
data/Rakefile CHANGED
@@ -1,2 +1,19 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ desc "Run tests for Travis CI"
9
+ task ci: [:style, :spec]
10
+
11
+ begin
12
+ require "chefstyle"
13
+ require "rubocop/rake_task"
14
+ RuboCop::RakeTask.new(:style) do |task|
15
+ task.options += ["--display-cop-names", "--no-color"]
16
+ end
17
+ rescue LoadError
18
+ puts "chefstyle/rubocop is not available. gem install chefstyle to do style checking."
19
+ end
@@ -1,26 +1,26 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'cookbook-omnifetch/version'
4
+ require "cookbook-omnifetch/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "cookbook-omnifetch"
8
8
  spec.version = CookbookOmnifetch::VERSION
9
9
  spec.authors = [
10
- 'Jamie Winsor',
11
- 'Josiah Kiehl',
12
- 'Michael Ivey',
13
- 'Justin Campbell',
14
- 'Seth Vargo',
15
- 'Daniel DeLeo'
10
+ "Jamie Winsor",
11
+ "Josiah Kiehl",
12
+ "Michael Ivey",
13
+ "Justin Campbell",
14
+ "Seth Vargo",
15
+ "Daniel DeLeo",
16
16
  ]
17
- spec.email = [
18
- 'jamie@vialstudios.com',
19
- 'jkiehl@riotgames.com',
20
- 'michael.ivey@riotgames.com',
21
- 'justin@justincampbell.me',
22
- 'sethvargo@gmail.com',
23
- 'dan@getchef.com'
17
+ spec.email = [
18
+ "jamie@vialstudios.com",
19
+ "jkiehl@riotgames.com",
20
+ "michael.ivey@riotgames.com",
21
+ "justin@justincampbell.me",
22
+ "sethvargo@gmail.com",
23
+ "dan@getchef.com",
24
24
  ]
25
25
  spec.summary = %q{Library code to fetch Chef cookbooks from a variety of sources to a local cache}
26
26
  spec.homepage = "http://www.getchef.com/"
@@ -31,9 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.test_files = spec.files.grep(%r{^spec/})
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.add_dependency "minitar", "~> 0.5.4"
34
+ spec.add_dependency "mixlib-archive", "~> 0.2"
35
35
 
36
36
  spec.add_development_dependency "rake", "~> 10.3"
37
- spec.add_development_dependency 'rspec','~> 3.0'
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
38
 
39
39
  end
@@ -6,7 +6,7 @@ require "cookbook-omnifetch/git"
6
6
  require "cookbook-omnifetch/github"
7
7
  require "cookbook-omnifetch/path"
8
8
  require "cookbook-omnifetch/artifactserver"
9
-
9
+ require "cookbook-omnifetch/chef_server"
10
10
 
11
11
  module CookbookOmnifetch
12
12
 
@@ -42,8 +42,8 @@ module CookbookOmnifetch
42
42
  def self.which(executable)
43
43
  if File.file?(executable) && File.executable?(executable)
44
44
  executable
45
- elsif ENV['PATH']
46
- path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
45
+ elsif ENV["PATH"]
46
+ path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |p|
47
47
  File.executable?(File.join(p, executable))
48
48
  end
49
49
  path && File.expand_path(executable, path)
@@ -1,9 +1,7 @@
1
- require 'cookbook-omnifetch/base'
1
+ require "cookbook-omnifetch/base"
2
2
 
3
- # TODO: probably this should be hidden behind DI for http stuff
4
- require 'zlib'
5
- require 'archive/tar/minitar'
6
- require 'tmpdir'
3
+ require "mixlib/archive"
4
+ require "tmpdir"
7
5
 
8
6
  module CookbookOmnifetch
9
7
 
@@ -48,12 +46,8 @@ module CookbookOmnifetch
48
46
 
49
47
  FileUtils.mkdir_p(staging_root) unless staging_root.exist?
50
48
  Dir.mktmpdir(nil, staging_root) do |staging_dir|
51
- Zlib::GzipReader.open(cache_path) do |gz_file|
52
- tar = Archive::Tar::Minitar::Input.new(gz_file)
53
- tar.each do |e|
54
- tar.extract_entry(staging_dir, e)
55
- end
56
- end
49
+ Mixlib::Archive.new(cache_path).extract(staging_dir, perms: false,
50
+ ignore: /^\./)
57
51
  staged_cookbook_path = File.join(staging_dir, cookbook_name)
58
52
  validate_cached!(staged_cookbook_path)
59
53
  FileUtils.mv(staged_cookbook_path, install_path)
@@ -91,8 +85,8 @@ module CookbookOmnifetch
91
85
 
92
86
  def lock_data
93
87
  out = {}
94
- out['artifactserver'] = uri
95
- out['version'] = cookbook_version
88
+ out["artifactserver"] = uri
89
+ out["version"] = cookbook_version
96
90
  out
97
91
  end
98
92
 
@@ -104,24 +98,13 @@ module CookbookOmnifetch
104
98
  "#to_lock must be implemented on #{self.class.name}!"
105
99
  end
106
100
 
107
-
108
- def ==(other)
109
- raise 'TODO'
110
- other.is_a?(GitLocation) &&
111
- other.uri == uri &&
112
- other.branch == branch &&
113
- other.tag == tag &&
114
- other.shortref == shortref &&
115
- other.rel == rel
116
- end
117
-
118
101
  # The path where all pristine tarballs from an artifactserver are held.
119
102
  # Tarballs are moved/swapped into this location once they have been staged
120
103
  # in a co-located staging directory.
121
104
  #
122
105
  # @return [Pathname]
123
106
  def cache_root
124
- Pathname.new(CookbookOmnifetch.cache_path).join('.cache', 'artifactserver')
107
+ Pathname.new(CookbookOmnifetch.cache_path).join(".cache", "artifactserver")
125
108
  end
126
109
 
127
110
  # The path where tarballs are downloaded to and unzipped. On certain platforms
@@ -135,7 +118,7 @@ module CookbookOmnifetch
135
118
  #
136
119
  # @return [Pathname]
137
120
  def staging_root
138
- Pathname.new(CookbookOmnifetch.cache_path).join('.cache_tmp', 'artifactserver')
121
+ Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactserver")
139
122
  end
140
123
 
141
124
  # The path where the pristine tarball is cached
@@ -1,4 +1,4 @@
1
- require 'cookbook-omnifetch/exceptions'
1
+ require "cookbook-omnifetch/exceptions"
2
2
 
3
3
  module CookbookOmnifetch
4
4
  class BaseLocation
@@ -0,0 +1,108 @@
1
+ require "cookbook-omnifetch/base"
2
+
3
+ module CookbookOmnifetch
4
+ class CookbookMetadata
5
+
6
+ FILE_TYPES = [
7
+ :resources,
8
+ :providers,
9
+ :recipes,
10
+ :definitions,
11
+ :libraries,
12
+ :attributes,
13
+ :files,
14
+ :templates,
15
+ :root_files,
16
+ ].freeze
17
+
18
+ def initialize(metadata)
19
+ @metadata = metadata
20
+ end
21
+
22
+ def files(&block)
23
+ FILE_TYPES.each do |type|
24
+ next unless @metadata.has_key?(type.to_s)
25
+
26
+ @metadata[type.to_s].each do |file|
27
+ yield file["url"], file["path"]
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ class ChefserverLocation < BaseLocation
34
+
35
+ attr_reader :cookbook_version
36
+
37
+ def initialize(dependency, options = {})
38
+ super
39
+ @cookbook_version = options[:version]
40
+ @http_client = options[:http_client]
41
+ @uri ||= options[:artifactserver]
42
+ end
43
+
44
+ def repo_host
45
+ @host ||= URI.parse(uri).host
46
+ end
47
+
48
+ def cookbook_name
49
+ dependency.name
50
+ end
51
+
52
+ def install
53
+ FileUtils.mkdir_p(staging_root) unless staging_root.exist?
54
+ md = http_client.get("/cookbooks/#{cookbook_name}/#{cookbook_version}")
55
+ CookbookMetadata.new(md).files do |url, path|
56
+ stage = staging_path.join(path)
57
+ FileUtils.mkdir_p(File.dirname(stage))
58
+
59
+ http_client.streaming_request(url) do |tempfile|
60
+ tempfile.close
61
+ FileUtils.mv(tempfile.path, stage)
62
+ end
63
+ end
64
+ FileUtils.mv(staging_path, install_path)
65
+ end
66
+
67
+ # Determine if this revision is installed.
68
+ #
69
+ # @return [Boolean]
70
+ def installed?
71
+ install_path.exist?
72
+ end
73
+
74
+ def http_client
75
+ @http_client
76
+ end
77
+
78
+ # The path where this cookbook would live in the store, if it were
79
+ # installed.
80
+ #
81
+ # @return [Pathname, nil]
82
+ def install_path
83
+ @install_path ||= CookbookOmnifetch.storage_path.join(cache_key)
84
+ end
85
+
86
+ def cache_key
87
+ "#{dependency.name}-#{cookbook_version}"
88
+ end
89
+
90
+ # The path where tarballs are downloaded to and unzipped. On certain platforms
91
+ # you have a better chance of getting an atomic move if your temporary working
92
+ # directory is on the same device/volume as the destination. To support this,
93
+ # we use a staging directory located under the cache path under the rather mild
94
+ # assumption that everything under the cache path is going to be on one device.
95
+ #
96
+ # Do not create anything under this directory that isn't randomly named and
97
+ # remember to release your files once you are done.
98
+ #
99
+ # @return [Pathname]
100
+ def staging_root
101
+ Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactserver")
102
+ end
103
+
104
+ def staging_path
105
+ staging_root.join(cache_key)
106
+ end
107
+ end
108
+ end
@@ -20,9 +20,9 @@ module CookbookOmnifetch
20
20
 
21
21
  class GitNotInstalled < GitError
22
22
  def initialize
23
- super 'You need to install Git before you can download ' \
24
- 'cookbooks from git repositories. For more information, please ' \
25
- 'see the Git docs: http://git-scm.org.'
23
+ super "You need to install Git before you can download " \
24
+ "cookbooks from git repositories. For more information, please " \
25
+ "see the Git docs: http://git-scm.org."
26
26
  end
27
27
  end
28
28
 
@@ -1,7 +1,7 @@
1
- require 'tmpdir'
2
- require 'cookbook-omnifetch'
3
- require 'cookbook-omnifetch/base'
4
- require 'cookbook-omnifetch/exceptions'
1
+ require "tmpdir"
2
+ require "cookbook-omnifetch"
3
+ require "cookbook-omnifetch/base"
4
+ require "cookbook-omnifetch/exceptions"
5
5
 
6
6
  module CookbookOmnifetch
7
7
  class GitLocation < BaseLocation
@@ -23,7 +23,7 @@ module CookbookOmnifetch
23
23
  @rel = options[:rel]
24
24
 
25
25
  # The revision to parse
26
- @rev_parse = options[:ref] || options[:branch] || options[:tag] || 'master'
26
+ @rev_parse = options[:ref] || options[:branch] || options[:tag] || "master"
27
27
  end
28
28
 
29
29
  # @see BaseLoation#installed?
@@ -41,26 +41,26 @@ module CookbookOmnifetch
41
41
 
42
42
  if cached?
43
43
  Dir.chdir(cache_path) do
44
- git %|fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"|
44
+ git %{fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"}
45
45
  end
46
46
  else
47
- git %|clone #{uri} "#{cache_path}" --bare --no-hardlinks|
47
+ git %{clone #{uri} "#{cache_path}" --bare --no-hardlinks}
48
48
  end
49
49
 
50
50
  Dir.chdir(cache_path) do
51
- @revision ||= git %|rev-parse #{@rev_parse}|
51
+ @revision ||= git %{rev-parse #{@rev_parse}}
52
52
  end
53
53
 
54
54
  # Clone into a scratch directory for validations
55
- git %|clone --no-checkout "#{cache_path}" "#{scratch_path}"|
55
+ git %{clone --no-checkout "#{cache_path}" "#{scratch_path}"}
56
56
 
57
57
  # Make sure the scratch directory is up-to-date and account for rel paths
58
58
  Dir.chdir(scratch_path) do
59
- git %|fetch --force --tags "#{cache_path}"|
60
- git %|reset --hard #{@revision}|
59
+ git %{fetch --force --tags "#{cache_path}"}
60
+ git %{reset --hard #{@revision}}
61
61
 
62
62
  if rel
63
- git %|filter-branch --subdirectory-filter "#{rel}" --force|
63
+ git %{filter-branch --subdirectory-filter "#{rel}" --force}
64
64
  end
65
65
  end
66
66
 
@@ -72,7 +72,7 @@ module CookbookOmnifetch
72
72
  FileUtils.cp_r(scratch_path, install_path)
73
73
 
74
74
  # Remove the git history
75
- FileUtils.rm_rf(File.join(install_path, '.git'))
75
+ FileUtils.rm_rf(File.join(install_path, ".git"))
76
76
 
77
77
  install_path.chmod(0777 & ~File.umask)
78
78
  ensure
@@ -91,11 +91,11 @@ module CookbookOmnifetch
91
91
 
92
92
  def ==(other)
93
93
  other.is_a?(GitLocation) &&
94
- other.uri == uri &&
95
- other.branch == branch &&
96
- other.tag == tag &&
97
- other.shortref == shortref &&
98
- other.rel == rel
94
+ other.uri == uri &&
95
+ other.branch == branch &&
96
+ other.tag == tag &&
97
+ other.shortref == shortref &&
98
+ other.rel == rel
99
99
  end
100
100
 
101
101
  def to_s
@@ -163,11 +163,11 @@ module CookbookOmnifetch
163
163
  # @raise [String]
164
164
  # the +$stdout+ from the command
165
165
  def git(command, error = true)
166
- unless CookbookOmnifetch.which('git') || CookbookOmnifetch.which('git.exe') || CookbookOmnifetch.which('git.bat')
166
+ unless CookbookOmnifetch.which("git") || CookbookOmnifetch.which("git.exe") || CookbookOmnifetch.which("git.bat")
167
167
  raise GitNotInstalled.new
168
168
  end
169
169
 
170
- response = CookbookOmnifetch.shell_out_class.shell_out(%|git #{command}|)
170
+ response = CookbookOmnifetch.shell_out_class.shell_out(%{git #{command}})
171
171
 
172
172
  if error && !response.success?
173
173
  raise GitCommandError.new(command, cache_path, response.stderr)
@@ -188,7 +188,7 @@ module CookbookOmnifetch
188
188
  # @return [Pathname]
189
189
  def cache_path
190
190
  Pathname.new(CookbookOmnifetch.cache_path)
191
- .join('.cache', 'git', Digest::SHA1.hexdigest(uri))
191
+ .join(".cache", "git", Digest::SHA1.hexdigest(uri))
192
192
  end
193
193
  end
194
194
  end