@smbcloud / cli / commits / 900e79a

fix client setup

Seto committed Jan 2, 2026 at 19:16 UTC 900e79afd4ccc95c1cd80d4edc66d2cb94b65285
47 files changed +143 -150
.env.example
-5
@@ -1,6 +1 @@
1 -CLI_CLIENT_ID=
2 -SIGIT_CLIENT_ID=
3 -WEB_CONSOLE_CLIENT_ID=
1 CLI_CLIENT_SECRET=
5 -SIGIT_CLIENT_SECRET=
6 -WEB_CONSOLE_CLIENT_SECRET=
Cargo.lock
+1 -1
@@ -2094,6 +2094,7 @@ dependencies = [
2094 "console 0.16.1",
2095 "dialoguer",
2096 "dirs",
2097 + "dotenv_codegen",
2098 "git2",
2099 "home",
2100 "indicatif",
@@ -2154,7 +2155,6 @@ dependencies = [
2155 name = "smbcloud-networking"
2156 version = "0.3.28"
2157 dependencies = [
2157 - "dotenv_codegen",
2158 "smbcloud-network",
2159 "url-builder",
2160 ]
Cargo.toml
+1
@@ -11,6 +11,7 @@ clap_mangen = "0.2.10"
11 console = "0.16"
12 dialoguer = "0.11.0"
13 dirs = "6.0"
14 +dotenv_codegen = "0.15"
15 git2 = "0.20.1"
16 home = "0.5.4"
17 indicatif = "0.17.11"
crates/cli/Cargo.toml
+1
@@ -29,6 +29,7 @@ clap_mangen = { workspace = true }
29 console = { workspace = true }
30 dialoguer = { workspace = true }
31 dirs = { workspace = true }
32 +dotenv_codegen = { workspace = true }
33 git2 = { workspace = true }
34 home = { workspace = true }
35 indicatif = { workspace = true }
crates/cli/src/account/forgot/mod.rs
+3 -4
@@ -1,5 +1,6 @@
1 use crate::{
2 cli::CommandResult,
3 + client,
4 ui::{fail_message, fail_symbol, succeed_message, succeed_symbol},
5 };
6 use anyhow::Result;
@@ -7,9 +8,7 @@ use dialoguer::{theme::ColorfulTheme, Input, Password};
8 use reqwest::{Client, StatusCode};
9 use smbcloud_model::forgot::{Args, Email, Param, UserUpdatePassword};
10 use smbcloud_network::environment::Environment;
10 -use smbcloud_networking::{
11 - constants::PATH_USERS_PASSWORD, smb_base_url_builder, smb_client::SmbClient,
12 -};
11 +use smbcloud_networking::{constants::PATH_USERS_PASSWORD, smb_base_url_builder};
12 use smbcloud_utils::email_validation;
13 use spinners::Spinner;
14
@@ -117,7 +116,7 @@ async fn input_code(env: Environment) -> Result<CommandResult> {
116 }
117
118 fn build_smb_forgot_url(env: Environment) -> String {
120 - let mut url_builder = smb_base_url_builder(env, &SmbClient::Cli);
119 + let mut url_builder = smb_base_url_builder(env, client());
120 url_builder.add_route(PATH_USERS_PASSWORD);
121 url_builder.build()
122 }
crates/cli/src/account/lib.rs
+2 -1
@@ -193,7 +193,8 @@ pub async fn process_connect_github(env: Environment, code: String) -> Result<Sm
193 }
194
195 fn build_authorize_smb_url(env: Environment) -> String {
196 - let mut url_builder = smb_base_url_builder(env, &SmbClient::Cli);
196 + let secret = "secret";
197 + let mut url_builder = smb_base_url_builder(env, (&SmbClient::Cli, secret));
198 url_builder.add_route(PATH_AUTHORIZE);
199 url_builder.build()
200 }
crates/cli/src/account/login/process.rs
+8 -9
@@ -5,6 +5,7 @@ use {
5 signup::{do_signup, signup_with_email, SignupMethod},
6 },
7 cli::CommandResult,
8 + client,
9 token::is_logged_in::is_logged_in as is_logged_in_async,
10 ui::{fail_message, fail_symbol, succeed_message, succeed_symbol},
11 },
@@ -25,9 +26,7 @@ use {
26 signup::{GithubEmail, Provider, SignupGithubParams, SignupUserGithub},
27 },
28 smbcloud_network::environment::Environment,
28 - smbcloud_networking::{
29 - constants::PATH_LINK_GITHUB_ACCOUNT, smb_base_url_builder, smb_client::SmbClient,
30 - },
29 + smbcloud_networking::{constants::PATH_LINK_GITHUB_ACCOUNT, smb_base_url_builder},
30 smbcloud_networking_account::{
31 check_email::check_email, login::login,
32 resend_email_verification::resend_email_verification as account_resend_email_verification,
@@ -214,7 +213,7 @@ async fn resend_email_verification(env: Environment, user: User) -> Result<Comma
213 .bold()
214 .to_string(),
215 );
217 - match account_resend_email_verification(env, SmbClient::Cli, user.email).await {
216 + match account_resend_email_verification(env, client(), user.email).await {
217 Ok(_) => Ok(CommandResult {
218 spinner,
219 symbol: succeed_symbol(),
@@ -292,7 +291,7 @@ async fn login_with_email(env: Environment) -> Result<CommandResult> {
291 }
292 };
293
295 - match check_email(env, SmbClient::Cli, &username).await {
294 + match check_email(env, client(), &username).await {
295 Ok(auth) => {
296 // Only continue with password input if email is found and confirmed.
297 if auth.error_code.is_some() {
@@ -327,7 +326,7 @@ async fn do_process_login(env: Environment, args: LoginArgs) -> Result<CommandRe
326 spinners::Spinners::SimpleDotsScrolling,
327 succeed_message("Loading"),
328 );
330 - let account_status = match login(env, SmbClient::Cli, args.username, args.password).await {
329 + let account_status = match login(env, client(), args.username, args.password).await {
330 Ok(response) => response,
331 Err(_) => return Err(anyhow!(fail_message("Check your internet connection."))),
332 };
@@ -466,7 +465,7 @@ async fn resend_reset_password_instruction(env: Environment, user: User) -> Resu
465 succeed_message("Sending reset password instruction..."),
466 );
467
469 - match account_resend_reset_password_instruction(env, SmbClient::Cli, user.email).await {
468 + match account_resend_reset_password_instruction(env, client(), user.email).await {
469 Ok(_) => {
470 spinner.stop_and_persist(
471 "✅",
@@ -509,7 +508,7 @@ async fn input_reset_password_token(env: Environment) -> Result<CommandResult> {
508 style("Resetting password...").green().bold().to_string(),
509 );
510
512 - match account_reset_password(env, SmbClient::Cli, token, password).await {
511 + match account_reset_password(env, client(), token, password).await {
512 Ok(_) => Ok(CommandResult {
513 spinner,
514 symbol: succeed_symbol(),
@@ -520,7 +519,7 @@ async fn input_reset_password_token(env: Environment) -> Result<CommandResult> {
519 }
520
521 fn build_smb_connect_github_url(env: Environment) -> String {
523 - let mut url_builder = smb_base_url_builder(env, &SmbClient::Cli);
522 + let mut url_builder = smb_base_url_builder(env, client());
523 url_builder.add_route(PATH_LINK_GITHUB_ACCOUNT);
524 url_builder.build()
525 }
crates/cli/src/account/logout/mod.rs
+2 -2
@@ -1,13 +1,13 @@
1 use {
2 crate::{
3 cli::CommandResult,
4 + client,
5 token::{get_smb_token::get_smb_token, smb_token_file_path::smb_token_file_path},
6 ui::{fail_message, fail_symbol, succeed_message, succeed_symbol},
7 },
8 anyhow::{anyhow, Result},
9 dialoguer::{theme::ColorfulTheme, Confirm},
10 smbcloud_network::environment::Environment,
10 - smbcloud_networking::smb_client::SmbClient,
11 smbcloud_networking_account::logout::logout,
12 spinners::Spinner,
13 std::fs,
@@ -68,7 +68,7 @@ pub async fn process_logout(env: Environment) -> Result<CommandResult> {
68
69 async fn do_process_logout(env: Environment) -> Result<()> {
70 let token = get_smb_token(env)?;
71 - match logout(env, SmbClient::Cli, token).await {
71 + match logout(env, client(), token).await {
72 Ok(_) => Ok(()),
73 Err(e) => Err(anyhow!("{e}")),
74 }
crates/cli/src/account/me/mod.rs
+2 -2
@@ -1,4 +1,5 @@
1 use crate::account::lib::is_logged_in;
2 +use crate::client;
3 use crate::token::get_smb_token::get_smb_token;
4 use crate::{
5 cli::CommandResult,
@@ -7,7 +8,6 @@ use crate::{
8 use anyhow::Result;
9 use smbcloud_model::account::User;
10 use smbcloud_network::environment::Environment;
10 -use smbcloud_networking::smb_client::SmbClient;
11 use smbcloud_networking_account::me::me;
12 use spinners::Spinner;
13 use tabled::{Table, Tabled};
@@ -51,7 +51,7 @@ pub async fn process_me(env: Environment) -> Result<CommandResult> {
51 succeed_message("Loading"),
52 );
53 let token = get_smb_token(env)?;
54 - match me(env, SmbClient::Cli, &token).await {
54 + match me(env, client(), &token).await {
55 Ok(user) => {
56 spinner.stop_and_persist(&succeed_symbol(), succeed_message("Loaded."));
57 show_user(&user);
crates/cli/src/account/signup/process.rs
+4 -3
@@ -3,6 +3,7 @@ use {
3 crate::{
4 account::lib::authorize_github,
5 cli::CommandResult,
6 + client,
7 token::smb_token_file_path::smb_token_file_path,
8 ui::{fail_message, fail_symbol, succeed_message, succeed_symbol},
9 },
@@ -13,7 +14,7 @@ use {
14 serde::Serialize,
15 smbcloud_model::signup::SignupResult,
16 smbcloud_network::environment::Environment,
16 - smbcloud_networking::{constants::PATH_USERS, smb_base_url_builder, smb_client::SmbClient},
17 + smbcloud_networking::{constants::PATH_USERS, smb_base_url_builder},
18 smbcloud_networking_account::signup::signup,
19 smbcloud_utils::email_validation,
20 spinners::Spinner,
@@ -155,7 +156,7 @@ pub async fn do_signup_email(
156 succeed_message("Signing you up"),
157 );
158
158 - match signup(env, SmbClient::Cli, email, password).await {
159 + match signup(env, client(), email, password).await {
160 Ok(_) => Ok(CommandResult {
161 spinner,
162 symbol: succeed_symbol(),
@@ -171,7 +172,7 @@ pub async fn do_signup_email(
172 }
173
174 fn build_smb_signup_url(env: Environment) -> String {
174 - let mut url_builder = smb_base_url_builder(env, &SmbClient::Cli);
175 + let mut url_builder = smb_base_url_builder(env, client());
176 url_builder.add_route(PATH_USERS);
177 url_builder.build()
178 }
crates/cli/src/deploy/config.rs
+1 -1
@@ -77,7 +77,7 @@ pub(crate) async fn check_project(
77 );
78 match get_project(
79 env,
80 - SmbClient::Cli,
80 + (&SmbClient::Cli, ""),
81 access_token.to_string(),
82 id.to_string(),
83 )
crates/cli/src/deploy/process_deploy.rs
+6 -12
@@ -2,6 +2,7 @@ use {
2 crate::{
3 account::login::process_login,
4 cli::CommandResult,
5 + client,
6 deploy::{
7 config::{check_config, check_project, credentials},
8 detect_runner::detect_runner,
@@ -15,7 +16,6 @@ use {
16 git2::{PushOptions, RemoteCallbacks, Repository},
17 smbcloud_model::project::{DeploymentPayload, DeploymentStatus},
18 smbcloud_network::environment::Environment,
18 - smbcloud_networking::smb_client::SmbClient,
19 smbcloud_networking_account::me::me,
20 smbcloud_networking_project::{
21 crud_project_deployment_create::create_deployment, crud_project_deployment_update::update,
@@ -104,15 +104,9 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
104 status: DeploymentStatus::Started,
105 };
106
107 - let created_deployment = create_deployment(
108 - env,
109 - SmbClient::Cli,
110 - &access_token,
111 - config.project.id,
112 - payload,
113 - )
114 - .await?;
115 - let user = me(env, SmbClient::Cli, &access_token).await?;
107 + let created_deployment =
108 + create_deployment(env, client(), &access_token, config.project.id, payload).await?;
109 + let user = me(env, client(), &access_token).await?;
110
111 let mut push_opts = PushOptions::new();
112 let mut callbacks = RemoteCallbacks::new();
@@ -165,7 +159,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
159 let result = handle.block_on(async {
160 update(
161 update_env, // Env is Copy
168 - SmbClient::Cli,
162 + client(),
163 access_token_for_update_cb.clone(),
164 project_id_for_update_cb,
165 deployment_id_for_update_cb,
@@ -201,7 +195,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
195 };
196 let result = update(
197 env,
204 - SmbClient::Cli,
198 + client(),
199 access_token.clone(),
200 config.project.id,
201 created_deployment.id,
crates/cli/src/deploy/setup_create_new_project.rs
+2 -3
@@ -1,5 +1,5 @@
1 use {
2 - crate::token::get_smb_token::get_smb_token,
2 + crate::{client, token::get_smb_token::get_smb_token},
3 dialoguer::{console::Term, theme::ColorfulTheme, Input, Select},
4 regex::Regex,
5 smbcloud_model::{
@@ -8,7 +8,6 @@ use {
8 runner::Runner,
9 },
10 smbcloud_network::environment::Environment,
11 - smbcloud_networking::smb_client::SmbClient,
11 smbcloud_networking_project::crud_project_create::create_project,
12 std::path::Path,
13 };
@@ -95,7 +94,7 @@ pub(crate) async fn create_new_project(
94
95 match create_project(
96 env,
98 - SmbClient::Cli,
97 + client(),
98 access_token,
99 ProjectCreate {
100 name,
crates/cli/src/deploy/setup_project.rs
+2 -2
@@ -1,5 +1,6 @@
1 use {
2 crate::{
3 + client,
4 deploy::{
5 setup_create_new_project::create_new_project, setup_select_project::select_project,
6 },
@@ -12,7 +13,6 @@ use {
13 project::Project,
14 },
15 smbcloud_network::environment::Environment,
15 - smbcloud_networking::smb_client::SmbClient,
16 smbcloud_networking_project::crud_project_read::get_projects,
17 smbcloud_utils::config::Config,
18 std::{env, fs, path::Path},
@@ -56,7 +56,7 @@ pub(crate) async fn setup_project(
56 },
57 };
58
59 - let projects = get_projects(env, SmbClient::Cli, access_token.to_string()).await?;
59 + let projects = get_projects(env, client(), access_token.to_string()).await?;
60
61 let project: Project = if !projects.is_empty() {
62 select_project(env, projects, &path_str).await?
crates/cli/src/lib.rs
+10
@@ -1,6 +1,16 @@
1 +use smbcloud_networking::smb_client::SmbClient;
2 +
3 pub mod account;
4 pub mod cli;
5 pub mod deploy;
6 pub mod project;
7 mod token;
8 mod ui;
9 +
10 +#[macro_use]
11 +extern crate dotenv_codegen;
12 +
13 +pub(crate) fn client() -> (&'static SmbClient, &'static str) {
14 + let secret = dotenv!("CLI_CLIENT_SECRET");
15 + (&SmbClient::Cli, secret)
16 +}
crates/cli/src/project/crud_create.rs
+2 -2
@@ -1,3 +1,4 @@
1 +use crate::client;
2 use crate::token::{get_smb_token::get_smb_token, is_logged_in::is_logged_in};
3 use crate::{
4 account::login::process_login,
@@ -13,7 +14,6 @@ use dialoguer::{theme::ColorfulTheme, Input};
14 use smbcloud_model::project::ProjectCreate;
15 use smbcloud_model::runner::Runner;
16 use smbcloud_network::environment::Environment;
16 -use smbcloud_networking::smb_client::SmbClient;
17 use smbcloud_networking_project::crud_project_create::create_project;
18 use spinners::Spinner;
19
@@ -75,7 +75,7 @@ pub async fn process_project_init(
75 let access_token = get_smb_token(env)?;
76 match create_project(
77 env,
78 - SmbClient::Cli,
78 + client(),
79 access_token,
80 ProjectCreate {
81 name: project_name.clone(),
crates/cli/src/project/crud_delete.rs
+2 -2
@@ -1,3 +1,4 @@
1 +use crate::client;
2 use crate::token::get_smb_token::get_smb_token;
3 use crate::{
4 account::lib::is_logged_in,
@@ -7,7 +8,6 @@ use crate::{
8 use anyhow::{anyhow, Result};
9 use dialoguer::{theme::ColorfulTheme, Input};
10 use smbcloud_network::environment::Environment;
10 -use smbcloud_networking::smb_client::SmbClient;
11 use smbcloud_networking_project::crud_project_delete::delete_project;
12 use spinners::Spinner;
13
@@ -34,7 +34,7 @@ pub async fn process_project_delete(env: Environment, id: String) -> Result<Comm
34 });
35 }
36 let access_token = get_smb_token(env)?;
37 - match delete_project(env, SmbClient::Cli, access_token, id).await {
37 + match delete_project(env, client(), access_token, id).await {
38 Ok(_) => Ok(CommandResult {
39 spinner,
40 symbol: succeed_symbol(),
crates/cli/src/project/crud_read.rs
+4 -4
@@ -1,5 +1,6 @@
1 use std::{fs::OpenOptions, io::Write};
2
3 +use crate::client;
4 use crate::token::get_smb_token::get_smb_token;
5 use crate::{
6 cli::CommandResult,
@@ -9,7 +10,6 @@ use anyhow::{anyhow, Result};
10 use log::debug;
11 use smbcloud_model::project::{Config, Project};
12 use smbcloud_network::environment::Environment;
12 -use smbcloud_networking::smb_client::SmbClient;
13 use smbcloud_networking_project::crud_project_read::{get_project, get_projects};
14 use spinners::Spinner;
15 use tabled::{Table, Tabled};
@@ -50,7 +50,7 @@ pub async fn process_project_list(env: Environment) -> Result<CommandResult> {
50 succeed_message("Loading"),
51 );
52 let token = get_smb_token(env)?;
53 - match get_projects(env, SmbClient::Cli, token).await {
53 + match get_projects(env, client(), token).await {
54 Ok(projects) => {
55 spinner.stop_and_persist(&succeed_symbol(), succeed_message("Loaded."));
56 let msg = if projects.is_empty() {
@@ -85,7 +85,7 @@ pub async fn process_project_show(env: Environment, id: String) -> Result<Comman
85 succeed_message("Loading"),
86 );
87 let access_token = get_smb_token(env)?;
88 - match get_project(env, SmbClient::Cli, access_token, id).await {
88 + match get_project(env, client(), access_token, id).await {
89 Ok(project) => {
90 spinner.stop_and_persist(&succeed_symbol(), succeed_message("Loaded."));
91 let message = succeed_message(&format!("Showing project {}.", &project.name));
@@ -139,7 +139,7 @@ pub(crate) fn show_project_detail(project: &Project) {
139
140 pub(crate) async fn process_project_use(env: Environment, id: String) -> Result<CommandResult> {
141 let access_token = get_smb_token(env)?;
142 - let project = get_project(env, SmbClient::Cli, access_token, id).await?;
142 + let project = get_project(env, client(), access_token, id).await?;
143
144 let config = Config {
145 current_project: Some(project),
crates/cli/src/project/crud_update.rs
+6 -10
@@ -1,9 +1,11 @@
1 -use crate::token::{get_smb_token::get_smb_token, is_logged_in::is_logged_in};
1 +use crate::{
2 + client,
3 + token::{get_smb_token::get_smb_token, is_logged_in::is_logged_in},
4 +};
5 use anyhow::{anyhow, Result};
6 use dialoguer::{console::Term, theme::ColorfulTheme, Input, Select};
7 use smbcloud_model::runner::Runner;
8 use smbcloud_network::environment::Environment;
6 -use smbcloud_networking::smb_client::SmbClient;
9 use smbcloud_networking_project::{
10 crud_project_read::get_project, crud_project_update::update_project,
11 };
@@ -23,13 +25,7 @@ pub async fn process_project_update(env: Environment, project_id: String) -> Res
25 }
26
27 let access_token = get_smb_token(env)?;
26 - let project = get_project(
27 - env,
28 - SmbClient::Cli,
29 - access_token.clone(),
30 - project_id.clone(),
31 - )
32 - .await?;
28 + let project = get_project(env, client(), access_token.clone(), project_id.clone()).await?;
29
30 if let Some(project_description) = project.description {
31 println!("Description: {}", description(&project_description));
@@ -59,7 +55,7 @@ pub async fn process_project_update(env: Environment, project_id: String) -> Res
55 );
56 update_project(
57 env,
62 - SmbClient::Cli,
58 + client(),
59 access_token,
60 project_id,
61 &new_description,
crates/cli/src/project/deployment.rs
+3 -4
@@ -1,3 +1,4 @@
1 +use crate::client;
2 use crate::token::get_smb_token::get_smb_token;
3 use crate::{
4 cli::CommandResult,
@@ -7,7 +8,6 @@ use crate::{
8 use anyhow::Result;
9 use smbcloud_model::project::Deployment;
10 use smbcloud_network::environment::Environment;
10 -use smbcloud_networking::smb_client::SmbClient;
11 use smbcloud_networking_project::crud_project_deployment_read::{get_deployment, get_deployments};
12 use spinners::Spinner;
13 use tabled::{Table, Tabled};
@@ -30,7 +30,7 @@ pub(crate) async fn process_deployment(
30 let deployment_id: i32 = deployment_id.parse()?;
31 let deployment = get_deployment(
32 env,
33 - SmbClient::Cli,
33 + client(),
34 access_token,
35 config.project.id,
36 deployment_id,
@@ -41,8 +41,7 @@ pub(crate) async fn process_deployment(
41 } else {
42 // List all deployments for the project
43 let access_token = get_smb_token(env)?;
44 - let deployments =
45 - get_deployments(env, SmbClient::Cli, access_token, config.project.id).await?;
44 + let deployments = get_deployments(env, client(), access_token, config.project.id).await?;
45 spinner.stop_and_persist(&succeed_symbol(), succeed_message("Load all deployments"));
46 show_project_deployments(&deployments);
47 };
crates/cli/src/token/is_logged_in.rs
+6 -4
@@ -1,7 +1,9 @@
1 use {
2 - crate::token::get_smb_token::get_smb_token, smbcloud_model::error_codes::ErrorResponse,
3 - smbcloud_network::environment::Environment, smbcloud_networking::smb_client::SmbClient,
4 - smbcloud_networking_account::me::me, tracing::debug,
2 + crate::{client, token::get_smb_token::get_smb_token},
3 + smbcloud_model::error_codes::ErrorResponse,
4 + smbcloud_network::environment::Environment,
5 + smbcloud_networking_account::me::me,
6 + tracing::debug,
7 };
8
9 pub async fn is_logged_in(env: Environment) -> Result<bool, ErrorResponse> {
@@ -10,7 +12,7 @@ pub async fn is_logged_in(env: Environment) -> Result<bool, ErrorResponse> {
12 Ok(token) => token,
13 Err(_) => return Ok(false),
14 };
13 - match me(env, SmbClient::Cli, &access_token).await {
15 + match me(env, client(), &access_token).await {
16 Ok(user) => {
17 debug!("Authorized as: {:?}", user.id);
18 Ok(true)
crates/smbcloud-network/src/network.rs
+1 -1
@@ -130,7 +130,7 @@ pub async fn request_login(builder: RequestBuilder) -> Result<AccountStatus, Err
130 match error_response {
131 ErrorResponse::Error {
132 error_code,
133 - message,
133 + message: _,
134 } => match error_code {
135 ErrorCode::EmailNotVerified => Ok(AccountStatus::Incomplete {
136 status: smbcloud_model::account::ErrorCode::EmailUnverified,
crates/smbcloud-networking-account-wasm/src/login.rs
+9 -1
@@ -9,7 +9,15 @@ pub async fn login(
9 username: String,
10 password: String,
11 ) -> Result<JsValue, JsValue> {
12 - match smbcloud_networking_account::login::login(env, SmbClient::Cli, username, password).await {
12 + let secret = "wasm-secret";
13 + match smbcloud_networking_account::login::login(
14 + env,
15 + (&SmbClient::Cli, secret),
16 + username,
17 + password,
18 + )
19 + .await
20 + {
21 Ok(response) => Ok(serde_wasm_bindgen::to_value(&response)?),
22 Err(error) => Err(serde_wasm_bindgen::to_value(&error)?),
23 }
crates/smbcloud-networking-account-wasm/src/me.rs
+2 -1
@@ -5,7 +5,8 @@ use wasm_bindgen::prelude::wasm_bindgen;
5
6 #[wasm_bindgen]
7 pub async fn me(env: Environment, access_token: String) -> Result<JsValue, JsValue> {
8 - match smbcloud_networking_account::me::me(env, SmbClient::Cli, &access_token).await {
8 + let secret = "wasm-secret";
9 + match smbcloud_networking_account::me::me(env, (&SmbClient::Cli, secret), &access_token).await {
10 Ok(response) => Ok(serde_wasm_bindgen::to_value(&response)?),
11 Err(error) => Err(serde_wasm_bindgen::to_value(&error)?),
12 }
crates/smbcloud-networking-account/Cargo.toml
+1 -1
@@ -19,8 +19,8 @@ readme = "README.md"
19
20 [dependencies]
21 log = { workspace = true }
22 -reqwest = { workspace = true, features = ["json", "rustls-tls-native-roots"] }
22 openssl = { version = "0.10", features = ["vendored"] }
23 +reqwest = { workspace = true, features = ["json", "rustls-tls-native-roots"] }
24 serde_json = { workspace = true }
25 smbcloud-model = { workspace = true }
26 smbcloud-network = { workspace = true }
crates/smbcloud-networking-account/src/check_email.rs
+3 -3
@@ -9,17 +9,17 @@ use {
9
10 pub async fn check_email(
11 env: Environment,
12 - client: SmbClient,
12 + client: (&SmbClient, &str),
13 email: &str,
14 ) -> Result<SmbAuthorization, ErrorResponse> {
15 let builder = Client::new()
16 - .get(build_url(env, &client, email))
16 + .get(build_url(env, client, email))
17 .header("Accept", "application/json")
18 .header("Content-Type", "application/x-www-form-urlencoded");
19 request(builder).await
20 }
21
22 -fn build_url(env: Environment, client: &SmbClient, email: &str) -> String {
22 +fn build_url(env: Environment, client: (&SmbClient, &str), email: &str) -> String {
23 let mut url_builder = smb_base_url_builder(env, client);
24 url_builder.add_route(PATH_USERS_CHECK_EMAIL);
25 url_builder.add_param("email", email);
crates/smbcloud-networking-account/src/login.rs
+3 -3
@@ -14,7 +14,7 @@ use {
14
15 pub async fn login(
16 env: Environment,
17 - client: SmbClient,
17 + client: (&SmbClient, &str),
18 username: String,
19 password: String,
20 ) -> Result<AccountStatus, ErrorResponse> {
@@ -25,13 +25,13 @@ pub async fn login(
25 },
26 };
27 let builder = Client::new()
28 - .post(build_smb_login_url(env, &client))
28 + .post(build_smb_login_url(env, client))
29 .json(&login_params)
30 .header("User-agent", SMB_USER_AGENT);
31 request_login(builder).await
32 }
33
34 -pub(crate) fn build_smb_login_url(env: Environment, client: &SmbClient) -> String {
34 +pub(crate) fn build_smb_login_url(env: Environment, client: (&SmbClient, &str)) -> String {
35 let mut url_builder = smb_base_url_builder(env, client);
36 url_builder.add_route(PATH_USERS_SIGN_IN);
37 url_builder.build()
crates/smbcloud-networking-account/src/logout.rs
+3 -3
@@ -9,11 +9,11 @@ use {
9
10 pub async fn logout(
11 env: Environment,
12 - client: SmbClient,
12 + client: (&SmbClient, &str),
13 access_token: String,
14 ) -> Result<(), ErrorResponse> {
15 let response = match Client::new()
16 - .delete(build_smb_logout_url(env, &client))
16 + .delete(build_smb_logout_url(env, client))
17 .header("Authorization", access_token)
18 .header("Accept", "application/json")
19 .header("Content-Type", "application/x-www-form-urlencoded")
@@ -38,7 +38,7 @@ pub async fn logout(
38 }
39 }
40
41 -fn build_smb_logout_url(env: Environment, client: &SmbClient) -> String {
41 +fn build_smb_logout_url(env: Environment, client: (&SmbClient, &str)) -> String {
42 let mut url_builder = smb_base_url_builder(env, client);
43 url_builder.add_route(PATH_USERS_SIGN_OUT);
44 url_builder.build()
crates/smbcloud-networking-account/src/me.rs
+3 -3
@@ -6,18 +6,18 @@ use smbcloud_networking::{constants::PATH_USERS_ME, smb_base_url_builder, smb_cl
6
7 pub async fn me(
8 env: Environment,
9 - client: SmbClient,
9 + client: (&SmbClient, &str),
10 access_token: &str,
11 ) -> Result<User, ErrorResponse> {
12 let builder = Client::new()
13 - .get(build_smb_info_url(env, &client))
13 + .get(build_smb_info_url(env, client))
14 .header("Authorization", access_token)
15 .header("Accept", "application/json")
16 .header("Content-Type", "application/x-www-form-urlencoded");
17 request(builder).await
18 }
19
20 -fn build_smb_info_url(env: Environment, client: &SmbClient) -> String {
20 +fn build_smb_info_url(env: Environment, client: (&SmbClient, &str)) -> String {
21 let mut url_builder = smb_base_url_builder(env, client);
22 url_builder.add_route(PATH_USERS_ME);
23 url_builder.build()
crates/smbcloud-networking-account/src/oauth/get_account_status.rs
+3 -3
@@ -9,17 +9,17 @@ use {
9
10 pub async fn get_account_status(
11 env: Environment,
12 - client: SmbClient,
12 + client: (&SmbClient, &str),
13 email: &str,
14 ) -> Result<AccountStatus, ErrorResponse> {
15 let builder = Client::new()
16 - .get(build_url(env, &client, email))
16 + .get(build_url(env, client, email))
17 .header("Accept", "application/json")
18 .header("Content-Type", "application/x-www-form-urlencoded");
19 request_login(builder).await
20 }
21
22 -fn build_url(env: Environment, client: &SmbClient, email: &str) -> String {
22 +fn build_url(env: Environment, client: (&SmbClient, &str), email: &str) -> String {
23 let mut url_builder = smb_base_url_builder(env, client);
24 url_builder.add_route(PATH_ACCOUNT_STATUS);
25 url_builder.add_param("email", email);
crates/smbcloud-networking-account/src/remove.rs
+3 -3
@@ -7,7 +7,7 @@ use {
7
8 pub async fn remove(
9 env: Environment,
10 - client: SmbClient,
10 + client: (&SmbClient, &str),
11 user_agent: String,
12 access_token: &str,
13 ) -> Result<(), ErrorResponse> {
@@ -18,8 +18,8 @@ pub async fn remove(
18 request(builder).await
19 }
20
21 -fn build_smb_signup_url(env: Environment, client: SmbClient) -> String {
22 - let mut url_builder = smb_base_url_builder(env, &client);
21 +fn build_smb_signup_url(env: Environment, client: (&SmbClient, &str)) -> String {
22 + let mut url_builder = smb_base_url_builder(env, client);
23 url_builder.add_route(PATH_USERS);
24 url_builder.build()
25 }
crates/smbcloud-networking-account/src/resend_email_verification.rs
+4 -4
@@ -9,20 +9,20 @@ use {
9
10 pub async fn resend_email_verification(
11 env: Environment,
12 - client: SmbClient,
12 + client: (&SmbClient, &str),
13 email: String,
14 ) -> Result<SmbAuthorization, ErrorResponse> {
15 let builder = Client::new()
16 - .post(build_smb_resend_email_verification_url(env, &client))
16 + .post(build_smb_resend_email_verification_url(env, client))
17 .body(format!("email={}", email))
18 - .header("User-agent", client.id())
18 + .header("User-agent", client.0.id())
19 .header("Accept", "application/json")
20 .header("Content-Type", "application/x-www-form-urlencoded");
21
22 request(builder).await
23 }
24
25 -fn build_smb_resend_email_verification_url(env: Environment, client: &SmbClient) -> String {
25 +fn build_smb_resend_email_verification_url(env: Environment, client: (&SmbClient, &str)) -> String {
26 let mut url_builder = smb_base_url_builder(env, client);
27 url_builder.add_route(PATH_RESEND_CONFIRMATION);
28 url_builder.build()
crates/smbcloud-networking-account/src/resend_reset_password_instruction.rs
+4 -4
@@ -9,15 +9,15 @@ use {
9
10 pub async fn resend_reset_password_instruction(
11 env: Environment,
12 - client: SmbClient,
12 + client: (&SmbClient, &str),
13 email: String,
14 ) -> Result<SmbAuthorization, ErrorResponse> {
15 let builder = Client::new()
16 .post(build_smb_resend_reset_password_instructions_url(
17 - env, &client,
17 + env, client,
18 ))
19 .body(format!("email={}", email))
20 - .header("User-agent", client.id())
20 + .header("User-agent", client.0.id())
21 .header("Accept", "application/json")
22 .header("Content-Type", "application/x-www-form-urlencoded");
23
@@ -26,7 +26,7 @@ pub async fn resend_reset_password_instruction(
26
27 fn build_smb_resend_reset_password_instructions_url(
28 env: Environment,
29 - client: &SmbClient,
29 + client: (&SmbClient, &str),
30 ) -> String {
31 let mut url_builder = smb_base_url_builder(env, client);
32 url_builder.add_route(PATH_RESET_PASSWORD_INSTRUCTIONS);
crates/smbcloud-networking-account/src/reset_password.rs
+4 -5
@@ -13,7 +13,7 @@ use {
13
14 pub async fn reset_password(
15 env: Environment,
16 - client: SmbClient,
16 + client: (&SmbClient, &str),
17 token: String,
18 password: String,
19 ) -> Result<ResetPasswordResponse, ErrorResponse> {
@@ -27,17 +27,16 @@ pub async fn reset_password(
27 };
28
29 let builder = Client::new()
30 - .put(build_smb_reset_password_url(env))
30 + .put(build_smb_reset_password_url(env, client))
31 .json(&params)
32 - .header("User-agent", client.id())
32 .header("Accept", "application/json")
33 .header("Content-Type", "application/x-www-form-urlencoded");
34
35 request(builder).await
36 }
37
39 -fn build_smb_reset_password_url(env: Environment) -> String {
40 - let mut url_builder = smb_base_url_builder(env, &SmbClient::Cli);
38 +fn build_smb_reset_password_url(env: Environment, client: (&SmbClient, &str)) -> String {
39 + let mut url_builder = smb_base_url_builder(env, client);
40 url_builder.add_route(PATH_USERS_PASSWORD);
41 url_builder.build()
42 }
crates/smbcloud-networking-account/src/signup.rs
+4 -4
@@ -10,7 +10,7 @@ use {
10
11 pub async fn signup(
12 env: Environment,
13 - client: SmbClient,
13 + client: (&SmbClient, &str),
14 email: String,
15 password: String,
16 ) -> Result<SignupResult, ErrorResponse> {
@@ -18,13 +18,13 @@ pub async fn signup(
18 user: SignupUserEmail { email, password },
19 };
20 let builder = Client::new()
21 - .post(build_smb_signup_url(env, &client))
21 + .post(build_smb_signup_url(env, client))
22 .json(&params)
23 - .header("User-agent", client.id());
23 + .header("User-agent", client.0.id());
24 request(builder).await
25 }
26
27 -fn build_smb_signup_url(env: Environment, client: &SmbClient) -> String {
27 +fn build_smb_signup_url(env: Environment, client: (&SmbClient, &str)) -> String {
28 let mut url_builder = smb_base_url_builder(env, client);
29 url_builder.add_route(PATH_USERS);
30 url_builder.build()
crates/smbcloud-networking-project/src/crud_project_create.rs
+2 -2
@@ -10,12 +10,12 @@ use smbcloud_networking::{constants::SMB_USER_AGENT, smb_client::SmbClient};
10
11 pub async fn create_project(
12 env: Environment,
13 - client: SmbClient,
13 + client: (&SmbClient, &str),
14 access_token: String,
15 project: ProjectCreate,
16 ) -> Result<Project, ErrorResponse> {
17 let builder = Client::new()
18 - .post(build_project_url(env, &client))
18 + .post(build_project_url(env, client))
19 .json(&project)
20 .header("Authorization", access_token)
21 .header("User-agent", SMB_USER_AGENT);
crates/smbcloud-networking-project/src/crud_project_delete.rs
+2 -2
@@ -6,12 +6,12 @@ use smbcloud_networking::{constants::SMB_USER_AGENT, smb_client::SmbClient};
6
7 pub async fn delete_project(
8 env: Environment,
9 - client: SmbClient,
9 + client: (&SmbClient, &str),
10 access_token: String,
11 id: String,
12 ) -> Result<(), ErrorResponse> {
13 let builder = Client::new()
14 - .delete(build_project_url_with_id(env, &client, id))
14 + .delete(build_project_url_with_id(env, client, id))
15 .header("Authorization", access_token)
16 .header("User-agent", SMB_USER_AGENT);
17 request(builder).await
crates/smbcloud-networking-project/src/crud_project_deployment_create.rs
+2 -2
@@ -10,7 +10,7 @@ use smbcloud_networking::{constants::SMB_USER_AGENT, smb_client::SmbClient};
10
11 pub async fn create_deployment(
12 env: Environment,
13 - client: SmbClient,
13 + client: (&SmbClient, &str),
14 access_token: &str,
15 project_id: i32,
16 payload: DeploymentPayload,
@@ -18,7 +18,7 @@ pub async fn create_deployment(
18 let builder = Client::new()
19 .post(build_project_deployment_index(
20 env,
21 - &client,
21 + client,
22 project_id.to_string(),
23 ))
24 .json(&payload)
crates/smbcloud-networking-project/src/crud_project_deployment_read.rs
+4 -4
@@ -7,14 +7,14 @@ use smbcloud_networking::{constants::SMB_USER_AGENT, smb_client::SmbClient};
7
8 pub async fn get_deployments(
9 env: Environment,
10 - client: SmbClient,
10 + client: (&SmbClient, &str),
11 access_token: String,
12 project_id: i32,
13 ) -> Result<Vec<Deployment>, ErrorResponse> {
14 let builder = Client::new()
15 .get(build_project_deployment_index(
16 env,
17 - &client,
17 + client,
18 project_id.to_string(),
19 ))
20 .header("Authorization", access_token)
@@ -24,7 +24,7 @@ pub async fn get_deployments(
24
25 pub async fn get_deployment(
26 env: Environment,
27 - client: SmbClient,
27 + client: (&SmbClient, &str),
28 access_token: String,
29 project_id: i32,
30 deployment_id: i32,
@@ -32,7 +32,7 @@ pub async fn get_deployment(
32 let builder = Client::new()
33 .get(build_project_deployment(
34 env,
35 - &client,
35 + client,
36 project_id.to_string(),
37 deployment_id.to_string(),
38 ))
crates/smbcloud-networking-project/src/crud_project_deployment_update.rs
+2 -2
@@ -11,7 +11,7 @@ use crate::url_builder::build_project_deployment;
11
12 pub async fn update(
13 env: Environment,
14 - client: SmbClient,
14 + client: (&SmbClient, &str),
15 access_token: String,
16 project_id: i32,
17 deployment_id: i32,
@@ -19,7 +19,7 @@ pub async fn update(
19 ) -> Result<Deployment, ErrorResponse> {
20 let url = build_project_deployment(
21 env,
22 - &client,
22 + client,
23 project_id.to_string(),
24 deployment_id.to_string(),
25 );
crates/smbcloud-networking-project/src/crud_project_read.rs
+4 -4
@@ -8,12 +8,12 @@ use {
8
9 pub async fn get_project(
10 env: Environment,
11 - client: SmbClient,
11 + client: (&SmbClient, &str),
12 access_token: String,
13 id: String,
14 ) -> Result<Project, ErrorResponse> {
15 let builder: reqwest::RequestBuilder = Client::new()
16 - .get(build_project_url_with_id(env, &client, id))
16 + .get(build_project_url_with_id(env, client, id))
17 .header("Authorization", access_token)
18 .header("User-agent", SMB_USER_AGENT);
19 request(builder).await
@@ -21,11 +21,11 @@ pub async fn get_project(
21
22 pub async fn get_projects(
23 env: Environment,
24 - client: SmbClient,
24 + client: (&SmbClient, &str),
25 access_token: String,
26 ) -> Result<Vec<Project>, ErrorResponse> {
27 let builder = Client::new()
28 - .get(build_project_url(env, &client))
28 + .get(build_project_url(env, client))
29 .header("Authorization", access_token)
30 .header("User-agent", SMB_USER_AGENT);
31 request(builder).await
crates/smbcloud-networking-project/src/crud_project_update.rs
+2 -2
@@ -6,14 +6,14 @@ use smbcloud_networking::{constants::SMB_USER_AGENT, smb_client::SmbClient};
6
7 pub async fn update_project(
8 env: Environment,
9 - client: SmbClient,
9 + client: (&SmbClient, &str),
10 access_token: String,
11 project_id: String,
12 new_description: &str,
13 runner: Runner,
14 ) -> Result<Project, ErrorResponse> {
15 // PATCH is correct for partial update of description
16 - let url = build_project_url_with_id(env, &client, project_id.to_string());
16 + let url = build_project_url_with_id(env, client, project_id.to_string());
17 let builder = Client::new()
18 .patch(url)
19 .header("Authorization", access_token)
crates/smbcloud-networking-project/src/url_builder.rs
+4 -4
@@ -5,7 +5,7 @@ use {
5
6 // Private functions
7
8 -pub(crate) fn build_project_url(env: Environment, client: &SmbClient) -> String {
8 +pub(crate) fn build_project_url(env: Environment, client: (&SmbClient, &str)) -> String {
9 let mut url_builder = smb_base_url_builder(env, client);
10 url_builder.add_route("v1/projects");
11 url_builder.build()
@@ -13,7 +13,7 @@ pub(crate) fn build_project_url(env: Environment, client: &SmbClient) -> String
13
14 pub(crate) fn build_project_url_with_id(
15 env: Environment,
16 - client: &SmbClient,
16 + client: (&SmbClient, &str),
17 id: String,
18 ) -> String {
19 let mut url_builder = smb_base_url_builder(env, client);
@@ -24,7 +24,7 @@ pub(crate) fn build_project_url_with_id(
24
25 pub(crate) fn build_project_deployment_index(
26 env: Environment,
27 - client: &SmbClient,
27 + client: (&SmbClient, &str),
28 project_id: String,
29 ) -> String {
30 let mut url_builder = smb_base_url_builder(env, client);
@@ -36,7 +36,7 @@ pub(crate) fn build_project_deployment_index(
36
37 pub(crate) fn build_project_deployment(
38 env: Environment,
39 - client: &SmbClient,
39 + client: (&SmbClient, &str),
40 project_id: String,
41 id: String,
42 ) -> String {
crates/smbcloud-networking/.gitignore deleted
-1
@@ -1 +0,0 @@
1 -.env
crates/smbcloud-networking/Cargo.toml
-1
@@ -23,4 +23,3 @@ crate-type = ["cdylib", "rlib"]
23 [dependencies]
24 smbcloud-network = { workspace = true }
25 url-builder = { workspace = true }
26 -dotenv_codegen = "0.15"
crates/smbcloud-networking/src/lib.rs
+3 -6
@@ -6,15 +6,12 @@ use {
6 url_builder::URLBuilder,
7 };
8
9 -#[macro_use]
10 -extern crate dotenv_codegen;
11 -
12 -pub fn smb_base_url_builder(env: Environment, client: &SmbClient) -> URLBuilder {
9 +pub fn smb_base_url_builder(env: Environment, client: (&SmbClient, &str)) -> URLBuilder {
10 let mut url_builder = URLBuilder::new();
11 url_builder
12 .set_protocol(&env.api_protocol())
13 .set_host(&env.api_host())
17 - .add_param("client_id", client.id())
18 - .add_param("client_secret", client.secret());
14 + .add_param("client_id", client.0.id())
15 + .add_param("client_secret", client.1);
16 url_builder
17 }
crates/smbcloud-networking/src/smb_client.rs
+3 -10
@@ -7,16 +7,9 @@ pub enum SmbClient {
7 impl SmbClient {
8 pub fn id(&self) -> &str {
9 match self {
10 - SmbClient::Cli => dotenv!("CLI_CLIENT_ID"),
11 - SmbClient::Sigit => dotenv!("SIGIT_CLIENT_ID"),
12 - SmbClient::WebConsole => dotenv!("WEB_CONSOLE_CLIENT_ID"),
13 - }
14 - }
15 - pub fn secret(&self) -> &str {
16 - match self {
17 - SmbClient::Cli => dotenv!("CLI_CLIENT_SECRET"),
18 - SmbClient::Sigit => dotenv!("SIGIT_CLIENT_SECRET"),
19 - SmbClient::WebConsole => dotenv!("WEB_CONSOLE_CLIENT_SECRET"),
10 + SmbClient::Cli => "cli",
11 + SmbClient::Sigit => "sigit-app",
12 + SmbClient::WebConsole => "web",
13 }
14 }
15 }