Class: Homebrew::ResourceAuditor Private

Inherits:
Object
  • Object
show all
Defined in:
resource_auditor.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.

Auditor for checking common violations in Resources.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, spec_name, options = {}) ⇒ ResourceAuditor

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 a new instance of ResourceAuditor.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'resource_auditor.rb', line 11

def initialize(resource, spec_name, options = {})
  @name     = resource.name
  @version  = resource.version
  @checksum = resource.checksum
  @url      = resource.url
  @mirrors  = resource.mirrors
  @using    = resource.using
  @specs    = resource.specs
  @owner    = resource.owner
  @spec_name = spec_name
  @online    = options[:online]
  @strict    = options[:strict]
  @only      = options[:only]
  @except    = options[:except]
  @problems  = []
end

Instance Attribute Details

#checksumObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def checksum
  @checksum
end

#mirrorsObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def mirrors
  @mirrors
end

#nameObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def name
  @name
end

#ownerObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def owner
  @owner
end

#problemsObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def problems
  @problems
end

#spec_nameObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def spec_name
  @spec_name
end

#specsObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def specs
  @specs
end

#urlObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def url
  @url
end

#usingObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def using
  @using
end

#versionObject (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.



9
10
11
# File 'resource_auditor.rb', line 9

def version
  @version
end

Class Method Details

.curl_openssl_and_depsObject

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.



92
93
94
95
96
97
98
99
100
101
102
# File 'resource_auditor.rb', line 92

def self.curl_openssl_and_deps
  @curl_openssl_and_deps ||= begin
    formulae_names = ["curl", "openssl"]
    formulae_names += formulae_names.flat_map do |f|
      Formula[f].recursive_dependencies.map(&:name)
    end
    formulae_names.uniq
  rescue FormulaUnavailableError
    []
  end
end

Instance Method Details

#auditObject

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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'resource_auditor.rb', line 28

def audit
  only_audits = @only
  except_audits = @except

  methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name|
    name = audit_method_name.delete_prefix("audit_")
    next if only_audits&.exclude?(name)
    next if except_audits&.include?(name)

    send(audit_method_name)
  end

  self
end

#audit_checksumObject

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.



85
86
87
88
89
90
# File 'resource_auditor.rb', line 85

def audit_checksum
  return if spec_name == :head
  return unless DownloadStrategyDetector.detect(url, using) <= CurlDownloadStrategy

  problem "Checksum is missing" if checksum.blank?
end

#audit_download_strategyObject

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.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'resource_auditor.rb', line 55

def audit_download_strategy
  url_strategy = DownloadStrategyDetector.detect(url)

  if (using == :git || url_strategy == GitDownloadStrategy) && specs[:tag] && !specs[:revision]
    problem "Git should specify :revision when a :tag is specified."
  end

  return unless using

  if using == :cvs
    mod = specs[:module]

    problem "Redundant :module value in URL" if mod == name

    if url.match?(%r{:[^/]+$})
      mod = url.split(":").last

      if mod == name
        problem "Redundant CVS module appended to URL"
      else
        problem "Specify CVS module as `:module => \"#{mod}\"` instead of appending it to the URL"
      end
    end
  end

  return unless url_strategy == DownloadStrategyDetector.detect("", using)

  problem "Redundant :using value in URL"
end

#audit_urlsObject

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.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'resource_auditor.rb', line 104

def audit_urls
  return unless @online

  urls = [url] + mirrors
  urls.each do |url|
    next if !@strict && mirrors.include?(url)

    strategy = DownloadStrategyDetector.detect(url, using)
    if strategy <= CurlDownloadStrategy && !url.start_with?("file")
      if (http_content_problem = curl_check_http_content(url, "source URL", specs: specs))
        problem http_content_problem
      end
    elsif strategy <= GitDownloadStrategy
      problem "The URL #{url} is not a valid git URL" unless Utils::Git.remote_exists? url
    elsif strategy <= SubversionDownloadStrategy
      next unless DevelopmentTools.subversion_handles_most_https_certificates?
      next unless Utils::Svn.available?

      problem "The URL #{url} is not a valid svn URL" unless Utils::Svn.remote_exists? url
    end
  end
end

#audit_versionObject

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.



43
44
45
46
47
48
49
50
51
52
53
# File 'resource_auditor.rb', line 43

def audit_version
  if version.nil?
    problem "missing version"
  elsif !version.detected_from_url?
    version_text = version
    version_url = Version.detect(url, **specs)
    if version_url.to_s == version_text.to_s && version.instance_of?(Version)
      problem "version #{version_text} is redundant with version scanned from URL"
    end
  end
end

#problem(text) ⇒ 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.



127
128
129
# File 'resource_auditor.rb', line 127

def problem(text)
  @problems << text
end