-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.rs
More file actions
103 lines (101 loc) · 3.83 KB
/
Copy pathmod.rs
File metadata and controls
103 lines (101 loc) · 3.83 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Configuration Module for Create Command
//!
//! This module provides configuration Data Transfer Objects (DTOs) and validation for
//! creating deployment environments. It sits at the boundary between external configuration
//! sources (JSON files, CLI arguments, etc.) and the internal domain model.
//!
//! ## Architecture
//!
//! The configuration DTOs in this module are specific to the create command and are distinct
//! from both the domain and adapter layers:
//!
//! - **Configuration DTOs** (`application::command_handlers::create::config`): String-based
//! configuration objects that deserialize from external sources (JSON, TOML, CLI)
//! - **Domain Layer** (`domain::environment`): Strongly-typed domain entities
//! with business validation
//! - **Adapter Layer** (`adapters::ssh`): Infrastructure-specific implementations
//!
//! ## Key Components
//!
//! ### Value Objects
//!
//! - `EnvironmentCreationConfig` - Top-level configuration for environment creation
//! - `SshCredentialsConfig` - SSH credentials configuration (config layer)
//! - `EnvironmentSection` - Environment-specific settings
//!
//! Note: `SshCredentialsConfig` (config layer) is distinct from
//! `adapters::ssh::SshCredentials` (adapter layer). The config version uses
//! strings for paths and usernames, while the adapter version uses domain types.
//!
//! ### Type Conversion
//!
//! Configuration objects provide `to_*` methods that convert string-based
//! configuration to strongly-typed domain objects:
//!
//! - String environment name → `EnvironmentName`
//! - String username → `Username`
//! - String paths → `PathBuf`
//!
//! ### Error Handling
//!
//! All errors implement the `.help()` method following the project's tiered
//! help system pattern, providing actionable guidance for resolving issues.
//!
//! ## Usage Example
//!
//! ```rust
//! use torrust_tracker_deployer_lib::application::command_handlers::create::config::{
//! EnvironmentCreationConfig, EnvironmentSection, SshCredentialsConfig
//! };
//! use torrust_tracker_deployer_lib::domain::Environment;
//!
//! // Deserialize configuration from JSON
//! let json = r#"{
//! "environment": {
//! "name": "dev"
//! },
//! "ssh_credentials": {
//! "private_key_path": "fixtures/testing_rsa",
//! "public_key_path": "fixtures/testing_rsa.pub"
//! }
//! }"#;
//!
//! let config: EnvironmentCreationConfig = serde_json::from_str(json)?;
//!
//! // Convert to domain parameters
//! let (name, credentials, port) = config.to_environment_params()?;
//!
//! // Create domain entity
//! let environment = Environment::new(name, credentials, port);
//!
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Validation Strategy
//!
//! Validation occurs in two phases:
//!
//! 1. **Format Validation** (during conversion):
//! - Environment name format (via `EnvironmentName::new()`)
//! - Username format (via `Username::new()`)
//! - Path string to `PathBuf` conversion
//!
//! 2. **Business Validation** (during conversion):
//! - SSH key file existence
//! - SSH key file accessibility
//! - Domain-specific business rules
//!
//! ## Design Principles
//!
//! - **Type Safety**: String-based config → strongly-typed domain objects
//! - **Single Responsibility**: Config objects only handle deserialization and conversion
//! - **Explicit Errors**: All validation errors are explicit enum variants with context
//! - **Actionable Feedback**: All errors provide `.help()` with troubleshooting steps
//! - **Clean Separation**: Config layer is distinct from domain and adapter layers
pub mod environment_config;
pub mod errors;
pub mod ssh_credentials_config;
// Re-export commonly used types for convenience
pub use environment_config::{EnvironmentCreationConfig, EnvironmentSection};
pub use errors::CreateConfigError;
pub use ssh_credentials_config::SshCredentialsConfig;