pub(super) struct RestClient {
http: Client,
base_url: String,
headers: HeaderMap,
signer: Option<MacSigner>,
}Expand description
An HTTP client bound to a base URL, carrying the 1Password identity headers and an optional MAC signer. Requests are signed automatically once a signer is attached.
Fields§
§http: Client§base_url: String§headers: HeaderMap§signer: Option<MacSigner>Implementations§
Source§impl RestClient
impl RestClient
Sourcepub(super) fn new(
http: Client,
base_url: impl Into<String>,
client_id: &str,
user_agent: &str,
op_user_agent: &str,
) -> Result<RestClient, OnePasswordError>
pub(super) fn new( http: Client, base_url: impl Into<String>, client_id: &str, user_agent: &str, op_user_agent: &str, ) -> Result<RestClient, OnePasswordError>
Builds the base client with the identity headers derived from ClientInfo.
Sourcepub(super) fn with_base_url(&self, base_url: impl Into<String>) -> RestClient
pub(super) fn with_base_url(&self, base_url: impl Into<String>) -> RestClient
Derives a client for another API root. It keeps the transport and the headers, but does not sign its requests, as the signer belongs to the receiver.
Sourcepub(super) fn with_session_id(
&self,
session_id: &str,
) -> Result<RestClient, OnePasswordError>
pub(super) fn with_session_id( &self, session_id: &str, ) -> Result<RestClient, OnePasswordError>
Derives a client that adds the session id header.
Sourcepub(super) fn with_signer(&self, signer: MacSigner) -> RestClient
pub(super) fn with_signer(&self, signer: MacSigner) -> RestClient
Derives a client that signs every request. The signer carries the session id already, so this keeps whatever headers the receiver has.
Sourcepub(super) async fn post_json<T: DeserializeOwned>(
&self,
endpoint: &str,
body: Value,
) -> Result<T, OnePasswordError>
pub(super) async fn post_json<T: DeserializeOwned>( &self, endpoint: &str, body: Value, ) -> Result<T, OnePasswordError>
POSTs a JSON body and parses the JSON response.
Sourcepub(super) async fn post_json_or_empty<T: DeserializeOwned>(
&self,
endpoint: &str,
body: Value,
) -> Result<Option<T>, OnePasswordError>
pub(super) async fn post_json_or_empty<T: DeserializeOwned>( &self, endpoint: &str, body: Value, ) -> Result<Option<T>, OnePasswordError>
POSTs a JSON body and parses the JSON response, reporting an empty success body as None.
Some endpoints answer 200 with an empty body while the result is not ready yet, which must not be mistaken for a parse error.
Sourcepub(super) async fn post_json_unless_status<T: DeserializeOwned>(
&self,
endpoint: &str,
body: Value,
status: StatusCode,
) -> Result<Option<T>, OnePasswordError>
pub(super) async fn post_json_unless_status<T: DeserializeOwned>( &self, endpoint: &str, body: Value, status: StatusCode, ) -> Result<Option<T>, OnePasswordError>
POSTs a JSON body and parses the JSON response, or returns None when the server answers
with status, whatever the body.
Sourcepub(super) async fn put_json<T: DeserializeOwned>(
&self,
endpoint: &str,
body: Value,
) -> Result<T, OnePasswordError>
pub(super) async fn put_json<T: DeserializeOwned>( &self, endpoint: &str, body: Value, ) -> Result<T, OnePasswordError>
PUTs a JSON body and parses the JSON response.
Sourcepub(super) async fn put<T: DeserializeOwned>(
&self,
endpoint: &str,
) -> Result<T, OnePasswordError>
pub(super) async fn put<T: DeserializeOwned>( &self, endpoint: &str, ) -> Result<T, OnePasswordError>
PUTs with no body and parses the JSON response.
Sourcepub(super) async fn delete_json(
&self,
endpoint: &str,
body: Value,
) -> Result<(), OnePasswordError>
pub(super) async fn delete_json( &self, endpoint: &str, body: Value, ) -> Result<(), OnePasswordError>
DELETEs a JSON body. The response carries nothing to parse and errors surface for the caller to ignore.
Sourcepub(super) async fn get_encrypted_json<T: DeserializeOwned>(
&self,
endpoint: &str,
session_key: &AesKey,
) -> Result<T, OnePasswordError>
pub(super) async fn get_encrypted_json<T: DeserializeOwned>( &self, endpoint: &str, session_key: &AesKey, ) -> Result<T, OnePasswordError>
GETs an opdata envelope, decrypts it, and parses the JSON plaintext.
Sourcepub(super) async fn post_encrypted_json<T: DeserializeOwned>(
&self,
endpoint: &str,
params: Value,
session_key: &AesKey,
) -> Result<T, OnePasswordError>
pub(super) async fn post_encrypted_json<T: DeserializeOwned>( &self, endpoint: &str, params: Value, session_key: &AesKey, ) -> Result<T, OnePasswordError>
Encrypts params, POSTs the opdata envelope, then decrypts and parses the response.
Sourceasync fn request_json<T: DeserializeOwned>(
&self,
method: Method,
endpoint: &str,
body: Option<&Value>,
) -> Result<T, OnePasswordError>
async fn request_json<T: DeserializeOwned>( &self, method: Method, endpoint: &str, body: Option<&Value>, ) -> Result<T, OnePasswordError>
Sends a request and parses the JSON response.
async fn request( &self, method: Method, endpoint: &str, body: Option<&Value>, ) -> Result<String, OnePasswordError>
Auto Trait Implementations§
impl !Freeze for RestClient
impl !RefUnwindSafe for RestClient
impl !UnwindSafe for RestClient
impl Send for RestClient
impl Sync for RestClient
impl Unpin for RestClient
impl UnsafeUnpin for RestClient
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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