license_scout 2.2.0 → 2.4.0

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: fff0dd83efc21ff06cc8fcc66bd3035387d9a61ad6ac033c50c525612a477acf
4
- data.tar.gz: 934a3a5bbf27de7a5c0f6f0f657659e5a16a9e31d1bd6ebaff8d69365ba88299
3
+ metadata.gz: 0cc1880e883f74c45e68c9495f816f7e757a62f16701de45fa77e89c97ed6637
4
+ data.tar.gz: 43e3b7c1a111a7fa2f97f5340e3268547aead69d8ff38b8dfd57be47121e4aea
5
5
  SHA512:
6
- metadata.gz: 24a584c6ebf0e4820082a42948f012f4017c916da060572425081add7b9ade1a44679c8d460a3f68970d2b4cc88fda3d26f64012b38fceec1b38f928a697c10d
7
- data.tar.gz: 02e7b5e509e979d51662f985469ae929c96b20d0d85ba48dd89ce59add5afb9c5d8a5794116a3de184b2d7efa6999278bf88338eeb7ea3922f65040adfa8f2bd
6
+ metadata.gz: 4031e209faef9bb783dcef890f9d72ebe87df83711e7730a39680014ffe14bbb4880b9f0f201ed351890cb0b385b3ebe8eb8dee980cba3a702553e1dd738f435
7
+ data.tar.gz: 072b2ee320c4f4de3fbeeeca3aab2d4a08476325d441a62b94adcfccbb90ffb241576ab1f5d9f7b6dfb2e9b803057268a993e14dcbab0164dfe5f0f48c404102
data/README.md CHANGED
@@ -14,6 +14,7 @@ habitat | habitat
14
14
  nodejs | npm
15
15
  perl | cpan
16
16
  ruby | bundler
17
+ rust | cargo
17
18
 
18
19
  ## Installation
19
20
 
@@ -27,6 +28,7 @@ gem install license_scout
27
28
 
28
29
  * If you wish to scan for `berkshelf` dependencies, you'll need to manually install the Berkshelf gem in the same Ruby as License Scout
29
30
  * If you wish to scan for `mix` or `rebar` dependencies, you'll need to install Erlang OTP 18.3 or greater.
31
+ * If you wish to scan for `cargo` dependencies, you'll need to manually install cargo
30
32
 
31
33
  ### Habitat
32
34
 
@@ -179,12 +181,21 @@ license_content | A URL to a file where the raw text of the license can be downl
179
181
 
