matomo-rs 0.1.0

Async client for the Matomo Reporting API, focused on data export and migration
Documentation
use secrecy::SecretString;

/// How the client authenticates against the Matomo instance.
///
/// `token` works on all Matomo 5.x; `bearer` requires Matomo 5.4+.
#[derive(Clone)]
pub enum Auth {
    /// Sent as the `token_auth` form field in the POST body.
    Token(SecretString),
    /// Sent as an `Authorization: Bearer` header (Matomo 5.4+).
    Bearer(SecretString),
}

impl Auth {
    pub fn token(token: impl Into<String>) -> Self {
        Auth::Token(SecretString::from(token.into()))
    }

    pub fn bearer(token: impl Into<String>) -> Self {
        Auth::Bearer(SecretString::from(token.into()))
    }
}

impl std::fmt::Debug for Auth {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Auth::Token(_) => f.write_str("Auth::Token(<redacted>)"),
            Auth::Bearer(_) => f.write_str("Auth::Bearer(<redacted>)"),
        }
    }
}