18
18
from macaron .config .global_config import global_config
19
19
from macaron .errors import ConfigurationError
20
20
from macaron .output_reporter .reporter import HTMLReporter , JSONReporter , PolicyReporter
21
- from macaron .parsers .yaml .loader import YamlLoader
22
21
from macaron .policy_engine .policy_engine import run_policy_engine , show_prelude
23
22
from macaron .slsa_analyzer .analyzer import Analyzer
24
23
from macaron .slsa_analyzer .git_service import GIT_SERVICES
32
31
33
32
def analyze_slsa_levels_single (analyzer_single_args : argparse .Namespace ) -> None :
34
33
"""Run the SLSA checks against a single target repository."""
35
- if not (analyzer_single_args .repo_path or analyzer_single_args .package_url or analyzer_single_args .config_path ):
36
- # We don't mention --config-path as a possible option in this log message as it going to be move soon.
37
- # See: https://github.com/oracle/macaron/issues/417
34
+ if not (analyzer_single_args .repo_path or analyzer_single_args .package_url ):
38
35
logger .error (
39
36
"""Analysis target missing. Please provide a package url (PURL) and/or repo path.
40
37
Examples of a PURL can be seen at https://github.com/package-url/purl-spec:
41
38
pkg:github/micronaut-projects/micronaut-core."""
42
39
)
43
40
sys .exit (os .EX_USAGE )
44
41
45
- if analyzer_single_args .config_path and (analyzer_single_args .package_url or analyzer_single_args .repo_path ):
46
- # TODO: revisit when the config-path option is moved.
47
- # See: https://github.com/oracle/macaron/issues/417
48
- logger .error ("Cannot provide both config path and (package url (PURL) and/or repo path)." )
49
- sys .exit (os .EX_USAGE )
50
-
51
42
# Set provenance expectation path.
52
43
if analyzer_single_args .provenance_expectation is not None :
53
44
if not os .path .exists (analyzer_single_args .provenance_expectation ):
@@ -89,55 +80,45 @@ def analyze_slsa_levels_single(analyzer_single_args: argparse.Namespace) -> None
89
80
analyzer .reporters .append (JSONReporter ())
90
81
91
82
run_config = {}
92
- if analyzer_single_args .config_path :
93
- # Get user config from yaml file
94
- loaded_config = YamlLoader .load (analyzer_single_args .config_path )
95
- if loaded_config is None :
96
- logger .error ("The input yaml config at %s is invalid." , analyzer_single_args .config_path )
97
- sys .exit (os .EX_DATAERR )
98
- else :
99
- run_config = loaded_config
100
- else :
101
- repo_path = analyzer_single_args .repo_path
102
- purl = analyzer_single_args .package_url
103
- branch = analyzer_single_args .branch
104
- digest = analyzer_single_args .digest
105
-
106
- if repo_path and purl :
107
- # To provide the purl together with the repository path, the user must specify the commit digest unless the
108
- # purl has a version.
109
- try :
110
- purl_object = PackageURL .from_string (purl )
111
- except ValueError as error :
112
- logger .debug ("Could not parse PURL: %s" , error )
113
- sys .exit (os .EX_USAGE )
114
- if not (purl_object .version or digest ):
115
- logger .error (
116
- "Please provide the commit digest for the repo at %s that matches to the PURL string %s. Or "
117
- "include the version in the PURL" ,
118
- repo_path ,
119
- purl ,
120
- )
121
- sys .exit (os .EX_USAGE )
83
+ repo_path = analyzer_single_args .repo_path
84
+ purl = analyzer_single_args .package_url
85
+ branch = analyzer_single_args .branch
86
+ digest = analyzer_single_args .digest
87
+
88
+ if repo_path and purl :
89
+ # To provide the purl together with the repository path, the user must specify the commit digest unless the
90
+ # purl has a version.
91
+ try :
92
+ purl_object = PackageURL .from_string (purl )
93
+ except ValueError as error :
94
+ logger .debug ("Could not parse PURL: %s" , error )
95
+ sys .exit (os .EX_USAGE )
96
+ if not (purl_object .version or digest ):
97
+ logger .error (
98
+ "Please provide the commit digest for the repo at %s that matches to the PURL string %s. Or "
99
+ "include the version in the PURL" ,
100
+ repo_path ,
101
+ purl ,
102
+ )
103
+ sys .exit (os .EX_USAGE )
122
104
123
- # We need to use empty strings when the input values are of None type. This is because this dictionary will be
124
- # passed into the Configuration instance, where the existing values in Configuration.options are replaced by
125
- # whatever we assign it here. Technically, the data in ``Configuration`` class are not limited to only strings.
126
- # Therefore, it could be cases where the ``purl`` field is initialized as an empty string in the constructor
127
- # of the Configuration class, but if `` analyzer_single_args.package_url`` is None, the ``purl`` field is set
128
- # to None in the Configuration instance.
129
- # This inconsistency could cause potential issues when Macaron handles those inputs.
130
- # TODO: improve the implementation of ``Configuration`` class to avoid such inconsistencies.
131
- run_config = {
132
- "target" : {
133
- "id" : purl or repo_path or "" ,
134
- "purl" : purl or "" ,
135
- "path" : repo_path or "" ,
136
- "branch" : branch or "" ,
137
- "digest" : digest or "" ,
138
- },
139
- "dependencies" : [],
105
+ # We need to use empty strings when the input values are of None type. This is because this dictionary will be
106
+ # passed into the Configuration instance, where the existing values in Configuration.options are replaced by
107
+ # whatever we assign it here. Technically, the data in ``Configuration`` class are not limited to only strings.
108
+ # Therefore, it could be cases where the ``purl`` field is initialized as an empty string in the constructor
109
+ # of the Configuration class, but if `` analyzer_single_args.package_url`` is None, the ``purl`` field is set
110
+ # to None in the Configuration instance.
111
+ # This inconsistency could cause potential issues when Macaron handles those inputs.
112
+ # TODO: improve the implementation of ``Configuration`` class to avoid such inconsistencies.
113
+ run_config = {
114
+ "target" : {
115
+ "id" : purl or repo_path or "" ,
116
+ "purl" : purl or "" ,
117
+ "path" : repo_path or "" ,
118
+ "branch" : branch or "" ,
119
+ "digest" : digest or "" ,
140
120
}
121
+ }
141
122
142
123
prov_payload = None
143
124
if analyzer_single_args .provenance_file :
@@ -325,15 +306,6 @@ def main(argv: list[str] | None = None) -> None:
325
306
# Use Macaron to analyze one single repository.
326
307
single_analyze_parser = sub_parser .add_parser (name = "analyze" )
327
308
328
- # We make the mutually exclusive usage of --config-path and --repo-path optional
329
- # so that the user can provide the --package-url separately while keeping the current behavior of Macaron.
330
- # Note that if the user provides both --package-url and --config-path, we will still raise an error,
331
- # which is handled within the ``analyze_slsa_levels_single`` method.
332
- # When we remove the --config-path option, we can remove this group and instead add all relevant
333
- # options in the analyze command through ``single_analyze_parser``.
334
- # See: https://github.com/oracle/macaron/issues/417
335
- group = single_analyze_parser .add_mutually_exclusive_group (required = False )
336
-
337
309
single_analyze_parser .add_argument (
338
310
"-sbom" ,
339
311
"--sbom-path" ,
@@ -343,7 +315,7 @@ def main(argv: list[str] | None = None) -> None:
343
315
help = ("The path to the SBOM of the analysis target." ),
344
316
)
345
317
346
- group .add_argument (
318
+ single_analyze_parser .add_argument (
347
319
"-rp" ,
348
320
"--repo-path" ,
349
321
required = False ,
@@ -398,15 +370,6 @@ def main(argv: list[str] | None = None) -> None:
398
370
help = ("The path to the provenance file in in-toto format." ),
399
371
)
400
372
401
- group .add_argument (
402
- "-c" ,
403
- "--config-path" ,
404
- required = False ,
405
- type = str ,
406
- default = "" ,
407
- help = ("The path to the user configuration." ),
408
- )
409
-
410
373
single_analyze_parser .add_argument (
411
374
"--skip-deps" ,
412
375
required = False ,
0 commit comments