From 47c94f2c6c812f5c02aa1c8550d3eb6c5f5482dc Mon Sep 17 00:00:00 2001 From: VG Date: Wed, 4 Oct 2023 17:59:16 +0800 Subject: [PATCH] chore: fix login --- dozer-cli/src/cloud/client.rs | 4 ++- dozer-cli/src/cloud/login.rs | 5 +++ dozer-cli/src/errors.rs | 2 ++ dozer-cli/src/main.rs | 66 +++++++++++++++++++---------------- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/dozer-cli/src/cloud/client.rs b/dozer-cli/src/cloud/client.rs index cd4d32a476..6052b0e91c 100644 --- a/dozer-cli/src/cloud/client.rs +++ b/dozer-cli/src/cloud/client.rs @@ -362,7 +362,9 @@ impl DozerGrpcCloudClient for CloudClient { client_id: Option, client_secret: Option, ) -> Result<(), OrchestrationError> { - info!("Organisation and client details can be created in https://dashboard.dev.getdozer.io/login \n"); + info!( + "Organisation and client details can be created in https://cloud.getdozer.io/login \n" + ); let organisation_slug = match organisation_slug { None => { let mut organisation_slug = String::new(); diff --git a/dozer-cli/src/cloud/login.rs b/dozer-cli/src/cloud/login.rs index 8ae342d1be..646f9fe0d4 100644 --- a/dozer-cli/src/cloud/login.rs +++ b/dozer-cli/src/cloud/login.rs @@ -106,6 +106,11 @@ impl CredentialInfo { .json() .await .map_err(CloudCredentialError::HttpRequestError)?; + if json_response.get("error").is_some() { + return Err(CloudCredentialError::LoginError( + json_response.get("error").unwrap().to_string(), + )); + } serde_json::from_value::(json_response) .map_err(CloudCredentialError::JsonSerializationError) } diff --git a/dozer-cli/src/errors.rs b/dozer-cli/src/errors.rs index c4d7eef40a..ff97423846 100644 --- a/dozer-cli/src/errors.rs +++ b/dozer-cli/src/errors.rs @@ -269,6 +269,8 @@ pub enum CloudCredentialError { MissingCredentialFile, #[error("There's no profile with given name - Please try to login again")] MissingProfile, + #[error("{0}")] + LoginError(String), } #[derive(Debug, Error)] diff --git a/dozer-cli/src/main.rs b/dozer-cli/src/main.rs index 3946ab9e3f..f28b8a0298 100644 --- a/dozer-cli/src/main.rs +++ b/dozer-cli/src/main.rs @@ -136,54 +136,58 @@ fn run() -> Result<(), OrchestrationError> { if let Commands::Cloud(cloud) = &cli.cmd { render_logo(); let cloud = cloud.clone(); - if let CloudCommands::Login { + let res = if let CloudCommands::Login { organisation_slug, profile_name, client_id, client_secret, } = cloud.command.clone() { - return CloudClient::login( + CloudClient::login( runtime.clone(), cloud, organisation_slug, profile_name, client_id, client_secret, - ); - } - let config = init_configuration(&cli, runtime.clone())?; - let mut cloud_client = CloudClient::new(config.clone(), runtime.clone()); - let res = match cloud.command.clone() { - CloudCommands::Deploy(deploy) => { - cloud_client.deploy(cloud, deploy, cli.config_paths.clone()) - } - CloudCommands::Login { - organisation_slug: _, - profile_name: _, - client_id: _, - client_secret: _, - } => unreachable!("This is handled earlier"), - CloudCommands::Secrets(command) => cloud_client.execute_secrets_command(cloud, command), - CloudCommands::Delete => cloud_client.delete(cloud), - CloudCommands::Status => cloud_client.status(cloud), - CloudCommands::Monitor => cloud_client.monitor(cloud), - CloudCommands::Logs(logs) => cloud_client.trace_logs(cloud, logs), - CloudCommands::Version(version) => cloud_client.version(cloud, version), - CloudCommands::List(list) => cloud_client.list(cloud, list), - CloudCommands::SetApp { app_id } => { - CloudAppContext::save_app_id(app_id.clone())?; - info!("Using \"{app_id}\" app"); - Ok(()) - } - CloudCommands::ApiRequestSamples { endpoint } => { - cloud_client.print_api_request_samples(cloud, endpoint) + ) + } else { + let config = init_configuration(&cli, runtime.clone())?; + let mut cloud_client = CloudClient::new(config.clone(), runtime.clone()); + match cloud.command.clone() { + CloudCommands::Deploy(deploy) => { + cloud_client.deploy(cloud, deploy, cli.config_paths.clone()) + } + CloudCommands::Login { + organisation_slug: _, + profile_name: _, + client_id: _, + client_secret: _, + } => unreachable!("This is handled earlier"), + CloudCommands::Secrets(command) => { + cloud_client.execute_secrets_command(cloud, command) + } + CloudCommands::Delete => cloud_client.delete(cloud), + CloudCommands::Status => cloud_client.status(cloud), + CloudCommands::Monitor => cloud_client.monitor(cloud), + CloudCommands::Logs(logs) => cloud_client.trace_logs(cloud, logs), + CloudCommands::Version(version) => cloud_client.version(cloud, version), + CloudCommands::List(list) => cloud_client.list(cloud, list), + CloudCommands::SetApp { app_id } => { + CloudAppContext::save_app_id(app_id.clone())?; + info!("Using \"{app_id}\" app"); + Ok(()) + } + CloudCommands::ApiRequestSamples { endpoint } => { + cloud_client.print_api_request_samples(cloud, endpoint) + } } }; + return match res { Ok(_) => Ok(()), Err(e) => { - display_error(&e); + println!("{}", e); Err(e) } };