depend on proxmox 0.1.32, src/api2/access/user.rs: simplify code

This commit is contained in:
Dietmar Maurer 2020-05-19 09:49:39 +02:00
parent 88acc86129
commit 7d4e362993
2 changed files with 7 additions and 9 deletions

View File

@ -36,7 +36,7 @@ pam = "0.7"
pam-sys = "0.5" pam-sys = "0.5"
percent-encoding = "2.1" percent-encoding = "2.1"
pin-utils = "0.1.0" pin-utils = "0.1.0"
proxmox = { version = "0.1.31", features = [ "sortable-macro", "api-macro" ] } proxmox = { version = "0.1.32", features = [ "sortable-macro", "api-macro" ] }
#proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] } #proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] }
#proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro" ] } #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro" ] }
regex = "1.2" regex = "1.2"

View File

@ -88,24 +88,22 @@ pub fn list_users(
}, },
)] )]
/// Create new user. /// Create new user.
pub fn create_user(userid: String, password: Option<String>, param: Value) -> Result<(), Error> { pub fn create_user(password: Option<String>, param: Value) -> Result<(), Error> {
let _lock = crate::tools::open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; let _lock = crate::tools::open_file_locked(user::USER_CFG_LOCKFILE, std::time::Duration::new(10, 0))?;
let mut data = param.clone(); let user: user::User = serde_json::from_value(param)?;
data["userid"] = Value::from(userid.clone());
let user: user::User = serde_json::from_value(data)?;
let (mut config, _digest) = user::config()?; let (mut config, _digest) = user::config()?;
if let Some(_) = config.sections.get(&userid) { if let Some(_) = config.sections.get(&user.userid) {
bail!("user '{}' already exists.", userid); bail!("user '{}' already exists.", user.userid);
} }
let (username, realm) = crate::auth::parse_userid(&userid)?; let (username, realm) = crate::auth::parse_userid(&user.userid)?;
let authenticator = crate::auth::lookup_authenticator(&realm)?; let authenticator = crate::auth::lookup_authenticator(&realm)?;
config.set_data(&userid, "user", &user)?; config.set_data(&user.userid, "user", &user)?;
user::save_config(&config)?; user::save_config(&config)?;