Expand description
External Tool Adapters
This module contains thin wrappers (adapters) for external CLI tools used throughout the project. These adapters provide a consistent Rust interface for interacting with external command-line tools.
§Design Philosophy
All adapters in this module follow these principles:
- Thin wrappers: Minimal business logic, primarily command builders
- Consistent pattern: All use
CommandExecutorfromcrate::shared::command - Generic and reusable: Designed to be usable across different projects
- Infrastructure concerns: Handle external system interactions
§Architecture
Each adapter:
- Wraps an external CLI tool (SSH, Docker, Ansible, LXD,
OpenTofu) - Uses
CommandExecutoras a collaborator for actual command execution - Provides domain-specific methods that return typed results
- Handles tool-specific error cases with structured error types
§Available Adapters
ansible- Ansible configuration management tool wrapperdocker- Docker container platform wrapperlxd- LXD container and VM management wrappernetwork- Network diagnostic tools (netstat, ss) wrappersssh- SSH secure shell client wrappertofu-OpenTofuinfrastructure provisioning wrapper
§Example Usage
ⓘ
use std::sync::Arc;
use torrust_tracker_deployer_lib::adapters::ssh::{SshClient, SshConfig};
use torrust_tracker_deployer_lib::adapters::docker::DockerClient;
// Create SSH client adapter
let ssh_config = SshConfig::default();
let ssh_client = SshClient::new(Arc::new(ssh_config));
// Create Docker client adapter
let docker_client = DockerClient::new();§Relationship with Infrastructure Layer
While these adapters live at the top level (src/adapters/), application-specific
logic for using these tools remains in src/infrastructure/templating/:
src/adapters/: Generic CLI wrappers (this module)src/infrastructure/templating/: Application-specific template generation (e.g., Ansible inventory rendering,OpenTofuproject generation,Docker Composeconfigs)
This separation ensures adapters remain reusable while application-specific logic stays in the infrastructure layer.
Re-exports§
pub use ansible::AnsibleClient;pub use docker::DockerClient;pub use lxd::LxdClient;pub use network::NetstatClient;pub use network::SsClient;pub use ssh::SshClient;pub use ssh::SshConfig;pub use ssh::SshConnectionConfig;pub use ssh::SshCredentials;pub use ssh::SshPublicKey;pub use tofu::OpenTofuClient;