license_scout 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9424ab5a07b97ad3aae865f34272ef0929133dc59a2a2517099733b9f52b2d5d
4
- data.tar.gz: 49b5eef3a1c45e5d4941ef213f58e3530151357ab832dd9c5b69014148191543
3
+ metadata.gz: '083e8edafd9a99be05ba58d2af282874c2afedfef05cc7d5548f68c377178f63'
4
+ data.tar.gz: a00c763ddafbcf149fdfacc7b005bb372509f3bd07186858b3d9247976b2c5b3
5
5
  SHA512:
6
- metadata.gz: 0b4e3b501de6f26ec2f01b7a99f9b27620761ba183bc14be7febb6b8a3a54830ec3f3ec064e9fab64469359d44fbc5ae6f5ae91e41ab1537da20fff29c23f1f0
7
- data.tar.gz: 42310f9e3474e7b07242103e2f00295063ab87101417e89aa758a436b926959fb2dc8e297e086f9c16d755551001d745b3dd36c032ae9c4a1143b2dd894c828a
6
+ metadata.gz: c31dcd43c92cd006a7cc644389b8c29993002d6c2ec4d29db92553ce56dd6d551cc11c29a572ed5b54f3ee7d126c615a8b9f9956366c804252485490d7b5fe44
7
+ data.tar.gz: c4f345b2bd3f5a1cc7d8b36c00a0bbcf9ed4431e1829b0ff18b8e48e4a987dd6c6e134114829a87ba825ff43f4f0948bf0d7bb6cd9f5da11e261bdb475adfcf3
@@ -117,6 +117,9 @@ module LicenseScout
117
117
  reporter = LicenseScout::Reporter.new(collector.dependencies)
118
118
  reporter.report
119
119
  end
120
+ exit 0
121
+ rescue Exceptions::FailExit
122
+ exit 1
120
123
  end
121
124
  end
122
125
  end
@@ -35,6 +35,10 @@ module LicenseScout
35
35
  dependency_managers.each { |d| collect_licenses_from(d) }
36
36
 
37
37
  LicenseScout::Log.info("[collector] All licenses successfully collected")
38
+ rescue Exceptions::PackageNotFound => e
39
+ LicenseScout::Log.error("[collector] One of the project's transitive dependencies could not be found:")
40
+ LicenseScout::Log.error("[collector] #{e}")
41
+ raise Exceptions::FailExit.new(e)
38
42
  end
39
43
 
40
44
  private
@@ -16,6 +16,7 @@
16
16
  #
17
17
 
18
18
  require "license_scout/dependency_manager/base"
19
+ require "license_scout/exceptions"
19
20
 
20
21
  require "open-uri"
21
22
  require "mixlib/shellout"
@@ -24,6 +25,7 @@ module LicenseScout
24
25
  module DependencyManager
25
26
  class Habitat < Base
26
27
  DEFAULT_CHANNEL = "stable".freeze
28
+ FALLBACK_CHANNEL_FOR_FQ = "unstable".freeze
27
29
 
28
30
  def name
29
31
  "habitat"
@@ -54,20 +56,28 @@ module LicenseScout
54
56
 
55
57
  tdeps.sort.map do |tdep|
56
58
  o, n, v, r = tdep.split("/")
57
- c = channel_for_origin(o)
58
59
  dep_name = "#{o}/#{n}"
59
60
  dep_version = "#{v}-#{r}"
60
61
 
61
62
  dependency = new_dependency(dep_name, dep_version, nil)
62
63
 
63
64
  license_from_manifest(pkg_info(tdep)["manifest"]).each do |spdx|
64
- dependency.add_license(spdx, "https://bldr.habitat.sh/v1/depot/channels/#{o}/#{c}/pkgs/#{n}/#{v}/#{r}")
65
+ # We hard code the channel to "unstable" because a package could be
66
+ # demoted from any given channel except unstable in the future and
67
+ # we want the url metadata to be stable in order to give end users
68
+ # the ability to self-audit licenses
69
+ # tl;dr, we want a permalink not a nowlink
70
+ dependency.add_license(spdx, "https://bldr.habitat.sh/v1/depot/channels/#{o}/unstable/pkgs/#{n}/#{v}/#{r}")
65
71
  end
66
72
 
67
73
  dependency
68
74
  end.compact
69
75
  end
70
76
 
77
+ def fetched_urls
78
+ @fetched_urls ||= {}
79
+ end
80
+
71
81
  private
72
82
 
73
83
  def license_from_manifest(manifest_content)
@@ -94,27 +104,51 @@ module LicenseScout
94
104
 
95
105
  def pkg_info(pkg_ident)
96
106
  $habitat_pkg_info ||= {}
