Skip to content

Commit 38acc98

Browse files
fix: improve profile resolution for explicit cloud/enterprise commands (#353)
- Replace generic default_profile with type-specific defaults (default_enterprise, default_cloud) - Add resolve_enterprise_profile() and resolve_cloud_profile() helper methods - Update ConnectionManager to use type-specific resolution - Replace Default profile command with DefaultEnterprise and DefaultCloud - Resolution priority: explicit flag > type-specific default > first profile of matching type > error - Add comprehensive tests for profile resolution logic Fixes #350
1 parent 64a0073 commit 38acc98

File tree

7 files changed

+387
-176
lines changed

7 files changed

+387
-176
lines changed

crates/redisctl/src/cli.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,17 @@ pub enum ProfileCommands {
210210
name: String,
211211
},
212212

213-
/// Set the default profile
214-
#[command(visible_alias = "def")]
215-
Default {
216-
/// Profile name to set as default
213+
/// Set the default profile for enterprise commands
214+
#[command(name = "default-enterprise", visible_alias = "def-ent")]
215+
DefaultEnterprise {
216+
/// Profile name to set as default for enterprise commands
217+
name: String,
218+
},
219+
220+
/// Set the default profile for cloud commands
221+
#[command(name = "default-cloud", visible_alias = "def-cloud")]
222+
DefaultCloud {
223+
/// Profile name to set as default for cloud commands
217224
name: String,
218225
},
219226
}

crates/redisctl/src/commands/cloud/cloud_account.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::cli::{CloudProviderAccountCommands, OutputFormat};
44
use crate::commands::cloud::cloud_account_impl::{self, CloudAccountOperationParams};
5-
use crate::commands::cloud::utils::create_cloud_client_raw;
65
use crate::connection::ConnectionManager;
76
use crate::error::Result as CliResult;
87

@@ -13,8 +12,7 @@ pub async fn handle_cloud_account_command(
1312
output_format: OutputFormat,
1413
query: Option<&str>,
1514
) -> CliResult<()> {
16-
let profile = conn_mgr.get_profile(profile_name)?;
17-
let client = create_cloud_client_raw(profile).await?;
15+
let client = conn_mgr.create_cloud_client(profile_name).await?;
1816

1917
match command {
2018
CloudProviderAccountCommands::List => {

crates/redisctl/src/commands/cloud/connectivity/vpc_peering.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ pub async fn handle_vpc_peering_command(
2222
output_format: OutputFormat,
2323
query: Option<&str>,
2424
) -> CliResult<()> {
25-
let profile = conn_mgr.get_profile(profile_name)?;
26-
let client = crate::commands::cloud::utils::create_cloud_client_raw(profile).await?;
25+
let client = conn_mgr.create_cloud_client(profile_name).await?;
2726

2827
match command {
2928
VpcPeeringCommands::Get { subscription } => {

crates/redisctl/src/commands/cloud/utils.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use anyhow::Context;
44
use chrono::{DateTime, Utc};
55
use colored::Colorize;
6-
use redis_cloud::CloudClient;
76
use serde_json::Value;
87
use std::fs;
98
use std::io::{self, Write};
@@ -13,7 +12,7 @@ use tabled::Tabled;
1312
use std::io::IsTerminal;
1413

1514
use crate::cli::OutputFormat;
16-
use crate::config::Profile;
15+
1716
use crate::error::{RedisCtlError, Result as CliResult};
1817
use crate::output::print_output;
1918

@@ -253,30 +252,6 @@ pub fn confirm_action(message: &str) -> CliResult<bool> {
253252
Ok(input.trim().eq_ignore_ascii_case("y") || input.trim().eq_ignore_ascii_case("yes"))
254253
}
255254

256-
/// Create a raw cloud client from profile
257-
pub async fn create_cloud_client_raw(profile: &Profile) -> CliResult<CloudClient> {
258-
match &profile.credentials {
259-
crate::config::ProfileCredentials::Cloud {
260-
api_key,
261-
api_secret,
262-
api_url,
263-
} => {
264-
let client = redis_cloud::client::CloudClientBuilder::new()
265-
.api_key(api_key.clone())
266-
.api_secret(api_secret.clone())
267-
.base_url(api_url.clone())
268-
.build()
269-
.map_err(|e| {
270-
RedisCtlError::Configuration(format!("Failed to create cloud client: {}", e))
271-
})?;
272-
Ok(client)
273-
}
274-
_ => Err(RedisCtlError::Configuration(
275-
"Profile is not configured for Cloud deployment".to_string(),
276-
)),
277-
}
278-
}
279-
280255
/// Read file input, supporting @filename notation
281256
pub fn read_file_input(input: &str) -> CliResult<String> {
282257
if let Some(filename) = input.strip_prefix('@') {

0 commit comments

Comments
 (0)