Skip to main content

torrust_tracker_deployer_lib/adapters/
mod.rs

1//! External Tool Adapters
2//!
3//! This module contains thin wrappers (adapters) for external CLI tools used throughout
4//! the project. These adapters provide a consistent Rust interface for interacting with
5//! external command-line tools.
6//!
7//! ## Design Philosophy
8//!
9//! All adapters in this module follow these principles:
10//!
11//! - **Thin wrappers**: Minimal business logic, primarily command builders
12//! - **Consistent pattern**: All use `CommandExecutor` from `crate::shared::command`
13//! - **Generic and reusable**: Designed to be usable across different projects
14//! - **Infrastructure concerns**: Handle external system interactions
15//!
16//! ## Architecture
17//!
18//! Each adapter:
19//!
20//! 1. Wraps an external CLI tool (SSH, Docker, Ansible, LXD, `OpenTofu`)
21//! 2. Uses `CommandExecutor` as a collaborator for actual command execution
22//! 3. Provides domain-specific methods that return typed results
23//! 4. Handles tool-specific error cases with structured error types
24//!
25//! ## Available Adapters
26//!
27//! - **`ansible`** - Ansible configuration management tool wrapper
28//! - **`docker`** - Docker container platform wrapper
29//! - **`lxd`** - LXD container and VM management wrapper
30//! - **`network`** - Network diagnostic tools (netstat, ss) wrappers
31//! - **`ssh`** - SSH secure shell client wrapper
32//! - **`tofu`** - `OpenTofu` infrastructure provisioning wrapper
33//!
34//! ## Example Usage
35//!
36//! ```ignore
37//! use std::sync::Arc;
38//! use torrust_tracker_deployer_lib::adapters::ssh::{SshClient, SshConfig};
39//! use torrust_tracker_deployer_lib::adapters::docker::DockerClient;
40//!
41//! // Create SSH client adapter
42//! let ssh_config = SshConfig::default();
43//! let ssh_client = SshClient::new(Arc::new(ssh_config));
44//!
45//! // Create Docker client adapter
46//! let docker_client = DockerClient::new();
47//! ```
48//!
49//! ## Relationship with Infrastructure Layer
50//!
51//! While these adapters live at the top level (`src/adapters/`), application-specific
52//! logic for using these tools remains in `src/infrastructure/templating/`:
53//!
54//! - **`src/adapters/`**: Generic CLI wrappers (this module)
55//! - **`src/infrastructure/templating/`**: Application-specific template generation
56//!   (e.g., Ansible inventory rendering, `OpenTofu` project generation, `Docker Compose` configs)
57//!
58//! This separation ensures adapters remain reusable while application-specific logic
59//! stays in the infrastructure layer.
60
61pub mod ansible;
62pub mod docker;
63pub mod lxd;
64pub mod network;
65pub mod ssh;
66pub mod tofu;
67
68// Re-exports for commonly used types
69pub use ansible::AnsibleClient;
70pub use docker::DockerClient;
71pub use lxd::LxdClient;
72pub use network::{NetstatClient, SsClient};
73pub use ssh::{SshClient, SshConfig, SshConnectionConfig, SshCredentials, SshPublicKey};
74pub use tofu::OpenTofuClient;