Skip to main content

rusty_s3/actions/
mod.rs

1//! S3 request building and response parsing support
2
3use std::time::Duration;
4
5use jiff::Timestamp;
6use url::Url;
7
8pub use self::create_bucket::CreateBucket;
9pub use self::delete_bucket::DeleteBucket;
10pub use self::delete_object::DeleteObject;
11#[cfg(feature = "full")]
12pub use self::delete_objects::{DeleteObjects, DeleteObjectsResponse, ObjectIdentifier};
13#[cfg(feature = "full")]
14pub use self::get_bucket_policy::{GetBucketPolicy, GetBucketPolicyResponse};
15pub use self::get_object::GetObject;
16pub use self::head_bucket::HeadBucket;
17pub use self::head_object::HeadObject;
18#[cfg(feature = "xml")]
19#[doc(inline)]
20pub use self::list_objects_v2::{ListObjectsV2, ListObjectsV2Response};
21pub use self::multipart_upload::abort::AbortMultipartUpload;
22#[cfg(feature = "xml")]
23pub use self::multipart_upload::complete::CompleteMultipartUpload;
24#[cfg(feature = "xml")]
25pub use self::multipart_upload::create::{CreateMultipartUpload, CreateMultipartUploadResponse};
26#[cfg(feature = "xml")]
27pub use self::multipart_upload::list_parts::{ListParts, ListPartsResponse};
28pub use self::multipart_upload::upload::UploadPart;
29pub use self::put_object::PutObject;
30use crate::{Map, Method};
31
32#[cfg(feature = "xml")]
33pub(crate) const S3_XML_NS: &str = "http://s3.amazonaws.com/doc/2006-03-01/";
34
35mod create_bucket;
36mod delete_bucket;
37mod delete_object;
38#[cfg(feature = "full")]
39mod delete_objects;
40#[cfg(feature = "full")]
41mod get_bucket_policy;
42mod get_object;
43mod head_bucket;
44mod head_object;
45#[cfg(feature = "xml")]
46pub mod list_objects_v2;
47mod multipart_upload;
48mod put_object;
49
50/// A request which can be signed
51pub trait S3Action<'a> {
52    const METHOD: Method;
53
54    /// Sign a request for this action, using `METHOD` for the [`Method`]
55    fn sign(&self, expires_in: Duration) -> Url {
56        let now = Timestamp::now();
57        self.sign_with_time(expires_in, &now)
58    }
59
60    /// Get a mutable reference to the query string of this action
61    fn query_mut(&mut self) -> &mut Map<'a>;
62
63    /// Get a mutable reference to the signed headers of this action
64    ///
65    /// Headers specified here must also be present in the final request,
66    /// with the same value specified, otherwise the S3 API will return an error.
67    fn headers_mut(&mut self) -> &mut Map<'a>;
68
69    /// Takes the time at which the URL should be signed
70    /// Used for testing purposes
71    fn sign_with_time(&self, expires_in: Duration, time: &Timestamp) -> Url;
72}