Skip to content

Commit

Permalink
Validate tarbal checksum on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jan 16, 2024
1 parent 8193695 commit d6421db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 4 additions & 5 deletions registry/src/routes/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,15 @@ pub async fn publish(
// The uploaded contents in .tar.gz
let gzipped_archive = file.freeze();

let digest = sha256::digest(&*gzipped_archive);

// Extract the .tar.gz and its relevant contentss
// Extract the .tar.gz and its relevant contents
let (extension_views, pg_version) =
extractor::extract_extension_view(&gzipped_archive, &new_extension).map_err(|err| {
tracing::error!("Failed to decompress archive: {err}");
ExtensionRegistryError::ArchiveError
})?;

// TODO(ianstanton) Generate checksum
let file_byte_stream = ByteStream::from(gzipped_archive.clone());
let digest = sha256::digest(&*gzipped_archive);
let file_byte_stream = ByteStream::from(gzipped_archive);
let client = aws_sdk_s3::Client::new(&aws_config);
let uploaded_path = upload_extension(
&cfg.bucket_name,
Expand All @@ -310,6 +308,7 @@ pub async fn publish(
&new_extension,
&new_extension.vers,
pg_version,
&digest,
)
.await?;

Expand Down
4 changes: 4 additions & 0 deletions registry/src/uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub async fn upload(
path: &str,
content: ByteStream,
content_type: &str,
sha256: &str,
) -> Result<PutObjectOutput, SdkError<PutObjectError>> {
let obj = s3_client
.put_object()
Expand All @@ -46,6 +47,7 @@ pub async fn upload(
.key(path)
.cache_control(CACHE_CONTROL_IMMUTABLE)
.set_server_side_encryption(Some(Aes256))
.checksum_sha256(sha256)
.send()
.await;
debug!("OBJECT: {:?}", obj);
Expand All @@ -62,6 +64,7 @@ pub async fn upload_extension(
extension: &ExtensionUpload,
extension_version: &semver::Version,
pg_version: u8,
sha256: &str,
) -> Result<String, ExtensionRegistryError> {
let path_in_bucket =
extension_path(&extension.name, &extension_version.to_string(), pg_version);
Expand All @@ -72,6 +75,7 @@ pub async fn upload_extension(
&path_in_bucket,
file,
"application/gzip",
sha256,
)
.await?;

Expand Down

0 comments on commit d6421db

Please sign in to comment.