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_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 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 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
Mutably borrows from an owned value. Read more
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
Create a new handle for an Arc value Read more
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
Clone a handle Read more
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Consume a handle, getting back the initial
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> ⓘ
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 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> ⓘ
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