5 files changed
+42
-35
crates/cli/src/deploy/config.rs
+7
-26
@@ -4,14 +4,13 @@ use {
4
ui::{fail_message, fail_symbol, succeed_message, succeed_symbol},
5
},
6
git2::{Cred, CredentialType, Error},
7
- serde::{Deserialize, Serialize},
7
smbcloud_model::{
8
account::User,
9
error_codes::{ErrorCode, ErrorResponse},
11
- project::Project,
10
},
11
smbcloud_network::environment::Environment,
12
smbcloud_networking_project::crud_project_read::get_project,
13
+ smbcloud_utils::config::Config,
14
spinners::Spinner,
15
std::{fs, path::Path},
16
};
@@ -90,29 +89,11 @@ pub(crate) async fn check_project(
89
}
90
}
91
93
-#[derive(Deserialize, Serialize)]
94
-pub struct Config {
95
- pub name: String,
96
- pub description: Option<String>,
97
- pub project: Project,
98
-}
99
-
100
-impl Config {
101
- pub fn credentials(
102
- &self,
103
- user: User,
104
- ) -> impl FnMut(&str, Option<&str>, CredentialType) -> Result<Cred, Error> + '_ {
105
- move |_url, _username_from_url, _allowed_types| {
106
- Cred::ssh_key("git", None, Path::new(&self.ssh_key_path(user.id)), None)
107
- }
108
- }
109
-
110
- fn ssh_key_path(&self, user_id: i32) -> String {
111
- // Use the dirs crate to get the home directory
112
- let home = dirs::home_dir().expect("Could not determine home directory");
113
- let key_path = home.join(".ssh").join(format!("id_{}@smbcloud", user_id));
114
- let key_path_str = key_path.to_string_lossy().to_string();
115
- println!("Use key path: {}", key_path_str);
116
- key_path_str
92
+pub fn credentials(
93
+ config: &Config,
94
+ user: User,
95
+) -> impl FnMut(&str, Option<&str>, CredentialType) -> Result<Cred, Error> + '_ {
96
+ move |_url, _username_from_url, _allowed_types| {
97
+ Cred::ssh_key("git", None, Path::new(&config.ssh_key_path(user.id)), None)
98
}
99
}
crates/cli/src/deploy/process_deploy.rs
+2
-2
@@ -3,7 +3,7 @@ use {
3
account::login::process_login,
4
cli::CommandResult,
5
deploy::{
6
- config::{check_config, check_project},
6
+ config::{check_config, check_project, credentials},
7
detect_runner::detect_runner,
8
git::remote_deployment_setup,
9
remote_messages::{build_next_app, start_server},
@@ -118,7 +118,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
118
let update_deployment_id = created_deployment.id;
119
120
// Set the credentials
121
- callbacks.credentials(config.credentials(user));
121
+ callbacks.credentials(credentials(&config, user));
122
callbacks.sideband_progress(|data| {
123
// Convert bytes to string, print line by line
124
if let Ok(text) = std::str::from_utf8(data) {
crates/cli/src/deploy/setup_project.rs
+2
-2
@@ -1,8 +1,7 @@
1
use {
2
crate::{
3
deploy::{
4
- config::Config, setup_create_new_project::create_new_project,
5
- setup_select_project::select_project,
4
+ setup_create_new_project::create_new_project, setup_select_project::select_project,
5
},
6
token::get_smb_token::get_smb_token,
7
ui::highlight,
@@ -14,6 +13,7 @@ use {
13
},
14
smbcloud_network::environment::Environment,
15
smbcloud_networking_project::crud_project_read::get_projects,
16
+ smbcloud_utils::config::Config,
17
std::{env, fs, path::Path},
18
};
19
crates/smbcloud-utils/src/config.rs
new
+23
@@ -0,0 +1,23 @@
1
+use {
2
+ serde::{Deserialize, Serialize},
3
+ smbcloud_model::project::Project,
4
+};
5
+
6
+/// smbCloud config from the .smb/config.toml file.
7
+#[derive(Deserialize, Serialize)]
8
+pub struct Config {
9
+ pub name: String,
10
+ pub description: Option<String>,
11
+ pub project: Project,
12
+}
13
+
14
+impl Config {
15
+ pub fn ssh_key_path(&self, user_id: i32) -> String {
16
+ // Use the dirs crate to get the home directory
17
+ let home = dirs::home_dir().expect("Could not determine home directory");
18
+ let key_path = home.join(".ssh").join(format!("id_{}@smbcloud", user_id));
19
+ let key_path_str = key_path.to_string_lossy().to_string();
20
+ println!("Use key path: {}", key_path_str);
21
+ key_path_str
22
+ }
23
+}
crates/smbcloud-utils/src/lib.rs
+8
-5
@@ -1,9 +1,12 @@
1
-use std::{fs::OpenOptions, io::Write};
1
+use {
2
+ anyhow::{anyhow, Result},
3
+ log::debug,
4
+ regex::Regex,
5
+ smbcloud_model::project::Config,
6
+ std::{fs::OpenOptions, io::Write},
7
+};
8
3
-use anyhow::{anyhow, Result};
4
-use log::debug;
5
-use regex::Regex;
6
-use smbcloud_model::project::Config;
9
+pub mod config;
10
11
pub fn email_validation(input: &str) -> Result<(), &'static str> {
12
let email_regex = Regex::new(