@@ -181,53 +181,63 @@ def upload(self, request, path):
181181 serializer = PackageUploadSerializer (data = request .data )
182182 serializer .is_valid (raise_exception = True )
183183 artifact , filename = serializer .validated_data ["content" ]
184+ attestations = serializer .validated_data .get ("attestations" , None )
184185 repo_content = self .get_content (self .get_repository_version (self .distribution ))
185186 if repo_content .filter (filename = filename ).exists ():
186187 return HttpResponseBadRequest (reason = f"Package { filename } already exists in index" )
187188
188189 if settings .PYTHON_GROUP_UPLOADS :
189- return self .upload_package_group (repo , artifact , filename , request .session )
190+ return self .upload_package_group (
191+ repo , artifact , filename , attestations , request .session
192+ )
190193
191194 result = dispatch (
192195 tasks .upload ,
193196 exclusive_resources = [artifact , repo ],
194197 kwargs = {
195198 "artifact_sha256" : artifact .sha256 ,
196199 "filename" : filename ,
200+ "attestations" : attestations ,
197201 "repository_pk" : str (repo .pk ),
198202 },
199203 )
200204 return OperationPostponedResponse (result , request )
201205
202- def upload_package_group (self , repo , artifact , filename , session ):
206+ def upload_package_group (self , repo , artifact , filename , attestations , session ):
203207 """Steps 4 & 5, spawns tasks to add packages to index."""
204208 start_time = datetime .now (tz = timezone .utc ) + timedelta (seconds = 5 )
205209 task = "updated"
206210 if not session .get ("start" ):
207- task = self .create_group_upload_task (session , repo , artifact , filename , start_time )
211+ task = self .create_group_upload_task (
212+ session , repo , artifact , filename , attestations , start_time
213+ )
208214 else :
209215 sq = Session .objects .select_for_update (nowait = True ).filter (pk = session .session_key )
210216 try :
211217 with transaction .atomic ():
212218 sq .first ()
213219 current_start = datetime .fromisoformat (session ["start" ])
214220 if current_start >= datetime .now (tz = timezone .utc ):
215- session ["artifacts" ].append ((str (artifact .sha256 ), filename ))
221+ session ["artifacts" ].append ((str (artifact .sha256 ), filename , attestations ))
216222 session ["start" ] = str (start_time )
217223 session .modified = False
218224 session .save ()
219225 else :
220226 raise DatabaseError
221227 except DatabaseError :
222228 session .cycle_key ()
223- task = self .create_group_upload_task (session , repo , artifact , filename , start_time )
229+ task = self .create_group_upload_task (
230+ session , repo , artifact , filename , attestations , start_time
231+ )
224232 data = {"session" : session .session_key , "task" : task , "task_start_time" : start_time }
225233 return Response (data = data )
226234
227- def create_group_upload_task (self , cur_session , repository , artifact , filename , start_time ):
235+ def create_group_upload_task (
236+ self , cur_session , repository , artifact , filename , attestations , start_time
237+ ):
228238 """Creates the actual task that adds the packages to the index."""
229239 cur_session ["start" ] = str (start_time )
230- cur_session ["artifacts" ] = [(str (artifact .sha256 ), filename )]
240+ cur_session ["artifacts" ] = [(str (artifact .sha256 ), filename , attestations )]
231241 cur_session .modified = False
232242 cur_session .save ()
233243 task = dispatch (
@@ -536,7 +546,7 @@ def retrieve(self, request, path, package, version, filename):
536546 name__normalize = package , version = version , filename = filename
537547 ).first ()
538548 if package_content :
539- provenance = PackageProvenance . objects .filter (package = package_content ).first ()
549+ provenance = self . get_provenances ( repo_ver ) .filter (package = package_content ).first ()
540550 if provenance :
541551 return Response (data = provenance .provenance )
542552 return HttpResponseNotFound (f"{ package } { version } { filename } provenance does not exist." )
0 commit comments