Skip to content

Commit 266700e

Browse files
committed
chore: resolve staging merge conflicts
Signed-off-by: behnazh-w <[email protected]>
1 parent 2aead68 commit 266700e

File tree

7 files changed

+64
-64
lines changed

7 files changed

+64
-64
lines changed

src/macaron/slsa_analyzer/analyzer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
NoneDependencyAnalyzer,
3232
)
3333
from macaron.dependency_analyzer.cyclonedx import get_deps_from_sbom
34-
from macaron.errors import CloneError
35-
from macaron.errors import DuplicateError, NotFoundError
34+
from macaron.errors import CloneError, DuplicateError, NotFoundError
3635
from macaron.output_reporter.reporter import FileReporter
3736
from macaron.output_reporter.results import Record, Report, SCMStatus
3837
from macaron.slsa_analyzer import git_url
@@ -278,7 +277,7 @@ def resolve_dependencies(self, main_ctx: AnalyzeContext, sbom_path: str) -> dict
278277
if isinstance(dep_analyzer, NoneDependencyAnalyzer):
279278
logger.info(
280279
"Dependency analyzer is not available for %s",
281-
main_ctx.dynamic_data["build_spec"]["tool"].name,
280+
build_tool.name,
282281
)
283282
return {}
284283

@@ -728,7 +727,8 @@ def perform_checks(self, analyze_ctx: AnalyzeContext) -> dict[str, CheckResult]:
728727
# Determine the git service.
729728
remote_path = analyze_ctx.component.repository.remote_path if analyze_ctx.component.repository else None
730729
git_service = self.get_git_service(remote_path)
731-
if isinstance(git_service, NoneGitService):
730+
# Check remote_path to help mypy.
731+
if remote_path is None or isinstance(git_service, NoneGitService):
732732
logger.error("Unsupported git service for %s", analyze_ctx.component.purl)
733733
else:
734734
logger.info(
@@ -745,7 +745,7 @@ def perform_checks(self, analyze_ctx: AnalyzeContext) -> dict[str, CheckResult]:
745745
build_tool.name,
746746
)
747747

748-
if build_tool.is_detected( ):
748+
if build_tool.is_detected(analyze_ctx.component.repository.fs_path):
749749
logger.info("The repo uses %s build tool.", build_tool.name)
750750
analyze_ctx.dynamic_data["build_spec"]["tools"].append(build_tool)
751751

