Skip to content

Commit c49a041

Browse files
committed
Refactor License Scout
This is a major refactor of License Scout that modifies it's operating model to drive more configuration from external configuration managed by YAML files rather than by configuration stored within the gem itself. This allows teams to add exceptions, fallbacks, and other configuration based on their needs without requiring us to release a new version of the license_scout gem. Signed-off-by: Tom Duffield <[email protected]>
1 parent dbf7f01 commit c49a041

File tree

273 files changed

+25380
-8879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+25380
-8879
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
/tmp/
1111
/spec/examples.txt
1212
/license-cache/
13+
*-dependency-licenses.json

.rubocop.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AllCops:
2-
TargetRubyVersion: 2.2
3-
Excludes:
4-
- spec/fixtures/**/*
2+
Exclude:
3+
- 'bundle/**/*'
4+
- 'vendor/bundle/**/*'
5+
- 'spec/fixtures/**/*'

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.5.0

.travis.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
language: ruby
22
sudo: false
33

4+
cache: bundler
5+
46
# do not run expensive spec tests on PRs, only on branches
57
branches:
68
only:
79
- master
810

9-
before_install: gem install bundler
10-
rvm:
11-
- 2.2.6
11+
before_install:
12+
- source $HOME/otp/19.3/activate
13+
- erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell
14+
- gem install bundler

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM devchef/chefdk
1+
FROM chef/chefdk
22

33
COPY bin/ /usr/src/app/license_scout/bin/
44
COPY lib/ /usr/src/app/license_scout/lib/

README.md

+174-19
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,188 @@
1-
# license_scout
1+
# License Scout
22

3-
LicenseScout discovers and collects the licenses of a project and its
4-
dependencies, including transitive dependencies.
3+
License Scout is a utility that discovers and aggregates the licenses for your software project's transitive dependencies.
54

6-
Currently supported project types are:
5+
Currently supported Dependency Types and Dependency Managers are:
76

8-
* Chef - Berkshelf
9-
* Erlang - rebar
10-
* Golang - godeps
11-
* Javascript - npm
12-
* Perl - CPAN
13-
* Ruby - bundler
7+
Dependency Type | Supported Dependency Managers
8+
--- | ---
9+
chef_cookbook | berkshelf
10+
erlang | rebar
11+
elixir | mix
12+
golang | dep, godep, glide
13+
habitat | habitat
14+
nodejs | npm
15+
perl | cpan
16+
ruby | bundler
17+
18+
## Dependencies
19+
20+
* If you wish to scan for `berkshelf` dependencies, you'll need to manually install the Berkshelf gem in the same Ruby as License Scout
21+
* If you wish to scan for `mix` or `rebar` dependencies, you'll need to install Erlang OTP 18.3 or greater.
1422

1523
## Usage
1624

