9 files changed
+31
-21
docs/debugging.md
+5
@@ -12,4 +12,9 @@ $ cargo debugger --manifest-path smbcloud-cli/Cargo.toml -- account signup
12
Default environment is production. To run against dev environemt:
13
```bash
14
$ cargo run -- -e dev account login
15
+```
16
+
17
+Example debug the dev environment:
18
+```bash
19
+$ cargo debugger --manifest-path smbcloud-cli/Cargo.toml -- --environment dev account login
20
```
\ No newline at end of file
smbcloud-cli/src/account/forgot/mod.rs
+1
-1
@@ -39,7 +39,7 @@ pub async fn process_forgot(env: Environment) -> Result<CommandResult> {
39
"✅",
40
"Check your email and input your code here.".to_owned(),
41
);
42
- input_code(env.clone()).await
42
+ input_code(env).await
43
}
44
_ => Ok(CommandResult {
45
spinner,
smbcloud-cli/src/account/lib.rs
+2
-1
@@ -58,7 +58,7 @@ pub async fn authorize_github(env: &Environment) -> Result<SmbAuthorization> {
58
Ok(code) => {
59
debug!("Got code from channel: {:#?}", &code);
60
//Err(anyhow!("Failed to get code from channel."))
61
- process_connect_github(env.clone(), code).await
61
+ process_connect_github(*env, code).await
62
}
63
Err(e) => {
64
let error = anyhow!("Failed to get code from channel: {e}");
@@ -227,6 +227,7 @@ pub async fn save_token(env: Environment, response: &Response) -> Result<()> {
227
create_dir_all(path.join(env.smb_dir()))?;
228
let mut file = OpenOptions::new()
229
.create(true)
230
+ .truncate(true)
231
.write(true)
232
.open([path.to_str().unwrap(), "/", &env.smb_dir(), "/token"].join(""))?;
233
file.write_all(token.to_str()?.as_bytes())?;
smbcloud-cli/src/deploy/mod.rs
+2
-4
@@ -112,9 +112,7 @@ pub async fn process_deploy() -> Result<CommandResult> {
112
if ssh_config_path.exists() {
113
// println!("SSH config path: {:#?}", ssh_config_path);
114
// Open the file and read it
115
- let file =
116
- File::open(ssh_config_path.clone()).expect("Unable to open ssh config file");
117
- file
115
+ File::open(ssh_config_path.clone()).expect("Unable to open ssh config file")
116
} else {
117
spinner.stop_and_persist("😩", "No ssh config found.".to_owned());
118
return Ok(CommandResult {
@@ -182,7 +180,7 @@ pub async fn process_deploy() -> Result<CommandResult> {
180
});
181
push_opts.remote_callbacks(callbacks);
182
185
- let _push = match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
183
+ match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
184
Ok(_) => {}
185
Err(e) => {
186
println!("Failed to push to remote: {:#?}", e);
smbcloud-cli/src/project/mod.rs
+1
@@ -177,6 +177,7 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
177
debug!("{}", path.to_str().unwrap());
178
let mut file = OpenOptions::new()
179
.create(true)
180
+ .truncate(true)
181
.write(true)
182
.open([path.to_str().unwrap(), "/.smb/config.json"].join(""))?;
183
let json = serde_json::to_string(&config)?;
smbcloud-model/src/lib.rs
+3
-2
@@ -6,7 +6,7 @@ pub mod project;
6
pub mod signup;
7
8
pub mod ar_date_format {
9
- use chrono::{DateTime, TimeZone, Utc};
9
+ use chrono::{DateTime, Utc};
10
use serde::{self, Deserialize, Deserializer, Serializer};
11
12
const FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.f%#z";
@@ -38,7 +38,8 @@ pub mod ar_date_format {
38
D: Deserializer<'de>,
39
{
40
let s = String::deserialize(deserializer)?;
41
- Utc.datetime_from_str(&s, FORMAT)
41
+ DateTime::parse_from_str(&s, FORMAT)
42
+ .map(|dt| dt.with_timezone(&Utc))
43
.map_err(serde::de::Error::custom)
44
}
45
smbcloud-networking/src/environment.rs
+10
-7
@@ -10,22 +10,25 @@ impl std::fmt::Display for Environment {
10
}
11
}
12
13
-impl Environment {
14
- pub fn from_str(env: &str) -> Self {
15
- match env.to_lowercase().as_str() {
16
- "dev" => Environment::Dev,
17
- "production" => Environment::Production,
18
- _ => panic!("Invalid environment: {}", env),
13
+impl std::str::FromStr for Environment {
14
+ type Err = ();
15
+
16
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
17
+ match s.to_lowercase().as_str() {
18
+ "dev" => Ok(Environment::Dev),
19
+ "production" => Ok(Environment::Production),
20
+ _ => Err(()),
21
}
22
}
23
+}
24
25
+impl Environment {
26
pub fn to_str(&self) -> &str {
27
match self {
28
Environment::Dev => "dev",
29
Environment::Production => "production",
30
}
31
}
28
-
32
pub fn smb_dir(&self) -> String {
33
match self {
34
Environment::Dev => ".smb-dev".to_string(),
smbcloud-networking/src/lib.rs
+6
-6
@@ -5,7 +5,7 @@ use anyhow::{anyhow, Result};
5
use constants::{SMB_CLIENT_ID, SMB_CLIENT_SECRET};
6
use environment::Environment;
7
use log::debug;
8
-use std::path::PathBuf;
8
+use std::path::{Path, PathBuf};
9
use url_builder::URLBuilder;
10
11
pub async fn get_smb_token(env: Environment) -> Result<String> {
@@ -21,11 +21,11 @@ pub async fn get_smb_token(env: Environment) -> Result<String> {
21
22
pub fn smb_token_file_path(env: Environment) -> Option<PathBuf> {
23
match home::home_dir() {
24
- Some(path) => {
25
- debug!("Home directory: {}.", path.to_str().unwrap());
26
- let token_path = path.join(env.smb_dir()).join("/token");
27
- if token_path.exists() && token_path.is_file() {
28
- return Some(token_path);
24
+ Some(home_path) => {
25
+ let token_path = [&env.smb_dir(), "/token"].join("");
26
+ let token_file = home_path.join(Path::new(&token_path));
27
+ if token_file.exists() && token_file.is_file() {
28
+ return Some(token_file);
29
}
30
None
31
}
smbcloud-utils/src/lib.rs
+1
@@ -56,6 +56,7 @@ pub fn write_config(config: Config) -> Result<Config> {
56
debug!("{}", path.to_str().unwrap());
57
let mut file = OpenOptions::new()
58
.create(true)
59
+ .truncate(true)
60
.write(true)
61
.open([path.to_str().unwrap(), "/.smb/config.json"].join(""))?;
62
let json = serde_json::to_string(&config)?;