pub struct Client<T> { /* private fields */ }Expand description
A client type for interacting with a Bindle server
Implementations§
source§impl<T: TokenManager> Client<T>
impl<T: TokenManager> Client<T>
sourcepub fn new(
base_url: &str,
token_manager: T,
keyring: Arc<KeyRing>
) -> Result<Self>
pub fn new( base_url: &str, token_manager: T, keyring: Arc<KeyRing> ) -> Result<Self>
Returns a new Client with the given URL, configured using the default options.
This URL should be the FQDN plus any namespacing (like v1). So if you were running a
bindle server mounted at the v1 endpoint, your URL would look something like
http://my.bindle.com/v1/. Will return an error if the URL is not valid
This requires KeyRing to be wrapped in an Arc for efficiency sake. KeyRings can be
quite large and so we require it to be wrapped in an Arc to avoid a large clone cost
sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Returns a ClientBuilder configured with defaults
sourcepub async fn raw(
&self,
method: Method,
path: &str,
body: Option<impl Into<Body>>
) -> Result<Response>
pub async fn raw( &self, method: Method, path: &str, body: Option<impl Into<Body>> ) -> Result<Response>
Performs a raw request using the underlying HTTP client and returns the raw response. The path is just the path part of your URL. It will be joined with the configured base URL for the client.
sourcepub async fn create_invoice(&self, inv: Invoice) -> Result<InvoiceCreateResponse>
pub async fn create_invoice(&self, inv: Invoice) -> Result<InvoiceCreateResponse>
Creates the given invoice, returns a response containing the created invoice and a list of missing parcels (that have not yet been uploaded)
sourcepub async fn create_invoice_from_file<P: AsRef<Path>>(
&self,
file_path: P
) -> Result<InvoiceCreateResponse>
pub async fn create_invoice_from_file<P: AsRef<Path>>( &self, file_path: P ) -> Result<InvoiceCreateResponse>
Same as create_invoice, but takes a path to an invoice file
instead. This will load the invoice file directly into the request, skipping serialization
sourcepub async fn get_invoice<I>(&self, id: I) -> Result<VerifiedInvoice<Invoice>>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
pub async fn get_invoice<I>(&self, id: I) -> Result<VerifiedInvoice<Invoice>>where I: TryInto<Id>, I::Error: Into<ClientError>,
Returns the requested invoice from the bindle server if it exists.
This can take any form that can convert into the Id type, but generally speaking, this is
the canonical name of the bindle (e.g. example.com/foo/1.0.0). If you want to fetch a
yanked invoice, use the get_yanked_invoice function
Once the invoice is fetched, it will be verified using the configured verification strategy and keyring for this client
sourcepub async fn get_yanked_invoice<I>(
&self,
id: I
) -> Result<VerifiedInvoice<Invoice>>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
pub async fn get_yanked_invoice<I>( &self, id: I ) -> Result<VerifiedInvoice<Invoice>>where I: TryInto<Id>, I::Error: Into<ClientError>,
Same as get_invoice but allows you to fetch a yanked invoice
sourcepub async fn query_invoices(&self, query_opts: QueryOptions) -> Result<Matches>
pub async fn query_invoices(&self, query_opts: QueryOptions) -> Result<Matches>
Queries the bindle server for matching invoices as specified by the given query options
sourcepub async fn yank_invoice<I>(&self, id: I) -> Result<()>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
pub async fn yank_invoice<I>(&self, id: I) -> Result<()>where I: TryInto<Id>, I::Error: Into<ClientError>,
Yanks the invoice from availability on the bindle server. This can take any form that can
convert into the Id type, but generally speaking, this is the canonical name of the bindle
(e.g. example.com/foo/1.0.0)
sourcepub async fn create_parcel<I>(
&self,
bindle_id: I,
parcel_sha: &str,
data: Vec<u8>
) -> Result<()>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
pub async fn create_parcel<I>( &self, bindle_id: I, parcel_sha: &str, data: Vec<u8> ) -> Result<()>where I: TryInto<Id>, I::Error: Into<ClientError>,
Creates the given parcel using the SHA and the raw parcel data to upload to the server.
Parcels are only accessible through a bindle, so the Bindle ID is required as well
sourcepub async fn create_parcel_from_file<D, I>(
&self,
bindle_id: I,
parcel_sha: &str,
data_path: D
) -> Result<()>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
D: AsRef<Path>,
pub async fn create_parcel_from_file<D, I>( &self, bindle_id: I, parcel_sha: &str, data_path: D ) -> Result<()>where I: TryInto<Id>, I::Error: Into<ClientError>, D: AsRef<Path>,
Same as create_parcel, but takes a path to the parcel
file. This will be more efficient for large files as it will stream the data into the body
rather than taking the intermediate step of loading the bytes into a Vec.
sourcepub async fn create_parcel_from_stream<I, S, B>(
&self,
bindle_id: I,
parcel_sha: &str,
stream: S
) -> Result<()>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
S: Stream<Item = Result<B>> + Unpin + Send + Sync + 'static,
B: Buf,
pub async fn create_parcel_from_stream<I, S, B>( &self, bindle_id: I, parcel_sha: &str, stream: S ) -> Result<()>where I: TryInto<Id>, I::Error: Into<ClientError>, S: Stream<Item = Result<B>> + Unpin + Send + Sync + 'static, B: Buf,
Same as create_parcel, but takes a stream of parcel data as bytes
sourcepub async fn get_parcel<I>(&self, bindle_id: I, sha: &str) -> Result<Vec<u8>>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
pub async fn get_parcel<I>(&self, bindle_id: I, sha: &str) -> Result<Vec<u8>>where I: TryInto<Id>, I::Error: Into<ClientError>,
Returns the requested parcel (identified by its Bindle ID and SHA) as a vector of bytes
sourcepub async fn get_parcel_stream<I>(
&self,
bindle_id: I,
sha: &str
) -> Result<impl Stream<Item = Result<Bytes>>>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
pub async fn get_parcel_stream<I>( &self, bindle_id: I, sha: &str ) -> Result<impl Stream<Item = Result<Bytes>>>where I: TryInto<Id>, I::Error: Into<ClientError>,
Returns the requested parcel (identified by its Bindle ID and SHA) as a stream of bytes. This is useful for when you don’t want to read it into memory but are instead writing to a file or other location
sourcepub async fn get_missing_parcels<I>(&self, id: I) -> Result<Vec<Label>>where
I: TryInto<Id>,
I::Error: Into<ClientError>,
pub async fn get_missing_parcels<I>(&self, id: I) -> Result<Vec<Label>>where I: TryInto<Id>, I::Error: Into<ClientError>,
Gets the labels of missing parcels, if any, of the specified bindle. If the bindle is yanked, this will fail
sourcepub async fn get_host_keys(&self) -> Result<KeyRing>
pub async fn get_host_keys(&self) -> Result<KeyRing>
Fetches all the host public keys specified for the bindle server
Trait Implementations§
source§impl<T: TokenManager + Send + Sync + 'static> Provider for Client<T>
impl<T: TokenManager + Send + Sync + 'static> Provider for Client<T>
source§fn create_invoice<'life0, 'async_trait, I>(
&'life0 self,
invoice: I
) -> Pin<Box<dyn Future<Output = Result<(Invoice, Vec<Label>)>> + Send + 'async_trait>>where
I: Signed + Verified + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn create_invoice<'life0, 'async_trait, I>( &'life0 self, invoice: I ) -> Pin<Box<dyn Future<Output = Result<(Invoice, Vec<Label>)>> + Send + 'async_trait>>where I: Signed + Verified + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,
source§fn get_yanked_invoice<'life0, 'async_trait, I>(
&'life0 self,
id: I
) -> Pin<Box<dyn Future<Output = Result<Invoice>> + Send + 'async_trait>>where
I: TryInto<Id> + Send + 'async_trait,
I::Error: Into<ProviderError>,
Self: 'async_trait,
'life0: 'async_trait,
fn get_yanked_invoice<'life0, 'async_trait, I>( &'life0 self, id: I ) -> Pin<Box<dyn Future<Output = Result<Invoice>> + Send + 'async_trait>>where I: TryInto<Id> + Send + 'async_trait, I::Error: Into<ProviderError>, Self: 'async_trait, 'life0: 'async_trait,
get_invoicesource§fn yank_invoice<'life0, 'async_trait, I>(
&'life0 self,
id: I
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
I: TryInto<Id> + Send + 'async_trait,
I::Error: Into<ProviderError>,
Self: 'async_trait,
'life0: 'async_trait,
fn yank_invoice<'life0, 'async_trait, I>( &'life0 self, id: I ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where I: TryInto<Id> + Send + 'async_trait, I::Error: Into<ProviderError>, Self: 'async_trait, 'life0: 'async_trait,
source§fn create_parcel<'life0, 'life1, 'async_trait, I, R, B>(
&'life0 self,
bindle_id: I,
parcel_id: &'life1 str,
data: R
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
I: TryInto<Id> + Send + 'async_trait,
I::Error: Into<ProviderError>,
R: Stream<Item = Result<B>> + Unpin + Send + Sync + 'static + 'async_trait,
B: Buf + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create_parcel<'life0, 'life1, 'async_trait, I, R, B>( &'life0 self, bindle_id: I, parcel_id: &'life1 str, data: R ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where I: TryInto<Id> + Send + 'async_trait, I::Error: Into<ProviderError>, R: Stream<Item = Result<B>> + Unpin + Send + Sync + 'static + 'async_trait, B: Buf + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Stream Read moresource§fn get_parcel<'life0, 'life1, 'async_trait, I>(
&'life0 self,
bindle_id: I,
parcel_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<Bytes>> + Unpin + Send + Sync>>> + Send + 'async_trait>>where
I: TryInto<Id> + Send + 'async_trait,
I::Error: Into<ProviderError>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_parcel<'life0, 'life1, 'async_trait, I>( &'life0 self, bindle_id: I, parcel_id: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<Bytes>> + Unpin + Send + Sync>>> + Send + 'async_trait>>where I: TryInto<Id> + Send + 'async_trait, I::Error: Into<ProviderError>, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
source§fn parcel_exists<'life0, 'life1, 'async_trait, I>(
&'life0 self,
bindle_id: I,
parcel_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
I: TryInto<Id> + Send + 'async_trait,
I::Error: Into<ProviderError>,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parcel_exists<'life0, 'life1, 'async_trait, I>( &'life0 self, bindle_id: I, parcel_id: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where I: TryInto<Id> + Send + 'async_trait, I::Error: Into<ProviderError>, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
source§fn get_invoice<'life0, 'async_trait, I>(
&'life0 self,
id: I
) -> Pin<Box<dyn Future<Output = Result<Invoice>> + Send + 'async_trait>>where
I: TryInto<Id> + Send + 'async_trait,
I::Error: Into<ProviderError>,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn get_invoice<'life0, 'async_trait, I>( &'life0 self, id: I ) -> Pin<Box<dyn Future<Output = Result<Invoice>> + Send + 'async_trait>>where I: TryInto<Id> + Send + 'async_trait, I::Error: Into<ProviderError>, Self: Sync + 'async_trait, 'life0: 'async_trait,
source§fn validate_parcel<'life0, 'life1, 'async_trait, I>(
&'life0 self,
bindle_id: I,
parcel_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Label>> + Send + 'async_trait>>where
I: TryInto<Id> + Send + 'async_trait,
I::Error: Into<ProviderError>,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn validate_parcel<'life0, 'life1, 'async_trait, I>( &'life0 self, bindle_id: I, parcel_id: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<Label>> + Send + 'async_trait>>where I: TryInto<Id> + Send + 'async_trait, I::Error: Into<ProviderError>, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
get_yanked_invoice to avoid fetching
the invoice every single time a parcel is requested. Provider implementations may also
implement this function to include other validation logic if desired.