@smbcloud / cli / commits / 926a353

NO error

Seto Elkahfi committed Apr 15, 2023 at 10:42 UTC 926a3535d4acf8b7cd0d381c4b94dbdfa6f84e1c
24 files changed +140 -49
Cargo.lock
+27 -1
@@ -29,6 +29,17 @@ version = "1.0.69"
29 source = "registry+https://github.com/rust-lang/crates.io-index"
30 checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
31
32 +[[package]]
33 +name = "async-trait"
34 +version = "0.1.66"
35 +source = "registry+https://github.com/rust-lang/crates.io-index"
36 +checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc"
37 +dependencies = [
38 + "proc-macro2",
39 + "quote",
40 + "syn",
41 +]
42 +
43 [[package]]
44 name = "autocfg"
45 version = "1.1.0"
@@ -570,6 +581,17 @@ dependencies = [
581 "regex-automata",
582 ]
583
584 +[[package]]
585 +name = "maybe-async"
586 +version = "0.2.7"
587 +source = "registry+https://github.com/rust-lang/crates.io-index"
588 +checksum = "0f1b8c13cb1f814b634a96b2c725449fe7ed464a7b8781de8688be5ffbd3f305"
589 +dependencies = [
590 + "proc-macro2",
591 + "quote",
592 + "syn",
593 +]
594 +
595 [[package]]
596 name = "memchr"
597 version = "2.5.0"
@@ -1071,11 +1093,15 @@ dependencies = [
1093
1094 [[package]]
1095 name = "smbpndk-networking"
1074 -version = "0.0.1"
1096 +version = "0.1.0"
1097 dependencies = [
1098 + "async-trait",
1099 + "log",
1100 + "maybe-async",
1101 "reqwest",
1102 "serde",
1103 "serde_json",
1104 + "thiserror",
1105 ]
1106
1107 [[package]]
Cargo.toml
+3 -39
@@ -1,41 +1,5 @@
1 [workspace]
2 members = [
3 - "smbpndk-networking"
4 -]
5 -
6 -[package]
7 -name = "smbpndk-cli"
8 -version = "0.2.1"
9 -edition = "2021"
10 -description = "Command line tool for creating and managing SmbPndk resources."
11 -license = "Apache-2.0"
12 -repository = "https://github.com/smbpndk/smbpndk-cli"
13 -documentation = "https://docs.smbpndk.com/cli"
14 -keywords = ["cli", "cloud", "developer", "platform"]
15 -categories = ["command-line-utilities"]
16 -
17 -[[bin]]
18 -name = "smb"
19 -path = "src/main.rs"
20 -
21 -[dependencies]
22 -anyhow = "1.0.58"
23 -clap = { version = "4.1.6", features = ["derive"] }
24 -clap_mangen = "0.2.10"
25 -console = "0.15.0"
26 -dialoguer = "0.10.4"
27 -dirs = "4.0.0"
28 -dotenv = "0.15.0"
29 -home = "0.5.4"
30 -open = "4.0.1"
31 -regex = "1.3.1"
32 -reqwest = { version = "0.11", features = ["json"] }
33 -serde = { version = "1", features = ["derive"] }
34 -serde_json = "1.0.82"
35 -smbpndk-networking = { path = "smbpndk-networking" }
36 -spinners = "4.1.0"
37 -tokio = { version = "1.14.1", features = ["full"] }
38 -tracing = { version = "0.1.35", features = ["log"] }
39 -tracing-bunyan-formatter = "0.3.3"
40 -tracing-subscriber = { version = "0.3.14", features = ["registry", "env-filter"] }
41 -url-builder = "0.1.1"
3 + "smbpndk-networking",
4 + "smbpndk-cli"
5 +]
\ No newline at end of file
smbpndk-cli/Cargo.toml new
+36
@@ -0,0 +1,36 @@
1 +[package]
2 +name = "smbpndk-cli"
3 +version = "0.2.1"
4 +edition = "2021"
5 +description = "Command line tool for creating and managing SmbPndk resources."
6 +license = "Apache-2.0"
7 +repository = "https://github.com/smbpndk/smbpndk-cli"
8 +documentation = "https://docs.smbpndk.com/cli"
9 +keywords = ["cli", "cloud", "developer", "platform"]
10 +categories = ["command-line-utilities"]
11 +
12 +[[bin]]
13 +name = "smb"
14 +path = "src/main.rs"
15 +
16 +[dependencies]
17 +anyhow = "1.0.58"
18 +clap = { version = "4.1.6", features = ["derive"] }
19 +clap_mangen = "0.2.10"
20 +console = "0.15.0"
21 +dialoguer = "0.10.4"
22 +dirs = "4.0.0"
23 +dotenv = "0.15.0"
24 +home = "0.5.4"
25 +open = "4.0.1"
26 +regex = "1.3.1"
27 +reqwest = { version = "0.11", features = ["json"] }
28 +serde = { version = "1", features = ["derive"] }
29 +serde_json = "1.0.82"
30 +smbpndk-networking = { path = "../smbpndk-networking" }
31 +spinners = "4.1.0"
32 +tokio = { version = "1.14.1", features = ["full"] }
33 +tracing = { version = "0.1.35", features = ["log"] }
34 +tracing-bunyan-formatter = "0.3.3"
35 +tracing-subscriber = { version = "0.3.14", features = ["registry", "env-filter"] }
36 +url-builder = "0.1.1"
smbpndk-cli/src/account/404.html renamed
smbpndk-cli/src/account/forgot/mod.rs renamed
smbpndk-cli/src/account/hello.html renamed
smbpndk-cli/src/account/login/mod.rs renamed
smbpndk-cli/src/account/login/process.rs renamed
smbpndk-cli/src/account/mod.rs renamed
smbpndk-cli/src/account/model/mod.rs renamed
smbpndk-cli/src/account/signup/mod.rs renamed
smbpndk-cli/src/account/signup/process.rs renamed
smbpndk-cli/src/auth_app/cli.rs renamed
smbpndk-cli/src/auth_app/mod.rs renamed
smbpndk-cli/src/cli/mod.rs renamed
smbpndk-cli/src/constants.rs renamed
smbpndk-cli/src/lib.rs renamed
smbpndk-cli/src/main.rs renamed
smbpndk-cli/src/projects/crud/mod.rs renamed
smbpndk-cli/src/projects/mod.rs renamed
smbpndk-cli/src/util.rs renamed
smbpndk-networking/Cargo.toml
+6 -2
@@ -1,9 +1,13 @@
1 [package]
2 name = "smbpndk-networking"
3 -version = "0.0.1"
3 +version = "0.1.0"
4 edition = "2021"
5
6 [dependencies]
7 reqwest = { version = "0.11", features = ["json"] }
8 serde = { version = "1", features = ["derive"] }
9 -serde_json = "1.0.82"
\ No newline at end of file
9 +serde_json = "1.0.82"
10 +thiserror = "1.0.29"
11 +async-trait = { version = "0.1.51", optional = true }
12 +log = "0.4.14"
13 +maybe-async = { version = "0.2", features = ["is_sync"] }
\ No newline at end of file
smbpndk-networking/src/common.rs new
+60
@@ -0,0 +1,60 @@
1 +use std::collections::HashMap;
2 +use std::fmt;
3 +
4 +use maybe_async::maybe_async;
5 +use serde_json::Value;
6 +
7 +pub type Headers = HashMap<String, String>;
8 +pub type Query<'a> = HashMap<&'a str, &'a str>;
9 +pub type Form<'a> = HashMap<&'a str, &'a str>;
10 +
11 +/// This trait represents the interface to be implemented for an HTTP client,
12 +/// which is kept separate from the Spotify client for cleaner code. Thus, it
13 +/// also requires other basic traits that are needed for the Spotify client.
14 +///
15 +/// When a request doesn't need to pass parameters, the empty or default value
16 +/// of the payload type should be passed, like `json!({})` or `Query::new()`.
17 +/// This avoids using `Option<T>` because `Value` itself may be null in other
18 +/// different ways (`Value::Null`, an empty `Value::Object`...), so this removes
19 +/// redundancy and edge cases (a `Some(Value::Null), for example, doesn't make
20 +/// much sense).
21 +#[maybe_async]
22 +pub trait BaseHttpClient: Send + Default + Clone + fmt::Debug {
23 + type Error;
24 +
25 + // This internal function should always be given an object value in JSON.
26 + async fn get(
27 + &self,
28 + url: &str,
29 + headers: Option<&Headers>,
30 + payload: &Query,
31 + ) -> Result<String, Self::Error>;
32 +
33 + async fn post(
34 + &self,
35 + url: &str,
36 + headers: Option<&Headers>,
37 + payload: &Value,
38 + ) -> Result<String, Self::Error>;
39 +
40 + async fn post_form(
41 + &self,
42 + url: &str,
43 + headers: Option<&Headers>,
44 + payload: &Form<'_>,
45 + ) -> Result<String, Self::Error>;
46 +
47 + async fn put(
48 + &self,
49 + url: &str,
50 + headers: Option<&Headers>,
51 + payload: &Value,
52 + ) -> Result<String, Self::Error>;
53 +
54 + async fn delete(
55 + &self,
56 + url: &str,
57 + headers: Option<&Headers>,
58 + payload: &Value,
59 + ) -> Result<String, Self::Error>;
60 +}
smbpndk-networking/src/lib.rs
+8 -7
@@ -1,11 +1,12 @@
1 -use serde_json::Value;
2 -use std::collections::HashMap;
3 -use std::time::Duration;
1 +mod common;
2 +
3 +//use async_trait::async_trait;
4 +use common::{BaseHttpClient, Form, Headers, Query};
5 +use maybe_async::async_impl;
6 use reqwest::Method;
7 use reqwest::RequestBuilder;
6 -
7 -pub type Headers = HashMap<String, String>;
8 -pub type Query<'a> = HashMap<&'a str, &'a str>;
8 +use serde_json::Value;
9 +use std::time::Duration;
10
11 pub trait HttpClient: Send + Default {
12 type Error;
@@ -96,4 +97,4 @@ impl ReqwestClient {
97 Err(ReqwestError::StatusCode(response))
98 }
99 }
99 -}
\ No newline at end of file
100 +}