Class: UffizziCore::GoogleRegistryClient

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

Defined Under Namespace

Classes: RequestResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry_url:, username:, password:) ⇒ GoogleRegistryClient

Returns a new instance of GoogleRegistryClient.



6
7
8
9
10
# File 'app/clients/uffizzi_core/google_registry_client.rb', line 6

def initialize(registry_url:, username:, password:)
  @registry_url = registry_url
  @connection = build_connection(registry_url, username, password)
  @token = access_token&.result&.token
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'app/clients/uffizzi_core/google_registry_client.rb', line 4

def connection
  @connection
end

#registry_urlObject

Returns the value of attribute registry_url.



4
5
6
# File 'app/clients/uffizzi_core/google_registry_client.rb', line 4

def registry_url
  @registry_url
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'app/clients/uffizzi_core/google_registry_client.rb', line 4

def token
  @token
end

Instance Method Details

#access_tokenObject



19
20
21
22
23
24
25
26
# File 'app/clients/uffizzi_core/google_registry_client.rb', line 19

def access_token
  service = URI.parse(registry_url).hostname
  url = "/v2/token?service=#{service}"

  response = connection.get(url, {})

  RequestResult.new(result: response.body)
end

#authentificated?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/clients/uffizzi_core/google_registry_client.rb', line 28

def authentificated?
  token.present?
end

#manifests(image:, tag:) ⇒ Object



12
13
14
15
16
17
# File 'app/clients/uffizzi_core/google_registry_client.rb', line 12

def manifests(image:, tag:)
  url = "/v2/#{image}/manifests/#{tag}"
  response = connection.get(url)

  RequestResult.quiet.new(result: response.body, headers: response.headers)
end