Module: Homebrew::Bundle::Trust Private

Defined in:
bundle/trust.rb

Overview

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

Converts Brewfile trusted options into trust-store entries.

Class Method Summary collapse

Class Method Details

.entries(entries) ⇒ Array<Array<(Symbol, 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.

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'bundle/trust.rb', line 19

def self.entries(entries)
  entries.flat_map do |entry|
    trusted = entry.options[:trusted]
    full_name = T.cast(entry.options.fetch(:full_name, entry.name), String)

    entry_type = entry.type

    case entry_type
    when :tap
      next [] if trusted.blank?

      clone_target = entry.options[:clone_target].presence
      tap_reference = if clone_target
        require "tap"
        ::Tap.remote_to_reference(clone_target.to_s) || clone_target.to_s
      else
        entry.name
      end
      next [[:tap, tap_reference]] if trusted == true
      next [] unless trusted.is_a?(Hash)

      unsupported_keys = trusted.keys - TRUSTED_ITEM_KEYS.values.flatten
      raise UsageError, "Unsupported trusted keys: #{unsupported_keys.join(", ")}" if unsupported_keys.present?

      TRUSTED_ITEM_KEYS.flat_map do |type, keys|
        keys.flat_map do |key|
          Array(trusted[key]).filter_map do |item|
            item_name = case item
            when String, Symbol, Integer
              Utils.name_from_full_name(item.to_s)
            end
            next if item_name.blank?

            [type, "#{tap_reference}/#{item_name}"]
          end
        end
      end
    when :brew, :cask
      # Only fully-qualified names map to a tap, so unqualified names
      # cannot be meaningfully trusted.
      next [] if trusted != true || !Utils.full_name?(full_name)

      type = (entry_type == :brew) ? :formula : :cask
      [[type, full_name]]
    else
      []
    end
  end.uniq
end