Skip to content

Add delete_object fn to client #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 17, 2023
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
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
#[cfg(feature = "genproto")]
fn generate_protos() {
download_file(
"https://raw.githubusercontent.com/lightningdevkit/vss-server/ff4b5fc6a079ed8719eb8be7ec35ca1d01c1cc55/app/src/main/proto/vss.proto",
"https://raw.githubusercontent.com/lightningdevkit/vss-server/ac646dd419bc70db2b79772b1bfa1b2d9a4b8b53/app/src/main/proto/vss.proto",
"src/proto/vss.proto",
).unwrap();

Expand Down
23 changes: 21 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use reqwest::Client;

use crate::error::VssError;
use crate::types::{
GetObjectRequest, GetObjectResponse, ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest,
PutObjectResponse,
DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse, ListKeyVersionsRequest,
ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse,
};

/// Thin-client to access a hosted instance of Versioned Storage Service (VSS).
/// The provided [`VssClient`] API is minimalistic and is congruent to the VSS server-side API.
#[derive(Clone)]
pub struct VssClient {
base_url: String,
client: Client,
Expand Down Expand Up @@ -59,6 +60,24 @@ impl VssClient {
}
}

/// Deletes the given `key` and `value` in `request`.
/// Makes a service call to the `DeleteObject` endpoint of the VSS server.
/// For API contract/usage, refer to docs for [`DeleteObjectRequest`] and [`DeleteObjectResponse`].
pub async fn delete_object(&self, request: &DeleteObjectRequest) -> Result<DeleteObjectResponse, VssError> {
let url = format!("{}/deleteObject", self.base_url);

let response_raw = self.client.post(url).body(request.encode_to_vec()).send().await?;
let status = response_raw.status();
let payload = response_raw.bytes().await?;

if status.is_success() {
let response = DeleteObjectResponse::decode(&payload[..])?;
Ok(response)
} else {
Err(VssError::new(status, payload))
}
}

/// Lists keys and their corresponding version for a given [`ListKeyVersionsRequest::store_id`].
/// Makes a service call to the `ListKeyVersions` endpoint of the VSS server.
/// For API contract/usage, refer to docs for [`ListKeyVersionsRequest`] and [`ListKeyVersionsResponse`].
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Client-side library to interact with Versioned Storage Service (VSS).
//!
//! VSS is an open-source project designed to offer a server-side cloud storage solution specifically
//! tailored for non-custodial Lightning supporting mobile wallets. Its primary objective is to
//! tailored for noncustodial Lightning supporting mobile wallets. Its primary objective is to
//! simplify the development process for Lightning wallets by providing a secure means to store
//! and manage the essential state required for Lightning Network (LN) operations.
//!
Expand All @@ -10,13 +10,10 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_intra_doc_links)]

use crate::client::VssClient;
use crate::error::VssError;

/// Implements a thin-client ([`VssClient`]) to access a hosted instance of Versioned Storage Service (VSS).
/// Implements a thin-client ([`client::VssClient`]) to access a hosted instance of Versioned Storage Service (VSS).
pub mod client;

/// Implements the error type ([`VssError`]) returned on interacting with [`VssClient`]
/// Implements the error type ([`error::VssError`]) returned on interacting with [`client::VssClient`]
pub mod error;

/// Contains request/response types generated from the API definition of VSS.
Expand Down
Loading