Skip to content

Commit 7e84090

Browse files
committed
Add support for download URL as --input-list in batch-create #1524
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent fa9ac3f commit 7e84090

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

docs/command-line-interface.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ Required arguments (one of):
174174
| project-2 | pkg:deb/debian/curl@7.50.3 |
175175
+----------------+---------------------------------+
176176

177+
.. tip::
178+
In place of a local path, a download URL to the CSV file is supported for the
179+
``--input-list`` argument.
180+
177181
Optional arguments:
178182

179183
- ``--project-name-suffix`` Optional custom suffix to append to project names.
@@ -194,14 +198,15 @@ Optional arguments:
194198
Example: Processing Multiple Docker Images
195199
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
196200

197-
Assume multiple Docker images are available in a directory named ``local-data/`` on
201+
Suppose you have multiple Docker images stored in a directory named ``local-data/`` on
198202
the host machine.
199-
To process these images with the ``analyze_docker_image`` pipeline using asynchronous
200-
execution::
203+
To process these images using the ``analyze_docker_image`` pipeline with asynchronous
204+
execution, you can use this command::
201205

202206
$ docker compose run --rm \
203-
--volume local-data/:/input-data:ro \
204-
web scanpipe batch-create input-data/ \
207+
--volume local-data/:/input-data/:ro \
208+
web scanpipe batch-create
209+
--input-directory /input-data/ \
205210
--pipeline analyze_docker_image \
206211
--label "Docker" \
207212
--execute --async
@@ -224,6 +229,19 @@ Each Docker image in the ``local-data/`` directory will result in the creation o
224229
project with the specified pipeline (``analyze_docker_image``) executed by worker
225230
services.
226231

232+
Example: Processing Multiple Develop to Deploy Mapping
233+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234+
235+
To process an input list CSV file with the ``map_deploy_to_develop`` pipeline using
236+
asynchronous execution::
237+
238+
$ docker compose run --rm \
239+
web scanpipe batch-create \
240+
--input-list https://url/input_list.csv \
241+
--pipeline map_deploy_to_develop \
242+
--label "d2d_mapping" \
243+
--execute --async
244+
227245
`$ scanpipe list-pipeline [--verbosity {0,1,2,3}]`
228246
--------------------------------------------------
229247

scanpipe/management/commands/batch-create.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
from django.core.management import CommandError
2828
from django.core.management.base import BaseCommand
2929

30+
import requests
31+
3032
from scanpipe.management.commands import CreateProjectCommandMixin
3133
from scanpipe.management.commands import PipelineCommandMixin
34+
from scanpipe.pipes import fetch
3235

3336

3437
class Command(CreateProjectCommandMixin, PipelineCommandMixin, BaseCommand):
@@ -54,7 +57,8 @@ def add_arguments(self, parser):
5457
"Path to a CSV file with project names and input URLs. "
5558
"The first column must contain project names, and the second column "
5659
"should list comma-separated input URLs (e.g., Download URL, PURL, or "
57-
"Docker reference)."
60+
"Docker reference). "
61+
"In place of a local path, a download URL to the CSV file is supported."
5862
),
5963
)
6064
parser.add_argument(
@@ -110,7 +114,16 @@ def handle_input_directory(self, **options):
110114
self.created_project_count += 1
111115

112116
def handle_input_list(self, **options):
113-
input_file = Path(options["input_list"])
117+
input_file = options["input_list"]
118+
119+
if input_file.startswith("http"):
120+
try:
121+
download = fetch.fetch_http(input_file)
122+
except requests.exceptions.RequestException as e:
123+
raise CommandError(e)
124+
input_file = download.path
125+
126+
input_file = Path(input_file)
114127
if not input_file.exists():
115128
raise CommandError(f"The {input_file} file does not exist.")
116129

0 commit comments

Comments
 (0)