renamed: src/config/remotes.rs -> src/config/remote.rs
And use 'remote' instead of 'remotes' everywhere.
This commit is contained in:
		| @ -2,11 +2,11 @@ use proxmox::api::router::{Router, SubdirMap}; | |||||||
| use proxmox::api::list_subdirs_api_method; | use proxmox::api::list_subdirs_api_method; | ||||||
|  |  | ||||||
| pub mod datastore; | pub mod datastore; | ||||||
| pub mod remotes; | pub mod remote; | ||||||
|  |  | ||||||
| const SUBDIRS: SubdirMap = &[ | const SUBDIRS: SubdirMap = &[ | ||||||
|     ("datastore", &datastore::ROUTER), |     ("datastore", &datastore::ROUTER), | ||||||
|     ("remotes", &remotes::ROUTER), |     ("remote", &remote::ROUTER), | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
| pub const ROUTER: Router = Router::new() | pub const ROUTER: Router = Router::new() | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ use serde_json::Value; | |||||||
| use proxmox::api::{api, ApiMethod, Router, RpcEnvironment}; | use proxmox::api::{api, ApiMethod, Router, RpcEnvironment}; | ||||||
| 
 | 
 | ||||||
| use crate::api2::types::*; | use crate::api2::types::*; | ||||||
| use crate::config::remotes; | use crate::config::remote; | ||||||
| 
 | 
 | ||||||
| #[api(
 | #[api(
 | ||||||
|     input: { |     input: { | ||||||
| @ -14,7 +14,7 @@ use crate::config::remotes; | |||||||
|         description: "The list of configured remotes (with config digest).", |         description: "The list of configured remotes (with config digest).", | ||||||
|         type: Array, |         type: Array, | ||||||
|         items: { |         items: { | ||||||
|             type: remotes::Remote, |             type: remote::Remote, | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
| )] | )] | ||||||
| @ -25,7 +25,7 @@ pub fn list_remotes( | |||||||
|     _rpcenv: &mut dyn RpcEnvironment, |     _rpcenv: &mut dyn RpcEnvironment, | ||||||
| ) -> Result<Value, Error> { | ) -> Result<Value, Error> { | ||||||
| 
 | 
 | ||||||
|     let (config, digest) = remotes::config()?; |     let (config, digest) = remote::config()?; | ||||||
| 
 | 
 | ||||||
|     Ok(config.convert_to_array("name", Some(&digest))) |     Ok(config.convert_to_array("name", Some(&digest))) | ||||||
| } | } | ||||||
| @ -48,7 +48,7 @@ pub fn list_remotes( | |||||||
|                 schema: PROXMOX_USER_ID_SCHEMA, |                 schema: PROXMOX_USER_ID_SCHEMA, | ||||||
|             }, |             }, | ||||||
|             password: { |             password: { | ||||||
|                 schema: remotes::REMOTE_PASSWORD_SCHEMA, |                 schema: remote::REMOTE_PASSWORD_SCHEMA, | ||||||
|             }, |             }, | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
| @ -56,11 +56,11 @@ pub fn list_remotes( | |||||||
| /// Create new remote.
 | /// Create new remote.
 | ||||||
| pub fn create_remote(name: String, param: Value) -> Result<(), Error> { | 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) { |     if let Some(_) = config.sections.get(&name) { | ||||||
|         bail!("remote '{}' already exists.", 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)?; |     config.set_data(&name, "remote", &remote)?; | ||||||
| 
 | 
 | ||||||
|     remotes::save_config(&config)?; |     remote::save_config(&config)?; | ||||||
| 
 | 
 | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
| @ -83,12 +83,12 @@ pub fn create_remote(name: String, param: Value) -> Result<(), Error> { | |||||||
|     }, |     }, | ||||||
|     returns: { |     returns: { | ||||||
|         description: "The remote configuration (with config digest).", |         description: "The remote configuration (with config digest).", | ||||||
|         type: remotes::Remote, |         type: remote::Remote, | ||||||
|     }, |     }, | ||||||
| )] | )] | ||||||
| /// Read remote configuration data.
 | /// Read remote configuration data.
 | ||||||
