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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//! SSH config structure.
use crate::connect_info::ConnectInfo;
use serde::{ Deserialize, Serialize };
//------------------------------------------------------------------------------
/// Structure that stores operations and connection information for the
/// connection destination.
//------------------------------------------------------------------------------
#[derive(Debug, Serialize, Deserialize)]
pub struct SshConfig
{
project: String,
environment: String,
remote_path: Option<String>,
remote_cache_path: Option<String>,
git_path: Option<String>,
git_src_path: Option<String>,
backup_path: Option<String>,
db_host: Option<String>,
db_host_reader: Option<String>,
db_port: Option<u16>,
db_name: Option<String>,
db_user: Option<String>,
db_password: Option<String>,
db_root_user: Option<String>,
db_root_password: Option<String>,
connect_info: ConnectInfo,
tunnels: Option<Vec<ConnectInfo>>,
}
impl SshConfig
{
//--------------------------------------------------------------------------
/// Returns the project name.
//--------------------------------------------------------------------------
pub fn project( &self ) -> String
{
self.project.clone()
}
//--------------------------------------------------------------------------
/// Returns the environment name.
//--------------------------------------------------------------------------
pub fn environment( &self ) -> String
{
self.environment.clone()
}
//--------------------------------------------------------------------------
/// Returns the remote path.
//--------------------------------------------------------------------------
pub fn remote_path( &self ) -> String
{
self.remote_path
.clone()
.unwrap_or("".to_string())
.trim_end_matches("/")
.to_string()
}
//--------------------------------------------------------------------------
/// Returns the remote cache path.
//--------------------------------------------------------------------------
pub fn remote_cache_path( &self ) -> String
{
self.remote_cache_path
.clone()
.unwrap_or("".to_string())
.trim_end_matches("/")
.to_string()
}
//--------------------------------------------------------------------------
/// Returns the git path.
//--------------------------------------------------------------------------
pub fn git_path( &self ) -> String
{
self.git_path
.clone()
.unwrap_or("".to_string())
.trim_end_matches("/")
.to_string()
}
//--------------------------------------------------------------------------
/// Returns the git source path.
//--------------------------------------------------------------------------
pub fn git_src_path( &self ) -> String
{
self.git_src_path
.clone()
.unwrap_or("".to_string())
.trim_end_matches("/")
.to_string()
}
//--------------------------------------------------------------------------
/// Get relative path from Git base path to Git source path.
//--------------------------------------------------------------------------
pub fn get_git_relative_path( &self ) -> String
{
let git_path = self.git_path();
let git_src_path = self.git_src_path();
git_src_path
.replace(&git_path, "")
.trim_start_matches("/")
.to_string()
}
//--------------------------------------------------------------------------
/// Returns the backup path.
//--------------------------------------------------------------------------
pub fn backup_path( &self ) -> String
{
self.backup_path
.clone()
.unwrap_or("".to_string())
.trim_end_matches("/")
.to_string()
}
//--------------------------------------------------------------------------
/// Returns the database host.
//--------------------------------------------------------------------------
pub fn db_host( &self ) -> String
{
self.db_host.clone().unwrap_or("".to_string())
}
//--------------------------------------------------------------------------
/// Returns the database host for reader.
//--------------------------------------------------------------------------
pub fn db_host_reader( &self ) -> String
{
self.db_host_reader.clone().unwrap_or(self.db_host())
}
//--------------------------------------------------------------------------
/// Returns the database port.
//--------------------------------------------------------------------------
pub fn db_port( &self ) -> u16
{
self.db_port.unwrap_or(3306)
}
//--------------------------------------------------------------------------
/// Returns the database name.
//--------------------------------------------------------------------------
pub fn db_name( &self ) -> String
{
self.db_name.clone().unwrap_or("".to_string())
}
//--------------------------------------------------------------------------
/// Returns the database user.
//--------------------------------------------------------------------------
pub fn db_user( &self ) -> String
{
self.db_user.clone().unwrap_or("root".to_string())
}
//--------------------------------------------------------------------------
/// Returns the database password.
//--------------------------------------------------------------------------
pub fn db_password( &self ) -> String
{
self.db_password.clone().unwrap_or("".to_string())
}
//--------------------------------------------------------------------------
/// Returns the database root user.
//--------------------------------------------------------------------------
pub fn db_root_user( &self ) -> String
{
self.db_root_user.clone().unwrap_or("root".to_string())
}
//--------------------------------------------------------------------------
/// Returns the database root password.
//--------------------------------------------------------------------------
pub fn db_root_password( &self ) -> String
{
self.db_root_password.clone().unwrap_or("".to_string())
}
//--------------------------------------------------------------------------
/// Returns the connect info.
//--------------------------------------------------------------------------
pub fn connect_info( &self ) -> &ConnectInfo
{
&self.connect_info
}
//--------------------------------------------------------------------------
/// Returns the tunnels.
//--------------------------------------------------------------------------
pub fn tunnels( &self ) -> &Option<Vec<ConnectInfo>>
{
&self.tunnels
}
}