[pbs-devel] [PATCH v3 proxmox-backup 10/18] manager: add commands for managing LDAP realms

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Feb 10 11:16:20 CET 2023


On February 9, 2023 2:31 pm, Lukas Wagner wrote:
> Adds commands for managing LDAP realms, including user sync, to
> `proxmox-backup-manager`.
> 
> Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
> ---
>  pbs-config/src/domains.rs              |  12 +-
>  src/bin/proxmox-backup-manager.rs      |   1 +
>  src/bin/proxmox_backup_manager/ldap.rs | 152 +++++++++++++++++++++++++
>  src/bin/proxmox_backup_manager/mod.rs  |   2 +
>  4 files changed, 165 insertions(+), 2 deletions(-)
>  create mode 100644 src/bin/proxmox_backup_manager/ldap.rs
> 
> [..]

> diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
> index 86adabe3..740fdc49 100644
> --- a/src/bin/proxmox-backup-manager.rs
> +++ b/src/bin/proxmox-backup-manager.rs
> @@ -427,6 +427,7 @@ async fn run() -> Result<(), Error> {
>          .insert("datastore", datastore_commands())
>          .insert("disk", disk_commands())
>          .insert("dns", dns_commands())
> +        .insert("ldap", ldap_commands())
>          .insert("network", network_commands())
>          .insert("node", node_commands())
>          .insert("user", user_commands())
> diff --git a/src/bin/proxmox_backup_manager/ldap.rs b/src/bin/proxmox_backup_manager/ldap.rs
> new file mode 100644
> index 00000000..538c313b
> --- /dev/null
> +++ b/src/bin/proxmox_backup_manager/ldap.rs
> @@ -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(
> +    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?;
> +        }
> +    }

possibly late to the party given that the "handle_worker" move got applied already..

is there a good reason for introducing this instead of calling the endpoint over
the API and using the "I just spawned a task and want to poll the output" helper
(pbs_client::view_task_result), like the rest of proxmox-backup-manager does?

> +
> +    Ok(Value::Null)
> +}
> +





More information about the pbs-devel mailing list