Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/integration-tests/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use storage::client::StorageControl;
use storage::model::Bucket;
use storage::model::bucket::iam_config::UniformBucketLevelAccess;
use storage::model::bucket::{HierarchicalNamespace, IamConfig};
use storage::model::request_helpers::KeyAes256;
use storage::model_ext::KeyAes256;
use storage::streaming_source::{Seek, SizeHint, StreamingSource};
use storage_samples::cleanup_bucket;

Expand Down
4 changes: 2 additions & 2 deletions src/storage/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ impl std::fmt::Display for ChecksumMismatch {
///
/// # Example:
/// ```
/// # use google_cloud_storage::{model::request_helpers::KeyAes256, error::KeyAes256Error};
/// # use google_cloud_storage::{model_ext::KeyAes256, error::KeyAes256Error};
/// let invalid_key_bytes: &[u8] = b"too_short_key"; // Less than 32 bytes
/// let result = KeyAes256::new(invalid_key_bytes);
///
/// assert!(matches!(result, Err(KeyAes256Error::InvalidLength)));
/// ```
///
/// [KeyAes256]: crate::model::request_helpers::KeyAes256
/// [KeyAes256]: crate::model_ext::KeyAes256
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum KeyAes256Error {
Expand Down
5 changes: 3 additions & 2 deletions src/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ pub mod builder {
}
}
pub mod error;
pub mod model;
/// The messages and enums that are part of this client library.
pub use crate::control::model;
pub mod model_ext;
pub use crate::control::stub;

pub use storage::read_object::ObjectHighlights;
pub use storage::read_object::ReadObjectResponse;

#[allow(dead_code)]
Expand Down
24 changes: 0 additions & 24 deletions src/storage/src/model.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,65 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Types used in the request builders ([ReadObject] and/or [WriteObject])
//! to improve type safety or ergonomics.
//!
//! [ReadObject]: crate::builder::storage::ReadObject
//! [WriteObject]: crate::builder::storage::WriteObject
//! Extends [model][crate::model] with types that improve type safety and/or
//! ergonomics.

use crate::error::KeyAes256Error;
use sha2::{Digest, Sha256};

/// ObjectHighlights contains select metadata from a [crate::model::Object].
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ObjectHighlights {
/// The content generation of this object. Used for object versioning.
pub generation: i64,

/// The version of the metadata for this generation of this
/// object. Used for preconditions and for detecting changes in metadata. A
/// metageneration number is only meaningful in the context of a particular
/// generation of a particular object.
pub metageneration: i64,

/// Content-Length of the object data in bytes, matching [RFC 7230 §3.3.2].
///
/// [rfc 7230 §3.3.2]: https://tools.ietf.org/html/rfc7230#section-3.3.2
pub size: i64,

/// Content-Encoding of the object data, matching [RFC 7231 §3.1.2.2].
///
/// [rfc 7231 §3.1.2.2]: https://tools.ietf.org/html/rfc7231#section-3.1.2.2
pub content_encoding: String,

/// Hashes for the data part of this object. The checksums of the complete
/// object regardless of data range. If the object is read in full, the
/// client should compute one of these checksums over the read object and
/// compare it against the value provided here.
pub checksums: std::option::Option<crate::model::ObjectChecksums>,

/// Storage class of the object.
pub storage_class: String,

/// Content-Language of the object data, matching [RFC 7231 §3.1.3.2].
///
/// [rfc 7231 §3.1.3.2]: https://tools.ietf.org/html/rfc7231#section-3.1.3.2
pub content_language: String,

/// Content-Type of the object data, matching [RFC 7231 §3.1.1.5]. If an
/// object is stored without a Content-Type, it is served as
/// `application/octet-stream`.
///
/// [rfc 7231 §3.1.1.5]: https://tools.ietf.org/html/rfc7231#section-3.1.1.5
pub content_type: String,

/// Content-Disposition of the object data, matching [RFC 6266].
///
/// [rfc 6266]: https://tools.ietf.org/html/rfc6266
pub content_disposition: String,

/// The etag of the object.
pub etag: String,
}

#[derive(Debug)]
/// KeyAes256 represents an AES-256 encryption key used with the
/// Customer-Supplied Encryption Keys (CSEK) feature.
Expand All @@ -32,15 +82,15 @@ use sha2::{Digest, Sha256};
///
/// Creating a `KeyAes256` instance from a valid byte slice:
/// ```
/// # use google_cloud_storage::{model::request_helpers::KeyAes256, error::KeyAes256Error};
/// # use google_cloud_storage::{model_ext::KeyAes256, error::KeyAes256Error};
/// let raw_key_bytes: [u8; 32] = [0x42; 32]; // Example 32-byte key
/// let key_aes_256 = KeyAes256::new(&raw_key_bytes)?;
/// # Ok::<(), KeyAes256Error>(())
/// ```
///
/// Handling an error for an invalid key length:
/// ```
/// # use google_cloud_storage::{model::request_helpers::KeyAes256, error::KeyAes256Error};
/// # use google_cloud_storage::{model_ext::KeyAes256, error::KeyAes256Error};
/// let invalid_key_bytes: &[u8] = b"too_short_key"; // Less than 32 bytes
/// let result = KeyAes256::new(invalid_key_bytes);
///
Expand All @@ -57,7 +107,7 @@ impl KeyAes256 {
///
/// # Example
/// ```
/// # use google_cloud_storage::{model::request_helpers::KeyAes256, error::KeyAes256Error};
/// # use google_cloud_storage::{model_ext::KeyAes256, error::KeyAes256Error};
/// let raw_key_bytes: [u8; 32] = [0x42; 32]; // Example 32-byte key
/// let key_aes_256 = KeyAes256::new(&raw_key_bytes)?;
/// # Ok::<(), KeyAes256Error>(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
//! [Seek]: crate::streaming_source::Seek

use super::RESUMABLE_UPLOAD_QUANTUM;
use crate::model::request_helpers::{KeyAes256, tests::create_key_helper};
use crate::model_ext::{KeyAes256, tests::create_key_helper};
use crate::storage::client::tests::{
MockBackoffPolicy, MockRetryPolicy, MockRetryThrottler, test_builder,
};
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/storage/perform_upload/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use super::*;
use crate::builder::storage::WriteObject;
use crate::model::request_helpers::{KeyAes256, tests::create_key_helper};
use crate::model_ext::{KeyAes256, tests::create_key_helper};
use crate::storage::client::tests::{test_builder, test_inner_client};
use serde_json::{Value, json};
use std::collections::BTreeMap;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/storage/perform_upload/unbuffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ mod resumable_tests;
mod tests {
use super::*;
use crate::builder::storage::WriteObject;
use crate::model::request_helpers::{KeyAes256, tests::create_key_helper};
use crate::model_ext::{KeyAes256, tests::create_key_helper};
use crate::storage::client::{
Storage,
tests::{test_builder, test_inner_client},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
//!
//! [Seek]: crate::streaming_source::Seek

use crate::model::request_helpers::{KeyAes256, tests::create_key_helper};
use crate::model_ext::{KeyAes256, tests::create_key_helper};
use crate::storage::client::{Storage, tests::test_builder};
use crate::streaming_source::{BytesSource, SizeHint, tests::UnknownSize};
use gax::retry_policy::RetryPolicyExt;
Expand Down
60 changes: 4 additions & 56 deletions src/storage/src/storage/read_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use super::client::*;
use super::*;
use crate::error::{RangeError, ReadError};
use crate::model::ObjectChecksums;
use crate::model::request_helpers::KeyAes256;
use crate::model_ext::KeyAes256;
use crate::model_ext::ObjectHighlights;
use crate::read_resume_policy::ReadResumePolicy;
use crate::storage::checksum::{
ChecksumEngine,
Expand Down Expand Up @@ -289,7 +290,7 @@ where
///
/// Example:
/// ```
/// # use google_cloud_storage::{model::request_helpers::KeyAes256, client::Storage};
/// # use google_cloud_storage::{model_ext::KeyAes256, client::Storage};
/// # async fn sample(client: &Storage) -> anyhow::Result<()> {
/// let key: &[u8] = &[97; 32];
/// let response = client
Expand Down Expand Up @@ -752,59 +753,6 @@ where
}
}

/// ObjectHighlights contains select metadata from a [crate::model::Object].
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ObjectHighlights {
/// The content generation of this object. Used for object versioning.
pub generation: i64,

/// The version of the metadata for this generation of this
/// object. Used for preconditions and for detecting changes in metadata. A
/// metageneration number is only meaningful in the context of a particular
/// generation of a particular object.
pub metageneration: i64,

/// Content-Length of the object data in bytes, matching [RFC 7230 §3.3.2].
///
/// [rfc 7230 §3.3.2]: https://tools.ietf.org/html/rfc7230#section-3.3.2
pub size: i64,

/// Content-Encoding of the object data, matching [RFC 7231 §3.1.2.2].
///
/// [rfc 7231 §3.1.2.2]: https://tools.ietf.org/html/rfc7231#section-3.1.2.2
pub content_encoding: String,

/// Hashes for the data part of this object. The checksums of the complete
/// object regardless of data range. If the object is read in full, the
/// client should compute one of these checksums over the read object and
/// compare it against the value provided here.
pub checksums: std::option::Option<crate::model::ObjectChecksums>,

/// Storage class of the object.
pub storage_class: String,

/// Content-Language of the object data, matching [RFC 7231 §3.1.3.2].
///
/// [rfc 7231 §3.1.3.2]: https://tools.ietf.org/html/rfc7231#section-3.1.3.2
pub content_language: String,

/// Content-Type of the object data, matching [RFC 7231 §3.1.1.5]. If an
/// object is stored without a Content-Type, it is served as
/// `application/octet-stream`.
///
/// [rfc 7231 §3.1.1.5]: https://tools.ietf.org/html/rfc7231#section-3.1.1.5
pub content_type: String,

/// Content-Disposition of the object data, matching [RFC 6266].
///
/// [rfc 6266]: https://tools.ietf.org/html/rfc6266
pub content_disposition: String,

/// The etag of the object.
pub etag: String,
}

/// Returns the object checksums to validate against.
///
/// For some responses, the checksums are not expected to match the data.
Expand Down Expand Up @@ -916,7 +864,7 @@ mod tests {
use super::client::tests::{test_builder, test_inner_client};
use super::*;
use crate::error::ChecksumMismatch;
use crate::model::request_helpers::{KeyAes256, tests::create_key_helper};
use crate::model_ext::{KeyAes256, tests::create_key_helper};
use futures::TryStreamExt;
use httptest::{Expectation, Server, matchers::*, responders::status_code};
use std::collections::HashMap;
Expand Down
4 changes: 2 additions & 2 deletions src/storage/src/storage/write_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::client::*;
use super::perform_upload::PerformUpload;
use super::streaming_source::{Seek, StreamingSource};
use super::*;
use crate::model::request_helpers::KeyAes256;
use crate::model_ext::KeyAes256;
use crate::storage::checksum::{
ChecksumEngine,
details::{Crc32c, Known, KnownCrc32c, KnownMd5, Md5, update as checksum_update},
Expand Down Expand Up @@ -568,7 +568,7 @@ impl<T, C> WriteObject<T, C> {
/// ```
/// # use google_cloud_storage::client::Storage;
/// # async fn sample(client: &Storage) -> anyhow::Result<()> {
/// # use google_cloud_storage::model::request_helpers::KeyAes256;
/// # use google_cloud_storage::model_ext::KeyAes256;
/// let key: &[u8] = &[97; 32];
/// let response = client
/// .write_object("projects/_/buckets/my-bucket", "my-object", "hello world")
Expand Down
Loading