vara 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ module Vara
2
+ class StaticVersioner
3
+ PRODUCT_VERSION_KEY = 'product_version'.freeze
4
+ TO_VERSION_KEY = 'to_version'.freeze
5
+ MIGRATIONS_KEY = 'migrations'.freeze
6
+ MIGRATIONS_RULES_KEY = 'rules'.freeze
7
+ MIGRATIONS_RULES_TO_KEY = 'to'.freeze
8
+
9
+ # @param product_directory_path [String]
10
+ # @param version [String] the product version
11
+ def initialize(product_directory_path, version)
12
+ @product_directory_path = product_directory_path
13
+ @version = version
14
+ end
15
+
16
+ # @param metadata_hash [Hash] Hash contents of full product metadata
17
+ # @return [Hash] product metadata with product version value updated
18
+ def update_metadata(metadata_hash)
19
+ metadata_hash[PRODUCT_VERSION_KEY].gsub!(/^.*$/, version)
20
+ metadata_hash
21
+ end
22
+
23
+ # @param migrations_hash [Hash] Hash contents of full content migrations
24
+ # @return [Hash] content migrations with product version value updated if necessary
25
+ def update_content_migrations(migrations_hash)
26
+ migrations_hash[TO_VERSION_KEY] = version unless migrations_hash[TO_VERSION_KEY].nil?
27
+ migrations_hash.fetch(MIGRATIONS_KEY, []).each do |migration|
28
+ migration.fetch(MIGRATIONS_RULES_KEY, []).each do |rule|
29
+ next unless updates_product_version?(rule)
30
+ rule[MIGRATIONS_RULES_TO_KEY] = version
31
+ end
32
+ end
33
+ migrations_hash
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :product_directory_path, :version
39
+
40
+ def updates_product_version?(rule_hash)
41
+ rule_hash['type'] == 'update' && rule_hash['selector'] == 'product_version'
42
+ end
43
+ end
44
+ end
45
+
46
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
47
+ # All rights reserved.
48
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
49
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
50
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
52
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
53
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ require 'digest/md5'
2
+ require 'open4'
3
+ require 'vara/downloader'
4
+ require 'vara/log'
5
+
6
+ module Vara
7
+ # Represents a binary file that is packaged in a .pivotal product
8
+ class Tarball
9
+ include Loggable
10
+
11
+ # @param [#basename,#url,#md5] metadata
12
+ # @param [String] target_dir path to folder where binary should be saved
13
+ def initialize(metadata, target_dir)
14
+ @metadata = metadata
15
+ @target_dir = target_dir
16
+ end
17
+
18
+ # Based on the metadata, downloads the binary from the metadata#url and verifies the checksum.
19
+ # @return [String] path to the downloaded/verified release taball
20
+ # @raise [RuntimeError] if the checksum of the downloaded file does not match the expected checksum
21
+ def sync_local_copy
22
+ download
23
+ validate_tarball
24
+ validate_checksum
25
+ path_to_binary
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :metadata, :target_dir
31
+
32
+ def path_to_binary
33
+ File.join(target_dir, metadata.basename)
34
+ end
35
+
36
+ def download
37
+ return if File.exist?(path_to_binary)
38
+
39
+ log.info("Beginning download of #{metadata.url} to #{path_to_binary}")
40
+ Downloader.download(metadata, path_to_binary)
41
+ log.info("File download from #{metadata.url} to #{path_to_binary} complete")
42
+ end
43
+
44
+ def validate_tarball
45
+ stdout_string = ''
46
+ stderr_string = ''
47
+ cmd_args = "tar -tvzf #{path_to_binary}"
48
+ status = Open4.popen4(cmd_args) do |_, _, stdout, stderr|
49
+ stdout_string = stdout.read
50
+ stderr_string = stderr.read
51
+ end
52
+
53
+ if status.success?
54
+ log.info("Verified that #{path_to_binary} as a valid tar file")
55
+ else
56
+ fail "Invalid tarball: #{path_to_binary}. Tar command STDOUT: #{stdout_string}\n STDERR:#{stderr_string}"
57
+ end
58
+ end
59
+
60
+ def validate_checksum
61
+ log.info("Beginning checksum validation of #{metadata}")
62
+ log.info("Path to File: #{path_to_binary}")
63
+ fail "Metadata doesn't include SHA1 or MD5 checksum!" unless metadata.md5 || metadata.sha1
64
+ validate_md5 if metadata.md5
65
+ validate_sha1 if metadata.sha1
66
+ log.info("#{metadata} checksum validation complete")
67
+ end
68
+
69
+ def validate_sha1
70
+ log.info("Expected SHA1: #{metadata.sha1}")
71
+ actual_sha1 = Digest::SHA1.file(path_to_binary).hexdigest
72
+ log.info("Actual SHA1: #{actual_sha1}")
73
+ fail "SHA1 doesn't match expected value!" unless actual_sha1 == metadata.sha1
74
+ end
75
+
76
+ def validate_md5
77
+ log.info("Expected MD5: #{metadata.md5}")
78
+ actual_md5 = Digest::MD5.file(path_to_binary).hexdigest
79
+ log.info("Actual MD5: #{actual_md5}")
80
+ fail "MD5 doesn't match expected value!" unless actual_md5 == metadata.md5
81
+ end
82
+ end
83
+ end
84
+
85
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
86
+ # All rights reserved.
87
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
88
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
89
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
90
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
91
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
92
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ module Vara
2
+ VERSION = '0.17.1'
3
+ end
4
+
5
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
6
+ # All rights reserved.
7
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
8
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
9
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
10
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
11
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
12
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vara
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.17.1
5
+ platform: ruby
6
+ authors:
7
+ - CF Release Engineering
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: open4
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubyzip
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Converts a product repository to a .pivotal file.
154
+ email:
155
+ - cf-releng@pivotallabs.com
156
+ executables:
157
+ - vara
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - LEGAL.txt
162
+ - README.md
163
+ - bin/vara
164
+ - lib/vara.rb
165
+ - lib/vara/cli.rb
166
+ - lib/vara/cli_helper.rb
167
+ - lib/vara/content_migrations_processor.rb
168
+ - lib/vara/downloader.rb
169
+ - lib/vara/git_inspector.rb
170
+ - lib/vara/linter.rb
171
+ - lib/vara/log.rb
172
+ - lib/vara/materials.rb
173
+ - lib/vara/md5_creator.rb
174
+ - lib/vara/metadata/compiled_packages.rb
175
+ - lib/vara/metadata/release.rb
176
+ - lib/vara/metadata/stemcell.rb
177
+ - lib/vara/prerelease_versioner.rb
178
+ - lib/vara/product.rb
179
+ - lib/vara/product_artifact_validator.rb
180
+ - lib/vara/product_artifact_zipper.rb
181
+ - lib/vara/product_contents.rb
182
+ - lib/vara/product_metadata.rb
183
+ - lib/vara/product_metadata_processor.rb
184
+ - lib/vara/product_resource_downloader.rb
185
+ - lib/vara/static_versioner.rb
186
+ - lib/vara/tarball.rb
187
+ - lib/vara/version.rb
188
+ homepage: ''
189
+ licenses:
190
+ - No License
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '2'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.4.5
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: Vara starts with a product git repository that meets specific requirements.
212
+ It creates, as deterministically as possible, a .pivotal file.
213
+ test_files: []