Skip to content
Open
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
14 changes: 0 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,7 @@ fn main() {

#[cfg(genproto)]
fn generate_protos() {
download_file(
"https://raw.githubusercontent.com/lightningdevkit/vss-server/022ee5e92debb60516438af0a369966495bfe595/proto/vss.proto",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While doing this on the server is fine, here I'd not want to do it until we have a better solution in place. Maybe we should go through with merging repos now that both are rust codebases, or have both depend on a shared vss-proto crate, to ensure version compat?

"src/proto/vss.proto",
).unwrap();

prost_build::compile_protos(&["src/proto/vss.proto"], &["src/"]).unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("vss.rs");
fs::copy(from_path, "src/types.rs").unwrap();
}

#[cfg(genproto)]
fn download_file(url: &str, save_to: &str) -> Result<(), Box<dyn std::error::Error>> {
let response = bitreq::get(url).send()?;
fs::create_dir_all(Path::new(save_to).parent().unwrap())?;
let mut out_file = File::create(save_to)?;
out_file.write_all(&response.into_bytes())?;
Ok(())
}
22 changes: 22 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::headers::{FixedHeaders, VssHeaderProvider};
use crate::types::{
DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse,
ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse,
VersionResponse,
};
use crate::util::retry::{retry, RetryPolicy};
use crate::util::KeyValueVecKeyPrinter;
Expand Down Expand Up @@ -76,6 +77,27 @@ impl<R: RetryPolicy<E = VssError>> VssClient<R> {
&self.base_url
}

/// Fetches the version of the VSS API served
pub async fn get_version(&self) -> Result<VersionResponse, VssError> {
let url = format!("{}/version", self.base_url);
let http_request = bitreq::get(url)
.with_header(CONTENT_TYPE, APPLICATION_OCTET_STREAM)
.with_timeout(DEFAULT_TIMEOUT_SECS)
.with_max_body_size(Some(MAX_RESPONSE_BODY_SIZE));

let response = self.client.send_async(http_request).await?;

let status_code = response.status_code;
let payload = response.into_bytes();

if (200..300).contains(&status_code) {
let response = VersionResponse::decode(&payload[..])?;
Ok(response)
} else {
Err(VssError::new(status_code, payload))
}
}

/// Fetches a value against a given `key` in `request`.
/// Makes a service call to the `GetObject` endpoint of the VSS server.
/// For API contract/usage, refer to docs for [`GetObjectRequest`] and [`GetObjectResponse`].
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod client;
pub mod error;

/// Contains request/response types generated from the API definition of VSS.
#[rustfmt::skip]
pub mod types;

/// Contains utils for encryption, requests-retries etc.
Expand Down
Loading
Loading