mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-10-04 19:58:14 +00:00
manager: add commands for managing LDAP realms
Adds commands for managing LDAP realms, including user sync, to `proxmox-backup-manager`. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
parent
73757fe2df
commit
2b75fbaa33
@ -71,13 +71,13 @@ pub fn complete_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn complete_openid_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
fn complete_realm_of_type(realm_type: &str) -> Vec<String> {
|
||||||
match config() {
|
match config() {
|
||||||
Ok((data, _digest)) => data
|
Ok((data, _digest)) => data
|
||||||
.sections
|
.sections
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(id, (t, _))| {
|
.filter_map(|(id, (t, _))| {
|
||||||
if t == "openid" {
|
if t == realm_type {
|
||||||
Some(id.to_string())
|
Some(id.to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -87,3 +87,11 @@ pub fn complete_openid_realm_name(_arg: &str, _param: &HashMap<String, String>)
|
|||||||
Err(_) => Vec::new(),
|
Err(_) => Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn complete_openid_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
||||||
|
complete_realm_of_type("openid")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn complete_ldap_realm_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
||||||
|
complete_realm_of_type("ldap")
|
||||||
|
}
|
||||||
|
@ -427,6 +427,7 @@ async fn run() -> Result<(), Error> {
|
|||||||
.insert("datastore", datastore_commands())
|
.insert("datastore", datastore_commands())
|
||||||
.insert("disk", disk_commands())
|
.insert("disk", disk_commands())
|
||||||
.insert("dns", dns_commands())
|
.insert("dns", dns_commands())
|
||||||
|
.insert("ldap", ldap_commands())
|
||||||
.insert("network", network_commands())
|
.insert("network", network_commands())
|
||||||
.insert("node", node_commands())
|
.insert("node", node_commands())
|
||||||
.insert("user", user_commands())
|
.insert("user", user_commands())
|
||||||
|
152
src/bin/proxmox_backup_manager/ldap.rs
Normal file
152
src/bin/proxmox_backup_manager/ldap.rs
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
use anyhow::Error;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use proxmox_router::{cli::*, ApiHandler, Permission, RpcEnvironment};
|
||||||
|
use proxmox_schema::api;
|
||||||
|
|
||||||
|
use pbs_api_types::{
|
||||||
|
Realm, PRIV_PERMISSIONS_MODIFY, PROXMOX_UPID_REGEX, REALM_ID_SCHEMA, REMOVE_VANISHED_SCHEMA,
|
||||||
|
};
|
||||||
|
|
||||||
|
use proxmox_backup::api2;
|
||||||
|
|
||||||
|
#[api(
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
"output-format": {
|
||||||
|
schema: OUTPUT_FORMAT,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)]
|
||||||
|
/// List configured LDAP realms
|
||||||
|
fn list_ldap_realms(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
||||||
|
let output_format = get_output_format(¶m);
|
||||||
|
|
||||||
|
let info = &api2::config::access::ldap::API_METHOD_LIST_LDAP_REALMS;
|
||||||
|
let mut data = match info.handler {
|
||||||
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = default_table_format_options()
|
||||||
|
.column(ColumnConfig::new("realm"))
|
||||||
|
.column(ColumnConfig::new("server1"))
|
||||||
|
.column(ColumnConfig::new("comment"));
|
||||||
|
|
||||||
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
||||||
|
|
||||||
|
Ok(Value::Null)
|
||||||
|
}
|
||||||
|
#[api(
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
realm: {
|
||||||
|
schema: REALM_ID_SCHEMA,
|
||||||
|
},
|
||||||
|
"output-format": {
|
||||||
|
schema: OUTPUT_FORMAT,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)]
|
||||||
|
|
||||||
|
/// Show LDAP realm configuration
|
||||||
|
fn show_ldap_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
||||||
|
let output_format = get_output_format(¶m);
|
||||||
|
|
||||||
|
let info = &api2::config::access::ldap::API_METHOD_READ_LDAP_REALM;
|
||||||
|
let mut data = match info.handler {
|
||||||
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = default_table_format_options();
|
||||||
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
||||||
|
|
||||||
|
Ok(Value::Null)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[api(
|
||||||
|
protected: true,
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
realm: {
|
||||||
|
type: Realm,
|
||||||
|
},
|
||||||
|
"dry-run": {
|
||||||
|
type: bool,
|
||||||
|
description: "If set, do not create/delete anything",
|
||||||
|
default: false,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
"remove-vanished": {
|
||||||
|
optional: true,
|
||||||
|
schema: REMOVE_VANISHED_SCHEMA,
|
||||||
|
},
|
||||||
|
"enable-new": {
|
||||||
|
description: "Enable newly synced users immediately",
|
||||||
|
optional: true,
|
||||||
|
type: bool,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
access: {
|
||||||
|
permission: &Permission::Privilege(&["access", "users"], PRIV_PERMISSIONS_MODIFY, false),
|
||||||
|
},
|
||||||
|
)]
|
||||||
|
/// Sync a given LDAP realm
|
||||||
|
async fn sync_ldap_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
||||||
|
let info = &api2::access::domain::API_METHOD_SYNC_REALM;
|
||||||
|
let data = match info.handler {
|
||||||
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(upid) = data.as_str() {
|
||||||
|
if PROXMOX_UPID_REGEX.is_match(upid) {
|
||||||
|
proxmox_rest_server::handle_worker(upid).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Value::Null)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ldap_commands() -> CommandLineInterface {
|
||||||
|
let cmd_def = CliCommandMap::new()
|
||||||
|
.insert("list", CliCommand::new(&API_METHOD_LIST_LDAP_REALMS))
|
||||||
|
.insert(
|
||||||
|
"show",
|
||||||
|
CliCommand::new(&API_METHOD_SHOW_LDAP_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", pbs_config::domains::complete_ldap_realm_name),
|
||||||
|
)
|
||||||
|
.insert(
|
||||||
|
"create",
|
||||||
|
CliCommand::new(&api2::config::access::ldap::API_METHOD_CREATE_LDAP_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", pbs_config::domains::complete_ldap_realm_name),
|
||||||
|
)
|
||||||
|
.insert(
|
||||||
|
"update",
|
||||||
|
CliCommand::new(&api2::config::access::ldap::API_METHOD_UPDATE_LDAP_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", pbs_config::domains::complete_ldap_realm_name),
|
||||||
|
)
|
||||||
|
.insert(
|
||||||
|
"delete",
|
||||||
|
CliCommand::new(&api2::config::access::ldap::API_METHOD_DELETE_LDAP_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", pbs_config::domains::complete_ldap_realm_name),
|
||||||
|
)
|
||||||
|
.insert(
|
||||||
|
"sync",
|
||||||
|
CliCommand::new(&API_METHOD_SYNC_LDAP_REALM)
|
||||||
|
.arg_param(&["realm"])
|
||||||
|
.completion_cb("realm", pbs_config::domains::complete_ldap_realm_name),
|
||||||
|
);
|
||||||
|
|
||||||
|
cmd_def.into()
|
||||||
|
}
|
@ -8,6 +8,8 @@ mod datastore;
|
|||||||
pub use datastore::*;
|
pub use datastore::*;
|
||||||
mod dns;
|
mod dns;
|
||||||
pub use dns::*;
|
pub use dns::*;
|
||||||
|
mod ldap;
|
||||||
|
pub use ldap::*;
|
||||||
mod network;
|
mod network;
|
||||||
pub use network::*;
|
pub use network::*;
|
||||||
mod prune;
|
mod prune;
|
||||||
|
Loading…
Reference in New Issue
Block a user