cookbook-omnifetch 0.5.1 → 0.6.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: 3a282e1e19a46033174edabb28146d168618a1ec
4
- data.tar.gz: c811e57b03d592fc1e91c51596a14a14fb090120
3
+ metadata.gz: 3c87b779ed374b94c79ed6d60c92d4acdacca050
4
+ data.tar.gz: c5f55d263dd9c5ccc81b96be560664d6d4ac882a
5
5
  SHA512:
6
- metadata.gz: 76e5d5008c709dfa9302d34955242c4349338ec91610079fef984e678e5fdc3cef7b60d252c32745220cf311a94ba29fb0a35b537dd6c8d97980396be4ef1812
7
- data.tar.gz: d44ae39c76394b6a89614418bfb43a5c27dd044708929111f21c3620ed65a2b6d20b4a7b387fd27289187b8c61e0728f8c4128c305336db920dd9f4f9e8c45a1
6
+ metadata.gz: 948bbab575f6693876e197978b3866b9489dc24c64b3860b94fee60cb5187d96fc3101559067aa163d0b44911aa90c10bc20f1a33de6d14e626cd41198337519
7
+ data.tar.gz: 1ad1cac27d2b6a6c84f01c8155a7dcf11f14f5af56c45dd842c50e6e86ff35369e501f81a9914646c07bfa60e9c47cb463506ce5d1b4ef5c23bc885bde277d5c
data/.travis.yml CHANGED
@@ -4,8 +4,8 @@ branches:
4
4
 
5
5
  language: ruby
6
6
  rvm:
7
- - 2.1
8
7
  - 2.2
9
- - 2.3.1
10
- before_install: gem install bundler -v 1.11.2
8
+ - 2.3.3
9
+ - 2.4.1
10
+ before_install: gem install bundler -v 1.14.6
11
11
  script: bundle exec rake ci
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.add_dependency "mixlib-archive", "~> 0.4"
35
35
 
36
- spec.add_development_dependency "rake", "~> 10.3"
36
+ spec.add_development_dependency "rake"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
38
 
39
39
  end
@@ -6,6 +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
+ require "cookbook-omnifetch/artifactory"
9
10
  require "cookbook-omnifetch/chef_server"
10
11
 
11
12
  module CookbookOmnifetch
