Skip to content

Commit 8e7fb59

Browse files
feat(cloud): add update single tag endpoint for Pro databases (#489)
Adds the ability to update a single tag value without replacing all tags: - Add UpdateTag CLI command to CloudDatabaseCommands - Add update_tag handler function in database_impl - Add CLI test for update-tag help Closes #471
1 parent 9d4067e commit 8e7fb59

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

crates/redisctl/src/cli/cloud.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,18 @@ pub enum CloudDatabaseCommands {
13291329
data: String,
13301330
},
13311331

1332+
/// Update a single tag value
1333+
UpdateTag {
1334+
/// Database ID (format: subscription_id:database_id)
1335+
id: String,
1336+
/// Tag key
1337+
#[arg(long)]
1338+
key: String,
1339+
/// Tag value
1340+
#[arg(long)]
1341+
value: String,
1342+
},
1343+
13321344
/// Delete a tag from database
13331345
DeleteTag {
13341346
/// Database ID (format: subscription_id:database_id)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ pub async fn handle_database_command(
205205
)
206206
.await
207207
}
208+
CloudDatabaseCommands::UpdateTag { id, key, value } => {
209+
super::database_impl::update_tag(
210+
conn_mgr,
211+
profile_name,
212+
id,
213+
key,
214+
value,
215+
output_format,
216+
query,
217+
)
218+
.await
219+
}
208220
CloudDatabaseCommands::DeleteTag { id, key } => {
209221
super::database_impl::delete_tag(conn_mgr, profile_name, id, key, output_format, query)
210222
.await

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,50 @@ pub async fn update_tags(
680680
Ok(())
681681
}
682682

683+
/// Update a single tag value
684+
pub async fn update_tag(
685+
conn_mgr: &ConnectionManager,
686+
profile_name: Option<&str>,
687+
id: &str,
688+
key: &str,
689+
value: &str,
690+
output_format: OutputFormat,
691+
query: Option<&str>,
692+
) -> CliResult<()> {
693+
let (subscription_id, database_id) = parse_database_id(id)?;
694+
let client = conn_mgr.create_cloud_client(profile_name).await?;
695+
696+
let request = json!({
697+
"value": value
698+
});
699+
700+
let response = client
701+
.put_raw(
702+
&format!(
703+
"/subscriptions/{}/databases/{}/tags/{}",
704+
subscription_id, database_id, key
705+
),
706+
request,
707+
)
708+
.await
709+
.context("Failed to update tag")?;
710+
711+
let result = if let Some(q) = query {
712+
apply_jmespath(&response, q)?
713+
} else {
714+
response
715+
};
716+
717+
match output_format {
718+
OutputFormat::Table => {
719+
println!("Tag '{}' updated successfully", key);
720+
}
721+
_ => print_json_or_yaml(result, output_format)?,
722+
}
723+
724+
Ok(())
725+
}
726+
683727
/// Delete a tag from database
684728
pub async fn delete_tag(
685729
conn_mgr: &ConnectionManager,

crates/redisctl/tests/cli_basic_tests.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,3 +2768,17 @@ fn test_enterprise_cluster_maintenance_mode_disable_help() {
27682768
.success()
27692769
.stdout(predicate::str::contains("maintenance"));
27702770
}
2771+
2772+
#[test]
2773+
fn test_cloud_database_update_tag_help() {
2774+
redisctl()
2775+
.arg("cloud")
2776+
.arg("database")
2777+
.arg("update-tag")
2778+
.arg("--help")
2779+
.assert()
2780+
.success()
2781+
.stdout(predicate::str::contains("Update a single tag value"))
2782+
.stdout(predicate::str::contains("--key"))
2783+
.stdout(predicate::str::contains("--value"));
2784+
}

0 commit comments

Comments
 (0)