class Proxy::Omaha::Release

Attributes

architecture[RW]
digests[W]
track[RW]
version[RW]

Public Class Methods

new(options) click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 13
def initialize(options)
  @track = options.fetch(:track).to_s
  @architecture = options.fetch(:architecture)
  @version = Gem::Version.new(options.fetch(:version))
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 65
def <=>(other)
  return unless self.class === other
  version.<=>(other.version)
end
==(other) click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 70
def ==(other)
  self.class === other && track == other.track && version == other.version && architecture == other.architecture
end
base_path() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 19
def base_path
  @base_path ||= File.join(Proxy::Omaha::Plugin.settings.contentpath, track, architecture)
end
complete?() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 150
def complete?
  missing_files.empty?
end
create() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 46
def create
  logger.debug "Creating #{track} #{version} #{architecture}"
  return false unless create_path
  return false unless download
  return false unless create_metadata
  true
end
create_metadata() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 90
def create_metadata
  metadata_provider.store(Metadata.new(
    :track => track,
    :release => version.to_s,
    :architecture => architecture,
    :size => File.size(updatefile),
    :sha1_b64 => Digest::SHA1.file(updatefile).base64digest,
    :sha256_b64 => Digest::SHA256.file(updatefile).base64digest
  ))
  true
rescue
  false
end
create_path() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 104
def create_path
  FileUtils.mkdir_p(path)
  true
rescue
  false
end
current?() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 54
def current?
  return false unless File.symlink?(current_path)
  File.readlink(current_path) == path
end
current_path() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 27
def current_path
  @current_path ||= File.join(base_path, 'current')
end
digest_files() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 146
def digest_files
  Dir.glob(File.join(path, '*.DIGESTS')).map { |file| File.basename(file) }
end
digests() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 166
def digests
  @digests ||= load_digests!
end
download() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 78
def download
  sources.map do |url|
    file = URI.parse(url).path.split('/').last
    next if file_exists?(file)
    dst = File.join(path, file)
    logger.debug "Downloading file #{url} to #{dst}"
    task = ::Proxy::Omaha::HttpDownload.new(url, dst)
    task.start
    task
  end.compact.each(&:join).map(&:result).all?
end
existing_files() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 138
def existing_files
  Dir.glob(File.join(path, '*')).map { |file| File.basename(file) }
end
exists?() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 35
def exists?
  File.directory?(path)
end
expected_files() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 134
def expected_files
  sources.map { |source| File.basename(source) }
end
file_exists?(file) click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 154
def file_exists?(file)
  File.file?(File.join(path, file))
end
file_urls(base_url) click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 199
def file_urls(base_url)
  existing_files.map do |file|
    [base_url, 'omahareleases', track, architecture, self, file].join('/')
  end
end
load_digests!() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 170
def load_digests!
  self.digests = {}
  digest_files.each do |digest_file|
    file = File.basename(digest_file, '.DIGESTS')
    File.readlines(File.join(path, digest_file)).each do |line|
      next unless line =~ /^\w+[ ]+\S+$/
      hexdigest = line.split(/[ ]+/).first
      self.digests[file] ||= []
      self.digests[file] << hexdigest
    end
  end
  self.digests
end
mark_as_current!() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 59
def mark_as_current!
  return true if current?
  File.unlink(current_path) if File.symlink?(current_path)
  FileUtils.ln_s(path, current_path)
end
metadata() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 31
def metadata
  metadata_provider.get(track, release, architecture)
end
missing_files() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 142
def missing_files
  expected_files - existing_files
end
path() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 23
def path
  @path ||= File.join(base_path, version.to_s)
end
purge() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 158
def purge
  FileUtils.rm(Dir.glob(File.join(path, '*')), :force => true)
  FileUtils.remove_dir(path)
  true
rescue
  false
end
sources() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 115
def sources
  upstream = "https://#{track}.release.core-os.net/#{architecture}/#{version}"
  [
    "#{upstream}/coreos_production_pxe.vmlinuz",
    "#{upstream}/coreos_production_pxe.DIGESTS",
    "#{upstream}/coreos_production_image.bin.bz2",
    "#{upstream}/coreos_production_image.bin.bz2.sig",
    "#{upstream}/coreos_production_image.bin.bz2.DIGESTS",
    "#{upstream}/coreos_production_pxe_image.cpio.gz",
    "#{upstream}/coreos_production_pxe_image.cpio.gz.DIGESTS",
    "#{upstream}/coreos_production_vmware_raw_image.bin.bz2",
    "#{upstream}/coreos_production_vmware_raw_image.bin.bz2.sig",
    "#{upstream}/coreos_production_vmware_raw_image.bin.bz2.DIGESTS",
    "#{upstream}/version.txt",
    "#{upstream}/version.txt.DIGESTS",
    "https://update.release.core-os.net/#{architecture}/#{version}/update.gz"
  ]
end
to_h() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 184
def to_h
  {
    :name => to_s,
    :current => current?,
    :architecture => architecture,
    :track => track,
    :complete => complete?,
    :files => existing_files
  }
end
to_json() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 195
def to_json
  to_h.to_json
end
to_s() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 74
def to_s
  version.to_s
end
updatefile() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 111
def updatefile
  File.join(path, 'update.gz')
end
valid?() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 39
def valid?
  existing_files.select { |file| file !~ /\.(DIGESTS|sig)$/ }.map do |file|
    next unless digests[file]
    digests[file].include?(Digest::MD5.file(File.join(path, file)).hexdigest)
  end.compact.all?
end

Private Instance Methods

metadata_provider() click to toggle source
# File lib/smart_proxy_omaha/release.rb, line 207
def metadata_provider
  MetadataProvider.new(
    :contentpath => Proxy::Omaha::Plugin.settings.contentpath
  )
end