@@ -0,0 +1,127 @@
1
+ require "cookbook-omnifetch/base"
2
+
3
+ require "mixlib/archive"
4
+ require "tmpdir"
5
+
6
+ module CookbookOmnifetch
7
+
8
+ class ArtifactoryLocation < BaseLocation
9
+
10
+ attr_reader :uri
11
+ attr_reader :cookbook_version
12
+ attr_reader :http_client
13
+
14
+ def initialize(dependency, options = {})
15
+ super
16
+ @uri ||= options[:artifactory]
17
+ @cookbook_version = options[:version]
18
+ @http_client = options[:http_client]
19
+ end
20
+
21
+ def repo_host
22
+ @host ||= URI.parse(uri).host
23
+ end
24
+
25
+ def cookbook_name
26
+ dependency.name
27
+ end
28
+
29
+ # Determine if this revision is installed.
30
+ #
31
+ # @return [Boolean]
32
+ def installed?
33
+ install_path.exist?
34
+ end
35
+
36
+ # Install the given cookbook. Subclasses that implement this method should
37
+ # perform all the installation and validation steps required.
38
+ #
39
+ # @return [void]
40
+ def install
41
+ FileUtils.mkdir_p(cache_root) unless cache_root.exist?
42
+
43
+ http_client.streaming_request(nil) do |tempfile|
44
+ tempfile.close
45
+ FileUtils.mv(tempfile.path, cache_path)
46
+ end
47
+
48
+ FileUtils.mkdir_p(staging_root) unless staging_root.exist?
49
+ Dir.mktmpdir(nil, staging_root) do |staging_dir|
50
+ Mixlib::Archive.new(cache_path).extract(staging_dir, perms: false)
51
+ staged_cookbook_path = File.join(staging_dir, cookbook_name)
52
+ validate_cached!(staged_cookbook_path)
53
+ FileUtils.mv(staged_cookbook_path, install_path)
54
+ end
55
+ end
56
+
57
+ def sanitized_version
58
+ cookbook_version
59
+ end
60
+
61
+ # The path where this cookbook would live in the store, if it were
62
+ # installed.
63
+ #
64
+ # @return [Pathname, nil]
65
+ def install_path
66
+ @install_path ||= CookbookOmnifetch.storage_path.join(cache_key)
67
+ end
68
+
69
+ def cache_key
70
+ "#{dependency.name}-#{cookbook_version}-#{repo_host}"
71
+ end
72
+
73
+ # The cached cookbook for this location.
74
+ #
75
+ # @return [CachedCookbook]
76
+ def cached_cookbook
77
+ raise AbstractFunction,
78
+ "#cached_cookbook must be implemented on #{self.class.name}!"
79
+ end
80
+
81
+ def lock_data
82
+ out = {}
83
+ out["artifactory"] = uri
84
+ out["version"] = cookbook_version
85
+ out
86
+ end
87
+
88
+ # The lockfile representation of this location.
89
+ #
90
+ # @return [string]
91
+ def to_lock
92
+ raise AbstractFunction,
93
+ "#to_lock must be implemented on #{self.class.name}!"
94
+ end
95
+
96
+ # The path where all pristine tarballs from an artifactserver are held.
97
+ # Tarballs are moved/swapped into this location once they have been staged
98
+ # in a co-located staging directory.
99
+ #
100
+ # @return [Pathname]
101
+ def cache_root
102
+ Pathname.new(CookbookOmnifetch.cache_path).join(".cache", "artifactserver")
103
+ end
104
+
105
+ # The path where tarballs are downloaded to and unzipped. On certain platforms
106
+ # you have a better chance of getting an atomic move if your temporary working
107
+ # directory is on the same device/volume as the destination. To support this,
108
+ # we use a staging directory located under the cache path under the rather mild
109
+ # assumption that everything under the cache path is going to be on one device.
110
+ #
111
+ # Do not create anything under this directory that isn't randomly named and
112
+ # remember to release your files once you are done.
113
+ #
114
+ # @return [Pathname]
115
+ def staging_root
116
+ Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactserver")
117
+ end
118
+
119
+ # The path where the pristine tarball is cached
120
+ #
121
+ # @return [Pathname]
122
+ def cache_path
123
+ cache_root.join("#{cache_key}.tgz")
124
+ end
125
+
126
+ end
127
+ end
@@ -1,3 +1,3 @@
1
1
  module CookbookOmnifetch
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+ require "cookbook-omnifetch/artifactory"
3
+ require "zlib"
4
+ require "archive/tar/minitar"
5
+
6
+ module CookbookOmnifetch
7
+ describe ArtifactoryLocation do
8
+
9
+ let(:cookbook_name) { "nginx" }
10
+
11
+ let(:cookbook_version) { "1.5.23" }
12
+
13
+ let(:http_client) { double("Chef::HTTP::Simple") }
14
+
15
+ let(:constraint) { double("Constraint") }
16
+
17
+ let(:dependency) { double("Dependency", name: cookbook_name, constraint: constraint) }
18
+
19
+ let(:url) { "https://artifactory.example.com/api/v1/cookbooks/nginx/versions/1.5.23/download" }
20
+
21
+ let(:options) { { artifactory: url, version: cookbook_version, http_client: http_client } }
22
+
23
+ subject(:public_repo_location) { described_class.new(dependency, options) }
24
+
25
+ it "has a URI" do
26
+ expect(public_repo_location.uri).to eq(url)
27
+ end
28
+
29
+ it "has a repo host" do
30
+ expect(public_repo_location.repo_host).to eq("artifactory.example.com")
31
+ end
32
+
33
+ it "has an exact version" do
34
+ expect(public_repo_location.cookbook_version).to eq("1.5.23")
35
+ end
36
+
37
+ it "has a cache key containing the site URI and version" do
38
+ expect(public_repo_location.cache_key).to eq("nginx-1.5.23-artifactory.example.com")
39
+ end
40
+
41
+ it "sets the install location as the cache path plus cache key" do
42
+ expected_install_path = Pathname.new("~/.berkshelf/cookbooks").expand_path.join("nginx-1.5.23-artifactory.example.com")
43
+ expect(public_repo_location.install_path).to eq(expected_install_path)
44
+ end
45
+
46
+ it "considers the cookbook installed if it exists in the main cache" do
47
+ expect(public_repo_location.install_path).to receive(:exist?).and_return(true)
48
+ expect(public_repo_location.installed?).to be true
49
+ end
50
+
51
+ it "considers the cookbook not installed if it doesn't exist in the main cache" do
52
+ expect(public_repo_location.install_path).to receive(:exist?).and_return(false)
53
+ expect(public_repo_location.installed?).to be false
54
+ end
55
+
56
+ it "provides lock data as a Hash" do
57
+ expected_data = {
58
+ "artifactory" => url,
59
+ "version" => "1.5.23",
60
+ }
61
+ expect(public_repo_location.lock_data).to eq(expected_data)
62
+ end
63
+ end
64
+ end
@@ -45,7 +45,7 @@ module CookbookOmnifetch
45
45
  let(:remote_path) { File.join(test_root, "remote") }
