Skip to content

Commit

Permalink
chore: fix login
Browse files Browse the repository at this point in the history
  • Loading branch information
v3g42 committed Oct 4, 2023
1 parent 7ba64f5 commit 47c94f2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
4 changes: 3 additions & 1 deletion dozer-cli/src/cloud/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ impl DozerGrpcCloudClient for CloudClient {
client_id: Option<String>,
client_secret: Option<String>,
) -> 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();
Expand Down
5 changes: 5 additions & 0 deletions dozer-cli/src/cloud/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TokenResponse>(json_response)
.map_err(CloudCredentialError::JsonSerializationError)
}
Expand Down
2 changes: 2 additions & 0 deletions dozer-cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
66 changes: 35 additions & 31 deletions dozer-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};
Expand Down

0 comments on commit 47c94f2

Please sign in to comment.