licensed 2.15.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +55 -11
  3. data/CHANGELOG.md +56 -1
  4. data/README.md +38 -81
  5. data/docs/adding_a_new_source.md +11 -8
  6. data/docs/commands/README.md +59 -0
  7. data/docs/commands/cache.md +35 -0
  8. data/docs/commands/env.md +10 -0
  9. data/docs/commands/list.md +23 -0
  10. data/docs/commands/migrate.md +10 -0
  11. data/docs/commands/notices.md +12 -0
  12. data/docs/commands/status.md +73 -0
  13. data/docs/commands/version.md +3 -0
  14. data/docs/configuration.md +9 -161
  15. data/docs/configuration/README.md +11 -0
  16. data/docs/configuration/allowed_licenses.md +17 -0
  17. data/docs/configuration/application_name.md +63 -0
  18. data/docs/configuration/application_source.md +64 -0
  19. data/docs/configuration/configuration_root.md +27 -0
  20. data/docs/configuration/configuring_multiple_apps.md +58 -0
  21. data/docs/configuration/dependency_source_enumerators.md +28 -0
  22. data/docs/configuration/ignoring_dependencies.md +19 -0
  23. data/docs/configuration/metadata_cache.md +106 -0
  24. data/docs/configuration/reviewing_dependencies.md +18 -0
  25. data/docs/{migrating_to_newer_versions.md → migrations/v2.md} +1 -1
  26. data/docs/migrations/v3.md +109 -0
  27. data/docs/sources/bundler.md +1 -11
  28. data/docs/sources/swift.md +4 -0
  29. data/lib/licensed.rb +1 -0
  30. data/lib/licensed/cli.rb +6 -3
  31. data/lib/licensed/commands/cache.rb +19 -20
  32. data/lib/licensed/commands/command.rb +104 -72
  33. data/lib/licensed/commands/environment.rb +12 -11
  34. data/lib/licensed/commands/list.rb +0 -19
  35. data/lib/licensed/commands/notices.rb +0 -19
  36. data/lib/licensed/commands/status.rb +13 -15
  37. data/lib/licensed/configuration.rb +105 -12
  38. data/lib/licensed/report.rb +44 -0
  39. data/lib/licensed/reporters/cache_reporter.rb +48 -64
  40. data/lib/licensed/reporters/json_reporter.rb +19 -21
  41. data/lib/licensed/reporters/list_reporter.rb +45 -58
  42. data/lib/licensed/reporters/notices_reporter.rb +33 -46
  43. data/lib/licensed/reporters/reporter.rb +37 -104
  44. data/lib/licensed/reporters/status_reporter.rb +58 -56
  45. data/lib/licensed/reporters/yaml_reporter.rb +19 -21
  46. data/lib/licensed/sources.rb +1 -0
  47. data/lib/licensed/sources/bundler.rb +36 -217
  48. data/lib/licensed/sources/bundler/missing_specification.rb +54 -0
  49. data/lib/licensed/sources/go.rb +1 -1
  50. data/lib/licensed/sources/gradle.rb +2 -2
  51. data/lib/licensed/sources/npm.rb +4 -3
  52. data/lib/licensed/sources/nuget.rb +57 -27
  53. data/lib/licensed/sources/swift.rb +69 -0
  54. data/lib/licensed/version.rb +1 -1
  55. data/script/source-setup/go +1 -1
  56. data/script/source-setup/swift +22 -0
  57. metadata +27 -4
  58. data/docs/commands.md +0 -95
