pub struct S3Endpoint {
pub host: String,
pub region: String,
pub bucket: String,
pub access_key_id: String,
pub secret_access_key: String,
}Expand description
An S3-compatible bucket and the credentials to presign URLs for it.
S3Endpoint::r2 builds the one of an R2 bucket; the runtime helpers
(presign_get,
direct_upload…) read it from the
R2_* variables and secrets. Fill the fields yourself for another
S3-compatible store (AWS S3, MinIO…). Debug hides the secret.
§Examples
use ocre::storage::S3Endpoint;
let r2 = S3Endpoint::r2("0123abcd", "blog-storage", "AKID", "s3cr3t");
assert_eq!(r2.host, "0123abcd.r2.cloudflarestorage.com");
assert_eq!(r2.region, "auto");
assert!(!format!("{r2:?}").contains("s3cr3t"));Fields§
§host: StringHost name of the S3 API, without scheme (<account_id>.r2.cloudflarestorage.com).
region: StringSigning region: auto for R2.
bucket: StringBucket name, put first in the path (/<bucket>/<key>, path style); empty when the host already names the bucket.
access_key_id: StringAccess key ID of the credentials.
secret_access_key: StringSecret access key of the credentials.
Implementations§
Source§impl S3Endpoint
impl S3Endpoint
Sourcepub fn r2(
account_id: &str,
bucket: &str,
access_key_id: &str,
secret_access_key: &str,
) -> Self
pub fn r2( account_id: &str, bucket: &str, access_key_id: &str, secret_access_key: &str, ) -> Self
The S3 endpoint of an R2 bucket: host <account_id>.r2.cloudflarestorage.com, region auto, path-style URLs.
§Examples
let r2 = ocre::storage::S3Endpoint::r2("acc", "blog-storage", "AKID", "secret");
assert_eq!((r2.host.as_str(), r2.bucket.as_str()), ("acc.r2.cloudflarestorage.com", "blog-storage"));Sourcepub fn presign(
&self,
method: &str,
key: &str,
headers: &[(&str, &str)],
query: &[(&str, &str)],
now: i64,
expires_in: u64,
) -> Result<String>
pub fn presign( &self, method: &str, key: &str, headers: &[(&str, &str)], query: &[(&str, &str)], now: i64, expires_in: u64, ) -> Result<String>
Presigns a request on key (AWS SigV4, query-string form) and returns its https:// URL.
headers are signed too (host always is): the client must send
them with exactly these values, or the store refuses the request.
query adds parameters such as response-content-disposition. The
payload is not signed (UNSIGNED-PAYLOAD). now is the Unix time
of signing (ocre::now()); the URL works for
expires_in seconds. Pure: no binding, a few microseconds of CPU.
§Errors
Error::Internal when expires_in is 0 or over MAX_EXPIRES_IN (7 days).
§Examples
use ocre::storage::S3Endpoint;
let r2 = S3Endpoint::r2("acc", "blog-storage", "AKID", "secret");
let url = r2.presign("GET", "exports/report 1.csv", &[], &[], 1_790_000_000, 300).unwrap();
assert!(url.starts_with("https://acc.r2.cloudflarestorage.com/blog-storage/exports/report%201.csv?X-Amz-Algorithm="));
assert!(url.contains("&X-Amz-Expires=300&"));
assert!(r2.presign("GET", "k", &[], &[], 1_790_000_000, 8 * 24 * 3600).is_err());Trait Implementations§
Source§impl Clone for S3Endpoint
impl Clone for S3Endpoint
Source§fn clone(&self) -> S3Endpoint
fn clone(&self) -> S3Endpoint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for S3Endpoint
impl Debug for S3Endpoint
impl Eq for S3Endpoint
Source§impl PartialEq for S3Endpoint
impl PartialEq for S3Endpoint
Source§fn eq(&self, other: &S3Endpoint) -> bool
fn eq(&self, other: &S3Endpoint) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for S3Endpoint
Auto Trait Implementations§
impl Freeze for S3Endpoint
impl RefUnwindSafe for S3Endpoint
impl Send for S3Endpoint
impl Sync for S3Endpoint
impl Unpin for S3Endpoint
impl UnsafeUnpin for S3Endpoint
impl UnwindSafe for S3Endpoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.