-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.rs
More file actions
88 lines (85 loc) · 3.25 KB
/
mod.rs
File metadata and controls
88 lines (85 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Create Command Module
//!
//! This module implements the delivery-agnostic `CreateCommandHandler` for orchestrating
//! environment creation business logic. The command is synchronous and follows
//! existing patterns from `ProvisionCommandHandler`.
//!
//! ## Architecture
//!
//! The `CreateCommandHandler` implements the Command Pattern and uses Dependency Injection
//! to interact with infrastructure services through interfaces:
//!
//! - **Repository Pattern**: Persists environment state via `EnvironmentRepository`
//! - **Clock Abstraction**: Provides deterministic time for testing via `Clock` trait
//! - **Domain-Driven Design**: Uses domain objects from `domain::environment`
//!
//! ## Design Principles
//!
//! - **Delivery-Agnostic**: Works with CLI, REST API, or any delivery mechanism
//! - **Synchronous**: Follows existing patterns (no async/await)
//! - **Repository Responsibility**: Lets repository handle directory creation atomically
//! - **Explicit Errors**: All errors implement `.help()` with actionable guidance
//!
//! ## Usage Example
//!
//! ```rust,no_run
//! use std::sync::Arc;
//! use torrust_tracker_deployer_lib::application::command_handlers::create::CreateCommandHandler;
//! use torrust_tracker_deployer_lib::application::command_handlers::create::config::{
//! EnvironmentCreationConfig, EnvironmentSection, LxdProviderSection, ProviderSection,
//! SshCredentialsConfig,
//! };
//! use torrust_tracker_deployer_lib::application::command_handlers::create::config::tracker::TrackerSection;
//! use torrust_tracker_deployer_lib::infrastructure::persistence::repository_factory::RepositoryFactory;
//! use torrust_tracker_deployer_lib::shared::{SystemClock, Clock};
//!
//! // Setup dependencies
//! let repository_factory = RepositoryFactory::new(std::time::Duration::from_secs(30));
//! let repository = repository_factory.create(std::path::PathBuf::from("."));
//! let clock: Arc<dyn Clock> = Arc::new(SystemClock);
//!
//! // Create command
//! let command = CreateCommandHandler::new(repository, clock);
//!
//! // Prepare configuration
//! let config = EnvironmentCreationConfig::new(
//! EnvironmentSection {
//! name: "production".to_string(),
//! instance_name: None, // Auto-generate from environment name
//! },
//! SshCredentialsConfig::new(
//! "keys/prod_key".to_string(),
//! "keys/prod_key.pub".to_string(),
//! "torrust".to_string(),
//! 22,
//! ),
//! ProviderSection::Lxd(LxdProviderSection {
//! profile_name: "lxd-production".to_string(),
//! }),
//! TrackerSection::default(),
//! None, // prometheus
//! None, // grafana
//! None, // https
//! );
//!
//! // Execute command with working directory
//! let working_dir = std::path::Path::new(".");
//! match command.execute(config, working_dir) {
//! Ok(environment) => {
//! println!("Created environment: {}", environment.name());
//! }
//! Err(error) => {
//! eprintln!("Error: {}", error);
//! eprintln!("\n{}", error.help());
//! }
//! }
//! ```
pub mod config;
pub mod errors;
pub mod handler;
pub mod schema;
#[cfg(test)]
mod tests;
// Re-export main types for convenience
pub use errors::CreateCommandHandlerError;
pub use handler::CreateCommandHandler;