@@ -0,0 +1,59 @@
1
+ # Commands
2
+
3
+ Run `licensed -h` to see help content for running licensed commands.
4
+
5
+ - [cache](cache.md)
6
+ - [env](env.md)
7
+ - [list](list.md)
8
+ - [migrate](migrate.md)
9
+ - [notices](notices.md)
10
+ - [status](status.md)
11
+ - [version](verison.md)
12
+
13
+ Most commands accept a `-c`/`--config` option to specify a path to a configuration file or directory. If a directory is specified, `licensed` will look in that directory for a file named (in order of preference):
14
+
15
+ 1. `.licensed.yml`
16
+ 2. `.licensed.yaml`
17
+ 3. `.licensed.json`
18
+
19
+ If the option is not specified, the value will be set to the current directory.
20
+
21
+ ## Adding a new command
22
+
23
+ ### Implement new `Command` class
24
+
25
+ Licensed commands inherit and override the [`Licensed::Sources::Command`](../lib/licensed/commands/command.rb) class.
26
+
27
+ ### Required method overrides
28
+
29
+ 1. `Licensed::Commands::Command#evaluate_dependency`
30
+ - Runs a command execution on an application dependency.
31
+
32
+ The `evaluate_dependency` method should contain the specific command logic. This method has access to the application configuration, dependency source enumerator and dependency currently being evaluated as well as a reporting hash to contain information about the command execution.
33
+
34
+ ### Optional method overrides
35
+
36
+ The following methods break apart the different levels of command execution. Each method wraps lower levels of command execution in a corresponding reporter method.
37
+
38
+ 1. `Licensed::Commands::Command#run`
39
+ - Runs `run_app` for each application configuration found. Wraps the execution of all applications in `Reporter#report_run`.
40
+ 2. `Licensed::Commands::Command#run_app`
41
+ - Runs `run_source` for each dependency source enumerator enabled for the application configuration. Wraps the execution of all sources in `Reporter#report_app`.
42
+ 3. `Licensed::Commands::Command#run_source`
43
+ - Runs `run_dependency` for each dependency found in the source. Wraps the execution of all dependencies in `Reporter#report_source`.
44
+ 4. `Licensed::Commands::Command#run_dependency`
45
+ - Runs `evaluate_dependency` for the dependency. Wraps the execution of all dependencies in `Reporter#report_dependency`.
46
+
47
+ As an example, `Licensed::Commands::Command#run_app` calls `Reporter#report_app` to wrap every call to `Licensed::Commands::Command#run_source`.
48
+
49
+ ### Specifying additional report data
50
+
51
+ The `run` methods can be overridden and pass a block to `super` to provide additional reporting data or functionality.
52
+
53
+ ```ruby
54
+ def run_app(app)
55
+ super do |report|
56
+ report["my_app_data"] = true
57
+ end
58
+ end
59
+ ```
@@ -0,0 +1,35 @@
1
+ # `licensed cache`
2
+
3
+ The cache command finds all dependencies and ensures that each dependency has an up-to-date cached record.
4
+
5
+ Dependency records will be saved if:
6
+
7
+ 1. The `force` option is set
8
+ 2. No cached record is found
9
+ 3. The cached record's version is different than the current dependency's version
10
+ - If the cached record's license text contents matches the current dependency's license text then the `license` metadata from the cached record is retained for the new saved record.
11
+
12
+ After the cache command is run, any cached records that don't match up to a current application dependency will be deleted.
13
+
14
+ ## Options
15
+
16
+ - `--config`/`-c`: the path to the licensed configuration file
17
+ - default value: `./.licensed.yml`
18
+ - `--sources`/`-s`: runtime filter on which dependency sources are run. Sources must also be enabled in the licensed configuration file.
19
+ - default value: not set, all configured sources
20
+ - `--format`/`-f`: the output format
21
+ - default value: `yaml`
22
+ - `--force`: if set, forces all dependency metadata files to be recached
23
+ - default value: not set
24
+
25
+ ## Reported Data
26
+
27
+ The following data is reported for each dependency when the YAML or JSON report formats are used
28
+
29
+ - name: the licensed recognized name for the dependency including the app and source name
30
+ - e.g. the full name for the `thor` bundler dependency used by this tool is `licensed.bundler.thor`
31
+ - cached: true when the dependency's cached metadata file was updated, false otherwise
32
+ - version: the version of the enumerated dependency
33
+ - license: the dependency's SPDX license identifier
34
+ - filename: the full path on disk to the dependency's cached metadata file, if available
35
+ - warnings: any warning messages encountered while enumerating and caching dependency metadata, if available
@@ -0,0 +1,10 @@
1
+ # `licensed env`
2
+
3
+ Prints the runtime environment used by licensed after loading a configuration file. This can be different from the configuration file inputs, for example all paths will be given as absolute file paths and glob paths may be expanded.
4
+
5
+ ## Options
6
+
7
+ - `--config`/`-c`: the path to the licensed configuration file
8
+ - default value: `./.licensed.yml`
9
+ - `--format`/`-f`: the output format
10
+ - default value: `yaml`
@@ -0,0 +1,23 @@
1
+ # `licensed list`
2
+
3
+ The list command finds and prints the dependencies for all sources in all configured applications. No additional actions are taken on dependencies.
4
+
5
+ ## Options
6
+
7
+ - `--config`/`-c`: the path to the licensed configuration file
8
+ - default value: `./.licensed.yml`
9
+ - `--sources`/`-s`: runtime filter on which dependency sources are run. Sources must also be enabled in the licensed configuration file.
10
+ - default value: not set, all configured sources
11
+ - `--format`/`-f`: the output format
12
+ - default value: `yaml`
13
+ - `--licenses`/`-l`: if set, includes each dependency's detected license in the output
14
+ - default value: not set
15
+
16
+ ### Reported Data
17
+
18
+ The following data is reported for each dependency when the YAML or JSON report formats are used
19
+
20
+ - name: the licensed recognized name for the dependency including the app and source name
21
+ - e.g. the full name for the `thor` bundler dependency used by this tool is `licensed.bundler.thor`
22
+ - version: the version of the enumerated dependency
23
+ - license: (optional) the dependency's SPDX license identifier
@@ -0,0 +1,10 @@
1
+ # `licensed migrate`
2
+
3
+ Migrates the licensed configuration and cached metadata files from a previous version to the most recent version. This is not required for all major version updates. See [migrations documentation](../migrations) for details on the migrations needed for each major version.
4
+
5
+ ## Options
6
+
7
+ - `--config`/`-c`: the path to the licensed configuration file
8
+ - default value: `./.licensed.yml`
9
+ - `--from`/`-f`: the licensed version to migrate from
10
+ - required
@@ -0,0 +1,12 @@
1
+ # `licensed notices`
2
+
3
+ Outputs license and notice text for all dependencies in each app into a `NOTICE` file in the app's `cache_path`. If an app uses a shared cache path, the file name will contain the app name as well, e.g. `NOTICE.my_app`.
4
+
5
+ `NOTICE` file contents are retrieved from cached records, with the assumption that cached records have already been reviewed in a compliance workflow.
6
+
7
+ ## Options
8
+
9
+ - `--config`/`-c`: the path to the licensed configuration file
10
+ - default value: `./.licensed.yml`
11
+ - `--sources`/`-s`: runtime filter on which dependency sources are run. Sources must also be enabled in the licensed configuration file.
12
+ - default value: not set, all configured sources
@@ -0,0 +1,73 @@
1
+ # `licensed status`
2
+
3
+ The status command finds all dependencies and checks whether each dependency has a valid cached record.
4
+
5
+ A dependency will fail the status checks if:
6
+
7
+ 1. No cached record is found
8
+ 2. The cached record's version is different than the current dependency's version
9
+ 3. The cached record's `licenses` data is empty
10
+ 4. The cached record's `license` metadata doesn't match an `allowed` license from the dependency's application configuration.
11
+ - If `license: other` is specified and all of the `licenses` entries match an `allowed` license a failure will not be logged
12
+ 5. The cached record is flagged for re-review.
13
+ - This occurs when the record's license text has changed since the record was reviewed.
14
+
15
+ ## Options
16
+
17
+ - `--config`/`-c`: the path to the licensed configuration file
18
+ - default value: `./.licensed.yml`
19
+ - `--sources`/`-s`: runtime filter on which dependency sources are run. Sources must also be enabled in the licensed configuration file.
20
+ - default value: not set, all configured sources
21
+ - `--format`/`-f`: the output format
22
+ - default value: `yaml`
23
+ - `--force`: if set, forces all dependency metadata files to be recached
24
+ - default value: not set
25
+
26
+ ## Reported Data
27
+
28
+ The following data is reported for each dependency when the YAML or JSON report formats are used
29
+
30
+ - name: the licensed recognized name for the dependency including the app and source name
31
+ - e.g. the full name for the `thor` bundler dependency used by this tool is `licensed.bundler.thor`
32
+ - allowed: true if the dependency has passed all checks, false otherwise
33
+ - version: the version of the enumerated dependency
34
+ - license: the dependency's SPDX license identifier
35
+ - filename: the full path on disk to the dependency's cached metadata file, if available
36
+ - errors: any error messages from failed status checks, if available
37
+
38
+ ## Status errors and resolutions
39
+
40
+ ### cached dependency record not found
41
+
42
+ **Cause:** A dependency was found while running `licensed status` that does not have a corresponding cached metadata file
43
+ **Resolution:** Run `licensed cache` to update the metadata cache and create the missing metadata file
44
+
45
+ ### cached dependency record out of date
46
+
47
+ **Cause:** A dependency was found while running `licensed status` with a different version than is contained in the dependency's cached metadata file
48
+ **Resolution:** Run `licensed cache` to update the out-of-date metadata files
49
+
50
+ ### missing license text
51
+
52
+ **Cause:** A license determination was made, e.g. from package metadata, but no license text was found.
53
+ **Resolution:** Manually verify whether the dependency includes a file containing license text. If the dependency code that was downloaded locally does not contain the license text, please check the dependency source at the version listed in the dependency's cached metadata file to see if there is license text that can be used.
54
+
55
+ If the dependency does not include license text but does specify that it uses a specific license, please copy the standard license text from a [well known source](https://opensource.org/licenses).
56
+
57
+ ### license text has changed and needs re-review. if the new text is ok, remove the `review_changed_license` flag from the cached record
58
+
59
+ **Cause:** A dependency that is set as [reviewed] in the licensed configuration file has substantially changed and should be re-reviewed.
60
+ **Resolution:** Review the changes to the license text and classification, along with other metadata contained in the cached file for the dependency. If the dependency is still allowable for use in your project, remove the `review_changed_license` key from the cached record file.
61
+
62
+ ### license needs review
63
+
64
+ **Cause:** A dependency is using a license that is not in the configured [allowed list of licenses][allowed], and the dependency has not been marked [ignored] or [reviewed].
65
+ **Resolution:** Review the dependency's usage and specified license with someone familiar with OSS licensing and compliance rules to determine whether the dependency is allowable. Some common resolutions:
66
+
67
+ 1. The dependency's specified license text differed enough from the standard license text that it was not recognized and classified as `other`. If, with human review, the license text is recognizable then update the `license: other` value in the cached metadata file to the correct license.
68
+ 1. The dependency might need to be marked as [ignored] or [reviewed] if either of those scenarios are applicable.
69
+ 1. If the used license should be allowable without review (if your entity has a legal team, they may want to review this assessment), ensure the license SPDX is set as [allowed] in the licensed configuration file.
70
+
71
+ [allowed]: ../configuration/allowed_licenses.md
72
+ [ignored]: ../configuration/ignoring_dependencies.md
73
+ [reviewed]: ../configuration/reviewing_dependencies.md
@@ -0,0 +1,3 @@
1
+ # `licensed version`
2
+
3
+ Displays the current licensed version. Can also be run with `licensed -v` and `licensed --version`.
@@ -2,75 +2,12 @@
2
2
 
3
3
  A configuration file specifies the details of enumerating and operating on license metadata for apps.
4
4
 
5
- Configuration can be specified in either YML or JSON formats. Examples below are given in YML.
5
+ Configuration can be specified in either YML or JSON formats, with examples given in YML. The example
6
+ below describes common configuration values and their purposes. See [configuration options documentation](./configuration)
7
+ for in depth information.
6
8
 
7
- ## Configuration Paths
8
-
9
- `licensed` requires a path to enumerate dependencies at (`source_path`) and a path to store cached metadata (`cache_path`).
10
-
11
- To determine these paths across multiple environments where absolute paths will differ, a known root path is needed to evaluate relative paths against.
12
- In using a root, relative source and cache paths can be specified in the configuration file.
13
-
14
- When using a configuration file, the root property can be set as either a path that can be expanded from the configuration file directory using `File.expand_path`, or the value `true` to use the configuration file directory as the root.
15
-
16
- When creating a `Licensed::Dependency` manually with a `root` property, the property must be an absolute path - no path expansion will occur.
17
-
18
- If a root path is not specified, it will default to using the following, in order of precedence
19
- 1. the root of the local git repository, if run inside a git repository
20
- 2. the current directory
21
-
22
- ### Source path glob patterns
23
-
24
- The `source_path` property can use a glob path to share configuration properties across multiple application entrypoints.
25
-
26
- For example, there is a common pattern in Go projects to include multiple executable entrypoints under folders in `cmd`. Using a glob pattern allows users to avoid manually configuring and maintaining multiple licensed application `source_path`s. Using a glob pattern will also ensure that any new entrypoints matching the pattern are automatically picked up by licensed commands as they are added.
27
-
28
- ```yml
29
- sources:
30
- go: true
31
-
32
- # treat all directories under `cmd` as separate apps
33
- source_path: cmd/*
34
- ```
35
-
36
- Glob patterns are syntactic sugar for, and provide the same functionality as, manually specifying multiple `source_path` values. See the instructions on [specifying multiple apps](./#specifying-multiple-apps) below for additional considerations when using multiple apps.
37
-
38
- ## Restricting sources
39
-
40
- The `sources` configuration property specifies which sources `licensed` will use to enumerate dependencies.
41
- By default, `licensed` will generally try to enumerate dependencies from all sources. As a result,
42
- the configuration property should be used to explicitly disable sources rather than to enable a particular source.
43
-
44
- Be aware that this configuration is separate from an individual sources `#enabled?` method, which determines
45
- whether the source is valid for the current project. Even if a source is enabled in the configuration
46
- it may still determine that it can't enumerate dependencies for a project.
9
+ Additionally, some dependency sources have their own specific configuration options. See the [source documentation](./sources) for details.
47
10
 
48
- ```yml
49
- sources:
50
- bower: true
51
- bundler: false
52
- ```
53
-
54
- `licensed` determines which sources will try to enumerate dependencies based on the following rules:
55
- 1. If no sources are configured, all sources are enabled
56
- 2. If no sources are set to true, any unconfigured sources are enabled
57
- ```yml
58
- sources:
59
- bower: false
60
- # all other sources are enabled by default since there are no sources set to true
61
- ```
62
- 3. If any sources are set to true, any unconfigured sources are disabled
63
- ```yml
64
- sources:
65
- bower: true
66
- # all other sources are disabled by default because a source was set to true
67
- ```
68
-
69
- ## Applications
70
-
71
- What is an "app"? In the context of `licensed`, an app is a combination of a source path and a cache path.
72
-
73
- Configuration can be set up for single or multiple applications in the same repo. There are a number of settings available for each app:
74
11
  ```yml
75
12
  # If not set, defaults to the directory name of `source_path`
76
13
  name: 'My application'
@@ -129,100 +66,11 @@ reviewed:
129
66
  bower:
130
67
  - classlist # public domain
131
68
  - octicons
132
- ```
133
-
134
- ### Specifying a single app
135
- To specify a single app, either include a single app with `source_path` in the `apps` configuration, or remove the `apps` setting entirely.
136
-
137
- If the configuration does not contain an `apps` value, the root configuration will be used as an app definition. In this scenario, the `source_path` is not a required value and will default to the directory that `licensed` was executed from.
138
-
139
- If the configuration contains an `apps` value with a single app configuration, `source_path` must be specified. Additionally, the applications inherited `cache_path` value will contain the application name. See [Inherited cache_path values](#inherited_cache_path_values)
140
-
141
- ### Specifying multiple apps
142
- The configuration file can specify multiple source paths to enumerate metadata, each with their own configuration.
143
-
144
- Nearly all configuration settings can be inherited from root configuration to app configuration. Only `source_path` is required to define an app.
145
69
 
146
- Here are some examples:
147
-
148
- #### Inheriting configuration
149
- ```yml
150
- sources:
151
- go: true
152
- bundler: false
153
-
154
- ignored:
155
- bundler:
156
- - some-internal-gem
157
-
158
- reviewed:
159
- bundler:
160
- - bcrypt-ruby
161
-
162
- cache_path: 'path/to/cache'
163
- apps:
164
- - source_path: 'path/to/app1'
165
- - source_path: 'path/to/app2'
166
- sources:
167
- bundler: true
168
- go: false
169
- ```
170
-
171
- In this example, two apps have been declared. The first app, with `source_path` `path/to/app1`, inherits all configuration settings from the root configuration. The second app, with `source_path` `path/to/app2`, overrides the `sources` configuration and inherits all other settings.
172
-
173
- #### Default app names
174
- An app will not inherit a name set from the root configuration. If not provided, the `name` value will default to the directory name from `source_path`.
175
- ```yml
70
+ # A single configuration file can be used to enumerate dependencies for multiple
71
+ # projects. Each configuration is referred to as an "application" and must include
72
+ # a source path, at a minimum
176
73
  apps:
177
- - source_path: 'path/to/app1'
178
- - source_path: 'path/to/app2'
74
+ - source_path: path/to/application1
75
+ - source_path: path/to/application2
179
76
  ```
180
-
181
- In this example, the apps have names of `app1` and `app2`, respectively.
182
-
183
- #### Inherited cache_path values
184
- When an app inherits a `cache_path` from the root configuration, it will automatically append it's name to the end of the path to separate it's metadata from other apps. To force multiple apps to use the same path to cached metadata, explicitly set the `cache_path` value for each app.
185
- ```yml
186
- cache_path: 'path/to/cache'
187
- apps:
188
- - source_path: 'path/to/app1'
189
- name: 'app1'
190
- - source_path: 'path/to/app2'
191
- name: 'app2'
192
- - source_path: 'path/to/app3'
193
- name: 'app3'
194
- cache_path: 'path/to/app3/cache'
195
- ```
196
-
197
- In this example `app1` and `app2` have `cache_path` values of `path/to/cache/app1` and `path/to/cache/app2`, respectively. `app3` has an explicit path set to `path/to/app3/cache`
198
-
199
- ```yml
200
- apps:
201
- - source_path: 'path/to/app1'
202
- ```
203
-
204
- In this example, the root configuration will contain a default cache path of `.licenses`. `app1` will inherit this value and append it's name, resulting in a cache path of `.licenses/app1`.
205
-
206
- ### Sharing caches between apps
207
-
208
- Dependency caches can be shared between apps by setting the same cache path on each app.
209
-
210
- ```yaml
211
- apps:
212
- - source_path: "path/to/app1"
213
- cache_path: ".licenses/apps"
214
- - source_path: "path/to/app2"
215
- cache_path: ".licenses/apps"
216
- ```
217
-
218
- When using a source path with a glob pattern, the apps created from the glob pattern can share a dependency by setting an explicit cache path and setting `shared_cache` to true.
219
-
220
- ```yaml
221
- source_path: "path/to/apps/*"
222
- cache_path: ".licenses/apps"
223
- shared_cache: true
224
- ```
225
-
226
- ## Source specific configuration
227
-
228
- See the [source documentation](./sources) for details on any source specific configuration.
@@ -0,0 +1,11 @@
1
+ # Configuration options
2
+
3
+ 1. [Application source path](./application_source.md)
4
+ 1. [Dependency metadata cache](./metadata_cache.md)
5
+ 1. [Configuring multiple applications / monorepo support](./configuring_multiple_apps.md)
6
+ 1. [Configuration root](./configuration_root.md)
7
+ 1. [Application name](./application_name.md)
8
+ 1. [Dependency source enumerators](./dependency_source_enumerators.md)
9
+ 1. [Allowed licenses](./allowed_licenses.md)
10
+ 1. [Ignoring dependencies](./ignoring_dependencies.md)
11
+ 1. [Reviewing dependencies](./reviewing_dependencies.md)
@@ -0,0 +1,17 @@
1
+ # Allowed licenses
2
+
3
+ **Key**: allowed
4
+ **Default Value**: none
5
+
6
+ The list of allowed licenses is used with the [status command](../commands/status.md) to detail which licenses are allowable for use in the current project and do not need further review. If a dependency uses a license that is not included in the allowed list, and the dependency is not on the ignored or reviewed dependency lists, it will be flagged and the status command will fail.
7
+
8
+ This configuration value accepts an array of lower-cased [open source license SPDX identifiers](https://spdx.org/licenses/).
9
+
10
+ ```yml
11
+ # accepts lowercase SPDX license identifiers
12
+ allowed:
13
+ - mit
14
+ - bsd-2-clause
15
+ - bsd-3-clause
16
+ - isc
17
+ ```