Skip to content

Commit 22434a0

Browse files
pylapplaurentora
andauthored
[#2] [Feature] Get licenses from package manager files (#61) (#62)
* feat: #2 - add LicensesInventory tool Co-authored-by: Laurent BODY <[email protected]> Co-authored-by: Pierre-Yves Lapersonne <[email protected]> Signed-off-by: Laurent BODY <[email protected]> * chore: #2 - update CHANGELOG Signed-off-by: Pierre-Yves Lapersonne <[email protected]> * tests: #2 - update dry run / doctor script for new feature #2 Signed-off-by: Pierre-Yves Lapersonne <[email protected]> * chore: #2 - third-party list, clean config.ini Signed-off-by: Pierre-Yves Lapersonne <[email protected]> * chore: project - convert LICENSE files of third party to .txt instead of .md Signed-off-by: Pierre-Yves Lapersonne <[email protected]> Signed-off-by: Laurent BODY <[email protected]> Signed-off-by: Pierre-Yves Lapersonne <[email protected]> Co-authored-by: Laurent BODY <[email protected]> Signed-off-by: Laurent BODY <[email protected]> Signed-off-by: Pierre-Yves Lapersonne <[email protected]> Co-authored-by: Laurent BODY <[email protected]>
1 parent a2218ed commit 22434a0

Some content is hidden

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

60 files changed

+10932
-10
lines changed

AUTHORS.MD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Authors
22

3-
* Pierre-Yves Lapersonne <pierreyves(dot)lapersonne(at)orange(dot)com>
3+
* Laurent BODY <laurent(dot)body(at)orange(dot)com>
4+
* Pierre-Yves LAPERSONNE <pierreyves(dot)lapersonne(at)orange(dot)com>

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## Version 2.7.0
4+
5+
### Features
6+
7+
- [#2](https://github.com/Orange-OpenSource/floss-toolbox/issues/2) Package manager - Extract from files downloaded dependencies
8+
39
## Version 2.6.0
410

511
### Features

README.md

Lines changed: 150 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# floss-toolbox (version 2.6.0)
1+
# floss-toolbox
22

3-
Toolbox to help developers and open source referents to have cleaner projects in GitHub organizations.
3+
Toolbox to help developers and open source referents to have cleaner projects in _GitHub_ organizations, and more.
44

5-
Toolbox is mainly written in Shell because this language is very efficient for files processing and provides a strong and rich standard API with cool primitives. Contains also Ruby scripts. Ruby are shiny gems, I love them.
5+
Toolbox is mainly written in _Shell_ because this language is very efficient for files processing and provides a strong and rich standard API with cool primitives. Contains also _Ruby_ scripts. _Ruby_ are shiny gems, I love them. _Python_ is also used.
66

77
# Environment
88

99
You must have a _BASH_ ready environment and also _Ruby_.
1010
Environment:
1111
- _Bash_ version **3.2.5**
1212
- _Ruby_ version **2.7.1**
13-
- _Python_ version **3**
13+
- _Python_ version **3.7**
1414

1515
# Project tree
1616

@@ -490,4 +490,149 @@ brew install gitleaks
490490
You need to define in the _configuration.rb_ files the GitLab organisation ID at **GITLAB_ORGANIZATION_ID**.
491491
You have to also define the location to store clones at **REPOSITORIES_CLONE_LOCATION_PATH** and the access token at **GILAB_PERSONAL_ACCESS_TOKEN**.
492492

493-
**You should also have your _git_ environment ready i.e. add your SSH private key if you clone by SSH for example. _gh_ must be installed, and _python3_ be ready. Obviously _gitleaks_ must be installed**
493+
**You should also have your _git_ environment ready i.e. add your SSH private key if you clone by SSH for example. _gh_ must be installed, and _python3_ be ready. Obviously _gitleaks_ must be installed**
494+
495+
# Licenses inventory
496+
497+
_Keywords: #licenses #SPM #Gradle #Maven #NPMJS #package_
498+
499+
## Disclaimer
500+
501+
*This is quite experimental feature, with results which must be verified by a human.*
502+
*You must deal with platforms and APIs policies and fullfil them.*
503+
504+
*This is software is distributed on "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*
505+
506+
## Prerequisites
507+
508+
- _Python_ version **3.7**
509+
- _Python_ modules like _requests_, _xmltodict_ and _pytest-6.2.5_
510+
511+
```shell
512+
pip install requests
513+
pip install xmltodict
514+
pip install pytest
515+
```
516+
517+
## Fill the configuration file
518+
519+
Before to use the tools, the file 'config.ini' is at the root of the project, you have to personalize this file.
520+
521+
For example:
522+
```text
523+
[dependencies]
524+
# Where to find the package manager file above
525+
path to parse = /absolute/path/to/project_to_test
526+
# The name of the package manager file to process store above
527+
the filenames = go.mod
528+
# For outputs
529+
path to store the licenses = /absolute/path/to/project_to_test-licences
530+
```
531+
532+
where:
533+
- `path to parse` contains the dependencies manager files
534+
- `the filenames` contains the names of the dependencies manager files to process
535+
- `path to store the licenses` points to a folder containing the result files
536+
537+
## Run the tool
538+
539+
```shell
540+
python3 sources/main.py
541+
```
542+
543+
## Run the tests
544+
545+
To run integration tests:
546+
547+
```shell
548+
python3 -m pytest tests/integrationtests/test_search.py
549+
```
550+
551+
To run unit tests:
552+
553+
```shell
554+
python3 -m pytest tests/unittests/test_config.py
555+
python3 -m pytest tests/unittests/test_dependency.py
556+
python3 -m pytest tests/unittests/test_files_check_the_directory.py
557+
python3 -m pytest tests/unittests/test_files_get_the_filenames_by_name.py
558+
python3 -m pytest tests/unittests/test_files_write_and_read.py
559+
python3 -m pytest tests/unittests/test_filter.py
560+
python3 -m pytest tests/unittests/test_parsing.py
561+
python3 -m pytest tests/unittests/test_parsing_download.py
562+
```
563+
564+
or just
565+
566+
```shell
567+
python3 -m pytest tests/unittests/*.py
568+
```
569+
570+
## Managed platforms
571+
572+
### Go language
573+
574+
`go.mod` files are managed.
575+
Depending to the `go.mod` definitions implementation, some cases can be applied:
576+
577+
1. github.com will be requested if dependency starts by _github.com_
578+
2. pkg.go.dev will be requested for other cases
579+
580+
For example:
581+
582+
```text
583+
module ...
584+
585+
go 1.15
586+
587+
require (
588+
emperror.dev/errors v0.4.2 // <--- Request pkg.go.dev
589+
github.com/antihax/optional v1.0.0 // <--- Request github.com
590+
golang.org/x/tools v0.0.0-20201014231627-1610a49f37af // indirect // <--- Not managed
591+
k8s.io/api v0.20.2 // <--- Request pkg.go.dev
592+
sigs.k8s.io/controller-runtime v0.7.2 // <--- Request pkg.go.dev
593+
)
594+
```
595+
596+
### Gradle environment
597+
598+
`build.gradle` and `build.gradle.kts` files are managed.
599+
Some platforms are requests like _Maven Central_ (search.maven.org) and _GitHub_ (through api.github.com).
600+
601+
**Warning: unstable feature with maybe _Maven Central_ troubles.*
602+
603+
### Rust environment
604+
605+
`Cargo.lock` files are also managed.
606+
The _crates.io_ platform will be requested for each dependency found.
607+
608+
### JavaScript/Node.js environment
609+
610+
`package.json` files can be parsed too.
611+
The platform _npmjs.org_ wll be requested for each dependency found.
612+
613+
### Swift / SPM environment
614+
615+
If you use _Swift Package Manager_, you can parse `Package.swift` file.
616+
The tool will extract the dependency URLs and request some forges, e.g. _github.com_.
617+
618+
### Dart / Flutter environment
619+
620+
The `pubspec.yaml` files can also be processed.
621+
For each dependency found, the _pub.dev_ platform will be requested.
622+
623+
### Python
624+
625+
_Coming soon_
626+
627+
### CocoaPods
628+
629+
_Coming soon_
630+
631+
## Notes
632+
633+
The tool downloads a file for each dependency it found in the dependency manager file.
634+
These files containing the licenses are in directory like 'licenses/sub_folder', where 'sub_folder' is created for each platform: Gradle, Rust, etc.
635+
636+
A file 'licenses.txt' is created in the folder 'licenses'.
637+
This file contains the list of the licenses for each dependency.
638+
To personalize this folder, use 'config.ini'.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
================================================================================
2+
Apache 2.0 License
3+
================================================================================
4+
5+
Component: requests
6+
Copyright: 2019 Kenneth Reitz
7+
License Text URL: licenses/LICENSE-requests.txt
8+
Source Code: https://github.com/psf/requests
9+
10+
================================================================================
11+
MIT License
12+
================================================================================
13+
14+
Component: pytest
15+
Copyright: 2004 Holger Krekel and others
16+
License Text URL: licenses/LICENSE-pytest.txt
17+
Source Code: https://github.com/pytest-dev/pytest
18+
19+
Component: xmltodict
20+
Copyright: 2012 Martin Blech and individual contributors.
21+
License Text URL: licenses/LICENSE-xmltodict.txt
22+
Source Code: https://github.com/martinblech/xmltodict
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[dependencies]
2+
3+
# Absolute path pointing to directory with the dependencies manager files
4+
path to parse = ...
5+
6+
# Name of the dependencies manager files to process (pubspec.yaml, go.mod, package.json, Cargo.lock, buld.gradle(.kts)...)
7+
the filenames = ...
8+
9+
# Absolute path pointing to directory where result file and outputs are written
10+
path to store the licenses = ...
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2004 Holger Krekel and others
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)