Class: Dapp::Dimg::DockerRegistry::Base

Inherits:
Object
  • Object
show all
Includes:
Authorization, Request
Defined in:
lib/dapp/dimg/docker_registry/base.rb,
lib/dapp/dimg/docker_registry/base/request.rb,
lib/dapp/dimg/docker_registry/base/authorization.rb

Direct Known Subclasses

Dimg

Defined Under Namespace

Modules: Authorization, Request

Constant Summary collapse

API_VERSION =
'v2'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Authorization

#authorization_auth, #authorization_options, #authorization_token, #auths_section_from_docker_config, #handle_scope_option, #parse_authenticate_header

Methods included from Request

included, #raw_request, #request, #url_available?

Constructor Details

#initialize(repo, hostname_url, repo_suffix) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
# File 'lib/dapp/dimg/docker_registry/base.rb', line 14

def initialize(repo, hostname_url, repo_suffix)
  self.repo = repo
  self.hostname_url = hostname_url
  self.repo_suffix = repo_suffix
end

Instance Attribute Details

#hostname_urlObject

Returns the value of attribute hostname_url.



11
12
13
# File 'lib/dapp/dimg/docker_registry/base.rb', line 11

def hostname_url
  @hostname_url
end

#repoObject

Returns the value of attribute repo.



10
11
12
# File 'lib/dapp/dimg/docker_registry/base.rb', line 10

def repo
  @repo
end

#repo_suffixObject

Returns the value of attribute repo_suffix.



12
13
14
# File 'lib/dapp/dimg/docker_registry/base.rb', line 12

def repo_suffix
  @repo_suffix
end

Instance Method Details

#image_delete(tag) ⇒ Object



37
38
39
40
41
42
# File 'lib/dapp/dimg/docker_registry/base.rb', line 37

def image_delete(tag)
  api_request(repo_suffix, "/manifests/#{image_digest(tag)}",
              method: :delete,
              expects: [202, 404],
              headers: { Accept: 'application/vnd.docker.distribution.manifest.v2+json' })
end

#image_history(tag) ⇒ Object



44
45
46
47
# File 'lib/dapp/dimg/docker_registry/base.rb', line 44

def image_history(tag)
  response = manifest_v1(tag)
  JSON.load(response['history'].first['v1Compatibility'])
end

#image_id(tag) ⇒ Object



24
25
26
27
# File 'lib/dapp/dimg/docker_registry/base.rb', line 24

def image_id(tag)
  response = manifest_v2(tag)
  response['config']['digest'] if response['schemaVersion'] == 2
end

#image_labels(tag) ⇒ Object



33
34
35
# File 'lib/dapp/dimg/docker_registry/base.rb', line 33

def image_labels(tag)
  image_history(tag)['config']['Labels']
end

#image_parent_id(tag) ⇒ Object



29
30
31
# File 'lib/dapp/dimg/docker_registry/base.rb', line 29

def image_parent_id(tag)
  image_history(tag)['container_config']['Image']
end

#tagsObject



20
21
22
# File 'lib/dapp/dimg/docker_registry/base.rb', line 20

def tags
  api_request(repo_suffix, 'tags/list')['tags'] || []
end