Class: OsCtl::Repo::Downloader::Direct

Inherits:
Base
  • Object
show all
Defined in:
lib/osctl/repo/downloader/direct.rb

Overview

Download image in a specified format, no caching involved

Instance Attribute Summary

Attributes inherited from Base

#repo

Instance Method Summary collapse

Methods inherited from Base

#connect, #index_uri, #initialize

Constructor Details

This class inherits a constructor from OsCtl::Repo::Downloader::Base

Instance Method Details

#get(vendor, variant, arch, dist, vtag, format, opts = {}) ⇒ Object

yieldparam [String] downloaded data



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/osctl/repo/downloader/direct.rb', line 16

def get(vendor, variant, arch, dist, vtag, format, opts = {})
  connect do |http|
    index = Remote::Index.from_string(repo, http.get(uri.path).body)
    t = index.lookup(vendor, variant, arch, dist, vtag)

    fail 'image not found' unless t
    fail 'image not in given format' unless t.has_image?(format)

    uri = URI(t.abs_image_url(format))
    http.request_get(uri.path) do |res|
      fail 'bad response' unless res.code == '200'

      res.read_body do |fragment|
        yield(fragment)
      end
    end
  end
end

#listArray<Remote::Image>

Returns:



8
9
10
11
12
13
# File 'lib/osctl/repo/downloader/direct.rb', line 8

def list
  connect do |http|
    index = Remote::Index.from_string(repo, http.get(index_uri.path).body)
    index.images
  end
end