12 files changed
+95
-68
smbpndk-cli/src/account/forgot/mod.rs
+2
-4
@@ -1,12 +1,10 @@
1
+use crate::cli::CommandResult;
2
use anyhow::Result;
3
use console::style;
4
use dialoguer::{theme::ColorfulTheme, Input, Password};
5
use reqwest::{Client, StatusCode};
6
use serde::{Deserialize, Serialize};
6
-use smbpndk_model::{
7
- forgot::{Args, Email, Param, UserUpdatePassword},
8
- CommandResult,
9
-};
7
+use smbpndk_model::forgot::{Args, Email, Param, UserUpdatePassword};
8
use smbpndk_networking::{constants::PATH_USERS_PASSWORD, smb_base_url_builder};
9
use smbpndk_utils::email_validation;
10
use spinners::Spinner;
smbpndk-cli/src/account/login/process.rs
+6
-4
@@ -1,6 +1,9 @@
1
-use crate::account::{
2
- lib::{authorize_github, save_token},
3
- signup::{do_signup, SignupMethod},
1
+use crate::{
2
+ account::{
3
+ lib::{authorize_github, save_token},
4
+ signup::{do_signup, SignupMethod},
5
+ },
6
+ cli::CommandResult,
7
};
8
use anyhow::{anyhow, Result};
9
use console::{style, Term};
@@ -12,7 +15,6 @@ use smbpndk_model::{
15
forgot::{Param, UserUpdatePassword},
16
login::{LoginArgs, LoginParams, UserParam},
17
signup::{GithubEmail, Provider, SignupGithubParams, SignupUserGithub},
15
- CommandResult,
18
};
19
use smbpndk_networking::{
20
constants::{
smbpndk-cli/src/account/mod.rs
+1
-1
@@ -10,8 +10,8 @@ use self::{
10
login::{process_login, process_logout},
11
signup::process_signup,
12
};
13
+use crate::cli::CommandResult;
14
use anyhow::Result;
14
-use smbpndk_model::CommandResult;
15
16
pub async fn process_account(commands: Commands) -> Result<CommandResult> {
17
match commands {
smbpndk-cli/src/account/signup/process.rs
+2
-5
@@ -1,15 +1,12 @@
1
use super::SignupMethod;
2
-use crate::account::lib::authorize_github;
2
+use crate::{account::lib::authorize_github, cli::CommandResult};
3
use anyhow::{anyhow, Result};
4
use console::{style, Term};
5
use dialoguer::{theme::ColorfulTheme, Input, Password, Select};
6
use log::debug;
7
use reqwest::{Client, StatusCode};
8
use serde::Serialize;
9
-use smbpndk_model::{
10
- signup::{SignupEmailParams, SignupResult, SignupUserEmail},
11
- CommandResult,
12
-};
9
+use smbpndk_model::signup::{SignupEmailParams, SignupResult, SignupUserEmail};
10
use smbpndk_networking::{constants::PATH_USERS, smb_base_url_builder, smb_token_file_path};
11
use smbpndk_utils::email_validation;
12
use spinners::Spinner;
smbpndk-cli/src/cli/mod.rs
+7
@@ -1,5 +1,12 @@
1
use crate::{account, project};
2
use clap::{Parser, Subcommand};
3
+use spinners::Spinner;
4
+
5
+pub struct CommandResult {
6
+ pub spinner: Spinner,
7
+ pub symbol: String,
8
+ pub msg: String,
9
+}
10
11
#[derive(Parser)]
12
#[clap(author, version, about)]
smbpndk-cli/src/main.rs
+1
-1
@@ -1,12 +1,12 @@
1
use anyhow::{anyhow, Result};
2
use clap::Parser;
3
use console::style;
4
+use smbpndk_cli::cli::CommandResult;
5
use smbpndk_cli::{
6
account::process_account,
7
cli::{Cli, Commands},
8
project::process_project,
9
};
9
-use smbpndk_model::CommandResult;
10
use std::{
11
fs::{create_dir_all, OpenOptions},
12
path::PathBuf,
smbpndk-cli/src/project/mod.rs
+5
-1
@@ -1,11 +1,15 @@
1
pub mod cli;
2
3
use self::cli::Commands;
4
+use crate::cli::CommandResult;
5
use anyhow::{anyhow, Result};
6
use console::style;
7
use dialoguer::{theme::ColorfulTheme, Input};
8
use log::debug;
8
-use smbpndk_model::{CommandResult, Config, Project, ProjectCreate};
9
+use smbpndk_model::{
10
+ self,
11
+ project::{Config, Project, ProjectCreate},
12
+};
13
use smbpndk_networking_project::{create_project, delete_project, get_all, get_project};
14
use spinners::Spinner;
15
use std::{fs::OpenOptions, io::Write};
smbpndk-model/src/app_auth.rs
new
+20
@@ -0,0 +1,20 @@
1
+use crate::ar_date_format;
2
+use chrono::{DateTime, Utc};
3
+use serde::{Deserialize, Serialize};
4
+
5
+#[derive(Serialize, Deserialize, Debug)]
6
+pub struct AuthApp {
7
+ pub id: String,
8
+ pub secret: Option<String>,
9
+ pub name: String,
10
+ #[serde(with = "ar_date_format")]
11
+ pub created_at: DateTime<Utc>,
12
+ #[serde(with = "ar_date_format")]
13
+ pub updated_at: DateTime<Utc>,
14
+}
15
+
16
+#[derive(Serialize, Deserialize, Debug)]
17
+pub struct AuthAppCreate {
18
+ pub name: String,
19
+ pub description: String,
20
+}
smbpndk-model/src/lib.rs
+3
-50
@@ -1,13 +1,11 @@
1
pub mod account;
2
+pub mod app_auth;
3
pub mod forgot;
4
pub mod login;
5
+pub mod project;
6
pub mod signup;
7
6
-use chrono::{DateTime, Utc};
7
-use serde::{Deserialize, Serialize};
8
-use spinners::Spinner;
9
-
10
-mod ar_date_format {
8
+pub mod ar_date_format {
9
use chrono::{DateTime, TimeZone, Utc};
10
use serde::{self, Deserialize, Deserializer, Serializer};
11
@@ -44,48 +42,3 @@ mod ar_date_format {
42
.map_err(serde::de::Error::custom)
43
}
44
}
47
-
48
-pub struct CommandResult {
49
- pub spinner: Spinner,
50
- pub symbol: String,
51
- pub msg: String,
52
-}
53
-
54
-#[derive(Serialize, Deserialize, Debug)]
55
-pub struct AuthApp {
56
- pub id: String,
57
- pub secret: Option<String>,
58
- pub name: String,
59
- #[serde(with = "ar_date_format")]
60
- pub created_at: DateTime<Utc>,
61
- #[serde(with = "ar_date_format")]
62
- pub updated_at: DateTime<Utc>,
63
-}
64
-
65
-#[derive(Serialize, Deserialize, Debug)]
66
-pub struct AuthAppCreate {
67
- pub name: String,
68
- pub description: String,
69
-}
70
-
71
-#[derive(Deserialize, Debug, Serialize)]
72
-pub struct Config {
73
- pub current_project: Option<Project>,
74
- pub current_auth_app: Option<AuthApp>,
75
-}
76
-
77
-#[derive(Deserialize, Debug, Serialize)]
78
-pub struct Project {
79
- pub id: i32,
80
- pub name: String,
81
- pub description: String,
82
- #[serde(with = "ar_date_format")]
83
- pub created_at: DateTime<Utc>,
84
- #[serde(with = "ar_date_format")]
85
- pub updated_at: DateTime<Utc>,
86
-}
87
-#[derive(Serialize, Debug)]
88
-pub struct ProjectCreate {
89
- pub name: String,
90
- pub description: String,
91
-}
smbpndk-model/src/project.rs
new
+43
@@ -0,0 +1,43 @@
1
+use crate::{app_auth::AuthApp, ar_date_format};
2
+use chrono::{DateTime, Utc};
3
+use serde::{Deserialize, Serialize};
4
+
5
+#[derive(Deserialize, Debug, Serialize)]
6
+pub struct Config {
7
+ pub current_project: Option<Project>,
8
+ pub current_auth_app: Option<AuthApp>,
9
+}
10
+
11
+#[derive(Deserialize, Debug, Serialize)]
12
+pub struct Project {
13
+ pub id: i32,
14
+ pub name: String,
15
+ pub description: String,
16
+ #[serde(with = "ar_date_format")]
17
+ pub created_at: DateTime<Utc>,
18
+ #[serde(with = "ar_date_format")]
19
+ pub updated_at: DateTime<Utc>,
20
+}
21
+#[derive(Serialize, Debug)]
22
+pub struct ProjectCreate {
23
+ pub name: String,
24
+ pub description: String,
25
+}
26
+
27
+#[cfg(test)]
28
+mod tests {
29
+ use super::*;
30
+ use serde_json::json;
31
+ #[test]
32
+ fn test_project_create() {
33
+ let project_create = ProjectCreate {
34
+ name: "test".to_owned(),
35
+ description: "test".to_owned(),
36
+ };
37
+ let json = json!({
38
+ "name": "test",
39
+ "description": "test",
40
+ });
41
+ assert_eq!(serde_json::to_value(project_create).unwrap(), json);
42
+ }
43
+}
smbpndk-networking-project/src/lib.rs
+4
-1
@@ -1,7 +1,10 @@
1
use anyhow::{anyhow, Result};
2
use log::debug;
3
use reqwest::Client;
4
-use smbpndk_model::{Project, ProjectCreate};
4
+use smbpndk_model::{
5
+ self,
6
+ project::{Project, ProjectCreate},
7
+};
8
use smbpndk_networking::{get_smb_token, smb_base_url_builder};
9
10
pub async fn get_all() -> Result<Vec<Project>> {
smbpndk-utils/src/lib.rs
+1
-1
@@ -3,7 +3,7 @@ use std::{fs::OpenOptions, io::Write};
3
use anyhow::{anyhow, Result};
4
use log::debug;
5
use regex::Regex;
6
-use smbpndk_model::Config;
6
+use smbpndk_model::project::Config;
7
8
pub fn email_validation(input: &str) -> Result<(), &'static str> {
9
let email_regex = Regex::new(