1818from macaron .config .global_config import global_config
1919from macaron .errors import ConfigurationError
2020from macaron .output_reporter .reporter import HTMLReporter , JSONReporter , PolicyReporter
21- from macaron .parsers .yaml .loader import YamlLoader
2221from macaron .policy_engine .policy_engine import run_policy_engine , show_prelude
2322from macaron .slsa_analyzer .analyzer import Analyzer
2423from macaron .slsa_analyzer .git_service import GIT_SERVICES
3231
3332def analyze_slsa_levels_single (analyzer_single_args : argparse .Namespace ) -> None :
3433 """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 ):
3835 logger .error (
3936 """Analysis target missing. Please provide a package url (PURL) and/or repo path.
4037 Examples of a PURL can be seen at https://github.com/package-url/purl-spec:
4138 pkg:github/micronaut-projects/micronaut-core."""
4239 )
4340 sys .exit (os .EX_USAGE )
4441
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-
5142 # Set provenance expectation path.
5243 if analyzer_single_args .provenance_expectation is not None :
5344 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
8980 analyzer .reporters .append (JSONReporter ())
9081
9182 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 )
122104
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 "" ,
140120 }
121+ }
141122
142123 prov_payload = None
143124 if analyzer_single_args .provenance_file :
@@ -325,15 +306,6 @@ def main(argv: list[str] | None = None) -> None:
325306 # Use Macaron to analyze one single repository.
326307 single_analyze_parser = sub_parser .add_parser (name = "analyze" )
327308
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-
337309 single_analyze_parser .add_argument (
338310 "-sbom" ,
339311 "--sbom-path" ,
@@ -343,7 +315,7 @@ def main(argv: list[str] | None = None) -> None:
343315 help = ("The path to the SBOM of the analysis target." ),
344316 )
345317
346- group .add_argument (
318+ single_analyze_parser .add_argument (
347319 "-rp" ,
348320 "--repo-path" ,
349321 required = False ,
@@ -398,15 +370,6 @@ def main(argv: list[str] | None = None) -> None:
398370 help = ("The path to the provenance file in in-toto format." ),
399371 )
400372
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-
410373 single_analyze_parser .add_argument (
411374 "--skip-deps" ,
412375 required = False ,
0 commit comments