Skip to content

Commit 5246452

Browse files
committed
keylimectl: test and document remaining commands
Test and document list, measured_boot, and policy commands. Assisted-by: Claude 4 Sonnet Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent aee5b53 commit 5246452

File tree

3 files changed

+923
-6
lines changed

3 files changed

+923
-6
lines changed

keylimectl/src/commands/list.rs

Lines changed: 177 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,80 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright 2025 Keylime Authors
33

4-
//! List commands for various resources
4+
//! List commands for various Keylime resources
5+
//!
6+
//! This module provides comprehensive listing functionality for all major Keylime resources,
7+
//! including agents, runtime policies, and measured boot policies. It offers both basic
8+
//! and detailed views depending on user requirements.
9+
//!
10+
//! # Resource Types
11+
//!
12+
//! The list command supports several resource types:
13+
//!
14+
//! 1. **Agents**: List all agents registered with the system
15+
//! - Basic view: Shows agent status from verifier
16+
//! - Detailed view: Combines data from both verifier and registrar
17+
//! 2. **Runtime Policies**: List all runtime/IMA policies
18+
//! 3. **Measured Boot Policies**: List all measured boot policies
19+
//!
20+
//! # Agent Listing Modes
21+
//!
22+
//! ## Basic Mode
23+
//! - Retrieves agent list from verifier only
24+
//! - Shows operational state and basic status
25+
//! - Faster operation, suitable for quick status checks
26+
//! - Shows: UUID, operational state
27+
//!
28+
//! ## Detailed Mode
29+
//! - Retrieves comprehensive data from both verifier and registrar
30+
//! - Shows complete agent information including TPM data
31+
//! - Slower operation but provides complete picture
32+
//! - Shows: UUID, operational state, IP, port, TPM keys, registration info
33+
//!
34+
//! # Policy Listing
35+
//!
36+
//! Policy listing provides an overview of all configured policies:
37+
//! - Policy names and metadata
38+
//! - Creation and modification timestamps
39+
//! - Policy status and validation state
40+
//!
41+
//! # Performance Considerations
42+
//!
43+
//! - Basic agent listing is optimized for speed
44+
//! - Detailed listing may take longer with many agents
45+
//! - Policy listing is generally fast as policies are typically fewer
46+
//! - Results are paginated automatically for large deployments
47+
//!
48+
//! # Examples
49+
//!
50+
//! ```rust
51+
//! use keylimectl::commands::list;
52+
//! use keylimectl::config::Config;
53+
//! use keylimectl::output::OutputHandler;
54+
//! use keylimectl::ListResource;
55+
//!
56+
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
57+
//! let config = Config::default();
58+
//! let output = OutputHandler::new(crate::OutputFormat::Json, false);
59+
//!
60+
//! // List agents with basic information
61+
//! let basic_agents = ListResource::Agents { detailed: false };
62+
//! let result = list::execute(&basic_agents, &config, &output).await?;
63+
//!
64+
//! // List agents with detailed information
65+
//! let detailed_agents = ListResource::Agents { detailed: true };
66+
//! let result = list::execute(&detailed_agents, &config, &output).await?;
67+
//!
68+
//! // List runtime policies
69+
//! let policies = ListResource::Policies;
70+
//! let result = list::execute(&policies, &config, &output).await?;
71+
//!
72+
//! // List measured boot policies
73+
//! let mb_policies = ListResource::MeasuredBootPolicies;
74+
//! let result = list::execute(&mb_policies, &config, &output).await?;
75+
//! # Ok(())
76+
//! # }
77+
//! ```
578
679
use crate::client::{registrar::RegistrarClient, verifier::VerifierClient};
780
use crate::config::Config;
@@ -10,7 +83,109 @@ use crate::output::OutputHandler;
1083
use crate::ListResource;
1184
use serde_json::{json, Value};
1285

