-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanups, fixing git-clean, dry-run option
- Loading branch information
Showing
18 changed files
with
320 additions
and
148 deletions.
There are no files selected for viewing
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,64 @@ | ||
use crate::prelude::*; | ||
use aws_sdk_s3::model::ObjectCannedAcl; | ||
use aws_sdk_s3::output::PutObjectOutput; | ||
use aws_sdk_s3::types::ByteStream; | ||
use bytes::Buf; | ||
|
||
pub async fn client_from_env() -> aws_sdk_s3::Client { | ||
aws_sdk_s3::Client::new(&aws_config::load_from_env().await) | ||
} | ||
|
||
#[derive(Clone, Derivative)] | ||
#[derivative(Debug)] | ||
pub struct BucketContext { | ||
#[derivative(Debug = "ignore")] | ||
pub client: aws_sdk_s3::Client, | ||
pub bucket: String, | ||
pub upload_acl: ObjectCannedAcl, | ||
pub key_prefix: String, | ||
} | ||
|
||
impl BucketContext {} | ||
|
||
impl BucketContext { | ||
pub async fn get(&self, path: &str) -> Result<ByteStream> { | ||
Ok(self | ||
.client | ||
.get_object() | ||
.bucket(&self.bucket) | ||
.key(format!("{}/{}", self.key_prefix, path)) | ||
.send() | ||
.await? | ||
.body) | ||
} | ||
|
||
pub async fn put(&self, path: &str, data: ByteStream) -> Result<PutObjectOutput> { | ||
dbg!(self | ||
.client | ||
.put_object() | ||
.bucket(&self.bucket) | ||
.acl(self.upload_acl.clone()) | ||
.key(format!("{}/{}", self.key_prefix, path)) | ||
.body(data)) | ||
.send() | ||
.await | ||
.anyhow_err() | ||
} | ||
|
||
#[instrument] | ||
pub async fn put_file(&self, path: &Path) -> Result<PutObjectOutput> { | ||
let stream = ByteStream::from_path(path).await?; | ||
let path = path.file_name().with_context(|| format!("Path {:?} has no file name", path))?; | ||
self.put(path.as_str(), stream).await | ||
} | ||
|
||
pub async fn get_yaml<T: DeserializeOwned>(&self, path: &str) -> Result<T> { | ||
let text = self.get(path).await?.collect().await?; | ||
serde_yaml::from_reader(text.reader()).anyhow_err() | ||
} | ||
|
||
pub async fn put_yaml(&self, path: &str, data: &impl Serialize) -> Result<PutObjectOutput> { | ||
let buf = serde_yaml::to_string(data)?; | ||
self.put(path, ByteStream::from(buf.into_bytes())).await | ||
} | ||
} |
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
Oops, something went wrong.