25+
License Scout's default behavior is to scan the current directory and return a breakdown of all the licenses it can find.
26+
1727
```bash
18-
$ bin/license_scout /dir/to/scout/successfully/
28+
my_project $ license_scout
29+
30+
+------+------------+------------+---------+
31+
| Type | Dependency | License(s) | Results |
32+
+------+------------+------------+---------+
33+
...
34+
```
35+
36+
LicenseScout will exit `0` if it was able to find licenses for all your dependencies. Otherwise, it will exit `1`.
37+
38+
Under the covers, License Scout leverages [Licensee](http://ben.balter.com/licensee/) (the same Ruby Gem [GitHub](https://developer.github.com/v3/licenses/) uses to detect [OSS licenses](https://spdx.org/licenses/)). In addition to using Licensee to scan your source code for licenses, License Scout will go a step further and attempt to determine if the metadata provided by the Dependency Manager specifies which license each dependency uses. At the end of the process, License Scout will provide you a Dependency Manifest following information:
39+
40+
1. The name of the license(s) (the SPDX ID if the a recognized open source license).
41+
2. The name of the file where the License Scout found the license.
42+
3. The contents of the license file (if available).
43+
44+
In addition to the printout provided to STDOUT, License Scout will also save a JSON manifest of all your dependencies to disk.
45+
46+
```json
47+
{
48+
"license_manifest_version": 2,
49+
"generated_on": "<DATE>",
50+
"name": "<YOUR_PROJECT>",
51+
"dependencies": [...]
52+
}
53+
```
54+
55+
For more information about the structure of JSON manifest, please check out the full [JSON Schema](lib/license_scout/data/dependency_manifest_v2_schema.json).
56+
57+
### Result Types
58+
59+
License Scout will provide a summary of the licenses it finds to STDOUT. These results are intended to provide direction as to which actions may or may not be necessary to generate a Dependency Manifest that meets all of your compliance requirements. To do this it categorizes its findings into the following results.
60+
61+
Result | Description
62+
--- | ---
63+
Flagged | License Scout was able to determine the license for this software dependency, and it is one of the licenses you have explicitly flagged. You should either remove the dependency or [add an Exception](#dependency-exceptions).
64+
Missing | License Scout could not find any license files or license metadata associated with this dependency. You should contact the maintainer and/or specify a [Fallback License](#fallback-licenses).
65+
Unpermitted | License Scout was able to determine the license for this software dependency, but it is not one of the licenses you have explicitly allowed. You should either remove the dependency or [add an Exception](#dependency-exceptions).
66+
OK | There were no issues.
67+
Undetermined | License Scout found a license file but was unable to determine (with sufficient confidence) what license that file represents. License Scout was also unable to determine the license using Dependency Manager metadata. You should contact the maintainer and/or specify a [Fallback License](#fallback-licenses).
68+
69+
## Advanced Usage
70+
71+
### Configuration File(s)
72+
73+
You can control License Scout's behavior by providing one or more YAML configuration files, available either locally or via HTTP, to the `--config-files` option of the CLI.
74+
75+
```bash
76+
$ license_scout --config-files http://example.com/license_scout/common.yml,./.license_scout.yml
77+
```
78+
79+
License Scout evalutes these files in the order they are provided, allowing you to hydrate configuration by composing multiple files together. For example, you can have a single organization-wide configuration file that specifies what licenses are allowed and project-specific configuration file that specifies exceptions and which directories to scan.
80+
81+
#### How multiple configuration files are handled
82+
83+
License Scout uses [mixlib-config](https://github.com/chef/mixlib-config) to handle it's configuration. When loading multiple configuration files, mixlib-config (and thus License Scout) will not perform deep merges of Arrays. That means that License Scout will not merge (for example) `allowed_licenses` (or `flagged_licenses`) from two different configuration files; it will only take the `allowed_licenses` value from the configuration that is loaded last. This logic does not apply to the `fallbacks` or `exceptions`, because those are defined as [`config_contexts`](lib/license_scout/config.rb). It **does** apply to the individuals types specified within the `fallbacks` or `exceptions` however.
84+
85+
### Allowed and Flagged Licenses
1986

20-
$ bin/license_scout /dir/to/scout/unsuccessfully/
21-
Dependency 'gopkg.in_yaml.v2' version '53feefa2559fb8dfa8d81baad31be332c97d6c77' under 'go_godep' is missing license information.
22-
>> Found 41 dependencies for go_godep. 40 OK, 1 with problems
87+
License Scout provides you with the ability to provide a list of licenses that are explicitly allowed, or a list of licenses that should be flagged for further scrutiny.
88+
89+
- When you specify a list of `allowed_licenses`, License Scout will exit `1` if it detects a dependency with a license other than one on the list.
90+
- When you specify a list of `flagged_licenses`, License Scout will exit `1` if it finds a dependency with that license.
91+
92+
To add a license to the list of allowed or flagged licenses, you need only provide the array of licenses as a string in your configuration file. A configuration may have a list of allowed licenses _or_ flagged licenses, it cannot have both. _License Scout does not support regular expressions or glob-patterms for `allowed_licenses` or `flagged_licenses`._
93+
94+
```yaml
95+
allowed_licenses:
96+
- Apache-2.0
97+
98+
# OR
99+
100+
flagged_licenses:
101+
- Apache-2.0
23102
```
24103
25-
Detailed instructions for fixing licensing failures found by license_scout are now provided in the script's output. See [bin/license_scout](bin/license_scout) for more details.
104+
License Scout will compare these string values to the licenses it finds within the dependencies. License Scout does its best to resolve everything down to valid [SPDX IDs](https://spdx.org/licenses/), so you should specify licenses using their SDPX ID.
105+
106+
> _Warning: Because we cannot control how maintainers specify licenses in their metadata, there may be a situation where License Scout cannot correctly detect the intended SPDX ID. In this case, you may need to temporarily provide a temporary Fallback License in your configuration. If you encounter this situation, we encourage you to [open an Issue](https://github.com/chef/license_scout) with us._
107+
108+
### Dependency Exceptions
109+
110+
If you specify a list of allowed or flagged licenses, there may be a dependency that does not adhere to the specified license(s) for which you wish to make an exception. License Scout allows you to specify Exceptions to these lsits as part of your Configuration File.
111+
112+
```yaml
113+
---
114+
allowed_licenses:
115+
- Apache-2.0
116+
117+
exceptions:
118+
ruby:
119+
- name: bundler
120+
reason: Used only during .gem creation
121+
- name: json (1.8.3)
122+
```
123+
124+
Exceptions are organized by `type` (e.g. `ruby` - see Table above). There are two elements to each exception: a `name` and a `reason`.
125+
126+
Property | Description
127+
--- | ---
128+
`name` | Can be specified by `dep-name` or `dep-name (dep-version)` where `dep-name` is the name of the dependency as it exists in the Dependency Manifest and `dep-version` can be a traditional version, git reference, or type-specific version specification such as `$pkg_version-$pkg_release` for Habitat.
129+
`reason` | An optional string that will be included in the Dependency Manifest for documentation purposes.
130+
131+
Simple glob-style pattern matching _is_ supported for Exceptions, so you can have an Exception for a large collection of dependencies without enumerating them all.
132+
133+
```yaml
134+
---
135+
exceptions:
136+
chef_cookbook:
137+
- name: apache2 (5.*)
138+
reason: Allowed by TICKET-001
139+
habitat:
140+
- name: core/bundler (1.15.1-*)
141+
reason: Only used for .gem creation
142+
ruby:
143+
- name: aws-sdk-*
144+
reason: Exception granted by Bobo T. Clown on 2018/02/31
145+
```
146+
147+
### Fallback Licenses
148+
149+
In situations where License Scout is unable to determine the license for a particular dependency, either because Licensee was not able to identify any of the license files or the Dependency Manager did not provide any metadata that incidated how the dependency was licensed, you'll need to provide a Fallback License in your configuration. Like Exceptions, Fallback Licenses are grouped by `type`.
150+
151+
```yaml
152+
fallbacks:
153+
golang:
154+
- name: github.com/dchest/siphash
155+
license_id: CC0-1.0
156+
license_content: https://raw.githubusercontent.com/dchest/siphash/master/README.md
157+
```
158+
159+
Property | Description
160+
--- | ---
161+
name | The name of the dependency as it appears in the JSON manifest.
162+
license_id | The ID of the license as it appears in the JSON manifest.
163+
license_content | A URL to a file where the raw text of the license can be downloaded.
164+
165+
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.
166+
167+
## Configuration
168+
169+
Value | Description | Default
170+
--- | --- | ---
171+
directories | The fully-qualified local paths to the directories you wish to scan | _The current working directory._ |
172+
name | The name you want to give to the scan result. | _The basename of the first directory to be scanned._ |
173+
output_directory | The path to the directory where the output JSON file should be saved. | _The current working directory._ |
174+
log_level | What log information should be included in STDOUT | `info` |
175+
allowed_licenses | Only allow dependencies to have these licenses. | `[]` |
176+
flagged_licenses | An array of licenses that should be flagged for removal or exception. | `[]` |
177+
exceptions | An array of Exceptions. | `[]` |
178+
environment | A hash of additional Environment Variables to pass to [mixlib-shellout](https://github.com/chef/mixlib-shellout) | `{}` |
179+
escript_bin | The path to the `escript` binary you wish to use when shelling out to Erlang. | `escript` |
180+
ruby_bin | The path to the `ruby` binary you wish to use when shelling out to Ruby. | `ruby` |
181+
cpanm_root | The path to where the cpanminus install cache is located. | `~/.cpanm` |
26182

27183
## Contributing
28184

29-
This project is maintained by the contribution guidelines identified for
30-
[chef](https://github.com/chef/chef) project. You can find the guidelines here:
185+
This project is maintained by the contribution guidelines identified for [chef](https://github.com/chef/chef) project. You can find the guidelines here:
31186

32187
https://github.com/chef/chef/blob/master/CONTRIBUTING.md
33188

@@ -36,5 +191,5 @@ Pull requests in this project are merged when they have two :+1:s from maintaine
36191
## Maintainers
37192

38193
- [Dan DeLeo](https://github.com/danielsdeleo)
39-
- [Serdar Sutay](https://github.com/sersut)
40-
- [Ryan Cragun](https://github.com/ryancragun)
194+
- [Tom Duffield](https://github.com/tduffield)
195+

Rakefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
require "bundler/gem_tasks"
1919
require "rspec/core/rake_task"
20+
require "open-uri"
2021

2122
task default: :test
2223

@@ -36,4 +37,10 @@ rescue LoadError
3637
end
3738

3839
desc "Run all tests"
39-
task test: [:spec]
40+
task test: [:spec, :style]
41+
42+
desc "Refresh the SPDX JSON database"
43+
task :spdx do
44+
IO.copy_stream(open("https://spdx.org/licenses/licenses.json"), File.expand_path("./lib/license_scout/data/licenses.json"))
45+
IO.copy_stream(open("https://spdx.org/licenses/exceptions.json"), File.expand_path("./lib/license_scout/data/exceptions.json"))
46+
end

appveyor.yml

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
os: Windows Server 2012 R2
1+
os: Visual Studio 2017
22
platform:
33
- x64
44

@@ -7,13 +7,29 @@ branches:
77
only:
88
- master
99

10+
cache:
11+
- bundle
12+
13+
environment:
14+
matrix:
15+
- ruby_version: "25-x64"
16+
1017
install:
11-
- set PATH=C:\Ruby22\bin;%PATH%
18+
- systeminfo
19+
- winrm quickconfig -q
20+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
21+
- echo %PATH%
1222
- appveyor DownloadFile http://curl.haxx.se/ca/cacert.pem -FileName C:\cacert.pem
1323
- set SSL_CERT_FILE=C:\cacert.pem
14-
15-
build_script:
1624
- bundle install || bundle install || bundle install
1725

26+
build: off
27+
28+
before_test:
29+
- ruby --version
30+
- gem --version
31+
- bundler --version
32+
- bundle env
33+
1834
test_script:
19-
- bundle exec rake spec
35+
- bundle exec rake

bin/license_scout

+2-58
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,6 @@
1818

1919
$:.unshift File.expand_path("../../lib", __FILE__)
2020

21-
require "license_scout/collector"
22-
require "license_scout/overrides"
23-
require "license_scout/options"
21+
require "license_scout"
2422

25-
project_dir = ARGV[0] || File.expand_path(Dir.pwd)
26-
project_name = File.basename(project_dir)
27-
28-
# Create the output files under a specific directory in order not to pollute the
29-
# project_dir too much.
30-
output_dir = File.join(project_dir, "license-cache")
31-
32-
overrides = LicenseScout::Overrides.new
33-
34-
opts = LicenseScout::Options.new(overrides: overrides)
35-
36-
collector = LicenseScout::Collector.new(project_name, project_dir, output_dir, opts)
37-
38-
collector.run
39-
report = collector.issue_report
40-
41-
unless report.empty?
42-
puts report
43-
44-
puts <<-EXPLANATION
45-
46-
How to fix this depends on what information license_scout was unable to
47-
determine:
48-
49-
* If the package is missing license information, that means license_scout was
50-
unable to determine which license the package was released under. Depending
51-
on the package manager, this is usually specified in the package's metadata,
52-
for example, in the gemspec file for rubygems or in the package.json for npm.
53-
If you know which license a package was released under, MIT for example, you
54-
can add an override in license_scout's overrides.rb file in the section for
55-
the appropriate package manager like this:
56-
["package-name", "MIT", nil]
57-
58-
* If the package is missing the license file, that means license_scout could not
59-
find the license text in any of the places the license is typically found, for
60-
example, in a file named LICENSE in the root of the package. If the package
61-
includes the license text in a non standard location or in its source repo,
62-
you can indicate this by adding an override in license_scout's overrides.rb
63-
file in the section for the appropriate package manager like this:
64-
["package-name", nil, ["https://example.com/foocorp/package-name/master/LICENSE"]],
65-
66-
If you know that the package was released under one of the common software
67-
licenses, MIT for example, but does not include the license text in packaged
68-
releases or in its source repo, you can add an override in license_scout's
69-
overrides.rb file in the section for the appropriate package manager like
70-
this:
71-
["package-name", nil, [canonical("MIT")]]
72-
73-
See the closed pull requests on the license_scout repo for examples of how to
74-
do this:
75-
https://github.com/chef/license_scout/pulls?q=is%3Apr+is%3Aclosed
76-
EXPLANATION
77-
78-
exit 2
79-
end
23+
LicenseScout::CLI.new.run

bin/mix_lock_json

972 KB
Binary file not shown.

bin/rebar_lock_json

15.1 KB
Binary file not shown.

lib/license_scout.rb

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717

1818
module LicenseScout
1919
end
20+
21+
require "license_scout/cli"

0 commit comments

Comments
 (0)