Class: UffizziCore::DockerRegistryClient

Inherits:
Object
  • Object
show all
Defined in:
app/clients/uffizzi_core/docker_registry_client.rb

Defined Under Namespace

Classes: RequestResult

Constant Summary collapse

ACCEPTED_TYPES =
[
  'application/vnd.oci.image.index.v1+json',
  'application/vnd.oci.image.manifest.v1+json',
  'application/vnd.docker.distribution.manifest.v1+json',
  'application/vnd.docker.distribution.manifest.v2+json',
  'application/vnd.docker.distribution.manifest.list.v2+json',
  '*/*',
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(registry_url:, username: nil, password: nil) ⇒ DockerRegistryClient

Returns a new instance of DockerRegistryClient.



13
14
15
16
# File 'app/clients/uffizzi_core/docker_registry_client.rb', line 13

def initialize(registry_url:, username: nil, password: nil)
  @registry_url = registry_url
  @connection = build_connection(username, password)
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'app/clients/uffizzi_core/docker_registry_client.rb', line 18

def authenticated?
  @connection.get("#{@registry_url}/v2/")

  true
end

#manifests(image:, tag:, namespace: nil) ⇒ Object



24
25
26
27
28
29
30
# File 'app/clients/uffizzi_core/docker_registry_client.rb', line 24

def manifests(image:, tag:, namespace: nil)
  full_image = [namespace, image].compact.join('/')
  url = "#{@registry_url}/v2/#{full_image}/manifests/#{tag}"
  response = @connection.get(url)

  RequestResult.new(status: response.status, result: response.body)
end