Skip to content

Commit 172a6ba

Browse files
feat(cloud): add delete endpoint for PrivateLink (#487)
Adds the ability to delete PrivateLink configuration for a subscription: - Add delete method to PrivateLinkHandler in redis-cloud library - Add Delete command to PrivateLinkCommands CLI enum - Implement handle_delete with confirmation prompt (--force to skip) - Support async operation handling for delete operations - Add CLI test for privatelink delete help Closes #469
1 parent a48d9c8 commit 172a6ba

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

crates/redis-cloud/src/connectivity/private_link.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ impl PrivateLinkHandler {
171171
.await
172172
}
173173

174+
/// Delete PrivateLink
175+
///
176+
/// Deletes the AWS PrivateLink configuration for a subscription.
177+
///
178+
/// DELETE /subscriptions/{subscriptionId}/private-link
179+
///
180+
/// # Arguments
181+
///
182+
/// * `subscription_id` - The subscription ID
183+
///
184+
/// # Returns
185+
///
186+
/// Returns task information for tracking the deletion
187+
pub async fn delete(&self, subscription_id: i32) -> Result<Value> {
188+
self.client
189+
.delete_raw(&format!("/subscriptions/{}/private-link", subscription_id))
190+
.await
191+
}
192+
174193
/// Get Active-Active PrivateLink configuration
175194
///
176195
/// Gets the AWS PrivateLink configuration for an Active-Active (CRDB) subscription region.

crates/redisctl/src/cli/cloud.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,18 @@ pub enum PrivateLinkCommands {
480480
#[arg(long)]
481481
region: Option<i32>,
482482
},
483+
/// Delete PrivateLink configuration
484+
Delete {
485+
/// Subscription ID
486+
#[arg(long)]
487+
subscription: i32,
488+
/// Skip confirmation prompt
489+
#[arg(long)]
490+
force: bool,
491+
/// Async operation options
492+
#[command(flatten)]
493+
async_ops: crate::commands::cloud::async_utils::AsyncOperationArgs,
494+
},
483495
}
484496

485497
/// Cloud Task Commands

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ pub async fn handle_private_link_command(
6464
subscription,
6565
region,
6666
} => handle_get_script(&handler, *subscription, *region, output_format, query).await,
67+
PrivateLinkCommands::Delete {
68+
subscription,
69+
force,
70+
async_ops,
71+
} => {
72+
let params = ConnectivityOperationParams {
73+
conn_mgr,
74+
profile_name,
75+
client: &client,
76+
subscription_id: *subscription,
77+
async_ops,
78+
output_format,
79+
query,
80+
};
81+
handle_delete(&handler, &params, *force).await
82+
}
6783
}
6884
}
6985

@@ -208,3 +224,44 @@ async fn handle_get_script(
208224
print_formatted_output(data, output_format)?;
209225
Ok(())
210226
}
227+
228+
/// Delete PrivateLink configuration
229+
async fn handle_delete(
230+
handler: &PrivateLinkHandler,
231+
params: &ConnectivityOperationParams<'_>,
232+
force: bool,
233+
) -> CliResult<()> {
234+
// Confirmation prompt unless --force is used
235+
if !force {
236+
use dialoguer::Confirm;
237+
let confirm = Confirm::new()
238+
.with_prompt(format!(
239+
"Are you sure you want to delete PrivateLink for subscription {}?",
240+
params.subscription_id
241+
))
242+
.default(false)
243+
.interact()
244+
.map_err(|e| anyhow::anyhow!("Failed to read confirmation: {}", e))?;
245+
246+
if !confirm {
247+
println!("Delete operation cancelled");
248+
return Ok(());
249+
}
250+
}
251+
252+
let result = handler
253+
.delete(params.subscription_id)
254+
.await
255+
.context("Failed to delete PrivateLink")?;
256+
257+
handle_async_response(
258+
params.conn_mgr,
259+
params.profile_name,
260+
result,
261+
params.async_ops,
262+
params.output_format,
263+
params.query,
264+
"Delete PrivateLink",
265+
)
266+
.await
267+
}

crates/redisctl/tests/cli_basic_tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,3 +2808,18 @@ fn test_cloud_fixed_database_upgrade_redis_help() {
28082808
.stdout(predicate::str::contains("Upgrade Redis version"))
28092809
.stdout(predicate::str::contains("--version"));
28102810
}
2811+
2812+
#[test]
2813+
fn test_cloud_connectivity_privatelink_delete_help() {
2814+
redisctl()
2815+
.arg("cloud")
2816+
.arg("connectivity")
2817+
.arg("privatelink")
2818+
.arg("delete")
2819+
.arg("--help")
2820+
.assert()
2821+
.success()
2822+
.stdout(predicate::str::contains("Delete PrivateLink"))
2823+
.stdout(predicate::str::contains("--subscription"))
2824+
.stdout(predicate::str::contains("--force"));
2825+
}

0 commit comments

Comments
 (0)