imagemaster3000 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bf21239434489d0785772c0c87d1196e59fa578
4
- data.tar.gz: 35416c5698f997f32cdfc489b7f6153e089d2bb8
3
+ metadata.gz: f9ddf76551e39e0d2564d060fcf9a142b8462c7c
4
+ data.tar.gz: 7cd13f3d108660e57a4857aae1ec89648260d897
5
5
  SHA512:
6
- metadata.gz: 2fa58029147e0421d4df10c15ea5af35ecf9f7be1a2e31ef35f98a3ee67a5dada1a8fe3985bff35323bbd70e7c0390baf495ef5f79cd390a57a1c6b871b67c65
7
- data.tar.gz: 8754773e67451563527d37f811cc30711ac1a9ea275be2cd95baeda66871cc29b4180998d34043bcf0077276cfa04b4dc24abeb214a6e78bcb433369b4301fa1
6
+ metadata.gz: 10fd45c4b7c924ee7b6550223461bfb44455bbf284fb7987273035100edf2ad2e2eb825687c9a2443637678cb686831df53f40a14eaad53536ac427c7ba2ea17
7
+ data.tar.gz: 0a056a01e1e64cbf82acf53c153836b99d9bbc160e2ffd357d6a3d08e6839f5c76b77cbbc21d42d58ce9c4a691b7e1b05d55f09d82db3337af5e660f4691578d
@@ -4,6 +4,7 @@ require 'gpgme'
4
4
  module Imagemaster3000
5
5
  autoload :CLI, 'imagemaster3000/cli'
6
6
  autoload :Settings, 'imagemaster3000/settings'
7
+ autoload :Cleaner, 'imagemaster3000/cleaner'
7
8
  autoload :MainProcess, 'imagemaster3000/main_process'
8
9
 
9
10
  autoload :Errors, 'imagemaster3000/errors'
@@ -0,0 +1,25 @@
1
+ module Imagemaster3000
2
+ class Cleaner
3
+ CLEAN_FILE = File.join(Imagemaster3000::Settings[:'image-dir'], 'clean.list')
4
+
5
+ class << self
6
+ def clean
7
+ return unless File.exist? CLEAN_FILE
8
+
9
+ logger.debug 'Cleaning old images'
10
+ files = File.read(CLEAN_FILE).lines.map(&:strip)
11
+ files.each do |file|
12
+ logger.debug "Removing file #{file.inspect}"
13
+ File.delete file if File.exist? file
14
+ end
15
+ File.delete CLEAN_FILE
16
+ end
17
+
18
+ def write_clean_file(files)
19
+ clean_data = files.join("\n").concat("\n")
20
+ logger.debug "Writing clean file, new data:\n#{clean_data}"
21
+ File.write CLEAN_FILE, clean_data, mode: 'a'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -7,11 +7,12 @@ module Imagemaster3000
7
7
  logger.debug "Downloading image from #{url.inspect}"
8
8
 
9
9
  uri = URI.parse url
10
- filename = generate_filename(uri)
10
+ filename = generate_filename
11
+ @local_filename = filename
12
+ @remote_filename = File.basename(uri.path)
11
13
  retrieve_image(uri, filename)
12
14
 
13
15
  logger.debug "Image from #{url.inspect} was saved as #{filename.inspect}"
14
- @file = filename
15
16
  @size = File.size filename
16
17
  rescue ::URI::InvalidURIError, ::IOError => ex
17
18
  raise Imagemaster3000::Errors::DownloadError, ex
@@ -39,8 +40,8 @@ module Imagemaster3000
39
40
  raise Imagemaster3000::Errors::DownloadError, ex
40
41
  end
41
42
 
42
- def generate_filename(uri)
43
- File.join(Imagemaster3000::Settings[:'image-dir'], File.basename(uri.path))
43
+ def generate_filename
44
+ File.join(Imagemaster3000::Settings[:'image-dir'], SecureRandom.hex)
44
45
  end
45
46
  end
46
47
  end
@@ -3,7 +3,7 @@ module Imagemaster3000
3
3
  class Image
4
4
  include Downloadable
5
5
 
6
- attr_accessor :name, :url, :distribution, :version, :ram, :cpu, :actions, :verification, :file, :size
6
+ attr_accessor :name, :url, :distribution, :version, :ram, :cpu, :actions, :verification, :local_filename, :remote_filename, :size
7
7
 
