@@ -96,14 +96,16 @@ def validate(self, data):
9696 if action != "file_upload" :
9797 raise serializers .ValidationError (_ ("We do not support the :action {}" ).format (action ))
9898 file = data .get ("content" )
99+ # The Google Cloud Storage backend renames the file when the artifact is saved.
100+ filename = file .name
99101 for ext , packagetype in DIST_EXTENSIONS .items ():
100- if file . name .endswith (ext ):
102+ if filename .endswith (ext ):
101103 if (filetype := data .get ("filetype" )) and filetype != packagetype :
102104 raise serializers .ValidationError (
103105 {
104106 "filetype" : _ (
105107 "filetype {} does not match found filetype {} for file {}"
106- ).format (filetype , packagetype , file . name )
108+ ).format (filetype , packagetype , filename )
107109 }
108110 )
109111 break
@@ -113,7 +115,7 @@ def validate(self, data):
113115 "content" : _ (
114116 "Extension on {} is not a valid python extension "
115117 "(.whl, .exe, .egg, .tar.gz, .tar.bz2, .zip)"
116- ).format (file . name )
118+ ).format (filename )
117119 }
118120 )
119121
@@ -130,7 +132,7 @@ def validate(self, data):
130132 att_bundle = AttestationBundle (publisher = publisher , attestations = attestations )
131133 provenance = Provenance (attestation_bundles = [att_bundle ])
132134 try :
133- verify_provenance (file . name , sha256 , provenance , offline = True )
135+ verify_provenance (filename , sha256 , provenance , offline = True )
134136 except AttestationError as e :
135137 raise serializers .ValidationError (
136138 {"attestations" : _ ("Attestations failed verification: {}" ).format (e )}
@@ -143,8 +145,8 @@ def validate(self, data):
143145 except IntegrityError :
144146 artifact = Artifact .objects .get (sha256 = artifact .sha256 , pulp_domain = get_domain ())
145147 artifact .touch ()
146- log .info (f"Artifact for { file . name } already existed in database" )
147- data ["content" ] = (artifact , file . name )
148+ log .info (f"Artifact for { filename } already existed in database" )
149+ data ["content" ] = (artifact , filename )
148150 return data
149151
150152
0 commit comments