config/remote: add 'name' to Remote struct
and use it as section id, like with User Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
		
				
					committed by
					
						
						Dietmar Maurer
					
				
			
			
				
	
			
			
			
						parent
						
							880fa939d1
						
					
				
				
					commit
					db0c228719
				
			@ -88,7 +88,7 @@ pub fn list_remotes(
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
)]
 | 
					)]
 | 
				
			||||||
/// Create new remote.
 | 
					/// Create new remote.
 | 
				
			||||||
pub fn create_remote(name: String, param: Value) -> Result<(), Error> {
 | 
					pub fn create_remote(param: Value) -> Result<(), Error> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let _lock = crate::tools::open_file_locked(remote::REMOTE_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))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -96,11 +96,11 @@ pub fn create_remote(name: String, param: Value) -> Result<(), Error> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let (mut config, _digest) = remote::config()?;
 | 
					    let (mut config, _digest) = remote::config()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if let Some(_) = config.sections.get(&name) {
 | 
					    if let Some(_) = config.sections.get(&remote.name) {
 | 
				
			||||||
        bail!("remote '{}' already exists.", name);
 | 
					        bail!("remote '{}' already exists.", remote.name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    config.set_data(&name, "remote", &remote)?;
 | 
					    config.set_data(&remote.name, "remote", &remote)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    remote::save_config(&config)?;
 | 
					    remote::save_config(&config)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -29,6 +29,9 @@ pub const REMOTE_PASSWORD_SCHEMA: Schema = StringSchema::new("Password or auth t
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#[api(
 | 
					#[api(
 | 
				
			||||||
    properties: {
 | 
					    properties: {
 | 
				
			||||||
 | 
					        name: {
 | 
				
			||||||
 | 
					            schema: REMOTE_ID_SCHEMA,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        comment: {
 | 
					        comment: {
 | 
				
			||||||
            optional: true,
 | 
					            optional: true,
 | 
				
			||||||
            schema: SINGLE_LINE_COMMENT_SCHEMA,
 | 
					            schema: SINGLE_LINE_COMMENT_SCHEMA,
 | 
				
			||||||
@ -51,6 +54,7 @@ pub const REMOTE_PASSWORD_SCHEMA: Schema = StringSchema::new("Password or auth t
 | 
				
			|||||||
#[derive(Serialize,Deserialize)]
 | 
					#[derive(Serialize,Deserialize)]
 | 
				
			||||||
/// Remote properties.
 | 
					/// Remote properties.
 | 
				
			||||||
pub struct Remote {
 | 
					pub struct Remote {
 | 
				
			||||||
 | 
					    pub name: String,
 | 
				
			||||||
    #[serde(skip_serializing_if="Option::is_none")]
 | 
					    #[serde(skip_serializing_if="Option::is_none")]
 | 
				
			||||||
    pub comment: Option<String>,
 | 
					    pub comment: Option<String>,
 | 
				
			||||||
    pub host: String,
 | 
					    pub host: String,
 | 
				
			||||||
@ -66,7 +70,7 @@ fn init() -> SectionConfig {
 | 
				
			|||||||
        _ => unreachable!(),
 | 
					        _ => unreachable!(),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let plugin = SectionConfigPlugin::new("remote".to_string(), None, obj_schema);
 | 
					    let plugin = SectionConfigPlugin::new("remote".to_string(), Some("name".to_string()), obj_schema);
 | 
				
			||||||
    let mut config = SectionConfig::new(&REMOTE_ID_SCHEMA);
 | 
					    let mut config = SectionConfig::new(&REMOTE_ID_SCHEMA);
 | 
				
			||||||
    config.register_plugin(plugin);
 | 
					    config.register_plugin(plugin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user