8
8
  def initialize(name: nil, url: nil, distribution: nil, version: nil, ram: nil, cpu: nil, actions: nil, verification: nil)
9
9
  raise Imagemaster3000::Errors::ArgumentError, 'name, url, distribution or version cannot be nil' \
@@ -24,7 +24,7 @@
24
24
  <% end -%>
25
25
  "hv:format":"qcow2",
26
26
  "hv:size":"<%= image.size %>",
27
- "hv:uri":"<%= File.join(Imagemaster3000::Settings[:endpoint], File.basename(image.file)) %>",
27
+ "hv:uri":"<%= File.join(Imagemaster3000::Settings[:endpoint], File.basename(image.local_filename)) %>",
28
28
  "hv:version":"<%= image.version %>",
29
29
  <% if image.verification -%>
30
30
  "sl:checksum:sha512":"<%= image.verification[:hash][:checksum] %>",
@@ -9,6 +9,9 @@ module Imagemaster3000
9
9
  logger.debug 'Generating image list'
10
10
  image_list = Imagemaster3000::ImageList::Signer.sign(Imagemaster3000::ImageList::Generator.generate(images))
11
11
  File.write Imagemaster3000::Settings[:'image-list'], image_list
12
+ Imagemaster3000::Cleaner.clean
13
+ ensure
14
+ Imagemaster3000::Cleaner.write_clean_file images.map(&:local_filename)
12
15
  end
13
16
 
14
17
  private
@@ -16,7 +19,7 @@ module Imagemaster3000
16
19
  def process_image(image)
17
20
  image.download
18
21
  image.verify! if image.respond_to? :verify!
19
- image.actions.each { |action| action.run image.file } unless image.actions.blank?
22
+ image.actions.each { |action| action.run image.local_filename } unless image.actions.blank?
20
23
  end
21
24
  end
22
25
  end
@@ -4,15 +4,15 @@ module Imagemaster3000
4
4
  def verify_hash!
5
5
  logger.debug 'Verifying checksum'
6
6
  checksum = find_checksum!
7
- computed_checksum = verification[:hash][:function].file(file).hexdigest
7
+ computed_checksum = verification[:hash][:function].file(local_filename).hexdigest
8
8
 
9
9
  if checksum == computed_checksum
10
- verification[:hash][:checksum] = ::Digest::SHA512.file(file).hexdigest
10
+ verification[:hash][:checksum] = ::Digest::SHA512.file(local_filename).hexdigest
11
11
  return
12
12
  end
13
13
 
14
14
  raise Imagemaster3000::Errors::VerificationError,
15
- "Checksum mismatch for file #{file}: expected: #{checksum}, was: #{computed_checksum}"
15
+ "Checksum mismatch for file #{local_filename}: expected: #{checksum}, was: #{computed_checksum}"
16
16
  end
17
17
 
18
18
  private
@@ -23,7 +23,7 @@ module Imagemaster3000
23
23
 
24
24
  def find_checksum_line
25
25
  checksum_list = verification[:hash][:list]
26
- filename = File.basename(file)
26
+ filename = remote_filename
27
27
 
28
28
  logger.debug "Looking for filename #{filename.inspect} in list \n#{checksum_list}"
29
29
 
@@ -32,7 +32,7 @@ module Imagemaster3000
32
32
  unless found_lines.count == 1
33
33
 
34
34
  checksum_line = found_lines.first
35
- logger.debug "Found mathcing line #{checksum_line.inspect}"
35
+ logger.debug "Found matching line #{checksum_line.inspect}"
36
36
 
37
37
  checksum_line
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module Imagemaster3000
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagemaster3000
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Kimle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-05 00:00:00.000000000 Z
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -288,6 +288,7 @@ files:
288
288
  - lib/imagemaster3000/actions.rb
289
289
  - lib/imagemaster3000/actions/copy.rb
290
290
  - lib/imagemaster3000/actions/remove.rb
291
+ - lib/imagemaster3000/cleaner.rb
291
292
  - lib/imagemaster3000/cli.rb
292
293
  - lib/imagemaster3000/definitions.rb
293
294
  - lib/imagemaster3000/definitions/parser.rb