rusty_oss/actions/
mod.rs

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