13-
/// Execute a list command
86+
/// Execute a resource listing command
87+
///
88+
/// This is the main entry point for all resource listing operations. It dispatches
89+
/// to the appropriate handler based on the resource type and manages the complete
90+
/// operation lifecycle including data retrieval, formatting, and result reporting.
91+
///
92+
/// # Arguments
93+
///
94+
/// * `resource` - The specific resource type to list (Agents, Policies, or MeasuredBootPolicies)
95+
/// * `config` - Configuration containing service endpoints and authentication settings
96+
/// * `output` - Output handler for progress reporting and result formatting
97+
///
98+
/// # Returns
99+
///
100+
/// Returns a JSON value containing the listing results. The structure varies by resource type:
101+
///
102+
/// ## Agent Listing (Basic)
103+
/// ```json
104+
/// {
105+
/// "results": {
106+
/// "agent-uuid-1": "operational_state",
107+
/// "agent-uuid-2": "operational_state"
108+
/// }
109+
/// }
110+
/// ```
111+
///
112+
/// ## Agent Listing (Detailed)
113+
/// ```json
114+
/// {
115+
/// "detailed": true,
116+
/// "verifier": {
117+
/// "results": {
118+
/// "agent-uuid-1": {
119+
/// "operational_state": "Get Quote",
120+
/// "ip": "192.168.1.100",
121+
/// "port": 9002
122+
/// }
123+
/// }
124+
/// },
125+
/// "registrar": {
126+
/// "results": {
127+
/// "agent-uuid-1": {
128+
/// "aik_tpm": "base64-encoded-key",
129+
/// "ek_tpm": "base64-encoded-key",
130+
/// "ip": "192.168.1.100",
131+
/// "port": 9002,
132+
/// "active": true
133+
/// }
134+
/// }
135+
/// }
136+
/// }
137+
/// ```
138+
///
139+
/// ## Policy Listing
140+
/// ```json
141+
/// {
142+
/// "results": {
143+
/// "policy-name-1": {
144+
/// "created": "2025-01-01T00:00:00Z",
145+
/// "last_modified": "2025-01-02T12:00:00Z"
146+
/// }
147+
/// }
148+
/// }
149+
/// ```
150+
///
151+
/// # Error Handling
152+
///
153+
/// This function handles various error conditions:
154+
/// - Network failures when communicating with services
155+
/// - Service unavailability (verifier or registrar down)
156+
/// - Authentication/authorization failures
157+
/// - Empty result sets (no resources found)
158+
///
159+
/// # Performance Notes
160+
///
161+
/// - Basic agent listing is optimized for speed
162+
/// - Detailed agent listing requires two API calls (verifier + registrar)
163+
/// - Policy listing is typically fast due to smaller data volumes
164+
/// - Large deployments may experience longer response times
165+
///
166+
/// # Examples
167+
///
168+
/// ```rust
169+
/// use keylimectl::commands::list;
170+
/// use keylimectl::config::Config;
171+
/// use keylimectl::output::OutputHandler;
172+
/// use keylimectl::ListResource;
173+
///
174+
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
175+
/// let config = Config::default();
176+
/// let output = OutputHandler::new(crate::OutputFormat::Json, false);
177+
///
178+
/// // List agents (basic)
179+
/// let agents = ListResource::Agents { detailed: false };
180+
/// let result = list::execute(&agents, &config, &output).await?;
181+
/// println!("Found {} agents", result["results"].as_object().unwrap().len());
182+
///
183+
/// // List policies
184+
/// let policies = ListResource::Policies;
185+
/// let result = list::execute(&policies, &config, &output).await?;
186+
/// # Ok(())
187+
/// # }
188+
/// ```
14189
pub async fn execute(
15190
resource: &ListResource,
16191
config: &Config,

keylimectl/src/commands/measured_boot.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,9 @@ mod tests {
729729
"file not found",
730730
));
731731

732-
let contextual_error = io_error
733-
.with_context(|| "Failed to read measured boot policy file".to_string());
732+
let contextual_error = io_error.with_context(|| {
733+
"Failed to read measured boot policy file".to_string()
734+
});
734735

735736
assert!(contextual_error.is_err());
736737
let error = contextual_error.unwrap_err();

0 commit comments

Comments
 (0)