46
46
  let(:options) { { chef_server: url, version: cookbook_version, http_client: http_client } }
47
47
 
48
- let(:cookbook_files) { %w{. .. metadata.rb recipes} }
48
+ let(:cookbook_files) { %w{. .. metadata.rb recipes} }
49
49
  subject(:chef_server_location) { described_class.new(dependency, options) }
50
50
 
51
51
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookbook-omnifetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-02-02 00:00:00.000000000 Z
16
+ date: 2017-05-17 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: mixlib-archive
@@ -33,16 +33,16 @@ dependencies:
33
33
  name: rake
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - "~>"
36
+ - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: '10.3'
38
+ version: '0'
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - "~>"
43
+ - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: '10.3'
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +78,7 @@ files:
78
78
  - Rakefile
79
79
  - cookbook-omnifetch.gemspec
80
80
  - lib/cookbook-omnifetch.rb
81
+ - lib/cookbook-omnifetch/artifactory.rb
81
82
  - lib/cookbook-omnifetch/artifactserver.rb
82
83
  - lib/cookbook-omnifetch/base.rb
83
84
  - lib/cookbook-omnifetch/chef_server.rb
@@ -98,6 +99,7 @@ files:
98
99
  - spec/fixtures/cookbooks/example_cookbook/metadata.rb
99
100
  - spec/fixtures/cookbooks/example_cookbook/recipes/default.rb
100
101
  - spec/spec_helper.rb
102
+ - spec/unit/artifactory_spec.rb
101
103
  - spec/unit/artifactserver_spec.rb
102
104
  - spec/unit/base_spec.rb
103
105
  - spec/unit/chef_server_spec.rb
@@ -124,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  version: '0'
125
127
  requirements: []
126
128
  rubyforge_project:
127
- rubygems_version: 2.5.1
129
+ rubygems_version: 2.6.11
128
130
  signing_key:
129
131
  specification_version: 4
130
132
  summary: Library code to fetch Chef cookbooks from a variety of sources to a local
@@ -141,6 +143,7 @@ test_files:
141
143
  - spec/fixtures/cookbooks/example_cookbook/metadata.rb
142
144
  - spec/fixtures/cookbooks/example_cookbook/recipes/default.rb
143
145
  - spec/spec_helper.rb
146
+ - spec/unit/artifactory_spec.rb
144
147
  - spec/unit/artifactserver_spec.rb
145
148
  - spec/unit/base_spec.rb
146
149
  - spec/unit/chef_server_spec.rb