Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
02e70fe268
commit
a17dd2bd10
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1184,6 +1184,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nats",
|
"nats",
|
||||||
"prost",
|
"prost",
|
||||||
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -23,6 +23,7 @@ nats = "0.24.1"
|
|||||||
walkdir = "2.4.0"
|
walkdir = "2.4.0"
|
||||||
tar = "0.4.40"
|
tar = "0.4.40"
|
||||||
tokio-stream = { version = "0.1.14", features = ["full"] }
|
tokio-stream = { version = "0.1.14", features = ["full"] }
|
||||||
|
rand = "0.8.5"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tonic-build = "0.11.0"
|
tonic-build = "0.11.0"
|
||||||
|
@ -72,4 +72,32 @@ impl FileStore {
|
|||||||
|
|
||||||
Ok(archive_path)
|
Ok(archive_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_temp(&self, artifact_id: UploadArtifactID) -> anyhow::Result<PathBuf> {
|
||||||
|
tracing::trace!("getting archive: {}", artifact_id.to_string());
|
||||||
|
|
||||||
|
let archive_name = format!("temp/{}.tar", &artifact_id.to_string());
|
||||||
|
|
||||||
|
let obj = self
|
||||||
|
.client
|
||||||
|
.get_object()
|
||||||
|
.bucket("mybucket")
|
||||||
|
.key(&archive_name)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let archive_path = temp_dir()
|
||||||
|
.join("flux_releaser")
|
||||||
|
.join("downloads/cache")
|
||||||
|
.join(&archive_name);
|
||||||
|
tokio::fs::create_dir_all(archive_path.parent().unwrap()).await?;
|
||||||
|
let mut archive_file = tokio::fs::File::create(&archive_path).await?;
|
||||||
|
let mut buf_reader = BufReader::new(obj.body.into_async_read());
|
||||||
|
|
||||||
|
tokio::io::copy(&mut buf_reader, &mut archive_file).await?;
|
||||||
|
|
||||||
|
tracing::debug!("created archive: {}", archive_path.display());
|
||||||
|
|
||||||
|
Ok(archive_path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,16 @@ impl From<uuid::Uuid> for UploadArtifactID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<String> for UploadArtifactID {
|
||||||
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
|
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||||
|
let uuid = uuid::Uuid::parse_str(&value)?;
|
||||||
|
|
||||||
|
Ok(Self(uuid))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Deref for UploadArtifactID {
|
impl Deref for UploadArtifactID {
|
||||||
type Target = uuid::Uuid;
|
type Target = uuid::Uuid;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ use flux_releaser::{
|
|||||||
},
|
},
|
||||||
services::file_store::extensions::FileStoreExt,
|
services::file_store::extensions::FileStoreExt,
|
||||||
};
|
};
|
||||||
|
use rand::{thread_rng, Rng};
|
||||||
use tokio::{net::TcpListener, runtime::Runtime, time::sleep};
|
use tokio::{net::TcpListener, runtime::Runtime, time::sleep};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -144,7 +145,9 @@ async fn can_upload_artifact() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let mut client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
|
let mut client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
|
||||||
|
|
||||||
let bytes: [u8; 10000] = [0; 10000];
|
let mut bytes: [u8; 10000] = [0; 10000];
|
||||||
|
|
||||||
|
thread_rng().fill(&mut bytes[..]);
|
||||||
|
|
||||||
let chunks = bytes
|
let chunks = bytes
|
||||||
.chunks(bytes.len() / 100)
|
.chunks(bytes.len() / 100)
|
||||||
@ -157,7 +160,14 @@ async fn can_upload_artifact() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let resp = client.upload_artifact(req).await?;
|
let resp = client.upload_artifact(req).await?;
|
||||||
|
|
||||||
assert!(!resp.into_inner().upload_id.is_empty());
|
let upload_id = resp.into_inner().upload_id;
|
||||||
|
assert!(!upload_id.is_empty());
|
||||||
|
|
||||||
|
let actual_path = app.file_store().get_temp(upload_id.try_into()?).await?;
|
||||||
|
|
||||||
|
let actual_content = tokio::fs::read(actual_path).await?;
|
||||||
|
|
||||||
|
assert_eq!(&bytes[..], actual_content.as_slice());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user