1use std::fmt;
4
5#[derive(Eq, PartialEq, Clone)]
7pub enum RegistryAuth {
8 Anonymous,
10 Basic(String, String),
12 Bearer(String),
14}
15
16impl fmt::Debug for RegistryAuth {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 RegistryAuth::Anonymous => write!(f, "Anonymous"),
20 RegistryAuth::Basic(username, _) => f
21 .debug_tuple("Basic")
22 .field(username)
23 .field(&"<redacted>")
24 .finish(),
25 RegistryAuth::Bearer(_) => f.debug_tuple("Bearer").field(&"<redacted>").finish(),
26 }
27 }
28}
29
30pub(crate) trait Authenticable {
31 fn apply_authentication(self, auth: &RegistryAuth) -> Self;
32}
33
34impl Authenticable for reqwest::RequestBuilder {
35 fn apply_authentication(self, auth: &RegistryAuth) -> Self {
36 match auth {
37 RegistryAuth::Anonymous => self,
38 RegistryAuth::Basic(username, password) => self.basic_auth(username, Some(password)),
39 RegistryAuth::Bearer(token) => self.bearer_auth(token),
40 }
41 }
42}