Skip to main content

git_lfs_api/
auth.rs

1use reqwest::RequestBuilder;
2
3/// Authentication to attach to API requests.
4///
5/// Populated by the caller (typically from a credential helper).
6/// Resolving credentials (git-credential, keychain, etc.) is
7/// deliberately not this crate's job; see [`git-lfs-creds`][creds].
8///
9/// [creds]: https://docs.rs/git-lfs-creds
10#[derive(Debug, Clone)]
11pub enum Auth {
12    /// No `Authorization` header.
13    None,
14    /// HTTP Basic auth, sent as `Authorization: Basic <base64(user:pass)>`.
15    Basic { username: String, password: String },
16    /// Bearer token, sent as `Authorization: Bearer <token>`.
17    Bearer(String),
18}
19
20impl Auth {
21    pub(crate) fn apply(&self, req: RequestBuilder) -> RequestBuilder {
22        match self {
23            Auth::None => req,
24            Auth::Basic { username, password } => req.basic_auth(username, Some(password)),
25            Auth::Bearer(token) => req.bearer_auth(token),
26        }
27    }
28}