Skip to content

Commit 2b8c0b2

Browse files
committed
feat(cloud): complete --wait flag implementation for connectivity commands
- Updated all PSC handler functions to use handle_async_response - Updated all VPC Peering handlers (already done in previous commit) - Updated TGW handler function signatures to accept ConnectionManager - Replaced manual task ID handling with handle_async_response utility - All connectivity commands now support --wait, --wait-timeout, and --wait-interval flags Completes implementation for: - VPC Peering: 6 commands (create, update, delete + Active-Active variants) - PSC: 9 commands (service and endpoint operations + Active-Active variants) - TGW: 7 commands (attachment operations + Active-Active variants) Part of #196 Closes #196
1 parent ab5a636 commit 2b8c0b2

File tree

2 files changed

+117
-73
lines changed

2 files changed

+117
-73
lines changed

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

Lines changed: 92 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,23 @@ async fn delete_service(
284284
}
285285

286286
let handler = PscHandler::new(client.clone());
287-
handler
287+
let response = handler
288288
.delete_service(subscription_id)
289289
.await
290290
.context("Failed to delete PSC service")?;
291291

292-
eprintln!("PSC service deleted successfully");
293-
Ok(())
292+
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
293+
294+
handle_async_response(
295+
conn_mgr,
296+
profile_name,
297+
json_response,
298+
async_ops,
299+
output_format,
300+
query,
301+
"PSC service deleted successfully",
302+
)
303+
.await
294304
}
295305

296306
// ============================================================================
@@ -338,19 +348,18 @@ async fn create_endpoint(
338348
.await
339349
.context("Failed to create PSC endpoint")?;
340350

341-
// Convert response to JSON and check for task ID
342351
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
343-
if let Some(task_id) = json_response.get("taskId").and_then(|v| v.as_str()) {
344-
eprintln!("PSC endpoint creation initiated. Task ID: {}", task_id);
345-
eprintln!(
346-
"Use 'redisctl cloud task wait {}' to monitor progress",
347-
task_id
348-
);
349-
}
350352

351-
let data = handle_output(json_response, output_format, query)?;
352-
print_formatted_output(data, output_format)?;
353-
Ok(())
353+
handle_async_response(
354+
conn_mgr,
355+
profile_name,
356+
json_response,
357+
async_ops,
358+
output_format,
359+
query,
360+
"PSC endpoint created successfully",
361+
)
362+
.await
354363
}
355364

