Skip to content

Commit 70330d2

Browse files
feat(enterprise): add DNS suffix management commands (#161) (#295)
- Implement suffix list command to list all DNS suffixes - Add suffix get command to get specific suffix details - Support JMESPath query filtering for output - Add comprehensive mdBook documentation - Include unit tests for command parsing
1 parent 6df5824 commit 70330d2

File tree

6 files changed

+371
-0
lines changed

6 files changed

+371
-0
lines changed

crates/redisctl/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,10 @@ pub enum EnterpriseCommands {
10511051
#[command(subcommand)]
10521052
Stats(EnterpriseStatsCommands),
10531053

1054+
/// DNS suffix management
1055+
#[command(subcommand)]
1056+
Suffix(crate::commands::enterprise::suffix::SuffixCommands),
1057+
10541058
/// Usage report operations
10551059
#[command(subcommand, name = "usage-report")]
10561060
UsageReport(crate::commands::enterprise::usage_report::UsageReportCommands),

crates/redisctl/src/commands/enterprise/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ pub mod rbac;
2626
pub mod rbac_impl;
2727
pub mod shard;
2828
pub mod stats;
29+
pub mod suffix;
2930
pub mod usage_report;
3031
pub mod utils;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
use anyhow::Context;
2+
use clap::Subcommand;
3+
4+
use crate::{cli::OutputFormat, connection::ConnectionManager, error::Result as CliResult};
5+
6+
#[allow(dead_code)]
7+
pub async fn handle_suffix_command(
8+
conn_mgr: &ConnectionManager,
9+
profile_name: Option<&str>,
10+
suffix_cmd: SuffixCommands,
11+
output_format: OutputFormat,
12+
query: Option<&str>,
13+
) -> CliResult<()> {
14+
suffix_cmd
15+
.execute(conn_mgr, profile_name, output_format, query)
16+
.await
17+
}
18+
19+
#[derive(Debug, Clone, Subcommand)]
20+
pub enum SuffixCommands {
21+
/// List all DNS suffixes
22+
List,
23+
24+
/// Get a specific DNS suffix by name
25+
Get {
26+
/// DNS suffix name
27+
name: String,
28+
},
29+
}
30+
31+
impl SuffixCommands {
32+
#[allow(dead_code)]
33+
pub async fn execute(
34+
&self,
35+
conn_mgr: &ConnectionManager,
36+
profile_name: Option<&str>,
37+
output_format: OutputFormat,
38+
query: Option<&str>,
39+
) -> CliResult<()> {
40+
handle_suffix_command_impl(conn_mgr, profile_name, self, output_format, query).await
41+
}
42+
}
43+
44+
#[allow(dead_code)]
45+
async fn handle_suffix_command_impl(
46+
conn_mgr: &ConnectionManager,
47+
profile_name: Option<&str>,
48+
command: &SuffixCommands,
49+
output_format: OutputFormat,
50+
query: Option<&str>,
51+
) -> CliResult<()> {
52+
let client = conn_mgr.create_enterprise_client(profile_name).await?;
53+
54+
match command {
55+
SuffixCommands::List => {
56+
let response: serde_json::Value = client
57+
.get("/v1/suffixes")
58+
.await
59+
.context("Failed to list DNS suffixes")?;
60+
61+
let output_data = if let Some(q) = query {
62+
super::utils::apply_jmespath(&response, q)?
63+
} else {
64+
response
65+
};
66+
67+
super::utils::print_formatted_output(output_data, output_format)?;
68+
}
69+
SuffixCommands::Get { name } => {
70+
let response: serde_json::Value = client
71+
.get(&format!("/v1/suffix/{}", name))
72+
.await
73+
.context(format!("Failed to get DNS suffix '{}'", name))?;
74+
75+
let output_data = if let Some(q) = query {
76+
super::utils::apply_jmespath(&response, q)?
77+
} else {
78+
response
79+
};
80+
81+
super::utils::print_formatted_output(output_data, output_format)?;
82+
}
83+
}
84+
85+
Ok(())
86+
}
87+
88+
#[cfg(test)]
89+
mod tests {
90+
use super::*;
91+
92+
#[test]
93+
fn test_suffix_command_parsing() {
94+
use clap::Parser;
95+
96+
#[derive(Parser)]
97+
struct TestCli {
98+
#[command(subcommand)]
99+
cmd: SuffixCommands,
100+
}
101+
102+
// Test list command
103+
let cli = TestCli::parse_from(["test", "list"]);
104+
assert!(matches!(cli.cmd, SuffixCommands::List));
105+
106+
// Test get command
107+
let cli = TestCli::parse_from(["test", "get", "example.redis.local"]);
108+
if let SuffixCommands::Get { name } = cli.cmd {
109+
assert_eq!(name, "example.redis.local");
110+
} else {
111+
panic!("Expected Get command");
112+
}
113+
}
114+
}

crates/redisctl/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ async fn execute_enterprise_command(
375375
)
376376
.await
377377
}
378+
Suffix(suffix_cmd) => {
379+
commands::enterprise::suffix::handle_suffix_command(
380+
conn_mgr,
381+
profile,
382+
suffix_cmd.clone(),
383+
output,
384+
query,
385+
)
386+
.await
387+
}
378388
UsageReport(usage_report_cmd) => {
379389
commands::enterprise::usage_report::handle_usage_report_command(
380390
conn_mgr,

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
- [Endpoints](./enterprise/endpoints.md)
4848
- [Job Scheduler](./enterprise/job-scheduler.md)
4949
- [JSON Schema](./enterprise/jsonschema.md)
50+
- [DNS Suffixes](./enterprise/suffix.md)
5051
- [Workflows](./enterprise/workflows.md)
5152
- [Raw API Access](./enterprise/api-access.md)
5253

0 commit comments

Comments
 (0)