From 2043d9ee1fbde61ca36b1ae848ac45ead5bdcfb5 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 1 May 2019 15:39:23 -0400 Subject: [PATCH] set checksums as headers during first upload --- scripts/binary/s3-api.ts | 2 ++ scripts/binary/upload-unique-binary.coffee | 35 ++++++---------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/scripts/binary/s3-api.ts b/scripts/binary/s3-api.ts index 70ba2a5fd8..cf371ace45 100644 --- a/scripts/binary/s3-api.ts +++ b/scripts/binary/s3-api.ts @@ -120,6 +120,8 @@ export const s3helpers = { /** * Setting user metadata can be accomplished with copying the object back onto itself * with replaced metadata object. + * + * Hmm, does this need to fetch metadata and ACL first, then set it back? */ setUserMetadata (bucket: string, key: string, metadata: S3.Metadata, s3: S3): Promise { return new Promise((resolve, reject) => { diff --git a/scripts/binary/upload-unique-binary.coffee b/scripts/binary/upload-unique-binary.coffee index 42382e8f41..62bad96271 100644 --- a/scripts/binary/upload-unique-binary.coffee +++ b/scripts/binary/upload-unique-binary.coffee @@ -72,7 +72,14 @@ uploadFile = (options) -> headers = {} headers["Cache-Control"] = "no-cache" - key = null + # add custom metadata with checksums + # every value should be a string + checksum = hasha.fromFileSync(options.file) + size = fs.statSync(options.file).size + console.log('SHA256 checksum %s', checksum) + console.log('size', size) + headers["x-amz-meta-checksum"] = checksum + headers["x-amz-meta-size"] = String(size) gulp.src(options.file) .pipe rename (p) => @@ -81,34 +88,12 @@ uploadFile = (options) -> console.log("renaming upload to", p.dirname, p.basename) la(check.unemptyString(p.basename), "missing basename") la(check.unemptyString(p.dirname), "missing dirname") - key = p.dirname + uploadFileName p .pipe debug() .pipe publisher.publish(headers) .pipe awspublish.reporter() .on "error", reject - .on "end", () -> resolve(key) - -setChecksum = (filename, key) => - console.log('setting checksum for file %s', filename) - console.log('on s3 object %s', key) - - la(check.unemptyString(filename), 'expected filename', filename) - la(check.unemptyString(key), 'expected uploaded S3 key', key) - - checksum = hasha.fromFileSync(filename) - size = fs.statSync(filename).size - console.log('SHA256 checksum %s', checksum) - console.log('size', size) - - aws = uploadUtils.getS3Credentials() - s3 = s3helpers.makeS3(aws) - # S3 object metadata can only have string values - metadata = { - checksum, - size: String(size) - } - s3helpers.setUserMetadata(aws.bucket, key, metadata, s3) + .on "end", resolve uploadUniqueBinary = (args = []) -> options = minimist(args, { @@ -140,8 +125,6 @@ uploadUniqueBinary = (args = []) -> options.platformArch = uploadUtils.getUploadNameByOsAndArch(platform) uploadFile(options) - .then (key) -> - setChecksum(options.file, key) .then () -> cdnUrl = getCDN({ version: options.version,