| |
/// should be migrated away from. If it is used, a warning is logged.
|
| |
#[cfg(all(feature = "systemd", target_os = "linux"))]
|
| |
fn load_credential(id_suffix: &str) -> Option<PathBuf> {
|
| - |
const INFIX_NODE: &str = ".radicle.node.";
|
| - |
const PREFIX_DEV: &str = "dev";
|
| - |
const PREFIX_XYZ: &str = "xyz";
|
| - |
|
| - |
let id_dev = format!("{}{}{}", PREFIX_DEV, INFIX_NODE, id_suffix);
|
| - |
|
| - |
match radicle_systemd::credential::path(&id_dev) {
|
| - |
Ok(option) => option,
|
| - |
Err(err) => {
|
| - |
log::warn!(target: "node", "Failed to obtain of the systemd credential with ID '{id_dev}': {err}");
|
| - |
|
| - |
let id_xyz = format!("{}{}{}", PREFIX_XYZ, INFIX_NODE, id_suffix);
|
| - |
match radicle_systemd::credential::path(&id_xyz) {
|
| - |
Ok(option) => {
|
| - |
log::warn!(target: "node", "Obtained path of the systemd credential with ID '{id_xyz}'. Using this credential ID is discouraged. Please change the ID to '{id_dev}'.");
|
| - |
option
|
| - |
}
|
| - |
Err(err) => {
|
| - |
log::warn!(target: "node", "Failed to obtain path of the systemd credential with ID '{id_xyz}': {err}");
|
| - |
None
|
| - |
}
|
| - |
}
|
| - |
}
|
| + |
match credential::SystemdCredential::new(id_suffix)? {
|
| + |
credential::SystemdCredential::DotDev(path) => Some(path),
|
| + |
credential::SystemdCredential::DotXyz(path) => Some(path),
|
| |
}
|
| |
}
|
| |
|
| |
exit(1);
|
| |
}
|
| |
}
|
| + |
|
| + |
#[cfg(all(feature = "systemd", target_os = "linux"))]
|
| + |
mod credential {
|
| + |
use std::path::PathBuf;
|
| + |
|
| + |
pub(super) enum SystemdCredential {
|
| + |
DotDev(PathBuf),
|
| + |
DotXyz(PathBuf),
|
| + |
}
|
| + |
|
| + |
impl SystemdCredential {
|
| + |
const INFIX_NODE: &str = ".radicle.node.";
|
| + |
const PREFIX_DEV: &str = "dev";
|
| + |
const PREFIX_XYZ: &str = "xyz";
|
| + |
|
| + |
pub fn new(id_suffix: &str) -> Option<Self> {
|
| + |
let id_dev = Self::id_dev(id_suffix);
|
| + |
match radicle_systemd::credential::path(&id_dev) {
|
| + |
Ok(Some(path)) => Some(Self::DotDev(path)),
|
| + |
Ok(None) => Self::xyz_path(id_suffix, &id_dev),
|
| + |
Err(err) => {
|
| + |
log::warn!(target: "node", "Failed to obtain of the systemd credential with ID '{id_dev}': {err}");
|
| + |
Self::xyz_path(id_suffix, &id_dev)
|
| + |
}
|
| + |
}
|
| + |
}
|
| + |
|
| + |
fn xyz_path(id_suffix: &str, id_dev: &str) -> Option<Self> {
|
| + |
let id_xyz = Self::id_xyz(id_suffix);
|
| + |
match radicle_systemd::credential::path(&id_xyz) {
|
| + |
Ok(Some(path)) => {
|
| + |
log::warn!(target: "node", "Obtained path of the systemd credential with ID '{id_xyz}'. Using this credential ID is discouraged. Please change the ID to '{id_dev}'.");
|
| + |
Some(Self::DotXyz(path))
|
| + |
}
|
| + |
Ok(None) => None,
|
| + |
Err(err) => {
|
| + |
log::warn!(target: "node", "Failed to obtain path of the systemd credential with ID '{id_xyz}': {err}");
|
| + |
None
|
| + |
}
|
| + |
}
|
| + |
}
|
| + |
|
| + |
fn id_dev(id_suffix: &str) -> String {
|
| + |
format!("{}{}{}", Self::PREFIX_DEV, Self::INFIX_NODE, id_suffix)
|
| + |
}
|
| + |
|
| + |
fn id_xyz(id_suffix: &str) -> String {
|
| + |
format!("{}{}{}", Self::PREFIX_XYZ, Self::INFIX_NODE, id_suffix)
|
| + |
}
|
| + |
}
|
| + |
}
|