use std::collections::HashMap;
use serde::Serialize;
#[derive(Clone, Debug, Default, Serialize)]
pub struct RegistryAuth {
pub username: String,
pub password: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(rename = "serveraddress", skip_serializing_if = "Option::is_none")]
pub server: Option<String>
}
impl RegistryAuth {
pub(crate) fn as_config(&self) -> HashMap<String, RegistryConfig> {
if let Some(server) = self.server.as_ref() {
HashMap::from([
(server.clone(), RegistryConfig::with_auth(self))
])
}
else {
HashMap::new()
}
}
}
#[derive(Clone, Debug, Serialize)]
pub(crate) struct RegistryConfig {
pub username: String,
pub password: String,
}
impl RegistryConfig {
fn with_auth(auth: &RegistryAuth) -> Self {
RegistryConfig {
username: auth.username.clone(),
password: auth.password.clone()
}
}
}