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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `nr domain` manages domain names: `search`, `check`, `list`, `get`, `order`, `register`, `transfer`, `renew`, `nameservers set`, `autorenew on|off`, `lock on|off`, `dnssec`, `auth-code` and `contacts list`. Purchases are card only, show the price with tax, need the terms version (`--accept-terms`) and, with auto-renew, consent to renewal charges (`--mit-consent`); `--yes` skips the prompts. A card that needs 3-D Secure gets a portal link instead. See [docs/DOMAINS.md](docs/DOMAINS.md).
- API errors keep the `google.rpc.ErrorInfo` reason and metadata.

## [1.0.21] - 2026-11-29

### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ nr cluster operator upgrade
nr cluster deregister --name edge-ams-01
```

Domain names (search, register, transfer, renew, nameservers, DNSSEC, auto-renew) are under
`nr domain`; see [Domains](docs/DOMAINS.md).

Diagnostic messages go to **stderr**. Use `--output json` when you need machine-readable **stdout**. Exit codes: `0` success, `1` runtime failure, `2` usage error.

## Configuration
Expand All @@ -105,6 +108,7 @@ Optional config lives at `~/.nr/config.yaml`. Production API default is `https:/

- [Install](docs/INSTALL.md)
- [Configuration](docs/CONFIG.md)
- [Domains](docs/DOMAINS.md)
- [Troubleshooting](docs/TROUBLESHOOTING.md)
- [Security](SECURITY.md)
- [Contributing](CONTRIBUTING.md)
Expand Down
72 changes: 72 additions & 0 deletions docs/DOMAINS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Domains

`nr domain` searches, registers, transfers and manages domain names registered through
NodeRings. It works with a service account token (`NR_API_TOKEN`) or an `nr auth login` session.

```bash
nr domain search evergreen-coffee --tld com,io
nr domain check evergreen-coffee.com
nr domain contacts list
nr domain register evergreen-coffee.com --years 1 --contact <contact-id>
nr domain list
nr domain get evergreen-coffee.com
```

Every command takes `--output json` (`-o json`).

## Paying for domains

Domains are paid **by card only**; account credit and coupons do not apply. `register`,
`transfer` and `renew`:

1. create an order and show the price with tax,
2. ask you to accept the current domain registration terms (version and link are shown),
3. ask for consent to automatic renewal charges when auto-renew is on (the default),
4. ask to confirm the charge,
5. charge `--card <payment-method-id>` or the organization's default card, and
6. wait until the registry confirms (`--no-wait` to skip; `nr domain order <id>` shows it later).

Acceptance is never implied. With `--yes` (no prompts) pass the terms version and consent
explicitly:

```bash
nr domain register evergreen-coffee.com --contact <contact-id> \
--accept-terms 2026-12-01 --mit-consent --yes
nr domain register evergreen-coffee.com --contact <contact-id> \
--accept-terms 2026-12-01 --no-auto-renew --yes
```

