Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fancy-regex = "0.14"
flate2 = { version = "1.1.9", default-features = false, features = ["rust_backend"] }
futures-util = { version = "0.3", default-features = false, features = ["std", "sink"] }
globset = "0.4"
idna = "1"
open = "5.4.1"
oxc_allocator = "0.143"
oxc_ast = "0.143"
Expand Down
13 changes: 4 additions & 9 deletions rust/src/dns/add.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `dns add` — append new DNS records to a domain without touching existing ones.

use cli_engine::{Alignment, CommandResult, CommandSpec, RuntimeCommandSpec, TableColumn, Tier};
use cli_engine::{Alignment, CommandSpec, RuntimeCommandSpec, TableColumn, Tier};
use serde_json::{Value, json};

use crate::domain::make_client;
Expand All @@ -10,7 +10,7 @@ use crate::scopes::DOMAINS_DNS_UPDATE;
use super::conflicts::{WriteErrorContext, describe_write_error};
use super::records::{
RecordOptions, RecordWriteArgs, v3_records, validate_caa_fields, validate_svcb_fields,
validate_tlsa_fields, verify_with_list_action,
validate_tlsa_fields, verified_result,
};

// `dns add` creates one v3 record per `--data` value; it reports each outcome
Expand Down Expand Up @@ -124,6 +124,7 @@ pub(super) fn command() -> RuntimeCommandSpec {
let domain = args.domain;
let record_type = args.record_type;
let name = args.name;
let domain_format = args.domain_format.form();
validate_caa_fields(&record_type, &opts)
.map_err(crate::error::GddyError::validation)?;
validate_tlsa_fields(&record_type, &opts)
Expand Down Expand Up @@ -171,13 +172,7 @@ pub(super) fn command() -> RuntimeCommandSpec {
// All-created → success payload; any failure → non-zero error
// with a per-record breakdown.
summarize_add_outcomes(&domain, &record_type, &name, outcomes)
.map(|v| {
CommandResult::new(v).with_next_actions(vec![verify_with_list_action(
&domain,
&record_type,
&name,
)])
})
.map(|v| verified_result(domain_format, v, &domain, &record_type, &name))
.map_err(super::mutate_failed)
},
)
Expand Down
31 changes: 14 additions & 17 deletions rust/src/dns/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use cli_engine::{Alignment, CommandResult, CommandSpec, RuntimeCommandSpec, Tabl
use serde_json::{Value, json};

use crate::domain::{api_error, make_client};
use crate::idn::DomainFormArgs;
use crate::output_schema::output_schema;
use crate::scopes::DOMAINS_DNS_UPDATE;

use domains_client::types;

use super::records::{fetch_records, parse_write_type_arg, record_value, verify_with_list_action};
use super::records::{
ZONE_AND_NAME, fetch_records, parse_write_type_arg, record_value, verified_result,
};

output_schema!(DnsDeleteResult {
"domain": "string";
Expand Down Expand Up @@ -114,16 +117,19 @@ fn dry_run_delete_preview(
#[derive(Debug, Clone, clap::Args)]
struct DeleteArgs {
/// Domain whose records to delete (e.g. example.com).
#[arg(value_name = "DOMAIN")]
#[arg(value_name = "DOMAIN", value_parser = crate::idn::parse_name_arg)]
domain: String,

/// Record type (A, AAAA, ALIAS, CAA, CNAME, HTTPS, MX, SRV, SVCB, TLSA, TXT).
#[arg(long = "type", value_name = "TYPE", value_parser = parse_write_type_arg)]
record_type: String,

/// Record name relative to the domain (e.g. www).
#[arg(long, value_name = "NAME")]
#[arg(long, value_name = "NAME", value_parser = crate::idn::parse_name_arg)]
name: String,

#[command(flatten)]
domain_format: DomainFormArgs,
}

/// `records` only appears on the `--dry-run` preview (the real delete's
Expand Down Expand Up @@ -170,6 +176,7 @@ pub(super) fn command() -> RuntimeCommandSpec {
let domain = args.domain;
let record_type = args.record_type;
let name = args.name;
let domain_format = args.domain_format.form();

let debug = !ctx.middleware.debug.is_empty();
let client = make_client(&ctx).await?;
Expand All @@ -185,13 +192,9 @@ pub(super) fn command() -> RuntimeCommandSpec {
.await?;

if ctx.dry_run() {
return Ok(CommandResult::new(dry_run_delete_preview(
&domain,
&record_type,
&name,
&existing,
))
.with_dry_run());
let mut preview = dry_run_delete_preview(&domain, &record_type, &name, &existing);
domain_format.convert_fields(&mut preview, ZONE_AND_NAME);
return Ok(CommandResult::new(preview).with_dry_run());
}

let mut outcomes = Vec::with_capacity(existing.len());
Expand Down Expand Up @@ -221,13 +224,7 @@ pub(super) fn command() -> RuntimeCommandSpec {
}

summarize_delete_outcomes(&domain, &record_type, &name, &outcomes)
.map(|v| {
CommandResult::new(v).with_next_actions(vec![verify_with_list_action(
&domain,
&record_type,
&name,
)])
})
.map(|v| verified_result(domain_format, v, &domain, &record_type, &name))
.map_err(super::mutate_failed)
},
)
Expand Down
4 changes: 4 additions & 0 deletions rust/src/dns/guides/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ gddy dns delete example.com --type A --name www

Deleting something that doesn't match is a no-op success (`deleted: 0`), not an error. Preview with `--dry-run` first for anything you're not fully sure about.

## International domain names

Domain names and record names can be typed either as Unicode (`münchen.de`) or in their encoded form (`xn--mnchen-3ya.de`); both reach the same domain. Output shows Unicode by default. Add `--punycode` to any DNS command to show the encoded form instead. Record values (the `--data` of a CNAME, MX or TXT record) are never converted; enter them exactly as they should be stored.

## Type-specific flags

Most of these only apply to certain record types — set them only when the type calls for it:
Expand Down
13 changes: 10 additions & 3 deletions rust/src/dns/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cli_engine::{
use serde_json::{Value, json};

use crate::domain::make_client;
use crate::idn::DomainFormArgs;
use crate::scopes::DOMAINS_READ;

use domains_client::types;
Expand All @@ -16,7 +17,7 @@ use super::records::{fetch_records, merged_tlsa_data, parse_list_type_arg};
#[derive(Debug, Clone, clap::Args)]
struct ListArgs {
/// Domain whose records to list (e.g. example.com).
#[arg(value_name = "DOMAIN")]
#[arg(value_name = "DOMAIN", value_parser = crate::idn::parse_name_arg)]
domain: String,

/// Only records of this type (A, AAAA, ALIAS, CAA, CNAME, HTTPS, MX, NS,
Expand All @@ -25,8 +26,11 @@ struct ListArgs {
record_type: Option<String>,

/// Only records with this name (requires --type).
#[arg(long, value_name = "NAME", requires = "record_type")]
#[arg(long, value_name = "NAME", requires = "record_type", value_parser = crate::idn::parse_name_arg)]
name: Option<String>,

#[command(flatten)]
domain_format: DomainFormArgs,
}

/// A record is unreadable without its type/name/data, so those three are
Expand Down Expand Up @@ -85,9 +89,12 @@ pub(super) fn command() -> RuntimeCommandSpec {
)
.await?;

let out = build_list_output(&records).map_err(|e| {
let mut out = build_list_output(&records).map_err(|e| {
CliCoreError::message(format!("failed to serialize DNS records: {e}"))
})?;
for record in &mut out {
args.domain_format.form().convert_fields(record, &["name"]);
}
Ok(CommandResult::new(json!(out)))
},
)
Expand Down
67 changes: 64 additions & 3 deletions rust/src/dns/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
//! subcommand: type/name validation, the `RecordOptions` bundle, converting
//! CLI input into v3 `DnsRecord`s, and the paginated `list_dns_records` fetch.

use cli_engine::{CliCoreError, NextAction, NextActionParam};
use cli_engine::{CliCoreError, CommandResult, NextAction, NextActionParam};
use serde_json::Value;

use crate::domain::api_error;
use crate::idn::DomainForm;
use crate::next_action::next_action;

use domains_client::types;
Expand All @@ -23,6 +25,9 @@ pub(super) const LISTABLE_TYPES: &[&str] = &[
];
/// Default TTL (seconds) for `dns add`/`set` when `--ttl` is omitted (v3 requires a ttl).
pub(super) const DEFAULT_TTL: i64 = 3600;
/// The output fields of a DNS write that hold the zone and the record name.
pub(super) const ZONE_AND_NAME: &[&str] = &["domain", "name"];

/// Page size for the paginated v3 list; the handler pages through until every
/// matching record is collected.
const LIST_PAGE_SIZE: std::num::NonZeroU64 =
Expand Down Expand Up @@ -118,7 +123,7 @@ pub(crate) const CONDITIONALLY_REQUIRED_FLAGS: &[(&str, &str)] = &[
#[derive(Debug, Clone, clap::Args)]
pub(super) struct RecordWriteArgs {
/// Domain whose records to modify (e.g. example.com).
#[arg(value_name = "DOMAIN")]
#[arg(value_name = "DOMAIN", value_parser = crate::idn::parse_name_arg)]
pub(super) domain: String,

// `ignore_case` is load-bearing, not cosmetic. The `required_if_eq` predicates
Expand All @@ -131,9 +136,12 @@ pub(super) struct RecordWriteArgs {
pub(super) record_type: String,

/// Record name relative to the domain (e.g. www, @ for the apex).
#[arg(long, value_name = "NAME")]
#[arg(long, value_name = "NAME", value_parser = crate::idn::parse_name_arg)]
pub(super) name: String,

#[command(flatten)]
pub(super) domain_format: crate::idn::DomainFormArgs,

/// Record value (repeatable for multiple records on the same name). For
/// TLSA, this is the hex-encoded certificate association data; use
/// `--usage`/`--selector`/`--matching-type` for the rest.
Expand Down Expand Up @@ -432,10 +440,63 @@ pub(super) fn verify_with_list_action(domain: &str, record_type: &str, name: &st
.with_param("name", NextActionParam::value(name))
}

/// A mutation's success payload plus the "verify with `dns list`" next action,
/// with the zone and record name shown in `domain_format`.
pub(super) fn verified_result(
Comment thread
jpage-godaddy marked this conversation as resolved.
domain_format: DomainForm,
mut payload: Value,
domain: &str,
record_type: &str,
name: &str,
) -> CommandResult {
domain_format.convert_fields(&mut payload, ZONE_AND_NAME);
CommandResult::new(payload).with_next_actions(vec![verify_with_list_action(
&domain_format.render(domain),
record_type,
&domain_format.render(name),
)])
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn verified_result_shows_the_requested_form_of_zone_and_name() {
let payload = || {
serde_json::json!({
"domain": "xn--mnchen-3ya.de",
"name": "xn--bcher-kva",
"type": "A",
})
};
let unicode = verified_result(
DomainForm::Unicode,
payload(),
"xn--mnchen-3ya.de",
"A",
"xn--bcher-kva",
);
assert_eq!(unicode.data["domain"], "münchen.de");
assert_eq!(unicode.data["name"], "bücher");
let params =
serde_json::to_string(&unicode.metadata.next_actions).expect("next actions serialize");
assert!(
params.contains("münchen.de") && params.contains("bücher"),
"{params}"
);

let ascii = verified_result(
DomainForm::Punycode,
payload(),
"xn--mnchen-3ya.de",
"A",
"xn--bcher-kva",
);
assert_eq!(ascii.data["domain"], "xn--mnchen-3ya.de");
assert_eq!(ascii.data["name"], "xn--bcher-kva");
}

fn opts() -> RecordOptions {
RecordOptions {
ttl: None,
Expand Down
21 changes: 6 additions & 15 deletions rust/src/dns/set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::domain::{api_error, make_client};
use crate::output_schema::output_schema;
use crate::scopes::DOMAINS_DNS_UPDATE;

use super::records::verify_with_list_action;
use super::records::{
RecordOptions, RecordWriteArgs, fetch_records, v3_records, validate_caa_fields,
validate_svcb_fields, validate_tlsa_fields,
};
use super::records::{ZONE_AND_NAME, verified_result};

mod outcome;
mod plan;
Expand Down Expand Up @@ -99,6 +99,7 @@ pub(super) fn command() -> RuntimeCommandSpec {
let domain = args.write.domain;
let record_type = args.write.record_type;
let name = args.write.name;
let domain_format = args.write.domain_format.form();
let replace_conflicting = args.replace_conflicting_types;
validate_caa_fields(&record_type, &opts)
.map_err(crate::error::GddyError::validation)?;
Expand Down Expand Up @@ -143,13 +144,9 @@ pub(super) fn command() -> RuntimeCommandSpec {
let desired = v3_records(&name, &record_type, &data, &opts);
let plan = plan_set(&existing, &desired);
if ctx.dry_run() {
return Ok(CommandResult::new(dry_run_set_preview(
&domain,
&record_type,
&name,
&plan,
))
.with_dry_run());
let mut preview = dry_run_set_preview(&domain, &record_type, &name, &plan);
domain_format.convert_fields(&mut preview, ZONE_AND_NAME);
return Ok(CommandResult::new(preview).with_dry_run());
}

let mut outcomes = Vec::new();
Expand Down Expand Up @@ -208,13 +205,7 @@ pub(super) fn command() -> RuntimeCommandSpec {
}

summarize_set_outcomes(&domain, &record_type, &name, &outcomes)
.map(|v| {
CommandResult::new(v).with_next_actions(vec![verify_with_list_action(
&domain,
&record_type,
&name,
)])
})
.map(|v| verified_result(domain_format, v, &domain, &record_type, &name))
.map_err(super::mutate_failed)
},
)
Expand Down
8 changes: 8 additions & 0 deletions rust/src/domain/available.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use domains_client::types;
use super::common::{
api_error, fees_to_json, format_money, make_client, period_label, validate_domain_name,
};
use crate::idn::DomainFormArgs;
use crate::next_action::next_action;
use crate::output_schema::output_schema;
use crate::scopes::DOMAINS_READ;
Expand Down Expand Up @@ -114,6 +115,9 @@ struct AvailableArgs {
/// Optimize for speed (fast) or accuracy (full).
#[arg(long = "check-type", value_name = "TYPE", value_parser = ["fast", "full"])]
check_type: Option<String>,

#[command(flatten)]
domain_format: DomainFormArgs,
}

pub(super) fn command() -> RuntimeCommandSpec {
Expand Down Expand Up @@ -178,6 +182,10 @@ pub(super) fn command() -> RuntimeCommandSpec {
}
}

let domain_format = args.domain_format.form();
domain_format.convert_fields(&mut result, &["domain"]);
let resolved_domain = domain_format.render(&resolved_domain);

let cmd = CommandResult::new(result);
if body.available.unwrap_or(false) {
Ok(cmd.with_next_actions(vec![
Expand Down
Loading
Loading