@@ -149,38 +149,33 @@ def _extract_from_slsa_v1(payload: InTotoV1Payload) -> tuple[str | None, str | N
149
149
logger .debug ("No predicate in payload statement." )
150
150
return None , None
151
151
152
- build_def = json_extract (predicate , ["buildDefinition" ], dict )
153
- if not build_def :
154
- return None , None
155
-
156
- build_type = json_extract (build_def , ["buildType" ], str )
157
- if not build_type :
158
- return None , None
152
+ build_def = ProvenancePredicate .find_build_def (payload .statement )
159
153
160
154
# Extract the repository URL.
161
- match build_type :
162
- case "https://slsa-framework.github.io/gcb-buildtypes/triggered-build/v1" :
163
- repo = json_extract (build_def , ["externalParameters" , "sourceToBuild" , "repository" ], str )
164
- if not repo :
165
- repo = json_extract (build_def , ["externalParameters" , "configSource" , "repository" ], str )
166
- case "https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1" :
167
- repo = json_extract (build_def , ["externalParameters" , "workflow" , "repository" ], str )
168
- case "https://github.com/oracle/macaron/tree/main/src/macaron/resources/provenance-buildtypes/oci/v1" :
169
- repo = json_extract (build_def , ["externalParameters" , "source" ], str )
170
- case _:
171
- logger .debug ("Unsupported build type for SLSA v1: %s" , build_type )
172
- return None , None
155
+ if isinstance (build_def , SLSAGCBBuildDefinitionV1 ):
156
+ repo = json_extract (predicate , ["buildDefinition" , "externalParameters" , "sourceToBuild" , "repository" ], str )
157
+ if not repo :
158
+ repo = json_extract (predicate , ["buildDefinition" , "externalParameters" , "configSource" , "repository" ], str )
159
+ elif isinstance (build_def , SLSAGithubActionsBuildDefinitionV1 ):
160
+ repo = json_extract (predicate , ["buildDefinition" , "externalParameters" , "workflow" , "repository" ], str )
161
+ elif isinstance (build_def , SLSAOCIBuildDefinitionV1 ):
162
+ repo = json_extract (predicate , ["buildDefinition" , "externalParameters" , "source" ], str )
163
+ else :
164
+ logger .debug ("Unsupported build type for SLSA v1: %s" , type (build_def ))
165
+ return None , None
173
166
174
167
if not repo :
175
168
logger .debug ("Repo URL not found in SLSA v1 payload." )
176
169
return None , None
177
170
178
171
# Extract the commit hash.
179
172
commit = None
180
- if build_type == "https://github.com/oracle/macaron/tree/main/src/macaron/resources/provenance-buildtypes/oci/v1" :
181
- commit = json_extract (build_def , ["internalParameters" , "buildEnvVar" , "BLD_COMMIT_HASH" ], str )
173
+ if isinstance (build_def , SLSAOCIBuildDefinitionV1 ):
174
+ commit = json_extract (
175
+ predicate , ["buildDefinition" , "internalParameters" , "buildEnvVar" , "BLD_COMMIT_HASH" ], str
176
+ )
182
177
else :
183
- deps = json_extract (build_def , ["resolvedDependencies" ], list )
178
+ deps = json_extract (predicate , ["buildDefinition" , "resolvedDependencies" ], list )
184
179
if not deps :
185
180
return repo , None
186
181
for dep in deps :
0 commit comments