If no card is on file, or the card asks for **3-D Secure**, the CLI cannot finish the purchase
(the bank's check only runs in a browser). Nothing is charged; the command prints the portal
link where the same order can be paid.

Failed items are never charged. A partially completed order charges only the domains that were
registered, and the command exits with status 1.

## Transfers

Unlock the domain at the current registrar and get its auth code, then:

```bash
NR_DOMAIN_AUTH_CODE='...' nr domain transfer example.com --keep-nameservers
```

## Settings

```bash
nr domain nameservers set example.com --noderings
nr domain nameservers set example.com ns1.example.net ns2.example.net
nr domain autorenew on example.com --mit-consent
nr domain autorenew off example.com
nr domain lock on example.com
nr domain dnssec example.com managed
nr domain dnssec example.com custom --ds 12345:13:2:<digest>
nr domain renew example.com --years 1
```

## Sensitive actions

`nr domain auth-code` and `nr domain lock off` need a fresh sign-in (password and/or
two-factor code). The CLI does not ask for your password: it prints the portal link instead.
Callers that already hold a step-up token from `POST /v1/auth/reauthenticate` can pass it with
`--reauth-token` (or `NR_REAUTH_TOKEN`). Service accounts cannot do these actions.
49 changes: 49 additions & 0 deletions internal/api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ type APIError struct {
Message string
Details string
Code string // gRPC error code (e.g., "NOT_FOUND", "ALREADY_EXISTS")
// Reason and Metadata come from the first google.rpc.ErrorInfo detail
// (e.g. REQUIRES_PORTAL_VERIFICATION with metadata portal_url).
Reason string
Metadata map[string]string
}

// ErrorReason returns the google.rpc.ErrorInfo reason of an API error, or "".
func ErrorReason(err error) string {
var apiErr *APIError
if errors.As(err, &apiErr) && apiErr != nil {
return apiErr.Reason
}
return ""
}

// ErrorMetadata returns one google.rpc.ErrorInfo metadata value of an API error, or "".
func ErrorMetadata(err error, key string) string {
var apiErr *APIError
if errors.As(err, &apiErr) && apiErr != nil {
return apiErr.Metadata[key]
}
return ""
}

func (e *APIError) Error() string {
Expand Down Expand Up @@ -202,6 +224,7 @@ func fillAPIErrorFromObject(apiErr *APIError, obj map[string]json.RawMessage) {
if json.Unmarshal(raw, &details) != nil || len(details) == 0 {
return
}
applyErrorInfo(apiErr, details)
d := details[0]
if raw, ok := d["code"]; ok {
var s string
Expand All @@ -217,6 +240,32 @@ func fillAPIErrorFromObject(apiErr *APIError, obj map[string]json.RawMessage) {
}
}

// applyErrorInfo copies the reason and metadata of the first google.rpc.ErrorInfo detail.
func applyErrorInfo(apiErr *APIError, details []map[string]json.RawMessage) {
for _, d := range details {
var typ string
if raw, ok := d["@type"]; !ok || json.Unmarshal(raw, &typ) != nil || !strings.HasSuffix(typ, "google.rpc.ErrorInfo") {
continue
}
var info struct {
Reason string `json:"reason"`
Metadata map[string]string `json:"metadata"`
}
if raw, ok := d["reason"]; ok {
_ = json.Unmarshal(raw, &info.Reason)
}
if raw, ok := d["metadata"]; ok {
_ = json.Unmarshal(raw, &info.Metadata)
}
if info.Reason == "" {
continue
}
apiErr.Reason = info.Reason
apiErr.Metadata = info.Metadata
return
}
}

func applyStatusHeaders(apiErr *APIError, header http.Header) {
if header == nil {
return
Expand Down
20 changes: 20 additions & 0 deletions internal/api/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,23 @@ func TestIsProviderReviewPendingWrapped(t *testing.T) {
t.Fatal("generic 403 must not be treated as marketplace review")
}
}

func TestParseErrorErrorInfo(t *testing.T) {
t.Parallel()

body := `{"code":9,"message":"This card needs verification.","details":[` +
`{"@type":"type.googleapis.com/google.rpc.DebugInfo","detail":"x"},` +
`{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"REQUIRES_PORTAL_VERIFICATION","domain":"api","metadata":{"portal_url":"https://noderings.com/domains/checkout/o1"}}]}`
resp := &http.Response{StatusCode: http.StatusBadRequest, Status: "400 Bad Request", Body: io.NopCloser(strings.NewReader(body))}
err := fmt.Errorf("checkout: %w", ParseError(resp))

if got := ErrorReason(err); got != "REQUIRES_PORTAL_VERIFICATION" {
t.Fatalf("ErrorReason = %q", got)
}
if got := ErrorMetadata(err, "portal_url"); got != "https://noderings.com/domains/checkout/o1" {
t.Fatalf("ErrorMetadata = %q", got)
}
if ErrorReason(fmt.Errorf("plain")) != "" || ErrorMetadata(nil, "x") != "" {
t.Fatal("non-API errors have no reason")
}
}
Loading
Loading