Skip to content

Commit

Permalink
Use sha256 and new Fedora bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcrane committed Mar 11, 2024
1 parent 7ea79e8 commit 9852de7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ private async Task<ImportSource> GetImportSource(string source, Uri intendedPare

// Unless coming from other information, we *require* that S3 source folders have sha256 hashes in their metadata
// so we don't have to do this:

// TODAY
var s3Stream = await s3Client!.GetObjectStreamAsync(obj.BucketName, obj.Key, null);
var sha512Digest = Checksum.Sha512FromStream(s3Stream);
var sha256Digest = Checksum.Sha256FromStream(s3Stream);
// (and all our Fedora objects have sha-256)
// We can also do an eTag comparison for smaller files
// We can also do a size comparison as a sanity check - this can't catch all changes obvs
Expand All @@ -384,7 +386,7 @@ private async Task<ImportSource> GetImportSource(string source, Uri intendedPare
Path = sourcePath,
StorageType = StorageTypes.S3,
ExternalLocation = $"s3://{obj.BucketName}/{obj.Key}",
Digest = sha512Digest,
Digest = sha256Digest,
ContentType = GetDefaultContentType(nameAndParentPath.Name) // we may overwrite this later, e.g., from PREMIS data
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Region": "eu-west-1"
},
"Fedora-AWS-S3": {
"bucket": "uol-expts-fedora-01"
"bucket": "uol-expts-fedora-650"
},
"AllowedHosts": "*"
}
6 changes: 3 additions & 3 deletions LeedsExperiment/Preservation/FedoraWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private async void EnsureChecksum(BinaryFile binaryFile)
{
case StorageTypes.FileSystem:
var fi = new FileInfo(binaryFile.ExternalLocation);
expected = Checksum.Sha512FromFile(fi);
expected = Checksum.Sha256FromFile(fi);
break;
case StorageTypes.S3:
// TODO - get the SHA256 algorithm from AWS directly rather than compute it here
Expand All @@ -233,7 +233,7 @@ private async void EnsureChecksum(BinaryFile binaryFile)
// This would be an efficient way of doing this - but with this naive implementation
// we're going to read the object twice
var s3Stream = await s3Client!.GetObjectStreamAsync(s3Uri.Bucket, s3Uri.Key, null);
expected = Checksum.Sha512FromStream(s3Stream);
expected = Checksum.Sha256FromStream(s3Stream);
// could get a byte array here and then pass it along eventually to MakeBinaryPutOrPost
// for now just read it twice.
// Later we'll get the sha256 checksum from metadata
Expand Down Expand Up @@ -321,7 +321,7 @@ private async Task<HttpRequestMessage> MakeBinaryPutOrPost(HttpMethod httpMethod
{
var req = MakeHttpRequestMessage(location, httpMethod)
.InTransaction(transaction)
.WithDigest(binaryFile.Digest, "sha-512"); // move algorithm choice to config
.WithDigest(binaryFile.Digest, "sha-256"); // move algorithm choice to constant
if (httpMethod == HttpMethod.Post)
{
req.WithSlug(binaryFile.Slug);
Expand Down

0 comments on commit 9852de7

Please sign in to comment.