[pdm-devel] [PATCH datacenter-manager 1/3] remote config: let save_config take ownership
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Dec 1 10:29:13 CET 2025
as preparation for automatically modifying the saved config to split out token
secrets, if needed.
Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
lib/pdm-config/src/remotes.rs | 9 +++++----
server/src/api/remotes.rs | 6 +++---
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/pdm-config/src/remotes.rs b/lib/pdm-config/src/remotes.rs
index 74c4671..fc78707 100644
--- a/lib/pdm-config/src/remotes.rs
+++ b/lib/pdm-config/src/remotes.rs
@@ -47,7 +47,7 @@ pub fn config() -> Result<(SectionConfigData<Remote>, ConfigDigest), Error> {
/// Replace the currently persisted remotes config
///
/// Will panic if the the remote config instance has not been set before.
-pub fn save_config(config: &SectionConfigData<Remote>) -> Result<(), Error> {
+pub fn save_config(config: SectionConfigData<Remote>) -> Result<(), Error> {
instance().save_config(config)
}
@@ -57,7 +57,7 @@ pub trait RemoteConfig {
/// Lock the remotes config
fn lock_config(&self) -> Result<ApiLockGuard, Error>;
/// Replace the currently persisted remotes config
- fn save_config(&self, remotes: &SectionConfigData<Remote>) -> Result<(), Error>;
+ fn save_config(&self, remotes: SectionConfigData<Remote>) -> Result<(), Error>;
}
/// Default, production implementation for reading/writing the `remotes.cfg`
@@ -75,11 +75,12 @@ impl RemoteConfig for DefaultRemoteConfig {
let digest = openssl::sha::sha256(content.as_bytes());
let data = Remote::parse_section_config(REMOTES_CFG_FILENAME, &content)?;
+
Ok((data, digest.into()))
}
- fn save_config(&self, config: &SectionConfigData<Remote>) -> Result<(), Error> {
- let raw = Remote::write_section_config(REMOTES_CFG_FILENAME, config)?;
+ fn save_config(&self, config: SectionConfigData<Remote>) -> Result<(), Error> {
+ let raw = Remote::write_section_config(REMOTES_CFG_FILENAME, &config)?;
replace_config(REMOTES_CFG_FILENAME, raw.as_bytes())
}
}
diff --git a/server/src/api/remotes.rs b/server/src/api/remotes.rs
index 76b005d..a7463b9 100644
--- a/server/src/api/remotes.rs
+++ b/server/src/api/remotes.rs
@@ -184,7 +184,7 @@ pub async fn add_remote(mut entry: Remote, create_token: Option<String>) -> Resu
let name = entry.id.clone();
remotes.insert(entry.id.to_owned(), entry);
- pdm_config::remotes::save_config(&remotes)?;
+ pdm_config::remotes::save_config(remotes)?;
if let Err(e) = metric_collection::trigger_metric_collection(Some(name), false).await {
log::error!("could not trigger metric collection after adding remote: {e}");
@@ -268,7 +268,7 @@ pub fn update_remote(
entry.web_url = updater.web_url;
}
- pdm_config::remotes::save_config(&remotes)?;
+ pdm_config::remotes::save_config(remotes)?;
Ok(())
}
@@ -291,7 +291,7 @@ pub fn remove_remote(id: String) -> Result<(), Error> {
http_bail!(NOT_FOUND, "no such entry {id:?}");
}
- pdm_config::remotes::save_config(&remotes)?;
+ pdm_config::remotes::save_config(remotes)?;
Ok(())
}
--
2.47.3
More information about the pdm-devel
mailing list