97
- $habitat_pkg_info[pkg_ident] ||= begin
98
- pkg_origin, pkg_name, pkg_version, pkg_release = pkg_ident.split("/")
99
- pkg_channel = channel_for_origin(pkg_origin)
100
-
101
- base_api_uri = "https://bldr.habitat.sh/v1/depot/channels/#{pkg_origin}/#{pkg_channel}/pkgs/#{pkg_name}"
102
- if pkg_version.nil? && pkg_release.nil?
103
- base_api_uri += "/latest"
104
- elsif pkg_release.nil?
105
- base_api_uri += "/#{pkg_version}/latest"
106
- else
107
- base_api_uri += "/#{pkg_version}/#{pkg_release}"
108
- end
107
+ $habitat_pkg_info[pkg_ident] ||= pkg_info_with_channel_fallbacks(pkg_ident)
108
+ end
109
+
110
+ def pkg_info_with_channel_fallbacks(pkg_ident)
111
+ pkg_origin, pkg_name, pkg_version, pkg_release = pkg_ident.split("/")
112
+ pkg_channel = channel_for_origin(pkg_origin)
113
+
114
+ # Channel selection here is similar to the logic that
115
+ # Habitat uses. First, search in the user-provided channel,
116
+ # then search in stable, then use unstable IF it is a fully
117
+ # qualified package
118
+ info = get_pkg_info(pkg_origin, pkg_channel, pkg_name, pkg_version, pkg_release)
119
+ return info if info
120
+
121
+ if pkg_channel != DEFAULT_CHANNEL
122
+ LicenseScout::Log.debug("[habitat] Looking for #{pkg_ident} in #{DEFAULT_CHANNEL} channel")
123
+ info = get_pkg_info(pkg_origin, DEFAULT_CHANNEL, pkg_name, pkg_version, pkg_release)
124
+ return info if info
125
+ end
109
126
 
110
- LicenseScout::Log.debug("[habitat] Fetching pkg_info from #{base_api_uri}")
111
- FFI_Yajl::Parser.parse(open(base_api_uri).read)
112
- rescue OpenURI::HTTPError
113
- pkg_origin, pkg_name, = pkg_ident.split("/")
127
+ if !pkg_version.nil? && !pkg_release.nil?
128
+ LicenseScout::Log.debug("[habitat] Looking for #{pkg_ident} in #{FALLBACK_CHANNEL_FOR_FQ} channel since it is fully-qualified")
129
+ info = get_pkg_info(pkg_origin, FALLBACK_CHANNEL_FOR_FQ, pkg_name, pkg_version, pkg_release)
130
+ return info if info
131
+ end
132
+
133
+ raise LicenseScout::Exceptions::HabitatPackageNotFound.new("Could not find Habitat package #{pkg_ident}")
134
+ end
135
+
136
+ def get_pkg_info(origin, channel, name, version, release)
137
+ base_api_uri = "https://bldr.habitat.sh/v1/depot/channels/#{origin}/#{channel}/pkgs/#{name}"
138
+ if version.nil? && release.nil?
139
+ base_api_uri += "/latest"
140
+ elsif release.nil?
141
+ base_api_uri += "/#{version}/latest"
142
+ else
143
+ base_api_uri += "/#{version}/#{release}"
144
+ end
114
145
 
115
- LicenseScout::Log.warn("[habitat] Could not find pkg_info for #{pkg_ident} - trying for the latest version of #{pkg_origin}/#{pkg_name}")
116
- FFI_Yajl::Parser.parse(open("https://bldr.habitat.sh/v1/depot/channels/#{pkg_origin}/#{pkg_channel}/pkgs/#{pkg_name}/latest").read)
146
+ LicenseScout::Log.debug("[habitat] Fetching pkg_info from #{base_api_uri}")
147
+ FFI_Yajl::Parser.parse(open(base_api_uri).read).tap do |bldr_info|
148
+ fetched_urls["#{origin}/#{name}"] = base_api_uri
117
149
  end
150
+ rescue OpenURI::HTTPError
151
+ nil
118
152
  end
119
153
 
120
154
  def channel_for_origin(pkg_origin)
@@ -21,5 +21,8 @@ module LicenseScout
21
21
  class ConfigError < Error; end
22
22
  class MissingSourceDirectory < Error; end
23
23
  class UnsupportedExporter < Error; end
24
+ class PackageNotFound < Error; end
25
+ class HabitatPackageNotFound < PackageNotFound; end
26
+ class FailExit < Error; end
24
27
  end
25
28
  end
@@ -175,7 +175,7 @@ module LicenseScout
175
175
  puts " * Please add exceptions for the 'Flagged' or 'Not Allowed' dependencies" if @needs_exception
176
176
  puts " https://github.com/chef/license_scout#dependency-exceptions" if @needs_exception
177
177
 
178
- exit 1 if @did_fail
178
+ raise Exceptions::FailExit.new("missing or not allowed licenses detected") if @did_fail
179
179
  end
180
180
 
181
181
  def generate_dependency_license_manifest
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module LicenseScout
19
- VERSION = "2.1.0"
19
+ VERSION = "2.1.1"
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license_scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serdar Sutay
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-23 00:00:00.000000000 Z
12
+ date: 2018-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi-yajl