Class: OCIRegistry::Client
- Inherits:
-
Object
- Object
- OCIRegistry::Client
- Defined in:
- lib/oci_registry/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#token(repository) ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #download_and_extract_layers(repository, layers, file_name) ⇒ Object
-
#initialize(username: nil, password: nil, token: nil, host: 'registry-1.docker.io') ⇒ Client
constructor
A new instance of Client.
- #manifest(repository, tag) ⇒ Object
- #metadata(repository, tag) ⇒ Object
- #ping ⇒ Object
- #tags(repository, &block) ⇒ Object
Constructor Details
#initialize(username: nil, password: nil, token: nil, host: 'registry-1.docker.io') ⇒ Client
Returns a new instance of Client.
4 5 6 7 8 9 10 11 12 |
# File 'lib/oci_registry/client.rb', line 4 def initialize(username: nil, password: nil, token: nil, host: 'registry-1.docker.io') # Main Execution Flow @username = username @password = password @token = token # e.g. gcloud auth print-access-token @tokens = {} @manifests = {} @host = host end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/oci_registry/client.rb', line 3 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/oci_registry/client.rb', line 3 def password @password end |
#token(repository) ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/oci_registry/client.rb', line 3 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/oci_registry/client.rb', line 3 def username @username end |
Instance Method Details
#download_and_extract_layers(repository, layers, file_name) ⇒ Object
49 50 51 |
# File 'lib/oci_registry/client.rb', line 49 def download_and_extract_layers(repository, layers, file_name) OCIRegistry::Remote.download_and_extract_layers(host, self.token(repository), repository, layers, file_name) end |
#manifest(repository, tag) ⇒ Object
40 41 42 43 |
# File 'lib/oci_registry/client.rb', line 40 def manifest(repository, tag) slug = "#{repository}:#{tag}" @manifests[slug] = OCIRegistry::Remote.get_manifest(self.host, self.token(repository), repository, tag) end |
#metadata(repository, tag) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/oci_registry/client.rb', line 13 def (repository, tag) manifest = self.manifest(repository, tag) case manifest['mediaType'] when "application/vnd.docker.distribution.manifest.list.v2+json" # Multi-arch images have a manifest list manifest = manifest['manifests'].find { |m| m['platform']['architecture'] == 'amd64' && m['platform']['os'] == 'linux' } self.(repository, manifest['digest']) when "application/vnd.docker.distribution.manifest.v2+json" # Builders blob_digest = manifest['config']['digest'] OCIRegistry::Remote.get_blob(host, self.token(repository), repository, blob_digest) when "application/vnd.oci.image.index.v1+json" # Buildpacks give a collection of manifests as an index if they are multi-arch: manifest = manifest['manifests'].find { |s| s['platform']['architecture'] == 'amd64' && s['platform']['os'] == 'linux' } self.(repository, manifest['digest']) when "application/vnd.oci.image.manifest.v1+json" # OCI Images blob_digest = manifest['config']['digest'] OCIRegistry::Remote.get_blob(host, self.token(repository), repository, blob_digest) else raise "Unknown manifest type: #{manifest['mediaType']}" end end |
#ping ⇒ Object
52 53 54 55 |
# File 'lib/oci_registry/client.rb', line 52 def ping # ping the api OCIRegistry::Remote.http_get(URI("https://#{host}/v2/"), { 'Authorization' => "Bearer #{@token}" }) end |
#tags(repository, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/oci_registry/client.rb', line 44 def (repository, &block) = OCIRegistry::Remote.(self.host, self.token(repository), repository) return .each(&block) if block_given? end |