src/macaron/slsa_analyzer/checks/build_service_check.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,20 @@ def _check_build_tool(
147147
if build_cmd:
148148
# Get the permalink and HTML hyperlink tag of the CI file that triggered the bash command.
149149
trigger_link = ci_service.api_client.get_file_link(
150-
ctx.repo_full_name,
151-
ctx.commit_sha,
150+
ctx.component.repository.full_name,
151+
ctx.component.repository.commit_sha,
152152
ci_service.api_client.get_relative_path_of_workflow(os.path.basename(bash_cmd["CI_path"])),
153153
)
154154
# Get the permalink and HTML hyperlink tag of the source file of the bash command.
155155
bash_source_link = ci_service.api_client.get_file_link(
156-
ctx.repo_full_name, ctx.commit_sha, bash_cmd["caller_path"]
156+
ctx.component.repository.full_name, ctx.component.repository.commit_sha, bash_cmd["caller_path"]
157157
)
158158

159159
html_url = ci_service.has_latest_run_passed(
160-
ctx.repo_full_name,
161-
ctx.branch_name,
162-
ctx.commit_sha,
163-
ctx.commit_date,
160+
ctx.component.repository.full_name,
161+
ctx.component.repository.branch_name,
162+
ctx.component.repository.commit_sha,
163+
ctx.component.repository.commit_date,
164164
os.path.basename(bash_cmd["CI_path"]),
165165
)
166166

@@ -187,10 +187,11 @@ def _check_build_tool(
187187
predicate = ci_info["provenances"][0]["predicate"]
188188
predicate["buildType"] = f"Custom {ci_service.name}"
189189
predicate["builder"]["id"] = bash_source_link
190-
predicate["invocation"]["configSource"][
191-
"uri"
192-
] = f"{ctx.remote_path}@refs/heads/{ctx.branch_name}"
193-
predicate["invocation"]["configSource"]["digest"]["sha1"] = ctx.commit_sha
190+
predicate["invocation"]["configSource"]["uri"] = (
191+
f"{ctx.component.repository.remote_path}"
192+
f"@refs/heads/{ctx.component.repository.branch_name}"
193+
)
194+
predicate["invocation"]["configSource"]["digest"]["sha1"] = ctx.component.repository.commit_sha
194195
predicate["invocation"]["configSource"]["entryPoint"] = trigger_link
195196
predicate["metadata"]["buildInvocationId"] = html_url
196197
return CheckResultType.PASSED
@@ -201,7 +202,7 @@ def _check_build_tool(
201202
if isinstance(ci_service, unparsed_ci):
202203
if build_tool.ci_build_kws[ci_service.name]:
203204
_, config_name = ci_service.has_kws_in_config(
204-
build_tool.ci_build_kws[ci_service.name], repo_path=ctx.repo_path
205+
build_tool.ci_build_kws[ci_service.name], repo_path=ctx.component.repository.fs_path
205206
)
206207
if not config_name:
207208
break
@@ -222,10 +223,13 @@ def _check_build_tool(
222223
predicate = ci_info["provenances"][0]["predicate"]
223224
predicate["buildType"] = f"Custom {ci_service.name}"
224225
predicate["builder"]["id"] = config_name
225-
predicate["invocation"]["configSource"][
226-
"uri"
227-
] = f"{ctx.remote_path}@refs/heads/{ctx.branch_name}"
228-
predicate["invocation"]["configSource"]["digest"]["sha1"] = ctx.commit_sha
226+
predicate["invocation"]["configSource"]["uri"] = (
227+
f"{ctx.component.repository.remote_path}"
228+
f"@refs/heads/{ctx.component.repository.branch_name}"
229+
)
230+
predicate["invocation"]["configSource"]["digest"][
231+
"sha1"
232+
] = ctx.component.repository.commit_sha
229233
predicate["invocation"]["configSource"]["entryPoint"] = config_name
230234
return CheckResultType.PASSED
231235

tests/e2e/expected_results/multibuild_test/multibuild_test.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
"metadata": {
3-
<<<<<<< HEAD
43
"timestamps": "2023-06-18 21:51:40"
5-
=======
6-
"timestamps": "2023-06-15 05:18:53"
7-
>>>>>>> 4dd62bd (feat: introduce a new data model and software components based on PURL)
84
},
95
"target": {
106
"info": {

tests/e2e/expected_results/tinyMediaManager/tinyMediaManager.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
},
55
"target": {
66
"info": {
7-
"full_name": "tinyMediaManager/tinyMediaManager",
7+
"full_name": "pkg:gitlab.com/tinyMediaManager/tinyMediaManager@cca6b67a335074eca42136556f0a321f75dc4f48",
88
"local_cloned_path": "git_repos/gitlab_com/tinyMediaManager/tinyMediaManager",
99
"remote_path": "https://gitlab.com/tinyMediaManager/tinyMediaManager",
1010
"branch": "main",

tests/slsa_analyzer/checks/test_build_as_code_check.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,32 @@ def test_build_as_code_check(
5454

5555
# The target repo uses Maven build tool but does not deploy artifacts.
5656
use_build_tool = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
57-
use_build_tool.dynamic_data["build_spec"]["tool"] = [maven_tool]
57+
use_build_tool.dynamic_data["build_spec"]["tools"] = [maven_tool]
5858
assert check.run_check(use_build_tool, check_result) == CheckResultType.FAILED
5959

6060
# The target repo uses Gradle build tool but does not deploy artifacts.
6161
use_build_tool = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
62-
use_build_tool.dynamic_data["build_spec"]["tool"] = [gradle_tool]
62+
use_build_tool.dynamic_data["build_spec"]["tools"] = [gradle_tool]
6363
assert check.run_check(use_build_tool, check_result) == CheckResultType.FAILED
6464

6565
# The target repo uses Poetry build tool but does not deploy artifacts.
6666
use_build_tool = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
67-
use_build_tool.dynamic_data["build_spec"]["tool"] = [poetry_tool]
67+
use_build_tool.dynamic_data["build_spec"]["tools"] = [poetry_tool]
6868
assert check.run_check(use_build_tool, check_result) == CheckResultType.FAILED
6969

7070
# The target repo uses Pip build tool but does not deploy artifacts.
7171
use_build_tool = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
72-
use_build_tool.dynamic_data["build_spec"]["tool"] = [pip_tool]
72+
use_build_tool.dynamic_data["build_spec"]["tools"] = [pip_tool]
7373
assert check.run_check(use_build_tool, check_result) == CheckResultType.FAILED
7474

7575
# The target repo does not use a build tool.
7676
no_build_tool = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
77-
no_build_tool.dynamic_data["build_spec"]["tool"] = []
77+
no_build_tool.dynamic_data["build_spec"]["tools"] = []
7878
assert check.run_check(no_build_tool, check_result) == CheckResultType.FAILED
7979

8080
# Use mvn deploy to deploy the artifact.
8181
maven_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
82-
maven_deploy.dynamic_data["build_spec"]["tool"] = [maven_tool]
82+
maven_deploy.dynamic_data["build_spec"]["tools"] = [maven_tool]
8383
bash_commands["commands"] = [["mvn", "deploy"]]
8484
maven_deploy.dynamic_data["ci_services"] = [ci_info]
8585
assert check.run_check(maven_deploy, check_result) == CheckResultType.PASSED
@@ -96,7 +96,7 @@ def test_build_as_code_check(
9696

9797
# Use mvn but do not deploy artifacts.
9898
no_maven_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
99-
no_maven_deploy.dynamic_data["build_spec"]["tool"] = [maven_tool]
99+
no_maven_deploy.dynamic_data["build_spec"]["tools"] = [maven_tool]
100100
bash_commands["commands"] = [["mvn", "verify"]]
101101
no_maven_deploy.dynamic_data["ci_services"] = [ci_info]
102102
assert check.run_check(no_maven_deploy, check_result) == CheckResultType.FAILED
@@ -108,66 +108,66 @@ def test_build_as_code_check(
108108

109109
# Use gradle to deploy the artifact.
110110
gradle_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
111-
gradle_deploy.dynamic_data["build_spec"]["tool"] = [gradle_tool]
111+
gradle_deploy.dynamic_data["build_spec"]["tools"] = [gradle_tool]
112112
bash_commands["commands"] = [["./gradlew", "publishToSonatype"]]
113113
gradle_deploy.dynamic_data["ci_services"] = [ci_info]
114114
assert check.run_check(gradle_deploy, check_result) == CheckResultType.PASSED
115115

116116
# Use poetry publish to publish the artifact.
117117
poetry_publish = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
118-
poetry_publish.dynamic_data["build_spec"]["tool"] = [poetry_tool]
118+
poetry_publish.dynamic_data["build_spec"]["tools"] = [poetry_tool]
119119
bash_commands["commands"] = [["poetry", "publish"]]
120120
poetry_publish.dynamic_data["ci_services"] = [ci_info]
121121
assert check.run_check(poetry_publish, check_result) == CheckResultType.PASSED
122122

123123
# Use Poetry but do not deploy artifacts.
124124
no_poetry_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
125-
no_poetry_deploy.dynamic_data["build_spec"]["tool"] = [poetry_tool]
125+
no_poetry_deploy.dynamic_data["build_spec"]["tools"] = [poetry_tool]
126126
bash_commands["commands"] = [["poetry", "upload"]]
127127
no_poetry_deploy.dynamic_data["ci_services"] = [ci_info]
128128
assert check.run_check(no_maven_deploy, check_result) == CheckResultType.FAILED
129129

130130
# Use twine upload to deploy the artifact.
131131
twine_upload = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
132-
twine_upload.dynamic_data["build_spec"]["tool"] = [pip_tool]
132+
twine_upload.dynamic_data["build_spec"]["tools"] = [pip_tool]
133133
bash_commands["commands"] = [["twine", "upload", "dist/*"]]
134134
twine_upload.dynamic_data["ci_services"] = [ci_info]
135135
assert check.run_check(twine_upload, check_result) == CheckResultType.PASSED
136136

137137
# Use flit publish to deploy the artifact.
138138
flit_publish = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
139-
flit_publish.dynamic_data["build_spec"]["tool"] = [pip_tool]
139+
flit_publish.dynamic_data["build_spec"]["tools"] = [pip_tool]
140140
bash_commands["commands"] = [["flit", "publish"]]
141141
flit_publish.dynamic_data["ci_services"] = [ci_info]
142142
assert check.run_check(flit_publish, check_result) == CheckResultType.PASSED
143143

144144
# Test Jenkins.
145145
maven_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
146-
maven_deploy.dynamic_data["build_spec"]["tool"] = [maven_tool]
146+
maven_deploy.dynamic_data["build_spec"]["tools"] = [maven_tool]
147147
ci_info["service"] = jenkins_service
148148
bash_commands["commands"] = []
149149
maven_deploy.dynamic_data["ci_services"] = [ci_info]
150150
assert check.run_check(maven_deploy, check_result) == CheckResultType.FAILED
151151

152152
# Test Travis.
153153
maven_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
154-
maven_deploy.dynamic_data["build_spec"]["tool"] = [maven_tool]
154+
maven_deploy.dynamic_data["build_spec"]["tools"] = [maven_tool]
155155
ci_info["service"] = travis_service
156156
bash_commands["commands"] = []
157157
maven_deploy.dynamic_data["ci_services"] = [ci_info]
158158
assert check.run_check(maven_deploy, check_result) == CheckResultType.FAILED
159159

160160
# Test Circle CI.
161161
maven_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
162-
maven_deploy.dynamic_data["build_spec"]["tool"] = [maven_tool]
162+
maven_deploy.dynamic_data["build_spec"]["tools"] = [maven_tool]
163163
ci_info["service"] = circle_ci_service
164164
bash_commands["commands"] = []
165165
maven_deploy.dynamic_data["ci_services"] = [ci_info]
166166
assert check.run_check(maven_deploy, check_result) == CheckResultType.FAILED
167167

168168
# Test GitLab CI.
169169
maven_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
170-
maven_deploy.dynamic_data["build_spec"]["tool"] = [maven_tool]
170+
maven_deploy.dynamic_data["build_spec"]["tools"] = [maven_tool]
171171
ci_info["service"] = gitlab_ci_service
172172
bash_commands["commands"] = []
173173
maven_deploy.dynamic_data["ci_services"] = [ci_info]
@@ -222,7 +222,7 @@ def test_gha_workflow_deployment(
222222

223223
# This Github Actions workflow uses gh-action-pypi-publish to publish the artifact.
224224
gha_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
225-
gha_deploy.dynamic_data["build_spec"]["tool"] = [pip_tool]
225+
gha_deploy.dynamic_data["build_spec"]["tools"] = [pip_tool]
226226
gha_deploy.dynamic_data["ci_services"] = [ci_info]
227227

228228
root = GitHubNode(name="root", node_type=GHWorkflowType.NONE, source_path="", parsed_obj={}, caller_path="")
@@ -283,7 +283,7 @@ def test_travis_ci_deploy(
283283
check_result = CheckResult(justification=[]) # type: ignore
284284
gradle_deploy = MockAnalyzeContext(macaron_path=macaron_path, output_dir="")
285285
gradle_deploy.component.repository.fs_path = str(repo_path.absolute())
286-
gradle_deploy.dynamic_data["build_spec"]["tool"] = [gradle_tool]
286+
gradle_deploy.dynamic_data["build_spec"]["tools"] = [gradle_tool]
287287
gradle_deploy.dynamic_data["ci_services"] = [ci_info]
288288

289289
assert check.run_check(gradle_deploy, check_result) == expect_result

tests/slsa_analyzer/checks/test_build_script_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def test_build_script_check(self) -> None:
2323

2424
# The target repo uses a build tool.
2525
use_build_tool = MockAnalyzeContext(macaron_path=MacaronTestCase.macaron_path, output_dir="")
26-
use_build_tool.dynamic_data["build_spec"]["tool"] = [maven]
26+
use_build_tool.dynamic_data["build_spec"]["tools"] = [maven]
2727

2828
assert check.run_check(use_build_tool, check_result) == CheckResultType.PASSED
2929

3030
# The target repo does not use a build tool.
3131
no_build_tool = MockAnalyzeContext(macaron_path=MacaronTestCase.macaron_path, output_dir="")
32-
no_build_tool.dynamic_data["build_spec"]["tool"] = []
32+
no_build_tool.dynamic_data["build_spec"]["tools"] = []
3333

3434
assert check.run_check(no_build_tool, check_result) == CheckResultType.FAILED

0 commit comments

Comments
 (0)