Class: Kdep::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/kdep/registry.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry_url) ⇒ Registry

Returns a new instance of Registry.



12
13
14
15
16
17
18
# File 'lib/kdep/registry.rb', line 12

def initialize(registry_url)
  url = registry_url.chomp("/")
  parts = url.split("/", 2)
  @host = parts[0]
  @path_prefix = parts[1]
  @registry_url = url
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/kdep/registry.rb', line 10

def host
  @host
end

#path_prefixObject (readonly)

Returns the value of attribute path_prefix.



10
11
12
# File 'lib/kdep/registry.rb', line 10

def path_prefix
  @path_prefix
end

Instance Method Details

#list_tags(image) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kdep/registry.rb', line 20

def list_tags(image)
  repository = "#{@path_prefix}/#{image}"
  uri = URI("https://#{@host}/v2/#{repository}/tags/list")

  req = Net::HTTP::Get.new(uri)
  apply_auth(req, repository)

  response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
    http.request(req)
  end

  return [] if response.code == "404"

  unless response.code.start_with?("2")
    raise Error, "Registry returned #{response.code}: #{response.body}"
  end

  data = JSON.parse(response.body)
  data["tags"] || []
end