diff --git a/src/v1/objects.rs b/src/v1/objects.rs index c559aa4..44a2969 100644 --- a/src/v1/objects.rs +++ b/src/v1/objects.rs @@ -1,6 +1,7 @@ //! Types and APIs for interacting with GCS [Objects](https://cloud.google.com/storage/docs/json_api/v1/objects) use crate::common::StorageClass; +use http::uri::Authority; use std::collections::BTreeMap; #[doc(hidden)] @@ -27,7 +28,6 @@ mod rewrite; pub use delete::*; pub use download::*; pub use get::*; -use http::uri::Authority; pub use insert::*; pub use list::*; pub use patch::*; @@ -37,6 +37,8 @@ pub type Timestamp = time::OffsetDateTime; /// Helper struct used to collate all of the operations available for /// [Objects](https://cloud.google.com/storage/docs/json_api/v1/objects) +/// Additionally, it can also be used to specify a custom authority. +#[derive(Debug)] pub struct Object { authority: Authority, } diff --git a/tests/objects.rs b/tests/objects.rs index db24b28..b033f38 100644 --- a/tests/objects.rs +++ b/tests/objects.rs @@ -1,3 +1,4 @@ +use http::uri::Authority; use tame_gcs::{ common::{Conditionals, StandardQueryParameters}, objects::{self, DeleteObjectOptional, InsertObjectOptional, Metadata, Object}, @@ -31,6 +32,31 @@ fn insert_vanilla() { util::requests_eq(&insert_req, &expected); } +#[test] +fn insert_vanilla_using_custom_authority() { + let insert_req = Object::with_authority(Authority::from_static("0.0.0.0:4443")) + .insert_simple( + &( + &BucketName::non_validated("bucket"), + &ObjectName::non_validated("object/with/deep/path"), + ), + "great content", + 13, + None, + ) + .unwrap(); + + let expected = http::Request::builder() + .method(http::Method::POST) + .uri("https://0.0.0.0:4443/upload/storage/v1/b/bucket/o?name=object/with/deep/path&uploadType=media&prettyPrint=false") + .header(http::header::CONTENT_TYPE, "application/octet-stream") + .header(http::header::CONTENT_LENGTH, 13) + .body("great content") + .unwrap(); + + util::requests_eq(&insert_req, &expected); +} + #[test] fn insert_json_content() { let insert_req = Object::default() @@ -75,6 +101,24 @@ fn vanilla_get() { util::requests_eq(&get_req, &expected); } +#[test] +fn vanilla_get_using_custom_authority() { + let get_req = Object::with_authority(Authority::from_static("0.0.0.0:4443")) + .get( + &ObjectId::new("bucket", "test/with/path_separators").unwrap(), + None, + ) + .unwrap(); + + let expected = http::Request::builder() + .method(http::Method::GET) + .uri("https://0.0.0.0:4443/storage/v1/b/bucket/o/test%2Fwith%2Fpath_separators?alt=json&prettyPrint=false") + .body(std::io::empty()) + .unwrap(); + + util::requests_eq(&get_req, &expected); +} + #[test] fn delete_vanilla() { let delete_req = Object::default()