356365
async fn update_endpoint(
@@ -378,19 +387,18 @@ async fn update_endpoint(
378387
.await
379388
.context("Failed to update PSC endpoint")?;
380389

381-
// Convert response to JSON and check for task ID
382390
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
383-
if let Some(task_id) = json_response.get("taskId").and_then(|v| v.as_str()) {
384-
eprintln!("PSC endpoint update initiated. Task ID: {}", task_id);
385-
eprintln!(
386-
"Use 'redisctl cloud task wait {}' to monitor progress",
387-
task_id
388-
);
389-
}
390391

391-
let data = handle_output(json_response, output_format, query)?;
392-
print_formatted_output(data, output_format)?;
393-
Ok(())
392+
handle_async_response(
393+
conn_mgr,
394+
profile_name,
395+
json_response,
396+
async_ops,
397+
output_format,
398+
query,
399+
"PSC endpoint updated successfully",
400+
)
401+
.await
394402
}
395403

396404
async fn delete_endpoint(
@@ -416,13 +424,23 @@ async fn delete_endpoint(
416424
}
417425

418426
let handler = PscHandler::new(client.clone());
419-
handler
427+
let response = handler
420428
.delete_endpoint(subscription_id, endpoint_id)
421429
.await
422430
.context("Failed to delete PSC endpoint")?;
423431

424-
eprintln!("PSC endpoint deleted successfully");
425-
Ok(())
432+
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
433+
434+
handle_async_response(
435+
conn_mgr,
436+
profile_name,
437+
json_response,
438+
async_ops,
439+
output_format,
440+
query,
441+
"PSC endpoint deleted successfully",
442+
)
443+
.await
426444
}
427445

428446
async fn get_endpoint_creation_script(
@@ -494,22 +512,18 @@ async fn create_service_aa(
494512
.await
495513
.context("Failed to create Active-Active PSC service")?;
496514

497-
// Convert response to JSON and check for task ID
498515
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
499-
if let Some(task_id) = json_response.get("taskId").and_then(|v| v.as_str()) {
500-
eprintln!(
501-
"Active-Active PSC service creation initiated. Task ID: {}",
502-
task_id
503-
);
504-
eprintln!(
505-
"Use 'redisctl cloud task wait {}' to monitor progress",
506-
task_id
507-
);
508-
}
509516

510-
let data = handle_output(json_response, output_format, query)?;
511-
print_formatted_output(data, output_format)?;
512-
Ok(())
517+
handle_async_response(
518+
conn_mgr,
519+
profile_name,
520+
json_response,
521+
async_ops,
522+
output_format,
523+
query,
524+
"Active-Active PSC service created successfully",
525+
)
526+
.await
513527
}
514528

515529
async fn delete_service_aa(
@@ -534,13 +548,23 @@ async fn delete_service_aa(
534548
}
535549

536550
let handler = PscHandler::new(client.clone());
537-
handler
551+
let response = handler
538552
.delete_service_active_active(subscription_id)
539553
.await
540554
.context("Failed to delete Active-Active PSC service")?;
541555

542-
eprintln!("Active-Active PSC service deleted successfully");
543-
Ok(())
556+
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
557+
558+
handle_async_response(
559+
conn_mgr,
560+
profile_name,
561+
json_response,
562+
async_ops,
563+
output_format,
564+
query,
565+
"Active-Active PSC service deleted successfully",
566+
)
567+
.await
544568
}
545569

546570
// ============================================================================
@@ -588,22 +612,18 @@ async fn create_endpoint_aa(
588612
.await
589613
.context("Failed to create Active-Active PSC endpoint")?;
590614

591-
// Convert response to JSON and check for task ID
592615
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
593-
if let Some(task_id) = json_response.get("taskId").and_then(|v| v.as_str()) {
594-
eprintln!(
595-
"Active-Active PSC endpoint creation initiated. Task ID: {}",
596-
task_id
597-
);
598-
eprintln!(
599-
"Use 'redisctl cloud task wait {}' to monitor progress",
600-
task_id
601-
);
602-
}
603616

604-
let data = handle_output(json_response, output_format, query)?;
605-
print_formatted_output(data, output_format)?;
606-
Ok(())
617+
handle_async_response(
618+
conn_mgr,
619+
profile_name,
620+
json_response,
621+
async_ops,
622+
output_format,
623+
query,
624+
"Active-Active PSC endpoint created successfully",
625+
)
626+
.await
607627
}
608628

609629
async fn delete_endpoint_aa(
@@ -630,11 +650,21 @@ async fn delete_endpoint_aa(
630650
}
631651

632652
let handler = PscHandler::new(client.clone());
633-
handler
653+
let response = handler
634654
.delete_endpoint_active_active(subscription_id, region_id, endpoint_id)
635655
.await
636656
.context("Failed to delete Active-Active PSC endpoint")?;
637657

638-
eprintln!("Active-Active PSC endpoint deleted successfully");
639-
Ok(())
658+
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
659+
660+
handle_async_response(
661+
conn_mgr,
662+
profile_name,
663+
json_response,
664+
async_ops,
665+
output_format,
666+
query,
667+
"Active-Active PSC endpoint deleted successfully",
668+
)
669+
.await
640670
}

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub async fn handle_tgw_command(
3737
async_ops,
3838
} => {
3939
create_attachment(
40+
conn_mgr,
41+
profile_name,
4042
&client,
4143
*subscription_id,
4244
file,
@@ -243,9 +245,12 @@ async fn list_attachments(
243245
}
244246

245247
async fn create_attachment(
248+
conn_mgr: &ConnectionManager,
249+
profile_name: Option<&str>,
246250
client: &CloudClient,
247251
subscription_id: i32,
248252
file: &str,
253+
async_ops: &AsyncOperationArgs,
249254
output_format: OutputFormat,
250255
query: Option<&str>,
251256
) -> CliResult<()> {
@@ -259,25 +264,25 @@ async fn create_attachment(
259264
.await
260265
.context("Failed to create TGW attachment")?;
261266

262-
// Convert response to JSON and check for task ID
263267
let json_response = serde_json::to_value(&response).context("Failed to serialize response")?;
264-
if let Some(task_id) = json_response.get("taskId").and_then(|v| v.as_str()) {
265-
eprintln!("TGW attachment creation initiated. Task ID: {}", task_id);
266-
eprintln!(
267-
"Use 'redisctl cloud task wait {}' to monitor progress",
268-
task_id
269-
);
270-
}
271268

272-
let data = handle_output(json_response, output_format, query)?;
273-
print_formatted_output(data, output_format)?;
274-
Ok(())
269+
handle_async_response(
270+
conn_mgr,
271+
profile_name,
272+
json_response,
273+
async_ops,
274+
output_format,
275+
query,
276+
"TGW attachment created successfully",
277+
)
278+
.await
275279
}
276280

277281
async fn create_attachment_with_id(
278282
client: &CloudClient,
279283
subscription_id: i32,
280284
tgw_id: &str,
285+
async_ops: &AsyncOperationArgs,
281286
output_format: OutputFormat,
282287
query: Option<&str>,
283288
) -> CliResult<()> {
@@ -307,6 +312,7 @@ async fn update_attachment_cidrs(
307312
subscription_id: i32,
308313
attachment_id: &str,
309314
file: &str,
315+
async_ops: &AsyncOperationArgs,
310316
output_format: OutputFormat,
311317
query: Option<&str>,
312318
) -> CliResult<()> {
@@ -340,6 +346,9 @@ async fn delete_attachment(
340346
subscription_id: i32,
341347
attachment_id: &str,
342348
yes: bool,
349+
async_ops: &AsyncOperationArgs,
350+
output_format: OutputFormat,
351+
query: Option<&str>,
343352
) -> CliResult<()> {
344353
if !yes {
345354
let prompt = format!(
@@ -454,6 +463,7 @@ async fn create_attachment_aa(
454463
subscription_id: i32,
455464
region_id: i32,
456465
file: &str,
466+
async_ops: &AsyncOperationArgs,
457467
output_format: OutputFormat,
458468
query: Option<&str>,
459469
) -> CliResult<()> {
@@ -491,6 +501,7 @@ async fn update_attachment_cidrs_aa(
491501
region_id: i32,
492502
attachment_id: &str,
493503
file: &str,
504+
async_ops: &AsyncOperationArgs,
494505
output_format: OutputFormat,
495506
query: Option<&str>,
496507
) -> CliResult<()> {
@@ -533,6 +544,9 @@ async fn delete_attachment_aa(
533544
region_id: i32,
534545
attachment_id: &str,
535546
yes: bool,
547+
async_ops: &AsyncOperationArgs,
548+
output_format: OutputFormat,
549+
query: Option<&str>,
536550
) -> CliResult<()> {
537551
if !yes {
538552
let prompt = format!(

0 commit comments

Comments
 (0)