diff --git a/src/api2/config.rs b/src/api2/config.rs index 749a9ac3..a6fef19a 100644 --- a/src/api2/config.rs +++ b/src/api2/config.rs @@ -2,11 +2,11 @@ use proxmox::api::router::{Router, SubdirMap}; use proxmox::api::list_subdirs_api_method; pub mod datastore; -pub mod remotes; +pub mod remote; const SUBDIRS: SubdirMap = &[ ("datastore", &datastore::ROUTER), - ("remotes", &remotes::ROUTER), + ("remote", &remote::ROUTER), ]; pub const ROUTER: Router = Router::new() diff --git a/src/api2/config/remotes.rs b/src/api2/config/remote.rs similarity index 82% rename from src/api2/config/remotes.rs rename to src/api2/config/remote.rs index b9ece5c4..509343f2 100644 --- a/src/api2/config/remotes.rs +++ b/src/api2/config/remote.rs @@ -4,7 +4,7 @@ use serde_json::Value; use proxmox::api::{api, ApiMethod, Router, RpcEnvironment}; use crate::api2::types::*; -use crate::config::remotes; +use crate::config::remote; #[api( input: { @@ -14,7 +14,7 @@ use crate::config::remotes; description: "The list of configured remotes (with config digest).", type: Array, items: { - type: remotes::Remote, + type: remote::Remote, }, }, )] @@ -25,7 +25,7 @@ pub fn list_remotes( _rpcenv: &mut dyn RpcEnvironment, ) -> Result { - let (config, digest) = remotes::config()?; + let (config, digest) = remote::config()?; Ok(config.convert_to_array("name", Some(&digest))) } @@ -48,7 +48,7 @@ pub fn list_remotes( schema: PROXMOX_USER_ID_SCHEMA, }, password: { - schema: remotes::REMOTE_PASSWORD_SCHEMA, + schema: remote::REMOTE_PASSWORD_SCHEMA, }, }, }, @@ -56,11 +56,11 @@ pub fn list_remotes( /// Create new remote. pub fn create_remote(name: String, param: Value) -> Result<(), Error> { - let _lock = crate::tools::open_file_locked(remotes::REMOTES_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; + let _lock = crate::tools::open_file_locked(remote::REMOTE_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; - let remote: remotes::Remote = serde_json::from_value(param.clone())?; + let remote: remote::Remote = serde_json::from_value(param.clone())?; - let (mut config, _digest) = remotes::config()?; + let (mut config, _digest) = remote::config()?; if let Some(_) = config.sections.get(&name) { bail!("remote '{}' already exists.", name); @@ -68,7 +68,7 @@ pub fn create_remote(name: String, param: Value) -> Result<(), Error> { config.set_data(&name, "remote", &remote)?; - remotes::save_config(&config)?; + remote::save_config(&config)?; Ok(()) } @@ -83,12 +83,12 @@ pub fn create_remote(name: String, param: Value) -> Result<(), Error> { }, returns: { description: "The remote configuration (with config digest).", - type: remotes::Remote, + type: remote::Remote, }, )] /// Read remote configuration data. pub fn read_remote(name: String) -> Result { - let (config, digest) = remotes::config()?; + let (config, digest) = remote::config()?; let mut data = config.lookup_json("remote", &name)?; data.as_object_mut().unwrap() .insert("digest".into(), proxmox::tools::digest_to_hex(&digest).into()); @@ -116,7 +116,7 @@ pub fn read_remote(name: String) -> Result { }, password: { optional: true, - schema: remotes::REMOTE_PASSWORD_SCHEMA, + schema: remote::REMOTE_PASSWORD_SCHEMA, }, digest: { optional: true, @@ -135,16 +135,16 @@ pub fn update_remote( digest: Option, ) -> Result<(), Error> { - let _lock = crate::tools::open_file_locked(remotes::REMOTES_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; + let _lock = crate::tools::open_file_locked(remote::REMOTE_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; - let (mut config, expected_digest) = remotes::config()?; + let (mut config, expected_digest) = remote::config()?; if let Some(ref digest) = digest { let digest = proxmox::tools::hex_to_digest(digest)?; crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; } - let mut data: remotes::Remote = config.lookup("remote", &name)?; + let mut data: remote::Remote = config.lookup("remote", &name)?; if let Some(comment) = comment { let comment = comment.trim().to_string(); @@ -160,7 +160,7 @@ pub fn update_remote( config.set_data(&name, "remote", &data)?; - remotes::save_config(&config)?; + remote::save_config(&config)?; Ok(()) } @@ -181,7 +181,7 @@ pub fn delete_remote(name: String) -> Result<(), Error> { // fixme: locking ? // fixme: check digest ? - let (mut config, _digest) = remotes::config()?; + let (mut config, _digest) = remote::config()?; match config.sections.get(&name) { Some(_) => { config.sections.remove(&name); }, diff --git a/src/api2/pull.rs b/src/api2/pull.rs index b320daed..7028593a 100644 --- a/src/api2/pull.rs +++ b/src/api2/pull.rs @@ -14,7 +14,7 @@ use proxmox::api::{ApiMethod, Router, RpcEnvironment}; use crate::server::{WorkerTask}; use crate::backup::*; use crate::client::*; -use crate::config::remotes; +use crate::config::remote; use crate::api2::types::*; // fixme: implement filters @@ -365,8 +365,8 @@ async fn pull ( let tgt_store = DataStore::lookup_datastore(&store)?; - let (remote_config, _digest) = remotes::config()?; - let remote: remotes::Remote = remote_config.lookup("remote", &remote)?; + let (remote_config, _digest) = remote::config()?; + let remote: remote::Remote = remote_config.lookup("remote", &remote)?; let client = HttpClient::new(&remote.host, &remote.userid, Some(remote.password.clone()))?; let _auth_info = client.login() // make sure we can auth diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index f7b990c5..ee8822fa 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -7,7 +7,7 @@ use proxmox::api::{api, cli::*}; use proxmox_backup::configdir; use proxmox_backup::tools; -use proxmox_backup::config::{self, remotes::{self, Remote}}; +use proxmox_backup::config::{self, remote::{self, Remote}}; use proxmox_backup::api2::types::*; use proxmox_backup::client::*; use proxmox_backup::tools::ticket::*; @@ -44,29 +44,29 @@ fn connect() -> Result { Ok(client) } -fn remotes_commands() -> CommandLineInterface { +fn remote_commands() -> CommandLineInterface { use proxmox_backup::api2; let cmd_def = CliCommandMap::new() - .insert("list", CliCommand::new(&api2::config::remotes::API_METHOD_LIST_REMOTES)) + .insert("list", CliCommand::new(&api2::config::remote::API_METHOD_LIST_REMOTES)) .insert( "create", // fixme: howto handle password parameter? - CliCommand::new(&api2::config::remotes::API_METHOD_CREATE_REMOTE) + CliCommand::new(&api2::config::remote::API_METHOD_CREATE_REMOTE) .arg_param(&["name"]) ) .insert( "update", - CliCommand::new(&api2::config::remotes::API_METHOD_UPDATE_REMOTE) + CliCommand::new(&api2::config::remote::API_METHOD_UPDATE_REMOTE) .arg_param(&["name"]) - .completion_cb("name", config::remotes::complete_remote_name) + .completion_cb("name", config::remote::complete_remote_name) ) .insert( "remove", - CliCommand::new(&api2::config::remotes::API_METHOD_DELETE_REMOTE) + CliCommand::new(&api2::config::remote::API_METHOD_DELETE_REMOTE) .arg_param(&["name"]) - .completion_cb("name", config::remotes::complete_remote_name) + .completion_cb("name", config::remote::complete_remote_name) ); cmd_def.into() @@ -434,7 +434,7 @@ fn main() { let cmd_def = CliCommandMap::new() .insert("datastore", datastore_commands()) - .insert("remotes", remotes_commands()) + .insert("remote", remote_commands()) .insert("garbage-collection", garbage_collection_commands()) .insert("cert", cert_mgmt_cli()) .insert("task", task_mgmt_cli()) @@ -443,7 +443,7 @@ fn main() { CliCommand::new(&API_METHOD_PULL_DATASTORE) .arg_param(&["remote", "remote-store", "local-store"]) .completion_cb("local-store", config::datastore::complete_datastore_name) - .completion_cb("remote", config::remotes::complete_remote_name) + .completion_cb("remote", config::remote::complete_remote_name) .completion_cb("remote-store", complete_remote_datastore_name) ); @@ -457,7 +457,7 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap SectionConfig { config } -pub const REMOTES_CFG_FILENAME: &str = "/etc/proxmox-backup/remotes.cfg"; -pub const REMOTES_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remotes.lck"; +pub const REMOTE_CFG_FILENAME: &str = "/etc/proxmox-backup/remote.cfg"; +pub const REMOTE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remote.lck"; pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { - let content = match std::fs::read_to_string(REMOTES_CFG_FILENAME) { + let content = match std::fs::read_to_string(REMOTE_CFG_FILENAME) { Ok(c) => c, Err(err) => { if err.kind() == std::io::ErrorKind::NotFound { String::from("") } else { - bail!("unable to read '{}' - {}", REMOTES_CFG_FILENAME, err); + bail!("unable to read '{}' - {}", REMOTE_CFG_FILENAME, err); } } }; let digest = openssl::sha::sha256(content.as_bytes()); - let data = CONFIG.parse(REMOTES_CFG_FILENAME, &content)?; + let data = CONFIG.parse(REMOTE_CFG_FILENAME, &content)?; Ok((data, digest)) } pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { - let raw = CONFIG.write(REMOTES_CFG_FILENAME, &config)?; + let raw = CONFIG.write(REMOTE_CFG_FILENAME, &config)?; let backup_user = crate::backup::backup_user()?; let mode = nix::sys::stat::Mode::from_bits_truncate(0o0640); @@ -92,7 +92,7 @@ pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { .owner(nix::unistd::ROOT) .group(backup_user.gid); - replace_file(REMOTES_CFG_FILENAME, raw.as_bytes(), options)?; + replace_file(REMOTE_CFG_FILENAME, raw.as_bytes(), options)?; Ok(()) }