Skip to main content

coven_storage/
lib.rs

1//! The cloud home and what Coven keeps in it.
2//!
3//! A `CloudHome` is raw bytes in and out of one provider — S3 and its
4//! compatibles, CloudKit, and the OAuth providers (Google Drive, Dropbox,
5//! OneDrive). Above it, `CloudSyncConnection` applies the key layout and the
6//! at-rest protection, and exposes the exact-slot protocol-object and blob
7//! operations replication runs against. Beside them sit the join and restore
8//! codes that carry a home's coordinates between devices, and the OAuth
9//! authorization flow that obtains a provider session in the first place.
10
11pub mod cloud;
12mod cloud_object_storage;
13mod local_file;
14pub mod oauth;
15mod objects;
16pub mod provider_probe;
17mod remote;
18
19pub use cloud_object_storage::*;
20pub use objects::*;
21pub use remote::*;
22
23pub use cloud::cloudkit::{
24    CloudKitAcceptedShareRecord, CloudKitAtomicCreateBatch, CloudKitOps, CloudKitProviderIdentity,
25    CloudKitRecordCreate, CloudKitRecordVersion, CloudKitScope, CloudKitShare,
26    CloudKitShareAcceptance, CloudKitSharePermission,
27};
28pub use cloud::s3::S3CloudHome;
29#[cfg(any(test, feature = "test-utils"))]
30pub use cloud::test_utils::InMemoryCloudHome;
31pub use cloud::{
32    no_progress, write_cloud_object_stream, BlobBody, BoxPartSink, CloudAccessOutcome,
33    CloudAccessState, CloudFileReadError, CloudHome, CloudHomeError, CloudHomeJoinInfo,
34    CloudObjectStream, CloudObjectVersion, CloudVersionedObject, ConditionalWriteOutcome,
35    DownloadProgress, ExactCloudHome, ExactCreateOutcome, ExactSlotStorage, ExactUpload,
36    ExactUploadSource, PartSink, UploadControl, UploadProgress,
37};
38
39#[cfg(feature = "oauth-providers")]
40pub async fn fetch_account_email(
41    provider: coven_foundation::config::CloudProvider,
42    tokens: &crate::oauth::OAuthTokens,
43) -> Result<String, crate::oauth::OAuthError> {
44    use coven_foundation::config::CloudProvider;
45
46    let result = match provider {
47        CloudProvider::GoogleDrive => cloud::account_email::fetch_google(tokens).await,
48        CloudProvider::Dropbox => cloud::account_email::fetch_dropbox(tokens).await,
49        CloudProvider::OneDrive => cloud::account_email::fetch_onedrive(tokens).await,
50        other => {
51            return Err(crate::oauth::OAuthError::UnsupportedProvider(other));
52        }
53    };
54    result.map_err(crate::oauth::OAuthError::AccountFetch)
55}