Class: Fig::Lock::DockerClient

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/lock/docker_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = "#{ENV['HOME']}/.dockercfg") ⇒ DockerClient

Returns a new instance of DockerClient.



11
12
13
# File 'lib/fig/lock/docker_client.rb', line 11

def initialize(file="#{ENV['HOME']}/.dockercfg")
  @cfg = JSON.parse(File.read(file))
end

Instance Attribute Details

#cfgObject (readonly)

Returns the value of attribute cfg.



9
10
11
# File 'lib/fig/lock/docker_client.rb', line 9

def cfg
  @cfg
end

Instance Method Details

#base(registry) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/fig/lock/docker_client.rb', line 28

def base(registry)
  config = cfg[registry]
  if config
    auth = Base64.decode64(config['auth'])
    RestClient::Resource.new("https://#{auth}@#{registry}")
  else
    RestClient::Resource.new("https://#{registry}")
  end
end

#tags(repo) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fig/lock/docker_client.rb', line 15

def tags(repo)
  array = repo.split('/')
  registry = array[0]
  repo = array[1]
  name = array[2]
  if name.index(':')
    name = name.split(':')[0]
  end

  resource = base(registry)['v1']['repositories'][repo][name]['tags']
  JSON.parse(resource.get.body)
end