-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinternal_config.rs
More file actions
145 lines (132 loc) · 4.45 KB
/
Copy pathinternal_config.rs
File metadata and controls
145 lines (132 loc) · 4.45 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! Internal Config Module
//!
//! This module contains the `InternalConfig` struct which holds internal
//! configuration derived from user inputs.
//!
//! ## Purpose
//!
//! Internal configuration represents automatically derived paths and settings
//! that are calculated from user inputs. These are implementation details not
//! directly controlled by users.
//!
//! ## Semantic Category
//!
//! **Internal Config** fields are:
//! - Calculated from user inputs
//! - Not directly controlled by users
//! - Examples: build directory, data directory
//!
//! Add new fields here when: Need internal paths or derived configuration.
use crate::domain::environment::EnvironmentName;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
/// Base directory name for user data
const DATA_DIR_NAME: &str = "data";
/// Base directory name for build artifacts
const BUILD_DIR_NAME: &str = "build";
/// Internal paths and configuration derived from user inputs
///
/// This struct contains fields that are derived automatically from user inputs
/// and are not directly controlled by users. These represent internal
/// implementation details for organizing build artifacts and data.
///
/// # Examples
///
/// ```rust
/// use torrust_tracker_deployer_lib::domain::environment::internal_config::InternalConfig;
/// use std::path::PathBuf;
///
/// let internal_config = InternalConfig {
/// build_dir: PathBuf::from("build/production"),
/// data_dir: PathBuf::from("data/production"),
/// };
/// ```
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InternalConfig {
/// Build directory for this environment (derived from environment name)
pub build_dir: PathBuf,
/// Data directory for this environment (derived from environment name)
pub data_dir: PathBuf,
}
impl InternalConfig {
/// Creates a new `InternalConfig` with auto-generated directories
///
/// # Arguments
///
/// * `env_name` - The environment name used to generate directories
///
/// # Returns
///
/// A new `InternalConfig` with:
/// - `data_dir`: `data/{env_name}`
/// - `build_dir`: `build/{env_name}`
///
/// # Examples
///
/// ```rust
/// use torrust_tracker_deployer_lib::domain::environment::internal_config::InternalConfig;
/// use torrust_tracker_deployer_lib::domain::environment::EnvironmentName;
/// use std::path::PathBuf;
///
/// let env_name = EnvironmentName::new("production".to_string())?;
/// let config = InternalConfig::new(&env_name);
///
/// assert_eq!(config.data_dir, PathBuf::from("data/production"));
/// assert_eq!(config.build_dir, PathBuf::from("build/production"));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[must_use]
pub fn new(env_name: &EnvironmentName) -> Self {
// Generate environment-specific directories
let data_dir = PathBuf::from(DATA_DIR_NAME).join(env_name.as_str());
let build_dir = PathBuf::from(BUILD_DIR_NAME).join(env_name.as_str());
Self {
build_dir,
data_dir,
}
}
/// Returns the templates directory for this environment
///
/// Path: `data/{env_name}/templates/`
#[must_use]
pub fn templates_dir(&self) -> PathBuf {
self.data_dir.join(super::TEMPLATES_DIR_NAME)
}
/// Returns the traces directory for this environment
///
/// Path: `data/{env_name}/traces/`
#[must_use]
pub fn traces_dir(&self) -> PathBuf {
self.data_dir.join(super::TRACES_DIR_NAME)
}
/// Returns the ansible build directory
///
/// Path: `build/{env_name}/ansible`
#[must_use]
pub fn ansible_build_dir(&self) -> PathBuf {
self.build_dir.join(super::ANSIBLE_DIR_NAME)
}
/// Returns the `OpenTofu` build directory for the LXD provider
///
/// Path: `build/{env_name}/tofu/lxd`
#[must_use]
pub fn tofu_build_dir(&self) -> PathBuf {
self.build_dir
.join(super::TOFU_DIR_NAME)
.join(super::LXD_PROVIDER_NAME)
}
/// Returns the ansible templates directory
///
/// Path: `data/{env_name}/templates/ansible`
#[must_use]
pub fn ansible_templates_dir(&self) -> PathBuf {
self.templates_dir().join(super::ANSIBLE_DIR_NAME)
}
/// Returns the tofu templates directory
///
/// Path: `data/{env_name}/templates/tofu`
#[must_use]
pub fn tofu_templates_dir(&self) -> PathBuf {
self.templates_dir().join(super::TOFU_DIR_NAME)
}
}