@smbcloud / cli / commits / 914bd27

Cleanup

Seto Elkahfi committed Sep 11, 2023 at 14:24 UTC 914bd27fdc1d27739476af7a805ad8cd9c8dc470
14 files changed +2 -457
Cargo.lock
-39
@@ -38,41 +38,6 @@ version = "1.0.69"
38 source = "registry+https://github.com/rust-lang/crates.io-index"
39 checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
40
41 -[[package]]
42 -name = "app-fun"
43 -version = "0.3.3"
44 -
45 -[[package]]
46 -name = "app-oten"
47 -version = "0.3.3"
48 -dependencies = [
49 - "anyhow",
50 - "async-trait",
51 - "clap",
52 - "console",
53 - "dialoguer",
54 - "dirs",
55 - "home",
56 - "log",
57 - "maybe-async",
58 - "reqwest",
59 - "serde",
60 - "serde_json",
61 - "smbpndk-model",
62 - "smbpndk-networking",
63 - "smbpndk-utils",
64 - "spinners",
65 - "thiserror",
66 -]
67 -
68 -[[package]]
69 -name = "app-pkt"
70 -version = "0.3.3"
71 -
72 -[[package]]
73 -name = "app-rdb"
74 -version = "0.3.3"
75 -
41 [[package]]
42 name = "async-trait"
43 version = "0.1.66"
@@ -1265,10 +1230,6 @@ name = "smbpndk-cli"
1230 version = "0.3.3"
1231 dependencies = [
1232 "anyhow",
1268 - "app-fun",
1269 - "app-oten",
1270 - "app-pkt",
1271 - "app-rdb",
1233 "clap",
1234 "clap_mangen",
1235 "console",
Cargo.toml
-4
@@ -1,9 +1,5 @@
1 [workspace]
2 members = [
3 - "app-fun",
4 - "app-oten",
5 - "app-pkt",
6 - "app-rdb",
3 "smbpndk-cli",
4 "smbpndk-model",
5 "smbpndk-networking",
app-fun/Cargo.toml deleted
-14
@@ -1,14 +0,0 @@
1 -[package]
2 -name = "app-fun"
3 -version = "0.3.3"
4 -edition = "2021"
5 -authors = ["Seto Elkahfi <hej@setoelkahfi.se>"]
6 -description = "Command line tool for creating and managing SmbPndk resources."
7 -license = "Apache-2.0"
8 -repository = "https://github.com/smbpndk/smbpndk-cli"
9 -documentation = "https://docs.smbpndk.com/cli"
10 -keywords = ["cli", "cloud", "web2", "web3", "smbpndk"]
11 -categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
12 -readme = "./../README.md"
13 -
14 -[dependencies]
app-fun/src/lib.rs deleted
-14
@@ -1,14 +0,0 @@
1 -pub fn add(left: usize, right: usize) -> usize {
2 - left + right
3 -}
4 -
5 -#[cfg(test)]
6 -mod tests {
7 - use super::*;
8 -
9 - #[test]
10 - fn it_works() {
11 - let result = add(2, 2);
12 - assert_eq!(result, 4);
13 - }
14 -}
app-oten/Cargo.toml deleted
-31
@@ -1,31 +0,0 @@
1 -[package]
2 -name = "app-oten"
3 -version = "0.3.3"
4 -edition = "2021"
5 -authors = ["Seto Elkahfi <hej@setoelkahfi.se>"]
6 -description = "Command line tool for creating and managing SmbPndk resources."
7 -license = "Apache-2.0"
8 -repository = "https://github.com/smbpndk/smbpndk-cli"
9 -documentation = "https://docs.smbpndk.com/cli"
10 -keywords = ["cli", "cloud", "web2", "web3", "smbpndk"]
11 -categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
12 -readme = "./../README.md"
13 -
14 -[dependencies]
15 -anyhow = "1.0.58"
16 -async-trait = { version = "0.1.51", optional = true }
17 -clap = { version = "4.1.6", features = ["derive"] }
18 -console = "0.15.0"
19 -dialoguer = "0.10.4"
20 -dirs = "4.0.0"
21 -home = "0.5.4"
22 -log = "0.4.14"
23 -maybe-async = { version = "0.2", features = ["is_sync"] }
24 -reqwest = { version = "0.11", features = ["json"] }
25 -serde = { version = "1", features = ["derive"] }
26 -serde_json = "1.0.82"
27 -smbpndk-model = { version = "0.3", path = "../smbpndk-model" }
28 -smbpndk-networking = { version = "0.3", path = "../smbpndk-networking" }
29 -smbpndk-utils = { version = "0.3", path = "../smbpndk-utils" }
30 -spinners = "4.1.0"
31 -thiserror = "1.0.29"
app-oten/src/cli.rs deleted
-30
@@ -1,30 +0,0 @@
1 -use clap::Subcommand;
2 -
3 -#[derive(Subcommand)]
4 -pub enum Commands {
5 - #[clap(about = "Add new auth app.")]
6 - New {},
7 -
8 - #[clap(about = "List all your auth apps.")]
9 - List {},
10 -
11 - #[clap(about = "Show detail of a auth app.")]
12 - Show {
13 - /// Project Id
14 - #[clap(short, long, required = true)]
15 - id: String,
16 - },
17 -
18 - #[clap(about = "Delete a auth app.")]
19 - Delete {
20 - /// Project name
21 - #[clap(short, long, required = true)]
22 - id: String,
23 - },
24 -
25 - #[clap(about = "Use auth app for current CLI session.")]
26 - Use {
27 - #[clap(short, long, required = true)]
28 - id: String,
29 - },
30 -}
app-oten/src/handler.rs deleted
-176
@@ -1,176 +0,0 @@
1 -use crate::{cli::Commands, create_auth_app, delete_auth_app, get_auth_app, get_auth_apps};
2 -use anyhow::{anyhow, Result};
3 -use console::style;
4 -use dialoguer::{theme::ColorfulTheme, Confirm, Input};
5 -use smbpndk_model::{AuthAppCreate, CommandResult};
6 -use smbpndk_utils::{get_config, write_config};
7 -use spinners::Spinner;
8 -
9 -pub async fn process_auth_app(commands: Commands) -> Result<CommandResult> {
10 - match commands {
11 - Commands::New {} => {
12 - let app_name = Input::<String>::with_theme(&ColorfulTheme::default())
13 - .with_prompt("App name")
14 - .interact()
15 - .unwrap();
16 - let description = Input::<String>::with_theme(&ColorfulTheme::default())
17 - .with_prompt("Description")
18 - .interact()
19 - .unwrap();
20 -
21 - let spinner = Spinner::new(
22 - spinners::Spinners::SimpleDotsScrolling,
23 - style("Creating an auth app...").green().bold().to_string(),
24 - );
25 -
26 - match create_auth_app(AuthAppCreate {
27 - name: app_name.clone(),
28 - description: description.clone(),
29 - })
30 - .await
31 - {
32 - Ok(_) => Ok(CommandResult {
33 - spinner,
34 - symbol: "✅".to_owned(),
35 - msg: format!("An auth app created: {app_name}."),
36 - }),
37 - Err(e) => {
38 - println!("Error: {e:#?}");
39 - Ok(CommandResult {
40 - spinner,
41 - symbol: "😩".to_owned(),
42 - msg: format!("Failed to create an auth app: {app_name}."),
43 - })
44 - }
45 - }
46 - }
47 - Commands::List {} => {
48 - let spinner = Spinner::new(
49 - spinners::Spinners::SimpleDotsScrolling,
50 - style("Loading...").green().bold().to_string(),
51 - );
52 - match get_auth_apps().await {
53 - Ok(auth_apps) => {
54 - println!("auth_apps: {auth_apps:#?}");
55 - println!(
56 - "{0: <10} | {1: <30} | {2: <10} | {3: <10}",
57 - "ID", "Name", "Created at", "Updated at"
58 - );
59 - for project in auth_apps {
60 - let id = project.id.split("-").collect::<Vec<&str>>()[0].to_owned();
61 - let created_at = project.created_at.date_naive();
62 - let updated_at = project.updated_at.date_naive();
63 - println!(
64 - "{0: <10} | {1: <30} | {2: <10} | {3: <10}",
65 - id, project.name, created_at, updated_at
66 - );
67 - }
68 - Ok(CommandResult {
69 - spinner,
70 - symbol: "✅".to_owned(),
71 - msg: "Showing all auth apps.".to_owned(),
72 - })
73 - }
74 - Err(e) => {
75 - println!("Error: {e:#?}");
76 - Ok(CommandResult {
77 - spinner,
78 - symbol: "😩".to_owned(),
79 - msg: "Failed to get all auth apps.".to_owned(),
80 - })
81 - }
82 - }
83 - }
84 - Commands::Show { id } => {
85 - let spinner = Spinner::new(
86 - spinners::Spinners::SimpleDotsScrolling,
87 - style("Loading...").green().bold().to_string(),
88 - );
89 - match get_auth_app(&id).await {
90 - Ok(_) => Ok(CommandResult {
91 - spinner,
92 - symbol: "✅".to_owned(),
93 - msg: "Showing auth app.".to_owned(),
94 - }),
95 - Err(e) => {
96 - println!("Error: {e:#?}");
97 - Ok(CommandResult {
98 - spinner,
99 - symbol: "😩".to_owned(),
100 - msg: "Failed to get an auth app.".to_owned(),
101 - })
102 - }
103 - }
104 - }
105 - Commands::Delete { id } => {
106 - let spinner = Spinner::new(
107 - spinners::Spinners::SimpleDotsScrolling,
108 - style("Loading...").green().bold().to_string(),
109 - );
110 - match delete_auth_app(id).await {
111 - Ok(_) => Ok(CommandResult {
112 - spinner,
113 - symbol: "✅".to_owned(),
114 - msg: "Delete auth app succeed.".to_owned(),
115 - }),
116 - Err(e) => {
117 - println!("Error: {e:#?}");
118 - Ok(CommandResult {
119 - spinner,
120 - symbol: "😩".to_owned(),
121 - msg: "Failed to delete auth app.".to_owned(),
122 - })
123 - }
124 - }
125 - }
126 - Commands::Use { id } => {
127 - let mut spinner = Spinner::new(
128 - spinners::Spinners::SimpleDotsScrolling,
129 - style("Checking config file...").green().bold().to_string(),
130 - );
131 -
132 - let auth_app = get_auth_app(&id).await?;
133 - let mut config = get_config().await?;
134 -
135 - if let Some(auth_app) = config.current_auth_app {
136 - if auth_app.id != id {
137 - spinner.stop_with_message("Found a config.".to_string());
138 - let yes = Confirm::new()
139 - .with_prompt(format!(
140 - "Will change active auth_app to {}. Do you want to continue?",
141 - &id
142 - ))
143 - .interact()?;
144 - if !yes {
145 - let spinner = Spinner::new(
146 - spinners::Spinners::SimpleDotsScrolling,
147 - style("Cancelling operation...").green().bold().to_string(),
148 - );
149 - return Ok(CommandResult {
150 - spinner,
151 - symbol: "✅".to_owned(),
152 - msg: "Operation cancelled.".to_string(),
153 - });
154 - }
155 - }
156 - }
157 -
158 - config.current_auth_app = Some(auth_app);
159 - let spinner = Spinner::new(
160 - spinners::Spinners::SimpleDotsScrolling,
161 - style("Saving config...").green().bold().to_string(),
162 - );
163 - match write_config(config) {
164 - Ok(_) => Ok(CommandResult {
165 - spinner,
166 - symbol: "✅".to_owned(),
167 - msg: format!("Using auth_app: {:?}", &id),
168 - }),
169 - Err(_) => {
170 - let error = anyhow!("Failed while writing config.");
171 - Err(error)
172 - }
173 - }
174 - }
175 - }
176 -}
app-oten/src/lib.rs deleted
-89
@@ -1,89 +0,0 @@
1 -pub mod cli;
2 -pub mod handler;
3 -
4 -use anyhow::{anyhow, Result};
5 -use log::debug;
6 -use reqwest::Client;
7 -use smbpndk_model::{AuthApp, AuthAppCreate};
8 -use smbpndk_networking::{constants::BASE_URL, get_smb_token};
9 -
10 -async fn get_auth_apps() -> Result<Vec<AuthApp>> {
11 - // Get current token
12 - let token = get_smb_token().await?;
13 -
14 - let response = Client::new()
15 - .get([BASE_URL, "v1/auth_apps"].join(""))
16 - .header("Authorization", token)
17 - .send()
18 - .await?;
19 -
20 - match response.status() {
21 - reqwest::StatusCode::OK => {
22 - let auth_apps: Vec<AuthApp> = response.json().await?;
23 - Ok(auth_apps)
24 - }
25 - _ => Err(anyhow!("Failed to fetch auth apps.")),
26 - }
27 -}
28 -
29 -async fn get_auth_app(id: &str) -> Result<AuthApp> {
30 - // Get current token
31 - let token = get_smb_token().await?;
32 -
33 - let response = Client::new()
34 - .get([BASE_URL, "v1/auth_apps/", id].join(""))
35 - .header("Authorization", token)
36 - .send()
37 - .await?;
38 -
39 - match response.status() {
40 - reqwest::StatusCode::OK => {
41 - let auth_app: AuthApp = response.json().await?;
42 - println!("Auth app requested: {auth_app:#?}");
43 - Ok(auth_app)
44 - }
45 - _ => Err(anyhow!(format!(
46 - "Failed to find an auth app with id: {id}."
47 - ))),
48 - }
49 -}
50 -
51 -async fn delete_auth_app(id: String) -> Result<()> {
52 - // Get current token
53 - let token = get_smb_token().await?;
54 -
55 - let response = Client::new()
56 - .delete([BASE_URL, "v1/auth_apps/", &id].join(""))
57 - .header("Authorization", token)
58 - .send()
59 - .await?;
60 -
61 - match response.status() {
62 - reqwest::StatusCode::OK => {
63 - debug!("Project deleted.");
64 - Ok(())
65 - }
66 - _ => Err(anyhow!("Failed to delete an auth app.")),
67 - }
68 -}
69 -
70 -async fn create_auth_app(auth_app: AuthAppCreate) -> Result<AuthApp> {
71 - // Get current token
72 - let token = get_smb_token().await?;
73 -
74 - let response = Client::new()
75 - .post([BASE_URL, "v1/auth_apps"].join(""))
76 - .json(&auth_app)
77 - .header("Authorization", token)
78 - .send()
79 - .await?;
80 -
81 - match response.status() {
82 - reqwest::StatusCode::CREATED => {
83 - let auth_app: AuthApp = response.json().await?;
84 - println!("Project created: {auth_app:#?}");
85 - Ok(auth_app)
86 - }
87 - _ => Err(anyhow!("Failed to create an auth app.")),
88 - }
89 -}
app-pkt/Cargo.toml deleted
-14
@@ -1,14 +0,0 @@
1 -[package]
2 -name = "app-pkt"
3 -version = "0.3.3"
4 -edition = "2021"
5 -authors = ["Seto Elkahfi <hej@setoelkahfi.se>"]
6 -description = "Command line tool for creating and managing SmbPndk resources."
7 -license = "Apache-2.0"
8 -repository = "https://github.com/smbpndk/smbpndk-cli"
9 -documentation = "https://docs.smbpndk.com/cli"
10 -keywords = ["cli", "cloud", "web2", "web3", "smbpndk"]
11 -categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
12 -readme = "./../README.md"
13 -
14 -[dependencies]
app-pkt/src/lib.rs deleted
-14
@@ -1,14 +0,0 @@
1 -pub fn add(left: usize, right: usize) -> usize {
2 - left + right
3 -}
4 -
5 -#[cfg(test)]
6 -mod tests {
7 - use super::*;
8 -
9 - #[test]
10 - fn it_works() {
11 - let result = add(2, 2);
12 - assert_eq!(result, 4);
13 - }
14 -}
app-rdb/Cargo.toml deleted
-14
@@ -1,14 +0,0 @@
1 -[package]
2 -name = "app-rdb"
3 -version = "0.3.3"
4 -edition = "2021"
5 -authors = ["Seto Elkahfi <hej@setoelkahfi.se>"]
6 -description = "Command line tool for creating and managing SmbPndk resources."
7 -license = "Apache-2.0"
8 -repository = "https://github.com/smbpndk/smbpndk-cli"
9 -documentation = "https://docs.smbpndk.com/cli"
10 -keywords = ["cli", "cloud", "web2", "web3", "smbpndk"]
11 -categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
12 -readme = "./../README.md"
13 -
14 -[dependencies]
app-rdb/src/lib.rs deleted
-14
@@ -1,14 +0,0 @@
1 -pub fn add(left: usize, right: usize) -> usize {
2 - left + right
3 -}
4 -
5 -#[cfg(test)]
6 -mod tests {
7 - use super::*;
8 -
9 - #[test]
10 - fn it_works() {
11 - let result = add(2, 2);
12 - assert_eq!(result, 4);
13 - }
14 -}
smbpndk-cli/Cargo.toml
-4
@@ -17,10 +17,6 @@ path = "src/main.rs"
17
18 [dependencies]
19 anyhow = "1.0.58"
20 -app-fun = { version = "0.3.0", path = "../app-fun" }
21 -app-oten = { version = "0.3.0", path = "../app-oten" }
22 -app-pkt = { version = "0.3.0", path = "../app-pkt" }
23 -app-rdb = { version = "0.3.0", path = "../app-rdb" }
20 clap = { version = "4.1.6", features = ["derive"] }
21 clap_mangen = "0.2.10"
22 console = "0.15.0"
smbpndk-cli/src/cli/mod.rs
+2
@@ -26,11 +26,13 @@ pub enum Commands {
26 command: project::cli::Commands,
27 },
28
29 + /*
30 #[clap(about = "Manage your Oten authentication app. Add, delete, edit. Need authentication.")]
31 Oten {
32 #[clap(subcommand)]
33 command: app_oten::cli::Commands,
34 },
35 + */
36 // Function
37 /*
38 FunApp {