BigW Consortium Gitlab

blob.rb 768 Bytes
Newer Older
1
module ContainerRegistry
2 3 4
  class Blob
    attr_reader :repository, :config

5 6
    delegate :registry, :client, to: :repository

7 8 9 10 11 12 13 14 15
    def initialize(repository, config)
      @repository = repository
      @config = config || {}
    end

    def valid?
      digest.present?
    end

16 17 18 19
    def path
      "#{repository.path}@#{digest}"
    end

20
    def digest
21
      config['digest'] || config['blobSum']
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    end

    def type
      config['mediaType']
    end

    def size
      config['size']
    end

    def revision
      digest.split(':')[1]
    end

    def short_revision
      revision[0..8]
    end

    def delete
41
      client.delete_blob(repository.path, digest)
42 43 44
    end

    def data
45
      @data ||= client.blob(repository.path, digest, type)
46 47 48
    end
  end
end