Skip to content

Commit 4d276e9

Browse files
authored
SP-802 Add file list option to scanning (#41)
* added file list scanning option * updating action versions * removing error when no files are scanned
1 parent d2610b6 commit 4d276e9

File tree

10 files changed

+55
-33
lines changed

10 files changed

+55
-33
lines changed

.github/workflows/container-local-test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919

2020
steps:
2121
- name: Checkout Repository
22-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
2323

2424
# Setup and build the python package
2525
- name: Set up Python
26-
uses: actions/setup-python@v3
26+
uses: actions/setup-python@v5
2727
with:
2828
python-version: '3.10.x'
2929

@@ -36,12 +36,12 @@ jobs:
3636
run: make dist
3737

3838
- name: Setup Docker buildx
39-
uses: docker/setup-buildx-action@v2
39+
uses: docker/setup-buildx-action@v3
4040

4141
# Build Docker image with Buildx
4242
- name: Build Docker Image
4343
id: build-and-push
44-
uses: docker/build-push-action@v4
44+
uses: docker/build-push-action@v5
4545
with:
4646
context: .
4747
push: false

.github/workflows/container-publish-ghcr.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222

2323
steps:
2424
- name: Checkout Repository
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@v4
2626

2727
# Setup and build python package
2828
- name: Set up Python
29-
uses: actions/setup-python@v3
29+
uses: actions/setup-python@v5
3030
with:
3131
python-version: '3.10.x'
3232

@@ -40,16 +40,16 @@ jobs:
4040

4141
# Add support for more platforms with QEMU
4242
- name: Set up QEMU
43-
uses: docker/setup-qemu-action@v2
43+
uses: docker/setup-qemu-action@v3
4444

4545
# Workaround: https://github.com/docker/build-push-action/issues/461
4646
# uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
4747
- name: Setup Docker buildx
48-
uses: docker/setup-buildx-action@v2
48+
uses: docker/setup-buildx-action@v3
4949

5050
# Login against a Docker registry except on PR
5151
- name: Log into registry ${{ env.REGISTRY }}
52-
uses: docker/login-action@v2
52+
uses: docker/login-action@v3
5353
with:
5454
registry: ${{ env.REGISTRY }}
5555
username: ${{ github.actor }}
@@ -60,12 +60,12 @@ jobs:
6060
id: meta
6161
uses: docker/metadata-action@v4
6262
with:
63-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
63+
images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
6464

6565
# Build and push Docker image with Buildx (don't push on PR)
6666
- name: Build and push Docker image
6767
id: build-and-push
68-
uses: docker/build-push-action@v4
68+
uses: docker/build-push-action@v5
6969
with:
7070
context: .
7171
push: ${{ github.event_name != 'pull_request' }}

.github/workflows/python-local-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
build:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121

2222
- name: Set up Python
23-
uses: actions/setup-python@v3
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: '3.10.x'
2626

.github/workflows/python-publish-pypi.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
deploy:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

1616
- name: Set up Python
17-
uses: actions/setup-python@v3
17+
uses: actions/setup-python@v5
1818
with:
1919
python-version: '3.10.x'
2020

@@ -49,7 +49,7 @@ jobs:
4949
- name: Publish Package - ${{ github.ref_name }}
5050
uses: pypa/gh-action-pypi-publish@release/v1
5151
with:
52-
# skip_existing: true
52+
# skip-existing: true
5353
user: __token__
5454
password: ${{ secrets.PYPI_API_TOKEN }}
5555

@@ -65,10 +65,10 @@ jobs:
6565
needs: [ deploy ]
6666
runs-on: ubuntu-latest
6767
steps:
68-
- uses: actions/checkout@v3
68+
- uses: actions/checkout@v4
6969

7070
- name: Set up Python
71-
uses: actions/setup-python@v3
71+
uses: actions/setup-python@v5
7272
with:
7373
python-version: '3.10.x'
7474

.github/workflows/python-publish-testpypi.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
deploy:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

1515
- name: Set up Python
16-
uses: actions/setup-python@v3
16+
uses: actions/setup-python@v5
1717
with:
1818
python-version: '3.10.x'
1919

@@ -49,21 +49,21 @@ jobs:
4949
- name: Publish Test Package
5050
uses: pypa/gh-action-pypi-publish@release/v1
5151
with:
52-
skip_existing: true
52+
skip-existing: true
5353
user: __token__
5454
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
55-
repository_url: https://test.pypi.org/legacy/
55+
repository-url: https://test.pypi.org/legacy/
5656

5757
test:
5858
if: success()
5959
needs: [ deploy ]
6060
runs-on: ubuntu-latest
6161

6262
steps:
63-
- uses: actions/checkout@v3
63+
- uses: actions/checkout@v4
6464

6565
- name: Set up Python
66-
uses: actions/setup-python@v3
66+
uses: actions/setup-python@v5
6767
with:
6868
python-version: '3.10.x'
6969

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Upcoming changes...
1111

12+
## [1.13.0] - 2024-06-05
13+
### Added
14+
- Added `scan` command option to specify a list of files (`--files`) to analyse
15+
1216
## [1.12.3] - 2024-05-13
1317
### Fixed
1418
- Fixed export issue when license details are missing (SPDX/CycloneDX)
@@ -326,3 +330,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
326330
[1.12.1]: https://github.com/scanoss/scanoss.py/compare/v1.12.0...v1.12.1
327331
[1.12.2]: https://github.com/scanoss/scanoss.py/compare/v1.12.1...v1.12.2
328332
[1.12.3]: https://github.com/scanoss/scanoss.py/compare/v1.12.2...v1.12.3
333+
[1.13.0]: https://github.com/scanoss/scanoss.py/compare/v1.12.3...v1.13.0

cert_download.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# Attempt to download an SSL certificate from the specified host and convert to a PEM file
2727
#
2828

29-
script_name=$(basename $0)
29+
script_name=$(basename "$0")
3030

3131
help()
3232
{
@@ -47,7 +47,7 @@ VALID_ARGUMENTS=$#
4747
if [ "$VALID_ARGUMENTS" -eq 0 ]; then # No arguments supplied, print help
4848
help
4949
fi
50-
set -- $OPTS
50+
set -- "$OPTS"
5151

5252
force=0
5353
while :; do

src/scanoss/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
THE SOFTWARE.
2323
"""
2424

25-
__version__ = '1.12.3'
25+
__version__ = '1.13.0'

src/scanoss/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def setup_args() -> None:
7272
help='Use a dependency file instead of a folder (optional)')
7373
p_scan.add_argument('--stdin', '-s', metavar='STDIN-FILENAME', type=str,
7474
help='Scan the file contents supplied via STDIN (optional)')
75+
p_scan.add_argument('--files', '-e', type=str, nargs="*", help='List of files to scan.')
7576
p_scan.add_argument('--identify', '-i', type=str, help='Scan and identify components in SBOM file')
7677
p_scan.add_argument('--ignore', '-n', type=str, help='Ignore components specified in the SBOM file')
7778
p_scan.add_argument('--output', '-o', type=str, help='Output result file name (optional - default stdout).')
@@ -445,8 +446,8 @@ def scan(parser, args):
445446
args: Namespace
446447
Parsed arguments
447448
"""
448-
if not args.scan_dir and not args.wfp and not args.stdin and not args.dep:
449-
print_stderr('Please specify a file/folder, fingerprint (--wfp), dependency (--dep), or STDIN (--stdin)')
449+
if not args.scan_dir and not args.wfp and not args.stdin and not args.dep and not args.files:
450+
print_stderr('Please specify a file/folder, files (--files), fingerprint (--wfp), dependency (--dep), or STDIN (--stdin)')
450451
parser.parse_args([args.subparser, '-h'])
451452
exit(1)
452453
if args.pac and args.proxy:
@@ -556,6 +557,9 @@ def scan(parser, args):
556557
contents = sys.stdin.buffer.read()
557558
if not scanner.scan_contents(args.stdin, contents):
558559
exit(1)
560+
elif args.files:
561+
if not scanner.scan_files_with_options(args.files, args.dep, scanner.winnowing.file_map):
562+
exit(1)
559563
elif args.scan_dir:
560564
if not os.path.exists(args.scan_dir):
561565
print_stderr(f'Error: File or folder specified does not exist: {args.scan_dir}.')

src/scanoss/scanner.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,6 @@ def __finish_scan_threaded(self, file_map: dict = None) -> bool:
522522
else:
523523
raw_output += ",\n \"%s\":[%s]" % (file, json.dumps(dep_file, indent=2))
524524
# End for loop
525-
else:
526-
success = False
527525
raw_output += "\n}"
528526
parsed_json = None
529527
try:
@@ -625,7 +623,6 @@ def scan_files(self, files: []) -> bool:
625623
success = True
626624
if not files:
627625
raise Exception(f"ERROR: Please provide a non-empty list of filenames to scan")
628-
self.print_msg(f'Scanning {len(files)} files...')
629626
spinner = None
630627
if not self.quiet and self.isatty:
631628
spinner = Spinner('Fingerprinting ')
@@ -637,7 +634,23 @@ def scan_files(self, files: []) -> bool:
637634
file_count = 0 # count all files fingerprinted
638635
wfp_file_count = 0 # count number of files in each queue post
639636
scan_started = False
637+
filtered_files = []
638+
# Filter the files to remove anything we shouldn't scan
640639
for file in files:
640+
filename = os.path.basename(file)
641+
filtered_filenames = self.__filter_files([filename])
642+
if not filtered_filenames or len(filtered_filenames) == 0:
643+
self.print_debug(f'Skipping filtered file: {file}')
644+
continue
645+
paths = os.path.dirname(file).split(os.sep)
646+
if len(self.__filter_dirs(paths)) == len(paths): # Nothing found to filter
647+
filtered_files.append(file)
648+
else:
649+
self.print_debug(f'Skipping filtered (folder) file: {file}')
650+
if len(filtered_files) > 0:
651+
self.print_debug(f'Scanning {len(filtered_files)} files...')
652+
# Process all the requested files
653+
for file in filtered_files:
641654
if self.threaded_scan and self.threaded_scan.stop_scanning():
642655
self.print_stderr('Warning: Aborting fingerprinting as the scanning service is not available.')
643656
break
@@ -697,7 +710,7 @@ def scan_files(self, files: []) -> bool:
697710
if self.threaded_scan:
698711
success = self.__run_scan_threaded(scan_started, file_count)
699712
else:
700-
Scanner.print_stderr(f'Warning: No files found to scan from: {files}')
713+
Scanner.print_stderr(f'Warning: No files found to scan from: {filtered_files}')
701714
return success
702715

703716
def scan_files_with_options(self, files: [], deps_file: str = None, file_map: dict = None) -> bool:

0 commit comments

Comments
 (0)