Struct bindle::client::Client

source ·
pub struct Client<T> { /* private fields */ }
Expand description

A client type for interacting with a Bindle server

Implementations§

source§

impl<T: TokenManager> Client<T>

source

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

source

pub fn builder() -> ClientBuilder

Returns a ClientBuilder configured with defaults

source

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.

source

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)

source

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

source

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

source

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

source

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

source

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)

source

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

source

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.

source

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

source

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

source

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

source

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

source

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: Clone> Clone for Client<T>

source§

fn clone(&self) -> Client<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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,

This takes an invoice and creates it in storage. Returns the newly created invoice and a list of missing parcels Read more
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,

Load an invoice, even if it is yanked. This is called by the default implementation of get_invoice
source§

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,

Remove an invoice by ID
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,

Creates a parcel with the associated sha. The parcel can be anything that implements Stream Read more
source§

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,

Get a specific parcel using its SHA. Read more
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,

Checks if the given parcel exists in storage. Read more
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,

Load an invoice and return it Read more
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,

Checks if the given parcel ID exists within an invoice. The default implementation will fetch the parcel and check if the given parcel ID exists. Returns the parcel label if valid. Most providers should implement some sort of caching for 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.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Client<T>

§

impl<T> Send for Client<T>where T: Send,

§

impl<T> Sync for Client<T>where T: Sync,

§

impl<T> Unpin for Client<T>where T: Unpin,

§

impl<T> !UnwindSafe for Client<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more