Skip to content

feat: [#242] enhance provision command output with connection details#244

Merged
josecelano merged 2 commits intomainfrom
242-enhance-provision-command-output
Dec 17, 2025
Merged

feat: [#242] enhance provision command output with connection details#244
josecelano merged 2 commits intomainfrom
242-enhance-provision-command-output

Conversation

@josecelano
Copy link
Copy Markdown
Member

Summary

Enhances the provision command to display SSH connection details after successful infrastructure provisioning. This provides users with immediate, actionable information to connect to their newly provisioned instances.

Closes #242

Changes

New Features

  • Connection Details Display: After successful provisioning, users now see:
    • Instance IP address
    • SSH port
    • SSH private key path
    • SSH username
    • Ready-to-copy SSH connection command

Architecture

Implements a clean MVC pattern with proper DDD layering:

  • View Layer (src/presentation/views/commands/provision/):

    • ConnectionDetailsView: Renders formatted output
    • ConnectionDetailsData: DTO for connection information
    • Follows presentation → domain dependency (DDD compliant)
  • Controller (src/presentation/controllers/provision/handler.rs):

    • Orchestrates functional pipeline: Environment<Provisioned>ConnectionDetailsDataString → stdout
    • Uses From trait for clean DTO conversion
    • Proper error propagation with ? operator

Code Quality

  • Law of Demeter: Uses environment convenience methods (ssh_port(), ssh_username())
  • Functional Style: Pipeline composition eliminates intermediate variables
  • String Templates: Uses format! macro for efficient rendering
  • Error Handling: Proper Result propagation throughout the stack
  • Missing IP Handling: Gracefully displays warning (not error) if IP unavailable

Testing

  • 5 unit tests for view rendering:

    • Complete details with IP
    • Warning display when IP missing
    • Custom SSH ports
    • Absolute path handling
    • Path preservation
  • 4 controller tests (existing):

    • Invalid environment name
    • Empty environment name
    • Nonexistent environment
    • Valid environment name

All tests passing ✅

Output Example

Instance Connection Details:
  IP Address:        10.140.190.171
  SSH Port:          22
  SSH Private Key:   /home/user/.ssh/deploy_key
  SSH Username:      torrust

Connect using:
  ssh -i /home/user/.ssh/deploy_key torrust@10.140.190.171 -p 22

Technical Decisions

  1. From Trait Placement: Implemented in presentation layer (not domain) to maintain DDD - domain should not depend on presentation DTOs

  2. Output Channel: Uses ProgressReporter::result() to route to stdout (not stderr) since connection details are final command results, not progress information

  3. View Separation: Created new commands/ directory structure for command-specific views, maintaining clear organization

  4. Functional Pipeline: Used functional composition for clarity and to eliminate intermediate variables

Quality Checks

All pre-commit checks passed:

  • ✅ Linting (markdown, yaml, toml, cspell, clippy, rustfmt, shellcheck)
  • ✅ Dependencies (cargo machete)
  • ✅ Tests (unit + integration + E2E)
  • ✅ Documentation (cargo doc)

Related Documentation

Improved documentation to emphasize functional pipeline pattern and MVC
architecture. The rustdoc now clearly shows the data flow transformation:
Environment<Provisioned> → ConnectionDetailsData → String → stdout.

Detailed the MVC pattern components (Model, DTO, View, Controller, Output)
to make the architectural design explicit. Updated error documentation to
specify return type.
@josecelano josecelano self-assigned this Dec 17, 2025
Created draft refactoring plan for removing unnecessary CreateCommandHandler
progress steps from all presentation layer controllers. Handler creation is
instantaneous (just object construction) and doesn't warrant user-visible
progress reporting.

Key improvements:
- Better encapsulation: Move handler creation inside methods that use it
- Cleaner progress: Remove non-meaningful steps from user output
- Simpler code: Fewer methods, simpler signatures, clearer intent
- Consistent pattern: Apply same simplification across all controllers

Expected impact: ~70-95 lines removed across 5+ controllers

Status: Planning - discovered during #242 implementation
Target: provision, configure, register, release, run controllers
@josecelano josecelano marked this pull request as ready for review December 17, 2025 13:09
@josecelano
Copy link
Copy Markdown
Member Author

ACK 24c7c97

@josecelano josecelano merged commit 05e06be into main Dec 17, 2025
34 checks passed
josecelano added a commit that referenced this pull request Dec 17, 2025
Issue #242 has been implemented and merged in PR #244. Removing the issue
specification document as the work is complete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance Provision Command Output with SSH Connection Details

1 participant