@smbcloud / cli / commits / a4dc272

auth-app to app-oten

Seto Elkahfi committed Apr 29, 2023 at 16:32 UTC a4dc2727dbfee0ef3d8e97ac0623391d416539eb
16 files changed +53 -57
Cargo.lock
+6
@@ -39,6 +39,9 @@ version = "0.1.0"
39 dependencies = [
40 "anyhow",
41 "async-trait",
42 + "clap",
43 + "console",
44 + "dialoguer",
45 "dirs",
46 "home",
47 "log",
@@ -48,6 +51,8 @@ dependencies = [
51 "serde_json",
52 "smbpndk-model",
53 "smbpndk-networking",
54 + "smbpndk-utils",
55 + "spinners",
56 "thiserror",
57 ]
58
@@ -1132,6 +1137,7 @@ version = "0.1.0"
1137 dependencies = [
1138 "serde",
1139 "serde_json",
1140 + "spinners",
1141 ]
1142
1143 [[package]]
app-oten/Cargo.toml
+5
@@ -7,6 +7,9 @@ edition = "2021"
7 [dependencies]
8 anyhow = "1.0.58"
9 async-trait = { version = "0.1.51", optional = true }
10 +clap = { version = "4.1.6", features = ["derive"] }
11 +console = "0.15.0"
12 +dialoguer = "0.10.4"
13 dirs = "4.0.0"
14 home = "0.5.4"
15 log = "0.4.14"
@@ -16,4 +19,6 @@ serde = { version = "1", features = ["derive"] }
19 serde_json = "1.0.82"
20 smbpndk-model = { path = "../smbpndk-model" }
21 smbpndk-networking = { path = "../smbpndk-networking" }
22 +smbpndk-utils = { path = "../smbpndk-utils" }
23 +spinners = "4.1.0"
24 thiserror = "1.0.29"
app-oten/src/cli.rs renamed
app-oten/src/handler.rs renamed
+2 -5
@@ -1,14 +1,11 @@
1 -use crate::{auth_app::cli::Commands, cli::CommandResult};
1 +use crate::{cli::Commands, create_auth_app, delete_auth_app, get_auth_app, get_auth_apps};
2 use anyhow::{anyhow, Result};
3 -use app_oten::{create_auth_app, delete_auth_app, get_auth_app, get_auth_apps};
3 use console::style;
4 use dialoguer::{theme::ColorfulTheme, Confirm, Input};
6 -use smbpndk_model::AuthAppCreate;
5 +use smbpndk_model::{AuthAppCreate, CommandResult};
6 use smbpndk_utils::{get_config, write_config};
7 use spinners::Spinner;
8
10 -pub(crate) mod cli;
11 -
9 pub async fn process_auth_app(commands: Commands) -> Result<CommandResult> {
10 match commands {
11 Commands::New {} => {
app-oten/src/lib.rs
+4 -2
@@ -1,3 +1,6 @@
1 +pub mod cli;
2 +pub mod handler;
3 +
4 use anyhow::{anyhow, Result};
5 use log::debug;
6 use reqwest::Client;
@@ -40,8 +43,7 @@ pub async fn get_auth_app(id: &str) -> Result<AuthApp> {
43 Ok(auth_app)
44 }
45 _ => Err(anyhow!(format!(
43 - "Failed to find an auth app with id: {}.",
44 - id
46 + "Failed to find an auth app with id: {id}."
47 ))),
48 }
49 }
smbpndk-cli/Cargo.toml
+1 -1
@@ -17,6 +17,7 @@ path = "src/main.rs"
17
18 [dependencies]
19 anyhow = "1.0.58"
20 +app-oten = { path = "../app-oten" }
21 clap = { version = "4.1.6", features = ["derive"] }
22 clap_mangen = "0.2.10"
23 console = "0.15.0"
@@ -32,7 +33,6 @@ serde = { version = "1", features = ["derive"] }
33 serde_json = "1.0.82"
34 smbpndk-model = { path = "../smbpndk-model" }
35 smbpndk-networking = { path = "../smbpndk-networking" }
35 -app-oten = { path = "../app-oten" }
36 smbpndk-networking-project = { path = "../smbpndk-networking-project" }
37 smbpndk-utils = { path = "../smbpndk-utils" }
38 spinners = "4.1.0"
smbpndk-cli/src/account/forgot/mod.rs
+1 -2
@@ -3,12 +3,11 @@ use console::style;
3 use dialoguer::{theme::ColorfulTheme, Input, Password};
4 use reqwest::{Client, StatusCode};
5 use serde::{Deserialize, Serialize};
6 +use smbpndk_model::CommandResult;
7 use smbpndk_networking::constants::BASE_URL;
8 use smbpndk_utils::email_validation;
9 use spinners::Spinner;
10
10 -use crate::cli::CommandResult;
11 -
11 #[derive(Debug, Serialize)]
12 struct Args {
13 user: Email,
smbpndk-cli/src/account/login/process.rs
+5 -9
@@ -1,20 +1,16 @@
1 -use std::{
2 - fs::{self, create_dir_all, OpenOptions},
3 - io::Write,
4 -};
5 -
1 +use crate::account::model::{Data, Status, User};
2 use anyhow::{anyhow, Result};
3 use console::style;
4 use dialoguer::{theme::ColorfulTheme, Input, Password};
5 use log::debug;
6 use reqwest::Client;
7 use serde::{Deserialize, Serialize};
8 +use smbpndk_model::CommandResult;
9 use smbpndk_networking::constants::BASE_URL;
10 use spinners::Spinner;
14 -
15 -use crate::{
16 - account::model::{Data, Status, User},
17 - cli::CommandResult,
11 +use std::{
12 + fs::{self, create_dir_all, OpenOptions},
13 + io::Write,
14 };
15
16 pub struct LoginArgs {
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;
13 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
+9 -13
@@ -1,11 +1,4 @@
1 -use std::{
2 - fmt::{Display, Formatter},
3 - fs,
4 - io::{BufRead, BufReader, Write},
5 - net::{TcpListener, TcpStream},
6 - sync::mpsc::{self, Receiver, Sender},
7 -};
8 -
1 +use crate::account::model::{Data, Status, User};
2 use anyhow::{anyhow, Result};
3 use console::{style, Term};
4 use dialoguer::{theme::ColorfulTheme, Input, Password, Select};
@@ -13,14 +6,17 @@ use log::debug;
6 use regex::Regex;
7 use reqwest::{Client, StatusCode};
8 use serde::{Deserialize, Serialize};
9 +use smbpndk_model::CommandResult;
10 use smbpndk_networking::constants::BASE_URL;
11 use spinners::Spinner;
18 -use url_builder::URLBuilder;
19 -
20 -use crate::{
21 - account::model::{Data, Status, User},
22 - cli::CommandResult,
12 +use std::{
13 + fmt::{Display, Formatter},
14 + fs,
15 + io::{BufRead, BufReader, Write},
16 + net::{TcpListener, TcpStream},
17 + sync::mpsc::{self, Receiver, Sender},
18 };
19 +use url_builder::URLBuilder;
20
21 use super::SignupMethod;
22 pub struct SignupArgs {
smbpndk-cli/src/cli/mod.rs
+2 -10
@@ -1,13 +1,5 @@
1 +use crate::{account, project};
2 use clap::{Parser, Subcommand};
2 -use spinners::Spinner;
3 -
4 -use crate::{account, auth_app, project};
5 -
6 -pub struct CommandResult {
7 - pub spinner: Spinner,
8 - pub symbol: String,
9 - pub msg: String,
10 -}
3
4 #[derive(Parser)]
5 #[clap(author, version, about)]
@@ -37,7 +29,7 @@ pub enum Commands {
29 #[clap(about = "Manage your AuthApp. Add, delete, edit. Need authentication.")]
30 AuthApp {
31 #[clap(subcommand)]
40 - command: auth_app::cli::Commands,
32 + command: app_oten::cli::Commands,
33 },
34 // Function
35 /*
smbpndk-cli/src/lib.rs
-1
@@ -1,4 +1,3 @@
1 pub mod account;
2 -pub mod auth_app;
2 pub mod cli;
3 pub mod project;
smbpndk-cli/src/main.rs
+7 -8
@@ -1,20 +1,19 @@
1 use anyhow::{anyhow, Result};
2 +use app_oten::{self, handler::process_auth_app};
3 use clap::Parser;
4 use console::style;
5 use dotenv::dotenv;
6 +use smbpndk_cli::{
7 + account::process_account,
8 + cli::{Cli, Commands},
9 + project::process_project,
10 +};
11 +use smbpndk_model::CommandResult;
12 use std::{
13 fs::{create_dir_all, OpenOptions},
14 path::PathBuf,
15 str::FromStr,
16 };
10 -
11 -use smbpndk_cli::{
12 - account::process_account,
13 - auth_app::process_auth_app,
14 - cli::{Cli, CommandResult, Commands},
15 - project::process_project,
16 -};
17 -
17 use tracing::subscriber::set_global_default;
18 use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
19 use tracing_subscriber::{filter::LevelFilter, prelude::*, EnvFilter};
smbpndk-cli/src/project/mod.rs
+2 -5
@@ -1,18 +1,15 @@
1 pub mod cli;
2
3 +use self::cli::Commands;
4 use anyhow::{anyhow, Result};
5 use console::style;
6 use dialoguer::{theme::ColorfulTheme, Input};
7 use log::debug;
7 -use smbpndk_model::{Config, ProjectCreate};
8 +use smbpndk_model::{CommandResult, Config, ProjectCreate};
9 use smbpndk_networking_project::{create_project, delete_project, get_all, get_project};
10 use spinners::Spinner;
11 use std::{fs::OpenOptions, io::Write};
12
12 -use crate::cli::CommandResult;
13 -
14 -use self::cli::Commands;
15 -
13 pub async fn process_project(commands: Commands) -> Result<CommandResult> {
14 match commands {
15 Commands::New {} => {
smbpndk-model/Cargo.toml
+1
@@ -7,3 +7,4 @@ edition = "2021"
7 [dependencies]
8 serde = { version = "1", features = ["derive"] }
9 serde_json = "1.0.82"
10 +spinners = "4.1.0"
smbpndk-model/src/lib.rs
+7
@@ -1,4 +1,11 @@
1 use serde::{Deserialize, Serialize};
2 +use spinners::Spinner;
3 +
4 +pub struct CommandResult {
5 + pub spinner: Spinner,
6 + pub symbol: String,
7 + pub msg: String,
8 +}
9
10 #[derive(Serialize, Deserialize, Debug)]
11 pub struct AuthApp {