Class: Resource::BottleManifest Private

Inherits:
Resource
  • Object
show all
Defined in:
resource.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

A resource for a bottle manifest.

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bottle) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:



426
427
428
429
430
# File 'resource.rb', line 426

def initialize(bottle)
  super("#{bottle.name}_bottle_manifest")
  @bottle = bottle
  @manifest_annotations = T.let(nil, T.nilable(T::Hash[String, String]))
end

Instance Attribute Details

#bottle ⇒ Bottle (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



420
421
422
# File 'resource.rb', line 420

def bottle
  @bottle
end

#manifest_annotations=(value) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



423
424
425
# File 'resource.rb', line 423

def manifest_annotations=(value)
  @manifest_annotations = value
end

Instance Method Details

#bottle_size ⇒ Integer?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



470
471
472
# File 'resource.rb', line 470

def bottle_size
  manifest_annotations["sh.brew.bottle.size"]&.to_i
end

#clear_cache ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



433
434
435
436
# File 'resource.rb', line 433

def clear_cache
  super
  @manifest_annotations = nil
end

#download_queue_name ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



529
# File 'resource.rb', line 529

def download_queue_name = "#{bottle.name} (#{bottle.resource.version})"

#download_queue_type ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



526
# File 'resource.rb', line 526

def download_queue_type = "Bottle Manifest"

#downloaded_and_valid? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


447
448
449
450
451
452
453
454
455
# File 'resource.rb', line 447

def downloaded_and_valid?
  return false unless downloaded?

  with_context(quiet: true) { verify_download_integrity(cached_download) }
  true
rescue Error, ChecksumMismatchError
  clear_cache
  false
end

#image_ref(tag) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

The name an index gives the manifest of this bottle's build for a tag.

Parameters:

Returns:



506
507
508
509
510
511
# File 'resource.rb', line 506

def image_ref(tag)
  version = bottle.resource.version
  raise "Version is nil" if version.nil?

  GitHubPackages.version_rebuild(version, bottle.rebuild, tag.to_s)
end

#installed_size ⇒ Integer?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



475
476
477
# File 'resource.rb', line 475

def installed_size
  manifest_annotations["sh.brew.bottle.installed_size"]&.to_i
end

#path_exec_files ⇒ Array<String>?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



480
481
482
# File 'resource.rb', line 480

def path_exec_files
  manifest_annotations["sh.brew.path_exec_files"]&.split(",")
end

#platform_manifest_sha256s ⇒ Hash{Array<(String, String)> => String}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

The SHA-256 of each bottle's own manifest in a downloaded index, keyed by that manifest's name and the SHA-256 of its bottle. Bottles for several tags can share a SHA-256 but a client accepts only the manifest named for its own tag.

Returns:



518
519
520
521
522
523
# File 'resource.rb', line 518

def platform_manifest_sha256s
  JSON.parse(cached_manifest).fetch("manifests").to_h do |manifest|
    [manifest.fetch("annotations").fetch_values("org.opencontainers.image.ref.name", "sh.brew.bottle.digest"),
     manifest.fetch("digest").delete_prefix("sha256:")]
  end
end

#sbom_supplement ⇒ Hash{String => Object}?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'resource.rb', line 485

def sbom_supplement
  supplement = manifest_annotations["sh.brew.sbom.supplement"]
  return if supplement.blank?

  parsed_supplement = JSON.parse(supplement)
  return unless parsed_supplement.is_a?(Hash)

  if (tags = parsed_supplement["tags"]).is_a?(Hash)
    tag_supplement = tags[Utils::Bottles.tag.to_s]
    return tag_supplement if tag_supplement.is_a?(Hash)

    return
  end

  parsed_supplement
rescue JSON::ParserError
  nil
end

#tab ⇒ Hash{String => T.untyped}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

Raises:



458
459
460
461
462
463
464
465
466
467
# File 'resource.rb', line 458

def tab
  tab = manifest_annotations["sh.brew.tab"]
  raise Error, "Couldn't find tab from manifest." if tab.blank?

  begin
    JSON.parse(tab)
  rescue JSON::ParserError
    raise Error, "Couldn't parse tab JSON."
  end
end

#verify_download_integrity(filename) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



439
440
441
442
443
444
# File 'resource.rb', line 439

def verify_download_integrity(filename)
  # Only a manifest fetched by digest has a checksum. Without one we can
  # at least try parsing it.
  super if checksum
  tab
end