| pub fn read_remote(name: String) -> Result<Value, Error> { | pub fn read_remote(name: String) -> Result<Value, Error> { | ||||||
|     let (config, digest) = remotes::config()?; |     let (config, digest) = remote::config()?; | ||||||
|     let mut data = config.lookup_json("remote", &name)?; |     let mut data = config.lookup_json("remote", &name)?; | ||||||
|     data.as_object_mut().unwrap() |     data.as_object_mut().unwrap() | ||||||
|         .insert("digest".into(), proxmox::tools::digest_to_hex(&digest).into()); |         .insert("digest".into(), proxmox::tools::digest_to_hex(&digest).into()); | ||||||
| @ -116,7 +116,7 @@ pub fn read_remote(name: String) -> Result<Value, Error> { | |||||||
|             }, |             }, | ||||||
|             password: { |             password: { | ||||||
|                 optional: true, |                 optional: true, | ||||||
|                 schema: remotes::REMOTE_PASSWORD_SCHEMA, |                 schema: remote::REMOTE_PASSWORD_SCHEMA, | ||||||
|             }, |             }, | ||||||
|             digest: { |             digest: { | ||||||
|                 optional: true, |                 optional: true, | ||||||
| @ -135,16 +135,16 @@ pub fn update_remote( | |||||||
|     digest: Option<String>, |     digest: Option<String>, | ||||||
| ) -> Result<(), Error> { | ) -> 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 { |     if let Some(ref digest) = digest { | ||||||
|         let digest = proxmox::tools::hex_to_digest(digest)?; |         let digest = proxmox::tools::hex_to_digest(digest)?; | ||||||
|         crate::tools::detect_modified_configuration_file(&digest, &expected_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 { |     if let Some(comment) = comment { | ||||||
|         let comment = comment.trim().to_string(); |         let comment = comment.trim().to_string(); | ||||||
| @ -160,7 +160,7 @@ pub fn update_remote( | |||||||
| 
 | 
 | ||||||
|     config.set_data(&name, "remote", &data)?; |     config.set_data(&name, "remote", &data)?; | ||||||
| 
 | 
 | ||||||
|     remotes::save_config(&config)?; |     remote::save_config(&config)?; | ||||||
| 
 | 
 | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
| @ -181,7 +181,7 @@ pub fn delete_remote(name: String) -> Result<(), Error> { | |||||||
|     // fixme: locking ?
 |     // fixme: locking ?
 | ||||||
|     // fixme: check digest ?
 |     // fixme: check digest ?
 | ||||||
| 
 | 
 | ||||||
|     let (mut config, _digest) = remotes::config()?; |     let (mut config, _digest) = remote::config()?; | ||||||
| 
 | 
 | ||||||
|     match config.sections.get(&name) { |     match config.sections.get(&name) { | ||||||
|         Some(_) => { config.sections.remove(&name); }, |         Some(_) => { config.sections.remove(&name); }, | ||||||
| @ -14,7 +14,7 @@ use proxmox::api::{ApiMethod, Router, RpcEnvironment}; | |||||||
| use crate::server::{WorkerTask}; | use crate::server::{WorkerTask}; | ||||||
| use crate::backup::*; | use crate::backup::*; | ||||||
| use crate::client::*; | use crate::client::*; | ||||||
| use crate::config::remotes; | use crate::config::remote; | ||||||
| use crate::api2::types::*; | use crate::api2::types::*; | ||||||
|  |  | ||||||
| // fixme: implement filters | // fixme: implement filters | ||||||
| @ -365,8 +365,8 @@ async fn pull ( | |||||||
|  |  | ||||||
|     let tgt_store = DataStore::lookup_datastore(&store)?; |     let tgt_store = DataStore::lookup_datastore(&store)?; | ||||||
|  |  | ||||||
|     let (remote_config, _digest) = remotes::config()?; |     let (remote_config, _digest) = remote::config()?; | ||||||
|     let remote: remotes::Remote = remote_config.lookup("remote", &remote)?; |     let remote: remote::Remote = remote_config.lookup("remote", &remote)?; | ||||||
|  |  | ||||||
|     let client = HttpClient::new(&remote.host, &remote.userid, Some(remote.password.clone()))?; |     let client = HttpClient::new(&remote.host, &remote.userid, Some(remote.password.clone()))?; | ||||||
|     let _auth_info = client.login() // make sure we can auth |     let _auth_info = client.login() // make sure we can auth | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ use proxmox::api::{api, cli::*}; | |||||||
|  |  | ||||||
| use proxmox_backup::configdir; | use proxmox_backup::configdir; | ||||||
| use proxmox_backup::tools; | 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::api2::types::*; | ||||||
| use proxmox_backup::client::*; | use proxmox_backup::client::*; | ||||||
| use proxmox_backup::tools::ticket::*; | use proxmox_backup::tools::ticket::*; | ||||||
| @ -44,29 +44,29 @@ fn connect() -> Result<HttpClient, Error> { | |||||||
|     Ok(client) |     Ok(client) | ||||||
| } | } | ||||||
|  |  | ||||||
| fn remotes_commands() -> CommandLineInterface { | fn remote_commands() -> CommandLineInterface { | ||||||
|  |  | ||||||
|     use proxmox_backup::api2; |     use proxmox_backup::api2; | ||||||
|  |  | ||||||
|     let cmd_def = CliCommandMap::new() |     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( |         .insert( | ||||||
|             "create", |             "create", | ||||||
|             // fixme: howto handle password parameter? |             // 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"]) |                 .arg_param(&["name"]) | ||||||
|         ) |         ) | ||||||
|         .insert( |         .insert( | ||||||
|             "update", |             "update", | ||||||
|             CliCommand::new(&api2::config::remotes::API_METHOD_UPDATE_REMOTE) |             CliCommand::new(&api2::config::remote::API_METHOD_UPDATE_REMOTE) | ||||||
|                 .arg_param(&["name"]) |                 .arg_param(&["name"]) | ||||||
|                 .completion_cb("name", config::remotes::complete_remote_name) |                 .completion_cb("name", config::remote::complete_remote_name) | ||||||
|         ) |         ) | ||||||
|         .insert( |         .insert( | ||||||
|             "remove", |             "remove", | ||||||
|             CliCommand::new(&api2::config::remotes::API_METHOD_DELETE_REMOTE) |             CliCommand::new(&api2::config::remote::API_METHOD_DELETE_REMOTE) | ||||||
|                 .arg_param(&["name"]) |                 .arg_param(&["name"]) | ||||||
|                 .completion_cb("name", config::remotes::complete_remote_name) |                 .completion_cb("name", config::remote::complete_remote_name) | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|     cmd_def.into() |     cmd_def.into() | ||||||
| @ -434,7 +434,7 @@ fn main() { | |||||||
|  |  | ||||||
|     let cmd_def = CliCommandMap::new() |     let cmd_def = CliCommandMap::new() | ||||||
|         .insert("datastore", datastore_commands()) |         .insert("datastore", datastore_commands()) | ||||||
|         .insert("remotes", remotes_commands()) |         .insert("remote", remote_commands()) | ||||||
|         .insert("garbage-collection", garbage_collection_commands()) |         .insert("garbage-collection", garbage_collection_commands()) | ||||||
|         .insert("cert", cert_mgmt_cli()) |         .insert("cert", cert_mgmt_cli()) | ||||||
|         .insert("task", task_mgmt_cli()) |         .insert("task", task_mgmt_cli()) | ||||||
| @ -443,7 +443,7 @@ fn main() { | |||||||
|             CliCommand::new(&API_METHOD_PULL_DATASTORE) |             CliCommand::new(&API_METHOD_PULL_DATASTORE) | ||||||
|                 .arg_param(&["remote", "remote-store", "local-store"]) |                 .arg_param(&["remote", "remote-store", "local-store"]) | ||||||
|                 .completion_cb("local-store", config::datastore::complete_datastore_name) |                 .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) |                 .completion_cb("remote-store", complete_remote_datastore_name) | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
| @ -457,7 +457,7 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String | |||||||
|  |  | ||||||
|     let _ = proxmox::tools::try_block!({ |     let _ = proxmox::tools::try_block!({ | ||||||
|         let remote = param.get("remote").ok_or_else(|| format_err!("no remote"))?; |         let remote = param.get("remote").ok_or_else(|| format_err!("no remote"))?; | ||||||
|         let (remote_config, _digest) = remotes::config()?; |         let (remote_config, _digest) = remote::config()?; | ||||||
|  |  | ||||||
|         let remote: Remote = remote_config.lookup("remote", &remote)?; |         let remote: Remote = remote_config.lookup("remote", &remote)?; | ||||||
|  |  | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ use proxmox::tools::try_block; | |||||||
| use crate::buildcfg; | use crate::buildcfg; | ||||||
|  |  | ||||||
| pub mod datastore; | pub mod datastore; | ||||||
| pub mod remotes; | pub mod remote; | ||||||
|  |  | ||||||
| /// Check configuration directory permissions | /// Check configuration directory permissions | ||||||
| /// | /// | ||||||
|  | |||||||
| @ -60,28 +60,28 @@ fn init() -> SectionConfig { | |||||||
|     config |     config | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub const REMOTES_CFG_FILENAME: &str = "/etc/proxmox-backup/remotes.cfg"; | pub const REMOTE_CFG_FILENAME: &str = "/etc/proxmox-backup/remote.cfg"; | ||||||
| pub const REMOTES_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remotes.lck"; | pub const REMOTE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remote.lck"; | ||||||
| 
 | 
 | ||||||
| pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { | 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, |         Ok(c) => c, | ||||||
|         Err(err) => { |         Err(err) => { | ||||||
|             if err.kind() == std::io::ErrorKind::NotFound { |             if err.kind() == std::io::ErrorKind::NotFound { | ||||||
|                 String::from("") |                 String::from("") | ||||||
|             } else { |             } 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 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)) |     Ok((data, digest)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { | 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 backup_user = crate::backup::backup_user()?; | ||||||
|     let mode = nix::sys::stat::Mode::from_bits_truncate(0o0640); |     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) |         .owner(nix::unistd::ROOT) | ||||||
|         .group(backup_user.gid); |         .group(backup_user.gid); | ||||||
| 
 | 
 | ||||||
|     replace_file(REMOTES_CFG_FILENAME, raw.as_bytes(), options)?; |     replace_file(REMOTE_CFG_FILENAME, raw.as_bytes(), options)?; | ||||||
| 
 | 
 | ||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user