180
182
  In addition to including any files Licensee identified as potential license files (but couldn't identify), License Scout will also include the Fallback License you specified in the Dependency Manifest.
181
183
 
184
+ ### Searching Nested Subdirectories
185
+
186
+ License Scout's default behavior is to only look for dependency manager files in the root of the `directories` that you configure. This default behavior provides greater control over the dependencies that you want to appear in your report. For example, you may not want to enforce license acceptance on an internal-only tool that is included in a project.
187
+
188
+ License Scout will also scan subdirectories for all dependency manager files and generate a full report on all dependencies that the project uses. To do this, either specify the `--include-sub-directories` command line flag, or set `include_subdirectories` to true in your configuration file.
189
+
190
+ A common use case for this functionality is to run `license_scout` from the root of a project and get a full report for that project.
191
+
192
+ ```
193
+ license_scout --include-sub-directories
194
+ ```
195
+
182
196
  ## Habitat Channel Configuration
183
197
 
184
- By default License Scout searches for Habitat package in the `stable`
185
- channel. If your build process publishes packages to another channel
186
- by default, you can use the `channel_for_origin` habitat configuration
187
- option:
198
+ By default License Scout searches for Habitat package in the `stable` channel. If your build process publishes packages to another channel by default, you can use the `channel_for_origin` habitat configuration option:
188
199
 
189
200
  ```yaml
190
201
  habitat:
@@ -216,6 +227,7 @@ Format | Description
216
227
  Value | Description | Default
217
228
  --- | --- | ---
218
229
  directories | The fully-qualified local paths to the directories you wish to scan | _The current working directory._ |
230
+ include_subdirectories | Whether or not to include all nested sub-directories of `directories` in the search. | `false` |
219
231
  name | The name you want to give to the scan result. | _The basename of the first directory to be scanned._ |
220
232
  output_directory | The path to the directory where the output JSON file should be saved. | _The current working directory._ |
221
233
  log_level | What log information should be included in STDOUT | `info` |
@@ -42,6 +42,11 @@ module LicenseScout
42
42
  description: "Comma-separated list of directories to scan",
43
43
  proc: Proc.new { |d| d.split(",") }
44
44
 
45
+ option :include_subdirectories,
46
+ long: "--include-sub-directories",
47
+ description: "Include all sub-directories of 'directories' in the analysis",
48
+ boolean: true
49
+
45
50
  option :format,
46
51
  long: "--format FORMAT",
47
52
  description: "When exporting a Dependency Manifest, export to this format",
@@ -52,7 +57,7 @@ module LicenseScout
52
57
  short: "-l LEVEL",
53
58
  long: "--log-level LEVEL",
54
59
  description: "Set the log level",
55
- in: [:debug, :info, :warn, :error, :fatal],
60
+ in: %i{debug info warn error fatal},
56
61
  default: :info,
57
62
  proc: Proc.new { |l| l.to_sym }
58
63
 
@@ -57,7 +57,7 @@ module LicenseScout
57
57
  end
58
58
 
59
59
  def dependency_managers
60
- @dependency_managers ||= LicenseScout::Config.directories.map do |dir|
60
+ @dependency_managers ||= LicenseScout::Config.all_directories.map do |dir|
61
61
  LicenseScout::DependencyManager.implementations.map do |implementation|
62
62
  dep_mgr = implementation.new(File.expand_path(dir))
63
63
  if dep_mgr.detected?
@@ -28,6 +28,7 @@ module LicenseScout
28
28
 
29
29
  # Inputs
30
30
  default :directories, [File.expand_path(Dir.pwd)]
31
+ default :include_subdirectories, false
31
32
  default :name, File.basename(directories.first)
32
33
  default :config_files, [File.join(File.expand_path(Dir.pwd), ".license_scout.yml")]
33
34
 
@@ -49,6 +50,7 @@ module LicenseScout
49
50
  default :nodejs, []
50
51
  default :perl, []
51
52
  default :ruby, []
53
+ default :rust, []
52
54
  end
53
55
 
54
56
  config_context :fallbacks do
@@ -60,6 +62,7 @@ module LicenseScout
60
62
  default :nodejs, []
61
63
  default :perl, []
62
64
  default :ruby, []
65
+ default :rust, []
63
66
  end
64
67
 
65
68
  config_context :habitat do
@@ -79,6 +82,23 @@ module LicenseScout
79
82
 
80
83
  class << self
81
84
 
85
+ def all_directories
86
+ if include_subdirectories
87
+ new_directories = []
88
+
89
+ directories.each do |old_directory|
90
+ new_directories << old_directory
91
+ Dir.chdir(old_directory) do
92
+ new_directories << Dir.glob("**/*").select { |f| File.directory?(f) }.map { |d| File.join(old_directory, d) }
93
+ end
94
+ end
95
+
96
+ new_directories.flatten.compact
97
+ else
98
+ directories
99
+ end
100
+ end
101
+
82
102
  def validate!
83
103
  if !allowed_licenses.empty? && !flagged_licenses.empty?
84
104
  raise LicenseScout::Exceptions::ConfigError.new("You may specify a list of licenses to allow or flag. You may not specify both.")
@@ -94,7 +94,7 @@ module LicenseScout
94
94
 
95
95
  # @return [Boolean] Whether or not this object is equal to another one. Used for Set uniqueness.
96
96
  def eql?(other)
97
- other.kind_of?(self.class) && other.hash == hash
97
+ other.is_a?(self.class) && other.hash == hash
98
98
  end
99
99
 
100
100
  # @return [Integer] A hashcode that can be used to idenitfy this object. Used for Set uniqueness.
@@ -19,6 +19,7 @@ require "license_scout/dependency_manager/base"
19
19
 
20
20
  require "license_scout/dependency_manager/berkshelf"
21
21
  require "license_scout/dependency_manager/bundler"
22
+ require "license_scout/dependency_manager/cargo"
22
23
  require "license_scout/dependency_manager/cpanm"
23
24
  require "license_scout/dependency_manager/dep"
24
25
  require "license_scout/dependency_manager/glide"
@@ -34,6 +35,7 @@ module LicenseScout
34
35
  [
35
36
  Berkshelf,
36
37
  Bundler,
38
+ Cargo,
37
39
  Cpanm,
38
40
  Dep,
39
41
  Glide,
@@ -0,0 +1,95 @@
1
+ #
2
+ # Copyright:: Copyright 2016, Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "license_scout/dependency_manager/base"
19
+
20
+ module LicenseScout
21
+ module DependencyManager
22
+ class Cargo < Base
23
+ def name
24
+ "rust_cargo"
25
+ end
26
+
27
+ def type
28
+ "rust"
29
+ end
30
+
31
+ def signature
32
+ "Cargo and Cargo.lock files"
33
+ end
34
+
35
+ def install_command
36
+ "cargo build"
37
+ end
38
+
39
+ def detected?
40
+ File.exist?(cargo_file_path) && File.exist?(cargo_lockfile_path)
41
+ end
42
+
43
+ def dependencies
44
+ dependency_data.map do |crate_data|
45
+ dep_name = crate_data["name"]
46
+ dep_version = crate_data["version"]
47
+ dep_license = crate_data["license"]
48
+
49
+ dependency = new_dependency(dep_name, dep_version, nil)
50
+ dependency.add_license(dep_license, "https://crates.io/crates/#{dep_name}/#{dep_version}")
51
+
52
+ dependency
53
+ end.compact
54
+ end
55
+
56
+ private
57
+
58
+ def dependency_data
59
+ Dir.chdir(directory) do
60
+ install_cargo_license_crate
61
+
62
+ s = Mixlib::ShellOut.new("cargo license -d -j")
63
+ s.run_command
64
+ s.error!
65
+
66
+ json_dep_data = s.stdout
67
+ FFI_Yajl::Parser.parse(json_dep_data)
68
+ end
69
+ end
70
+
71
+ def install_cargo_license_crate
72
+ # Attempt to install cargo-license
73
+ s = Mixlib::ShellOut.new("cargo install cargo-license")
74
+ s.run_command
75
+
76
+ # If cargo-license is already installed, it will return an error
77
+ # but we can ignore it
78
+ # Any other error, however, should halt the process and be returned
79
+ # to the user
80
+ if s.stderr != "" && s.stderr !~ /binary `cargo-license` already exists/
81
+ s.error!
82
+ end
83
+ end
84
+
85
+ def cargo_file_path
86
+ File.join(directory, "Cargo.toml")
87
+ end
88
+
89
+ def cargo_lockfile_path
90
+ File.join(directory, "Cargo.lock")
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -63,7 +63,7 @@ module LicenseScout
63
63
  end
64
64
 
65
65
  def gopath(pkg)
66
- "#{ENV['GOPATH']}/src/#{pkg}"
66
+ "#{ENV["GOPATH"]}/src/#{pkg}"
67
67
  end
68
68
 
69
69
  def vendor_dir(pkg = nil)
@@ -60,7 +60,7 @@ module LicenseScout
60
60
  end
61
61
 
62
62
  def gopath(pkg)
63
- "#{ENV['GOPATH']}/src/#{pkg}"
63
+ "#{ENV["GOPATH"]}/src/#{pkg}"
64
64
  end
65
65
  end
66
66
  end
@@ -64,7 +64,7 @@ module LicenseScout
64
64
  end
65
65
 
66
66
  def gopath(pkg)
67
- "#{ENV['GOPATH']}/src/#{pkg}"
67
+ "#{ENV["GOPATH"]}/src/#{pkg}"
68
68
  end
69
69
  end
70
70
  end
@@ -65,7 +65,7 @@ module LicenseScout
65
65
  (exception_reason.nil? ? "" : exception_reason),
66
66
  id,
67
67
  source,
68
- content
68
+ content,
69
69
  ]
70
70
  end
71
71
  end
@@ -126,7 +126,7 @@ module LicenseScout
126
126
 
127
127
  def raw_github_url(url)
128
128
  case url
129
- when /github.com\/(.+)\/blob\/(.+)/
129
+ when %r{github.com/(.+)/blob/(.+)}
130
130
  "https://raw.githubusercontent.com/#{$1}/#{$2}"
131
131
  else
132
132
  url
@@ -32,6 +32,7 @@ module LicenseScout
32
32
  def find(license_id, force = false)
33
33
  return license_id if force
34
34
  return nil if license_id.nil? || %w{ NOASSERTION NONE }.include?(license_id)
35
+
35
36
  lookup(license_id) || find_by_special_case(license_id) || closest(license_id) || license_id
36
37
  end
37
38
 
@@ -71,6 +72,7 @@ module LicenseScout
71
72
  def find_by_special_case(license_id)
72
73
  gpl = gpl_match(license_id)
73
74
  return gpl unless gpl.nil?
75
+
74
76
  lookup(special_cases[license_id.downcase])
75
77
  end
76
78
 
@@ -81,6 +83,7 @@ module LicenseScout
81
83
  def gpl_match(license_id)
82
84
  match = license_id.match(/^(l|a)?gpl-?\s?_?v?(1|2|3)\.?(\d)?(\+)?$/i)
83
85
  return unless match
86
+
84
87
  lookup("#{match[1]}GPL-#{match[2]}.#{match[3] || 0}#{match[4]}".upcase)
85
88
  end
86
89
 
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module LicenseScout
19
- VERSION = "2.2.0".freeze
19
+ VERSION = "2.4.0".freeze
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license_scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Duffield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi-yajl
@@ -162,6 +162,7 @@ files:
162
162
  - lib/license_scout/dependency_manager/base.rb
163
163
  - lib/license_scout/dependency_manager/berkshelf.rb
164
164
  - lib/license_scout/dependency_manager/bundler.rb
165
+ - lib/license_scout/dependency_manager/cargo.rb
165
166
  - lib/license_scout/dependency_manager/cpanm.rb
166
167
  - lib/license_scout/dependency_manager/dep.rb
167
168
  - lib/license_scout/dependency_manager/glide.rb
@@ -197,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
198
  - !ruby/object:Gem::Version
198
199
  version: '0'
199
200
  requirements: []
200
- rubygems_version: 3.0.1
201
+ rubygems_version: 3.0.3
201
202
  signing_key:
202
203
  specification_version: 4
203
204
  summary: Discovers license files of a project's dependencies.