pub struct UserInputs { /* private fields */ }Expand description
User-provided configuration when creating an environment
This struct contains all fields that are provided by the user when creating an environment. These fields are immutable throughout the environment lifecycle and represent the user’s configuration choices.
§Cross-Service Invariants
The following invariants are validated at construction time:
- Grafana requires Prometheus: If Grafana is enabled, Prometheus must also be enabled
- HTTPS requires TLS services: If HTTPS section is present, at least one service must have TLS
- TLS requires HTTPS: If any service has TLS, HTTPS section must be present
§Examples
use torrust_tracker_deployer_lib::domain::{InstanceName, EnvironmentName, ProfileName};
use torrust_tracker_deployer_lib::domain::provider::{ProviderConfig, LxdConfig};
use torrust_tracker_deployer_lib::domain::environment::user_inputs::UserInputs;
use torrust_tracker_deployer_lib::domain::tracker::TrackerConfig;
use torrust_tracker_deployer_lib::domain::prometheus::PrometheusConfig;
use torrust_tracker_deployer_lib::domain::grafana::GrafanaConfig;
use torrust_tracker_deployer_lib::shared::Username;
use torrust_tracker_deployer_lib::adapters::ssh::SshCredentials;
use std::path::PathBuf;
let provider_config = ProviderConfig::Lxd(LxdConfig {
profile_name: ProfileName::new("torrust-profile-production".to_string())?,
});
let ssh_credentials = SshCredentials::new(
PathBuf::from("keys/prod_rsa"),
PathBuf::from("keys/prod_rsa.pub"),
Username::new("torrust".to_string())?,
);
let env_name = EnvironmentName::new("production".to_string())?;
// Create with defaults (includes Prometheus and Grafana)
let user_inputs = UserInputs::new(&env_name, provider_config, ssh_credentials, 22)?;
assert_eq!(user_inputs.name().as_str(), "production");
assert!(user_inputs.prometheus().is_some());
assert!(user_inputs.grafana().is_some());Implementations§
Source§impl UserInputs
impl UserInputs
Sourcepub fn new(
name: &EnvironmentName,
provider_config: ProviderConfig,
ssh_credentials: SshCredentials,
ssh_port: u16,
) -> Result<Self, UserInputsError>
pub fn new( name: &EnvironmentName, provider_config: ProviderConfig, ssh_credentials: SshCredentials, ssh_port: u16, ) -> Result<Self, UserInputsError>
Creates a new UserInputs with auto-generated instance name and default services
Creates a UserInputs with default tracker configuration, Prometheus, and Grafana
enabled. This is the standard setup for most deployments.
§Arguments
name- The validated environment nameprovider_config- Provider-specific configurationssh_credentials- SSH credentials for connecting to instancesssh_port- SSH port for connecting to instances
§Returns
A new UserInputs with:
- Auto-generated instance name:
torrust-tracker-vm-{env_name} - Default tracker configuration
- Prometheus and Grafana enabled (satisfies cross-service invariants)
§Errors
This constructor with defaults cannot fail because the default configuration (Prometheus + Grafana, no HTTPS) always satisfies cross-service invariants.
§Examples
use torrust_tracker_deployer_lib::domain::environment::{EnvironmentName, UserInputs};
use torrust_tracker_deployer_lib::domain::provider::{ProviderConfig, LxdConfig, Provider};
use torrust_tracker_deployer_lib::domain::ProfileName;
use torrust_tracker_deployer_lib::shared::Username;
use torrust_tracker_deployer_lib::adapters::ssh::SshCredentials;
use std::path::PathBuf;
let env_name = EnvironmentName::new("production".to_string())?;
let ssh_username = Username::new("torrust".to_string())?;
let ssh_credentials = SshCredentials::new(
PathBuf::from("keys/prod_rsa"),
PathBuf::from("keys/prod_rsa.pub"),
ssh_username,
);
let provider_config = ProviderConfig::Lxd(LxdConfig {
profile_name: ProfileName::new("torrust-profile-production".to_string())?,
});
let user_inputs = UserInputs::new(&env_name, provider_config, ssh_credentials, 22)?;
assert_eq!(user_inputs.instance_name().as_str(), "torrust-tracker-vm-production");
assert_eq!(user_inputs.provider(), Provider::Lxd);
Sourcepub fn with_tracker(
name: &EnvironmentName,
provider_config: ProviderConfig,
ssh_credentials: SshCredentials,
ssh_port: u16,
tracker: TrackerConfig,
prometheus: Option<PrometheusConfig>,
grafana: Option<GrafanaConfig>,
https: Option<HttpsConfig>,
backup: Option<BackupConfig>,
) -> Result<Self, UserInputsError>
pub fn with_tracker( name: &EnvironmentName, provider_config: ProviderConfig, ssh_credentials: SshCredentials, ssh_port: u16, tracker: TrackerConfig, prometheus: Option<PrometheusConfig>, grafana: Option<GrafanaConfig>, https: Option<HttpsConfig>, backup: Option<BackupConfig>, ) -> Result<Self, UserInputsError>
Creates a new UserInputs with custom tracker and service configuration
This constructor allows full control over all service configurations. Cross-service invariants are validated at construction time.
§Arguments
name- The validated environment nameprovider_config- Provider-specific configurationssh_credentials- SSH credentials for connecting to instancesssh_port- SSH port for connecting to instancestracker- Tracker deployment configurationprometheus- Optional Prometheus configurationgrafana- Optional Grafana configuration (requires Prometheus)https- Optional HTTPS/TLS configuration (requires TLS services)backup- Optional backup configuration
§Errors
GrafanaRequiresPrometheusif Grafana is configured without PrometheusHttpsSectionWithoutTlsServicesif HTTPS section exists but no service uses TLSTlsServicesWithoutHttpsSectionif a service uses TLS but HTTPS section is missing
Sourcepub fn name(&self) -> &EnvironmentName
pub fn name(&self) -> &EnvironmentName
Returns the environment name
Sourcepub fn instance_name(&self) -> &InstanceName
pub fn instance_name(&self) -> &InstanceName
Returns the instance name
Sourcepub fn ssh_credentials(&self) -> &SshCredentials
pub fn ssh_credentials(&self) -> &SshCredentials
Returns the SSH credentials
Sourcepub fn tracker(&self) -> &TrackerConfig
pub fn tracker(&self) -> &TrackerConfig
Returns the tracker configuration
Sourcepub fn prometheus(&self) -> Option<&PrometheusConfig>
pub fn prometheus(&self) -> Option<&PrometheusConfig>
Returns the Prometheus configuration if enabled
Sourcepub fn grafana(&self) -> Option<&GrafanaConfig>
pub fn grafana(&self) -> Option<&GrafanaConfig>
Returns the Grafana configuration if enabled
Sourcepub fn https(&self) -> Option<&HttpsConfig>
pub fn https(&self) -> Option<&HttpsConfig>
Returns the HTTPS configuration if enabled
Sourcepub fn backup(&self) -> Option<&BackupConfig>
pub fn backup(&self) -> Option<&BackupConfig>
Returns the backup configuration if enabled
Sourcepub fn provider(&self) -> Provider
pub fn provider(&self) -> Provider
Returns the provider type for this environment
§Examples
use torrust_tracker_deployer_lib::domain::environment::{EnvironmentName, UserInputs};
use torrust_tracker_deployer_lib::domain::provider::{ProviderConfig, LxdConfig, Provider};
use torrust_tracker_deployer_lib::domain::ProfileName;
use torrust_tracker_deployer_lib::shared::Username;
use torrust_tracker_deployer_lib::adapters::ssh::SshCredentials;
use std::path::PathBuf;
let env_name = EnvironmentName::new("test".to_string())?;
let ssh_credentials = SshCredentials::new(
PathBuf::from("keys/test_rsa"),
PathBuf::from("keys/test_rsa.pub"),
Username::new("torrust".to_string())?,
);
let provider_config = ProviderConfig::Lxd(LxdConfig {
profile_name: ProfileName::new("test-profile".to_string())?,
});
let user_inputs = UserInputs::new(&env_name, provider_config, ssh_credentials, 22)?;
assert_eq!(user_inputs.provider(), Provider::Lxd);
Sourcepub fn provider_config(&self) -> &ProviderConfig
pub fn provider_config(&self) -> &ProviderConfig
Returns a reference to the provider configuration
Use this to access provider-specific fields. For example:
if let Some(lxd_config) = user_inputs.provider_config().as_lxd() {
println!("LXD profile: {}", lxd_config.profile_name.as_str());
}Trait Implementations§
Source§impl Clone for UserInputs
impl Clone for UserInputs
Source§impl Debug for UserInputs
impl Debug for UserInputs
Source§impl<'de> Deserialize<'de> for UserInputs
impl<'de> Deserialize<'de> for UserInputs
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for UserInputs
impl RefUnwindSafe for UserInputs
impl Send for UserInputs
impl Sync for UserInputs
impl Unpin for UserInputs
impl UnsafeUnpin for UserInputs
impl UnwindSafe for UserInputs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request