Skip to content

Commit 7b0a22b

Browse files
committed
cmd-sign: simplify variables switcheroo
Create a new variable for the staging location instead of pushing the staging path on the prefix, only to then peel it off later to get back to its original value.
1 parent 88b0815 commit 7b0a22b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/cmd-sign

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ def robosign_oci(args, s3, build, gpgkey):
385385
# Upload them to S3. We upload to `staging/` first, and then will move
386386
# them to their final location once they're verified.
387387
sigstore_bucket, sigstore_prefix = get_bucket_and_prefix(args.s3_sigstore)
388-
sigstore_prefix = os.path.join(sigstore_prefix, 'staging')
388+
sigstore_staging = os.path.join(sigstore_prefix, 'staging')
389389

390390
# First, empty out staging/ so we don't accumulate cruft over time
391391
# https://stackoverflow.com/a/59026702
392392
# Note this assumes we don't run in parallel on the same sigstore
393393
# target, which is the case for us since only one release job can run at
394394
# a time per-stream and the S3 target location is stream-based.
395-
staging_objects = s3.list_objects_v2(Bucket=sigstore_bucket, Prefix=sigstore_prefix)
395+
staging_objects = s3.list_objects_v2(Bucket=sigstore_bucket, Prefix=sigstore_staging)
396396
objects_to_delete = [{'Key': obj['Key']} for obj in staging_objects.get('Contents', [])]
397397
if len(objects_to_delete) > 0:
398398
print(f'Deleting {len(objects_to_delete)} stale files')
@@ -401,7 +401,7 @@ def robosign_oci(args, s3, build, gpgkey):
401401
# now, upload the ones we want
402402
artifacts = []
403403
for f in files_to_upload:
404-
s3_key = os.path.join(sigstore_prefix, f['filename'])
404+
s3_key = os.path.join(sigstore_staging, f['filename'])
405405
print(f"Uploading s3://{sigstore_bucket}/{s3_key}")
406406
s3.upload_file(f['path'], sigstore_bucket, s3_key)
407407
artifacts.append({
@@ -435,10 +435,8 @@ def robosign_oci(args, s3, build, gpgkey):
435435
gpg('--quiet', '--import', gpgkey)
436436

437437
sig_counter = {}
438-
# peel off the '/staging' bit
439-
final_sigstore_prefix = os.path.dirname(sigstore_prefix)
440438
for f in files_to_upload:
441-
stg_s3_key = os.path.join(sigstore_prefix, f['filename'])
439+
stg_s3_key = os.path.join(sigstore_staging, f['filename'])
442440
stg_sig_s3_key = stg_s3_key + '.sig'
443441

444442
tmp_sig_path = os.path.join(d, f['filename'] + '.sig')
@@ -511,7 +509,7 @@ def robosign_oci(args, s3, build, gpgkey):
511509
sig_counter[sig_prefix] = sig_number
512510

513511
# upload to final location and make public
514-
final_s3_key = os.path.join(final_sigstore_prefix, sig_prefix, f"signature-{sig_number}")
512+
final_s3_key = os.path.join(sigstore_prefix, sig_prefix, f"signature-{sig_number}")
515513
print(f"Uploading {f['path']} to s3://{sigstore_bucket}/{final_s3_key}")
516514
s3.upload_file(f['path'], sigstore_bucket, final_s3_key, ExtraArgs={'ACL': 'public-read'})
517515

0 commit comments

Comments
 (0)