Skip to content

Update UserInputs to use ProviderConfig #207

@josecelano

Description

@josecelano

Task: Update UserInputs to use ProviderConfig

Epic: #205 - Add Hetzner Provider Support
Phase: 1 - Make LXD Explicit
Dependencies: #206 (Add Provider enum and ProviderConfig types)

Overview

Refactor the domain UserInputs struct to include provider configuration. This moves profile_name from being a global field to being part of LxdConfig, making provider-specific configuration explicit.

Current State

// src/domain/user_inputs.rs (current)
pub struct UserInputs {
    pub instance_name: InstanceName,
    pub profile_name: ProfileName,  // LXD-specific, but treated as global
    // ... other fields
}

Target State

// src/domain/user_inputs.rs (after this task)
use crate::domain::provider::ProviderConfig;

pub struct UserInputs {
    pub instance_name: InstanceName,     // Kept global - all providers need it
    pub provider_config: ProviderConfig, // Provider-specific config
    // ... other fields
}

impl UserInputs {
    /// Returns the LXD profile name if using LXD provider.
    ///
    /// # Panics
    ///
    /// Panics if not using LXD provider.
    pub fn lxd_profile_name(&self) -> &ProfileName {
        self.provider_config.as_lxd().profile_name
    }

    /// Returns the provider type.
    pub fn provider(&self) -> Provider {
        self.provider_config.provider()
    }
}

Implementation Steps

  1. Add import for ProviderConfig from crate::domain::provider
  2. Add provider_config field to UserInputs
  3. Remove profile_name field from UserInputs (it's now in LxdConfig)
  4. Add accessor methods for provider-specific fields
  5. Update all usages of user_inputs.profile_name throughout codebase

Code Changes Required

Files to Modify

  1. src/domain/user_inputs.rs - Main struct changes
  2. All files that access user_inputs.profile_name - Update to use accessor
  3. Tests that construct UserInputs - Update to include provider_config

Finding Usages

Search for:

  • user_inputs.profile_name
  • profile_name: in struct construction
  • UserInputs { struct literals

DDD Compliance

This change maintains DDD principles:

  • UserInputs remains in domain layer (semantic meaning: "what the user wants")
  • ProviderConfig is in domain layer (semantic meaning: "provider-specific validated configuration")
  • ProviderSection stays in application layer (raw JSON parsing)
  • The conversion ProviderSection → ProviderConfig happens in application layer before constructing UserInputs

Testing Requirements

Unit Tests

  • UserInputs construction with LXD provider config
  • UserInputs construction with Hetzner provider config
  • lxd_profile_name() accessor returns correct value
  • lxd_profile_name() panics for non-LXD provider
  • provider() method returns correct variant

Integration Tests

  • E2E tests still pass with updated UserInputs

Acceptance Criteria

  • UserInputs has provider_config: ProviderConfig field
  • profile_name field removed from UserInputs (moved to LxdConfig)
  • instance_name remains as global field in UserInputs
  • Accessor methods exist for provider-specific fields
  • All existing usages of profile_name updated
  • All tests pass
  • No compiler warnings

Notes

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions