Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]
### Changed
- [#98](https://github.com/saas-rs/cli/issues/98) Upgrade protocol from 0.2.7 → 0.5.5
- [#96](https://github.com/saas-rs/cli/issues/96) Upgrade 14 crates
- [#94](https://github.com/saas-rs/cli/issues/94) Upgrade Rust edition from 2021 → 2024
- [#92](https://github.com/saas-rs/cli/issues/92) Upgrade Rust from 1.89.0 → 1.93.0
Expand Down
24 changes: 10 additions & 14 deletions src/cmd/generate/do_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,33 @@ pub async fn do_generate(req: GenerateRequest) -> Result<(), Box<dyn std::error:
let tempdir = TempDir::new()?;
{
// Download FileInfo for patch file to get filename
let file_info = client
.find_file(FindFileRequest {
let file = {
let req = FindFileRequest {
id: res.file_id.clone(),
})
.await?
.into_inner()
.file_info
.unwrap();
};
let res = client.find_file(req).await?;
res.into_inner().file.unwrap()
};

// Open a local temp file for output
let mut file = File::options().create(true).truncate(true).write(true).open(format!(
"{}/{}",
tempdir.path().display(),
file_info.filename
))?;
let path = format!("{}/{}", tempdir.path().display(), file.filename);
let mut fs_file = File::options().create(true).truncate(true).write(true).open(path)?;

// Download chunks, and append them to temp file
let req = DownloadFileRequest { id: res.file_id };
let mut input_stream = client.download_file(req).await?.into_inner();
while let Some(res) = input_stream.next().await {
match res {
Ok(item) => {
file.write_all(&item.chunk)?;
fs_file.write_all(&item.chunk)?;
}
Err(e) => {
eprintln!("Failed downloading file: {e:?}");
std::process::exit(1);
}
}
}
file.flush()?;
fs_file.flush()?;

eprintln!("Response received");
}
Expand Down
24 changes: 12 additions & 12 deletions src/cmd/generate/do_generate_preflight.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::protocol::saas_rs::user::v1::{
generate_request::{Archive, Snapshot},
{FileInfo, UploadFileRequest, upload_file_request},
{File, UploadFileRequest, upload_file_request},
};
use crate::{apiclient, util};
use git2::Repository;
use log::debug;
use std::{fs, process::Command, str::from_utf8};
use tempfile::NamedTempFile;
use tokio::{fs::File, sync::mpsc};
use tokio::sync::mpsc;
use tokio_stream::StreamExt;
use tokio_util::codec::{BytesCodec, FramedRead};
use tonic::codegen::tokio_stream::wrappers::ReceiverStream;
Expand All @@ -28,13 +28,13 @@ pub async fn do_generate_preflight(
let project_id = util::git::find_or_create_default_project_id().await?;

// Archive the workspace
let file = NamedTempFile::new()?;
let archive = NamedTempFile::new()?;
let output = Command::new("git")
.arg("archive")
.arg("--format")
.arg("zip")
.arg("--output")
.arg(file.path().display().to_string())
.arg(archive.path().display().to_string())
.arg("HEAD")
.output()?;
if !output.status.success() {
Expand All @@ -49,22 +49,22 @@ pub async fn do_generate_preflight(
debug!("Archival completed");

// Prepare a FileInfo descriptor for the archive
let metadata = fs::metadata(file.path())?;
let file_info = FileInfo {
let metadata = fs::metadata(archive.path())?;
let file = File {
length: metadata.len() as u32,
filename: "archive.zip".to_string(),
..Default::default()
};

// Start task to feed an output stream with the FileInfo then the chunked contents
let file = File::open(file.path()).await?;
let mut file_reader_stream = FramedRead::new(file, BytesCodec::new());
let fs_file = tokio::fs::File::open(archive.path()).await?;
let mut file_reader_stream = FramedRead::new(fs_file, BytesCodec::new());
let (tx, rx) = mpsc::channel(2);
let outbound = ReceiverStream::new(rx);
tokio::spawn(async move {
// The first message is just the file info
let req = UploadFileRequest {
r#type: Some(upload_file_request::Type::FileInfo(file_info)),
r#type: Some(upload_file_request::Type::File(file)),
};
tx.send(req).await.unwrap();

Expand All @@ -91,12 +91,12 @@ pub async fn do_generate_preflight(

// Upload the workspace archive
let mut client = apiclient::new_user_service_client().await?;
let file_info = client.upload_file(outbound).await?.into_inner().file_info.unwrap();
debug!("Uploaded {file_info:?}");
let file = client.upload_file(outbound).await?.into_inner().file.unwrap();
debug!("Uploaded {file:?}");

// Respond
let snapshot = Snapshot::Archive(Archive {
file_ids: vec![file_info.id],
file_ids: vec![file.id],
});
Ok((project_id, snapshot))
}
32 changes: 17 additions & 15 deletions src/protocol/saas_rs.user.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub struct FindManyActionsResponse {
#[prost(message, repeated, tag = "1")]
pub actions: ::prost::alloc::vec::Vec<Action>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AccessToken {
#[prost(string, tag = "1")]
pub id: ::prost::alloc::string::String,
Expand All @@ -146,6 +146,8 @@ pub struct AccessToken {
pub owner_account_id: ::prost::alloc::string::String,
#[prost(string, optional, tag = "5")]
pub linked_account_id: ::core::option::Option<::prost::alloc::string::String>,
#[prost(message, optional, tag = "6")]
pub metadata: ::core::option::Option<::pbjson_types::Struct>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LoginRequest {
Expand Down Expand Up @@ -183,7 +185,7 @@ pub mod login_request {
RefreshTokenGrant(RefreshTokenGrant),
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LoginResponse {
#[prost(message, optional, tag = "1")]
pub access_token: ::core::option::Option<AccessToken>,
Expand Down Expand Up @@ -491,7 +493,7 @@ pub struct ValidateCheckoutSessionResponse {
pub errors: ::prost::alloc::vec::Vec<ErrorObject>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FileInfo {
pub struct File {
#[prost(string, tag = "1")]
pub id: ::prost::alloc::string::String,
#[prost(uint32, tag = "2")]
Expand All @@ -512,19 +514,19 @@ pub struct FileInfo {
pub updated_at: ::core::option::Option<::pbjson_types::Timestamp>,
#[prost(string, optional, tag = "1005")]
pub updated_by_account_id: ::core::option::Option<::prost::alloc::string::String>,
#[prost(oneof = "file_info::Owner", tags = "1006")]
pub owner: ::core::option::Option<file_info::Owner>,
#[prost(oneof = "file::Owner", tags = "1006")]
pub owner: ::core::option::Option<file::Owner>,
}
/// Nested message and enum types in `FileInfo`.
pub mod file_info {
/// Nested message and enum types in `File`.
pub mod file {
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Owner {
#[prost(string, tag = "1006")]
OwnerAccountId(::prost::alloc::string::String),
}
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct FileInfoFilter {
pub struct FileFilter {
#[prost(string, optional, tag = "1")]
pub id: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, optional, tag = "2")]
Expand Down Expand Up @@ -561,12 +563,12 @@ pub struct FindFileRequest {
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FindFileResponse {
#[prost(message, optional, tag = "1")]
pub file_info: ::core::option::Option<FileInfo>,
pub file: ::core::option::Option<File>,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct FindManyFilesRequest {
#[prost(message, optional, tag = "1")]
pub filter: ::core::option::Option<FileInfoFilter>,
pub filter: ::core::option::Option<FileFilter>,
#[prost(message, optional, tag = "2")]
pub field_mask: ::core::option::Option<::pbjson_types::FieldMask>,
#[prost(uint32, optional, tag = "3")]
Expand All @@ -577,17 +579,17 @@ pub struct FindManyFilesRequest {
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FindManyFilesResponse {
#[prost(message, repeated, tag = "1")]
pub file_infos: ::prost::alloc::vec::Vec<FileInfo>,
pub files: ::prost::alloc::vec::Vec<File>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UpdateFileRequest {
#[prost(message, optional, tag = "1")]
pub file_info: ::core::option::Option<FileInfo>,
pub file: ::core::option::Option<File>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UpdateFileResponse {
#[prost(message, optional, tag = "1")]
pub file_info: ::core::option::Option<FileInfo>,
pub file: ::core::option::Option<File>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UploadFileRequest {
Expand All @@ -599,15 +601,15 @@ pub mod upload_file_request {
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Type {
#[prost(message, tag = "1")]
FileInfo(super::FileInfo),
File(super::File),
#[prost(bytes, tag = "2")]
Chunk(::prost::alloc::vec::Vec<u8>),
}
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UploadFileResponse {
#[prost(message, optional, tag = "1")]
pub file_info: ::core::option::Option<FileInfo>,
pub file: ::core::option::Option<File>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GenerateRequest {
Expand Down
Loading