-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcredentials.rs
More file actions
73 lines (67 loc) · 2.6 KB
/
credentials.rs
File metadata and controls
73 lines (67 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! SSH credentials for remote instance authentication
//!
//! This module provides the `SshCredentials` struct which manages SSH authentication
//! information including private/public key paths and username configuration.
//!
//! ## Key Features
//!
//! - SSH key pair management (private and public keys)
//! - Username configuration for remote connections
//! - Integration with SSH connection establishment
//! - Support for creating SSH connections with target IP addresses
//!
//! The credentials are typically configured at startup and used throughout
//! the deployment process for secure remote access to provisioned instances.
use std::path::PathBuf;
use crate::shared::Username;
use serde::{Deserialize, Serialize};
/// SSH credentials for remote instance authentication.
///
/// Contains the static SSH authentication information that is known
/// at program startup, before any instances are provisioned.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SshCredentials {
/// Path to the SSH private key file for remote connections.
///
/// This key will be used by the SSH client to authenticate with remote
/// instances created during deployment. The corresponding public key
/// should be authorized on the target instances.
pub ssh_priv_key_path: PathBuf,
/// Path to the SSH public key file for remote connections.
///
/// This public key will be used for authorization on target instances
/// during the deployment process, typically injected into cloud-init
/// configurations or `authorized_keys` files.
pub ssh_pub_key_path: PathBuf,
/// Username for SSH connections to remote instances.
///
/// This username will be used when establishing SSH connections to
/// deployed instances. Common values include "ubuntu", "root", or "torrust".
pub ssh_username: Username,
}
impl SshCredentials {
/// Creates new SSH credentials with the provided parameters.
///
/// ```rust
/// # use std::path::PathBuf;
/// # use torrust_tracker_deployer_lib::shared::Username;
/// use torrust_tracker_deployer_lib::adapters::ssh::SshCredentials;
/// let credentials = SshCredentials::new(
/// PathBuf::from("/home/user/.ssh/deploy_key"),
/// PathBuf::from("/home/user/.ssh/deploy_key.pub"),
/// Username::new("ubuntu").unwrap(),
/// );
/// ```
#[must_use]
pub fn new(
ssh_priv_key_path: PathBuf,
ssh_pub_key_path: PathBuf,
ssh_username: Username,
) -> Self {
Self {
ssh_priv_key_path,
ssh_pub_key_path,
ssh_username,
}
}
}