Skip to main content

UserInputs

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

Source

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 name
  • provider_config - Provider-specific configuration
  • ssh_credentials - SSH credentials for connecting to instances
  • ssh_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);
Source

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 name
  • provider_config - Provider-specific configuration
  • ssh_credentials - SSH credentials for connecting to instances
  • ssh_port - SSH port for connecting to instances
  • tracker - Tracker deployment configuration
  • prometheus - Optional Prometheus configuration
  • grafana - Optional Grafana configuration (requires Prometheus)
  • https - Optional HTTPS/TLS configuration (requires TLS services)
  • backup - Optional backup configuration
§Errors
  • GrafanaRequiresPrometheus if Grafana is configured without Prometheus
  • HttpsSectionWithoutTlsServices if HTTPS section exists but no service uses TLS
  • TlsServicesWithoutHttpsSection if a service uses TLS but HTTPS section is missing
Source

pub fn name(&self) -> &EnvironmentName

Returns the environment name

Source

pub fn instance_name(&self) -> &InstanceName

Returns the instance name

Source

pub fn ssh_credentials(&self) -> &SshCredentials

Returns the SSH credentials

Source

pub fn ssh_port(&self) -> u16

Returns the SSH port

Source

pub fn tracker(&self) -> &TrackerConfig

Returns the tracker configuration

Source

pub fn prometheus(&self) -> Option<&PrometheusConfig>

Returns the Prometheus configuration if enabled

Source

pub fn grafana(&self) -> Option<&GrafanaConfig>

Returns the Grafana configuration if enabled

Source

pub fn https(&self) -> Option<&HttpsConfig>

Returns the HTTPS configuration if enabled

Source

pub fn backup(&self) -> Option<&BackupConfig>

Returns the backup configuration if enabled

Source

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);
Source

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

Source§

fn clone(&self) -> UserInputs

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UserInputs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for UserInputs

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for UserInputs

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> IntoResult<T> for T

Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,