diff --git a/dozer-cli/src/main.rs b/dozer-cli/src/main.rs index b287193e6b..a3ea2b85af 100644 --- a/dozer-cli/src/main.rs +++ b/dozer-cli/src/main.rs @@ -131,65 +131,12 @@ fn run() -> Result<(), OrchestrationError> { set_panic_hook(); - // Run Cloud - #[cfg(feature = "cloud")] - if let Commands::Cloud(cloud) = &cli.cmd { - render_logo(); - let cloud = cloud.clone(); - - let config = init_configuration(&cli, runtime.clone()).ok(); - 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, - } => cloud_client.login( - cloud, - organisation_slug, - profile_name, - client_id, - client_secret, - ), - 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 dozer_tracing::init_telemetry_closure( - None, - &Default::default(), - || -> Result<(), OrchestrationError> { - match res { - Ok(_) => Ok(()), - Err(e) => { - error!("{}", e); - Err(e) - } - } - }, - ); - } - - let config = init_configuration(&cli, runtime.clone())?; + let config_res = init_configuration(&cli, runtime.clone()); // Now we have access to telemetry configuration. Telemetry must be initialized in tokio runtime. - let app_id = config.cloud.app_id.as_deref().unwrap_or(&config.app_name); + let app_id = config_res + .as_ref() + .map(|c| c.cloud.app_id.as_deref().unwrap_or(&c.app_name)) + .ok(); // We always enable telemetry when running live. let telemetry_config = if matches!(cli.cmd, Commands::Live(_)) { @@ -198,10 +145,20 @@ fn run() -> Result<(), OrchestrationError> { metrics: Some(TelemetryMetricsConfig::Prometheus), } } else { - config.telemetry.clone() + config_res + .as_ref() + .map(|c| c.telemetry.clone()) + .unwrap_or(TelemetryConfig::default()) }; - let _telemetry = runtime.block_on(async { Telemetry::new(Some(app_id), &telemetry_config) }); + let _telemetry = runtime.block_on(async { Telemetry::new(app_id, &telemetry_config) }); + + // Run Cloud + #[cfg(feature = "cloud")] + if let Commands::Cloud(cloud) = &cli.cmd { + return run_cloud(cloud, runtime, &cli); + } + let config = config_res?; let mut dozer = init_dozer( runtime.clone(), @@ -273,6 +230,50 @@ fn run() -> Result<(), OrchestrationError> { }) } +fn run_cloud( + cloud: &dozer_cli::cli::cloud::Cloud, + runtime: Arc, + cli: &Cli, +) -> Result<(), OrchestrationError> { + render_logo(); + let cloud = cloud.clone(); + + let config = init_configuration(cli, runtime.clone()).ok(); + 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, + } => cloud_client.login( + cloud, + organisation_slug, + profile_name, + client_id, + client_secret, + ), + 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) + } + } +} + // Some commands dont need to initialize the orchestrator // This function is used to run those commands fn parse_and_generate() -> Result {