s3_simple/
lib.rs

1// Copyright 2024 Sebastian Dobe <sebastiandobe@mailbox.org>
2
3#![doc = include_str!("../README.md")]
4#![forbid(unsafe_code)]
5
6use base64::engine::general_purpose;
7use base64::Engine;
8use std::env;
9
10/// S3 Bucket operations, your main entrypoint
11pub use crate::bucket::{Bucket};
12/// Custom options for bucket connections
13pub use crate::bucket::{BucketOptions};
14/// S3 Credentials
15pub use crate::credentials::{AccessKeyId, AccessKeySecret, Credentials};
16/// Specialized S3 Error type which wraps errors from different sources
17pub use crate::error::S3Error;
18/// Specialized Response objects
19pub use crate::types::{HeadObjectResult, Object, PutStreamResponse};
20pub use reqwest::Response as S3Response;
21pub use reqwest::StatusCode as S3StatusCode;
22
23mod bucket;
24mod command;
25mod constants;
26mod credentials;
27mod error;
28mod signature;
29mod types;
30
31/// S3 Region Wrapper
32#[derive(Debug, Clone)]
33pub struct Region(pub String);
34
35impl Region {
36    pub fn new<S>(region: S) -> Self
37    where
38        S: Into<String>,
39    {
40       Self(region.into())
41    }
42
43    pub fn try_from_env() -> Result<Self, S3Error> {
44        Ok(Self(env::var("S3_REGION")?))
45    }
46
47    pub fn as_str(&self) -> &str {
48        self.0.as_str()
49    }
50}
51
52fn md5_url_encode(s: &[u8]) -> String {
53    general_purpose::STANDARD.encode(md5::compute(s).as_ref())
54}