Skip to main content

execute_command

Function execute_command 

Source
pub fn execute_command<L: LdapDirectory>(
    ctx: &ServiceContext<L>,
    command: &ParsedCommand,
) -> Result<Vec<Row>>
Expand description

Executes a parsed service-layer command against the configured LDAP port.

ยงExamples

use osp_cli::config::RuntimeConfig;
use osp_cli::ports::mock::MockLdapClient;
use osp_cli::services::{ParsedCommand, ServiceContext, execute_command};

let ctx = ServiceContext::new(
    Some("oistes".to_string()),
    MockLdapClient::default(),
    RuntimeConfig::default(),
);
// `MockLdapClient::default()` exposes a fixed `oistes` user fixture.
let rows = execute_command(
    &ctx,
    &ParsedCommand::LdapUser {
        uid: None,
        filter: Some("uid=oistes".to_string()),
        attributes: Some("uid,cn".to_string()),
    },
)
.unwrap();

assert_eq!(rows.len(), 1);
assert_eq!(rows[0].get("uid").and_then(|value| value.as_str()), Some("oistes"));