faucet-source-rest 0.2.0

REST API source connector for the faucet-stream ecosystem
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! HTTP Basic authentication.

use base64::Engine;
use faucet_core::FaucetError;
use reqwest::header::{HeaderMap, HeaderValue};

pub fn apply(headers: &mut HeaderMap, username: &str, password: &str) -> Result<(), FaucetError> {
    let encoded =
        base64::engine::general_purpose::STANDARD.encode(format!("{username}:{password}"));
    let val = HeaderValue::from_str(&format!("Basic {encoded}"))
        .map_err(|e| FaucetError::Auth(format!("invalid basic auth value: {e}")))?;
    headers.insert("Authorization", val);
    Ok(())
}