Struct ddmw_client::auth::Auth

source ·
pub struct Auth {
    pub name: Option<String>,
    pub pass_file: Option<String>,
    pub pass: Option<String>,
    pub token_file: Option<String>,
    pub token: Option<String>,
}
Expand description

Authentication context used to signal how to authenticate a connection.

Fields§

§name: Option<String>

Account name used to authenticate.

§pass_file: Option<String>

Load raw account passphrase from the specified filename.

§pass: Option<String>

Raw account passphrase to authenticate with. Only used if name has been set.

§token_file: Option<String>

Use the specified file for authentication token storage.

§token: Option<String>

Authentication token.

Implementations§

source§

impl Auth

source

pub fn have_pass(&self) -> bool

Return true if there’s either a raw passphrase set in pass or a passphrase file has beeen set in pass_file. This function does not validate if the passphrase file exists or is accessible.

source

pub fn get_pass(&self) -> Result<String, Error>

Get passphrase.

Return the raw pass field if set. Otherwise, load the pass_file if set, and return error if the passphrase could not be loaded from the file.

If neither pass nor pass_file have been set, return an error.

source

pub fn get_token(&self) -> Result<Option<String>, Error>

Get authentication token.

Return the raw token field if set. Otherwise, check if token_file is set. If it is, then attempt to load the token from it. If the file does not exist, then:

  • Return Ok(None) if account name and pass(file) have been set.
  • Return error if account name has not been set.
source

pub async fn authenticate<C>( &self, conn: &mut Framed<C, Codec> ) -> Result<Option<String>, Error>where C: AsyncRead + AsyncWrite + Unpin,

Helper function for authenticating a connection.

Authenticates the connection specified in conn, using the credentials stored in the Auth buffer using the following logic:

  1. If a raw token has been supplied in the token field, then attempt to authenticate with it and return the results.
  2. If a token_file has been been set, then:
    • If the file exists, try to load the authentication token, authenticate with it, and return the results.
    • If the file does not exist, then:
      • If account name and/or passphrase have not been set, then return error.
      • If account name and passphrase have been set, then continue.
  3. Make sure that an account name and a passphrase has been set. The passphrase is either set from the pass field or by loading the contents of the file in pass_file. Return error account name or passphrase can not be acquired.
  4. Authenticate using account name and passphrase. If a token_file was specified, then request an authentication token and store it in token_file on success. Return error on failure.

Trait Implementations§

source§

impl Clone for Auth

source§

fn clone(&self) -> Auth

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 Debug for Auth

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Auth

source§

fn default() -> Auth

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Auth

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Auth

§

impl Send for Auth

§

impl Sync for Auth

§

impl Unpin for Auth

§

impl UnwindSafe for Auth

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

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, U> Into<U> for Twhere 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> 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.
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.
source§

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

Performs the conversion.
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> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,