Skip to main content

VaultClient

Struct VaultClient 

Source
pub struct VaultClient {
    http: Client,
    download_http: Client,
    base: String,
    base_url: Url,
    device_id: String,
}

Fields§

§http: Client§download_http: Client§base: String§base_url: Url§device_id: String

Implementations§

Source§

impl VaultClient

Source

pub fn new(base: &str) -> Result<Self, VaultError>

Build a client for base, which may carry a trailing slash. The workspace’s production session builds its clients through VaultClient::with_clients so the machine’s TLS roots and https_only apply; this constructor is for local servers and tests.

Source

pub fn with_clients( base: &str, http: Client, download_http: Client, ) -> Result<Self, VaultError>

Build a client over callers’ own HTTP clients. The download client is separate because its read and total bounds are longer than an API call’s.

Source

pub fn base(&self) -> &str

The base URL this client talks to.

Source

fn unauth(&self, method: Method, path: &str) -> RequestBuilder

Source

fn authed(&self, method: Method, path: &str, token: &str) -> RequestBuilder

Source

async fn send_body( &self, resp: Response, fields: ErrorFields, ) -> Result<Zeroizing<String>, VaultError>

Read one response body, mapping a non-2xx status to its named error. The body is zeroized on every path: a token response’s body carries the access and refresh tokens. fields scopes which error fields may be surfaced, so the identity route never reads the API’s pointers.

Source

async fn send_json(&self, resp: Response) -> Result<Value, VaultError>

Read one response as JSON. An empty success body is Value::Null.

Source

async fn send_typed<T: DeserializeOwned>( &self, resp: Response, ) -> Result<T, VaultError>

Parse one response straight into T, zeroizing the raw text after the parse rather than leaving a token-bearing Value to drop unzeroized.

Source

async fn send_typed_oauth<T: DeserializeOwned>( &self, resp: Response, ) -> Result<T, VaultError>

The identity endpoints’ own parse: an error there is read through the OAuth pair only, never the API’s wider pointer set.

Source

async fn send_typed_with<T: DeserializeOwned>( &self, resp: Response, fields: ErrorFields, ) -> Result<T, VaultError>

Source

pub async fn prelogin(&self, email: &str) -> Result<Prelogin, VaultError>

POST /identity/accounts/prelogin, which is where Vaultwarden mounts it (the /api/accounts/prelogin forms answer 404).

Source

pub async fn login_password( &self, email: &str, master_password_hash: &str, two_factor: Option<&TwoFactorCode>, ) -> Result<TokenResponse, VaultError>

POST /identity/connect/token with the password grant.

Source

pub async fn refresh( &self, refresh_token: &str, ) -> Result<TokenResponse, VaultError>

POST /identity/connect/token with the refresh grant.

Source

pub async fn sync(&self, token: &str) -> Result<SyncData, VaultError>

GET /api/sync: the profile and every cipher and folder.

Source

pub async fn get_cipher( &self, token: &str, id: &str, ) -> Result<Value, VaultError>

Source

pub async fn create_cipher( &self, token: &str, body: &Value, ) -> Result<Value, VaultError>

Source

pub async fn update_cipher( &self, token: &str, id: &str, body: &Value, ) -> Result<Value, VaultError>

Source

pub async fn trash_cipher( &self, token: &str, id: &str, ) -> Result<Value, VaultError>

The soft delete. POST /api/ciphers/{id}/delete and DELETE /api/ciphers/{id} are permanent and are never called here.

Source

pub async fn restore_cipher( &self, token: &str, id: &str, ) -> Result<Value, VaultError>

Source

pub async fn list_folders(&self, token: &str) -> Result<Vec<Folder>, VaultError>

Source

pub async fn create_folder( &self, token: &str, name: &str, ) -> Result<Value, VaultError>

Source

pub async fn update_folder( &self, token: &str, id: &str, name: &str, ) -> Result<Value, VaultError>

Source

pub async fn delete_folder( &self, token: &str, id: &str, ) -> Result<Value, VaultError>

Source

pub async fn create_attachment_slot( &self, token: &str, cipher_id: &str, body: &Value, ) -> Result<Value, VaultError>

Create the v2 attachment slot, which records the wrapped key and the declared size the server later checks against the upload.

Source

pub async fn upload_attachment( &self, token: &str, cipher_id: &str, attachment_id: &str, data: &[u8], ) -> Result<Value, VaultError>

Upload the encrypted blob. Exactly one data part: v2 stored the key at slot time, and a second part leaks multipart boundary bytes into the stored blob through the server’s parser.

Source

pub async fn get_attachment_meta( &self, token: &str, cipher_id: &str, attachment_id: &str, ) -> Result<AttachmentMeta, VaultError>

The download metadata: the wrapped key and the signed URL.

Source

pub async fn delete_attachment( &self, token: &str, cipher_id: &str, attachment_id: &str, ) -> Result<Value, VaultError>

Delete one attachment. Used only by a replace, which names the old and the new file in one approval; it is never its own agent-callable tool.

Source

pub async fn download_attachment( &self, token: &str, url: &str, max_bytes: u64, ) -> Result<Vec<u8>, VaultError>

Download a signed attachment URL. The bytes are opaque ciphertext, so the request asks the proxy not to re-encode them. A relative URL is the API route and takes the bearer; an absolute one is signed and does not, and may only name this vault’s own host. max_bytes bounds the body while it streams, so an endless response cannot buffer past the cap.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 T
where U: From<T>,

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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