forked from GothenburgBitFactory/taskwarrior
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,555 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#![allow(unused_variables, dead_code)] | ||
use super::service::Service; | ||
use google_cloud_storage::client::{Client, ClientConfig}; | ||
use google_cloud_storage::http::objects; | ||
use tokio::runtime::Runtime; | ||
|
||
/// A [`Service`] implementation based on the Google Cloud Storage service. | ||
pub(in crate::server) struct GcpService { | ||
client: Client, | ||
rt: Runtime, | ||
bucket: String, | ||
encryption_secret: Vec<u8>, | ||
} | ||
|
||
impl GcpService { | ||
pub(in crate::server) fn new(bucket: String, encryption_secret: Vec<u8>) -> Self { | ||
let config = ClientConfig::default().anonymous(); // TODO | ||
Self { | ||
client: Client::new(config), | ||
rt: Runtime::new().expect("Could not build async runtime"), | ||
bucket, | ||
encryption_secret, | ||
} | ||
} | ||
} | ||
|
||
impl Service for GcpService { | ||
fn put(&mut self, name: &[u8], value: &[u8]) -> crate::errors::Result<()> { | ||
let name = String::from_utf8(name.to_vec()).expect("non-UTF8 object name"); | ||
let upload_type = objects::upload::UploadType::Simple(objects::upload::Media::new(name)); | ||
self.rt.block_on(self.client.upload_object( | ||
&objects::upload::UploadObjectRequest { | ||
bucket: self.bucket.clone(), | ||
..Default::default() | ||
}, | ||
value.to_vec(), | ||
&upload_type, | ||
))?; | ||
Ok(()) | ||
} | ||
|
||
fn get(&mut self, name: &[u8]) -> crate::errors::Result<Option<Vec<u8>>> { | ||
let name = String::from_utf8(name.to_vec()).expect("non-UTF8 object name"); | ||
let data = self.rt.block_on(self.client.download_object( | ||
&objects::get::GetObjectRequest { | ||
bucket: self.bucket.clone(), | ||
object: name, | ||
..Default::default() | ||
}, | ||
&objects::download::Range::default(), | ||
))?; | ||
Ok(Some(data)) | ||
} | ||
|
||
fn del(&mut self, name: &[u8]) -> crate::errors::Result<()> { | ||
todo!() | ||
} | ||
|
||
fn list<'a>( | ||
&'a mut self, | ||
prefix: &'a [u8], | ||
) -> crate::errors::Result<Box<dyn Iterator<Item = &'a [u8]> + 'a>> { | ||
todo!() | ||
} | ||
|
||
fn compare_and_swap( | ||
&mut self, | ||
name: &[u8], | ||
existing_value: Option<Vec<u8>>, | ||
new_value: Vec<u8>, | ||
) -> crate::errors::Result<bool> { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*! | ||
* Support for cloud-service-backed sync. | ||
* | ||
* All of these operate using a similar approach, with specific patterns of object names. The | ||
* process of adding a new version requires a compare-and-swap operation that sets a new version | ||
* as the "latest" only if the existing "latest" has the expected value. This ensures a continuous | ||
* chain of versions, even if multiple replicas attempt to sync at the same time. | ||
*/ | ||
|
||
mod server; | ||
mod service; | ||
|
||
pub(in crate::server) use server::CloudServer; | ||
|
||
#[cfg(feature = "server-gcp")] | ||
pub(in crate::server) mod gcp; |
Oops, something went wrong.