dnsync 0.2.1

DNS Sync and Control with MCP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
use inquire::validator::Validation;
use inquire::{Confirm, InquireError, MultiSelect, Select, Text};

use crate::control_plane::config::{
    CLOUDFLARE_DEFAULT_BASE_URL, DnsServerConfig, DnsTransportConfig, DohTransportConfig,
    DotTransportConfig, DoqTransportConfig, EndpointUpdate, McpPermissions,
    PANGOLIN_DEFAULT_BASE_URL, PIHOLE_DEFAULT_BASE_URL, ServerLocation, TECHNITIUM_DEFAULT_BASE_URL,
    UNIFI_DEFAULT_BASE_URL, ValidationEndpointConfig, VendorKind,
};
use crate::control_plane::policy::PolicyRule;
use crate::core::error::{Error, Result};

pub fn run_add_wizard(existing_ids: &[String]) -> Result<DnsServerConfig> {
    let existing: Vec<String> = existing_ids.iter().map(|s| s.to_lowercase()).collect();
    let id = Text::new("Server ID:")
        .with_help_message("Unique identifier for this server entry")
        .with_validator(move |input: &str| {
            if existing.iter().any(|id| id == &input.to_lowercase()) {
                Ok(Validation::Invalid(
                    format!("a server with id '{input}' already exists").into(),
                ))
            } else {
                Ok(Validation::Valid)
            }
        })
        .prompt()
        .map_err(wizard_err)?;

    let vendor = {
        let choices = vec![
            VendorChoice {
                kind: VendorKind::Technitium,
                label: "technitium",
            },
            VendorChoice {
                kind: VendorKind::Pangolin,
                label: "pangolin",
            },
            VendorChoice {
                kind: VendorKind::Cloudflare,
                label: "cloudflare",
            },
            VendorChoice {
                kind: VendorKind::Unifi,
                label: "unifi",
            },
            VendorChoice {
                kind: VendorKind::Pihole,
                label: "pihole",
            },
        ];
        Select::new("Vendor:", choices)
            .prompt()
            .map_err(wizard_err)?
            .kind
    };

    let default_url = match vendor {
        VendorKind::Technitium => TECHNITIUM_DEFAULT_BASE_URL,
        VendorKind::Pangolin => PANGOLIN_DEFAULT_BASE_URL,
        VendorKind::Cloudflare => CLOUDFLARE_DEFAULT_BASE_URL,
        VendorKind::Unifi => UNIFI_DEFAULT_BASE_URL,
        VendorKind::Pihole => PIHOLE_DEFAULT_BASE_URL,
    };

    let base_url = optional_text(
        "Base URL:",
        &format!("Press Enter for default ({default_url}), or type a custom URL"),
        Some(default_url),
    )?;

    let token_env = optional_text(
        "Token environment variable:",
        "Name of the env var holding the API token (recommended). Leave empty to skip.",
        None,
    )?;

    let token = if token_env.is_none() {
        optional_text(
            "API token (stored in plain text — prefer token env var above):",
            "Leave empty to skip",
            None,
        )?
    } else {
        None
    };

    let org_id = match vendor {
        VendorKind::Pangolin => {
            optional_text("Organisation ID (Pangolin):", "Leave empty to skip", None)?
        }
        VendorKind::Unifi => Some(
            Text::new("Site name (UniFi):")
                .with_help_message(
                    "Human-readable site name (e.g. \"Default\") or site UUID; stored in org_id. \
                     Run `dns settings` after saving to list valid site names.",
                )
                .with_validator(|input: &str| {
                    if input.trim().is_empty() {
                        Ok(Validation::Invalid(
                            "site is required for UniFi".into(),
                        ))
                    } else {
                        Ok(Validation::Valid)
                    }
                })
                .prompt()
                .map_err(wizard_err)?,
        ),
        _ => None,
    };

    let location = {
        let choices = vec![
            LocationChoice {
                value: None,
                label: "auto-detect",
            },
            LocationChoice {
                value: Some(ServerLocation::Local),
                label: "local",
            },
            LocationChoice {
                value: Some(ServerLocation::External),
                label: "external",
            },
        ];
        Select::new("Location:", choices)
            .with_help_message(
                "auto-detect infers from the base URL (localhost/private IP → local)",
            )
            .prompt()
            .map_err(wizard_err)?
            .value
    };

    let access: Vec<PolicyRule> = {
        let choices = vec![
            AccessChoice {
                rule: PolicyRule::Read,
                label: "read   (list/export/stats/settings)",
            },
            AccessChoice {
                rule: PolicyRule::Write,
                label: "write  (create/update/import/flush)",
            },
            AccessChoice {
                rule: PolicyRule::Delete,
                label: "delete (delete zones/records/cache)",
            },
        ];
        let defaults: Vec<usize> = (0..choices.len()).collect();
        let chosen = MultiSelect::new("MCP allowed operations:", choices)
            .with_default(&defaults)
            .with_help_message("Select which operations are permitted for MCP tools on this server")
            .prompt()
            .map_err(wizard_err)?;
        chosen.into_iter().map(|c| c.rule).collect()
    };

    let mut allowed_zones: Vec<String> = Vec::new();
    loop {
        let help = if allowed_zones.is_empty() {
            "Restrict zone-targeting tools to specific zones; subdomains are also permitted. Leave empty to skip.".to_string()
        } else {
            format!(
                "Added: {} — enter another, or leave empty to finish",
                allowed_zones.join(", ")
            )
        };
        let zone = match Text::new("Allowed zone:").with_help_message(&help).prompt() {
            Ok(z) => z,
            Err(InquireError::OperationCanceled | InquireError::OperationInterrupted) => {
                return Err(Error::cancelled());
            }
            Err(e) => return Err(wizard_err(e)),
        };
        if zone.is_empty() {
            break;
        }
        allowed_zones.push(zone);
    }

    let mut validation_endpoints: Vec<ValidationEndpointConfig> = Vec::new();
    loop {
        let help = if validation_endpoints.is_empty() {
            "Optional DNS validation endpoints as name:transport:address (transport: dns, doh, dot). Leave empty to skip.".to_string()
        } else {
            format!(
                "Added: {} — enter another, or leave empty to finish",
                validation_endpoints
                    .iter()
                    .map(|endpoint| endpoint.name.as_str())
                    .collect::<Vec<_>>()
                    .join(", ")
            )
        };
        let endpoint = match Text::new("Validation endpoint:")
            .with_help_message(&help)
            .prompt()
        {
            Ok(endpoint) => endpoint,
            Err(InquireError::OperationCanceled | InquireError::OperationInterrupted) => {
                return Err(Error::cancelled());
            }
            Err(e) => return Err(wizard_err(e)),
        };
        if endpoint.is_empty() {
            break;
        }
        validation_endpoints.push(endpoint.parse::<ValidationEndpointConfig>().map_err(Error::parse)?);
    }

    let (dns, dot, doh, doq) = prompt_transport_endpoints_for_add()?;

    Ok(DnsServerConfig {
        id,
        vendor,
        location,
        base_url,
        base_url_env: None,
        token,
        token_env,
        org_id,
        cluster: None,
        dns,
        dot,
        doh,
        doq,
        mcp: McpPermissions {
            access,
            allowed_zones,
        },
        validation_endpoints,
    })
}

/// Interactive wizard for updating a single transport endpoint on an existing server.
///
/// Shows the current status of each endpoint and prompts the user to pick one to
/// configure, update, or remove.
pub fn run_server_wizard(server: &DnsServerConfig) -> Result<EndpointUpdate> {
    let choices = vec![
        EndpointChoice {
            protocol: EndpointProtocol::Dns,
            label: format_endpoint_label("dns", "plain DNS, port 53", endpoint_addr_status(server.dns.as_ref(), false)),
        },
        EndpointChoice {
            protocol: EndpointProtocol::Dot,
            label: format_endpoint_label("dot", "DNS-over-TLS, port 853", endpoint_addr_status(server.dot.as_ref(), false)),
        },
        EndpointChoice {
            protocol: EndpointProtocol::Doh,
            label: format_endpoint_label("doh", "DNS-over-HTTPS", endpoint_addr_status(server.doh.as_ref(), true)),
        },
        EndpointChoice {
            protocol: EndpointProtocol::Doq,
            label: format_endpoint_label("doq", "DNS-over-QUIC", endpoint_addr_status(server.doq.as_ref(), false)),
        },
    ];

    let chosen = Select::new("Select endpoint to configure:", choices)
        .with_help_message("Use arrow keys to select; current status shown on the right")
        .prompt()
        .map_err(wizard_err)?;

    match chosen.protocol {
        EndpointProtocol::Dns => {
            let cfg = configure_or_remove("DNS", server.dns.as_ref(), |existing| {
                prompt_dns_config(existing)
            })?;
            Ok(EndpointUpdate::Dns(cfg))
        }
        EndpointProtocol::Dot => {
            let cfg = configure_or_remove("DoT", server.dot.as_ref(), |existing| {
                prompt_dot_config(existing)
            })?;
            Ok(EndpointUpdate::Dot(cfg))
        }
        EndpointProtocol::Doh => {
            let cfg = configure_or_remove("DoH", server.doh.as_ref(), |existing| {
                prompt_doh_config(existing)
            })?;
            Ok(EndpointUpdate::Doh(cfg))
        }
        EndpointProtocol::Doq => {
            let cfg = configure_or_remove("DoQ", server.doq.as_ref(), |existing| {
                prompt_doq_config(existing)
            })?;
            Ok(EndpointUpdate::Doq(cfg))
        }
    }
}

/// Lets the user pick a server by ID from a list. Returns the chosen server ID.
pub fn run_server_picker(servers: &[DnsServerConfig]) -> Result<String> {
    let choices: Vec<ServerChoice> = servers
        .iter()
        .map(|s| ServerChoice {
            id: s.id.clone(),
            label: format_server_summary(s),
        })
        .collect();

    let chosen = Select::new("Select server to update:", choices)
        .prompt()
        .map_err(wizard_err)?;

    Ok(chosen.id)
}

// ─── Transport endpoint prompts ───────────────────────────────────────────────

fn prompt_transport_endpoints_for_add() -> Result<(
    Option<DnsTransportConfig>,
    Option<DotTransportConfig>,
    Option<DohTransportConfig>,
    Option<DoqTransportConfig>,
)> {
    let configure = Confirm::new("Configure DNS transport endpoints (dns/dot/doh/doq)?")
        .with_default(false)
        .with_help_message(
            "Set up direct DNS query endpoints for validation and resolution. \
             You can always add these later with `dns config server <id> <protocol>`.",
        )
        .prompt()
        .map_err(wizard_err)?;

    if !configure {
        return Ok((None, None, None, None));
    }

    let choices = vec![
        ProtocolChoice { id: 0, label: "dns  (plain DNS, port 53)" },
        ProtocolChoice { id: 1, label: "dot  (DNS-over-TLS, port 853)" },
        ProtocolChoice { id: 2, label: "doh  (DNS-over-HTTPS)" },
        ProtocolChoice { id: 3, label: "doq  (DNS-over-QUIC)" },
    ];

    let selected = MultiSelect::new("Select protocols to configure:", choices)
        .with_help_message("Space to toggle, Enter to confirm")
        .prompt()
        .map_err(wizard_err)?;

    let mut dns = None;
    let mut dot = None;
    let mut doh = None;
    let mut doq = None;

    for choice in selected {
        match choice.id {
            0 => dns = Some(prompt_dns_config(None)?),
            1 => dot = Some(prompt_dot_config(None)?),
            2 => doh = Some(prompt_doh_config(None)?),
            3 => doq = Some(prompt_doq_config(None)?),
            _ => unreachable!(),
        }
    }

    Ok((dns, dot, doh, doq))
}

fn prompt_dns_config(existing: Option<&DnsTransportConfig>) -> Result<DnsTransportConfig> {
    let addr = Text::new("Address (host:port):")
        .with_help_message("e.g. 10.0.0.1:53 or dns.example.com:53")
        .with_default(
            existing
                .and_then(|e| e.addr.as_deref())
                .unwrap_or(""),
        )
        .prompt()
        .map_err(wizard_err)?;

    let timeout_ms = optional_u64(
        "Timeout (ms):",
        "Query timeout in milliseconds, e.g. 2000. Leave empty to use the default.",
        existing.and_then(|e| e.timeout_ms),
    )?;

    let enabled = Confirm::new("Enable this endpoint?")
        .with_default(existing.map_or(true, |e| e.enabled))
        .prompt()
        .map_err(wizard_err)?;

    let addr = addr.trim().to_string();
    Ok(DnsTransportConfig {
        enabled,
        addr: Some(addr).filter(|a| !a.is_empty()),
        timeout_ms,
    })
}

fn prompt_dot_config(existing: Option<&DotTransportConfig>) -> Result<DotTransportConfig> {
    let addr = Text::new("Address (host:port):")
        .with_help_message("e.g. 10.0.0.1:853 or dns.example.com:853")
        .with_default(
            existing
                .and_then(|e| e.addr.as_deref())
                .unwrap_or(""),
        )
        .prompt()
        .map_err(wizard_err)?;

    let server_name = optional_text(
        "TLS server name (SNI):",
        "Hostname for TLS certificate validation. Leave empty to use the hostname from address.",
        existing.and_then(|e| e.server_name.as_deref()),
    )?;

    let timeout_ms = optional_u64(
        "Timeout (ms):",
        "Query timeout in milliseconds, e.g. 2000. Leave empty to use the default.",
        existing.and_then(|e| e.timeout_ms),
    )?;

    let enabled = Confirm::new("Enable this endpoint?")
        .with_default(existing.map_or(true, |e| e.enabled))
        .prompt()
        .map_err(wizard_err)?;

    let addr = addr.trim().to_string();
    Ok(DotTransportConfig {
        enabled,
        addr: Some(addr).filter(|a| !a.is_empty()),
        server_name,
        timeout_ms,
    })
}

fn prompt_doh_config(existing: Option<&DohTransportConfig>) -> Result<DohTransportConfig> {
    let url = optional_text(
        "URL:",
        "Full HTTPS URL, e.g. https://dns.example.com/dns-query",
        existing.and_then(|e| e.url.as_deref()),
    )?;

    let addr = optional_text(
        "Address override (host:port):",
        "Override the TCP address resolved from the URL, e.g. 10.0.0.1:443. Leave empty to use DNS.",
        existing.and_then(|e| e.addr.as_deref()),
    )?;

    let server_name = optional_text(
        "TLS server name (SNI):",
        "Hostname for TLS certificate validation. Leave empty to use the hostname from the URL.",
        existing.and_then(|e| e.server_name.as_deref()),
    )?;

    let timeout_ms = optional_u64(
        "Timeout (ms):",
        "Query timeout in milliseconds, e.g. 2000. Leave empty to use the default.",
        existing.and_then(|e| e.timeout_ms),
    )?;

    let enabled = Confirm::new("Enable this endpoint?")
        .with_default(existing.map_or(true, |e| e.enabled))
        .prompt()
        .map_err(wizard_err)?;

    Ok(DohTransportConfig {
        enabled,
        url,
        addr,
        server_name,
        timeout_ms,
    })
}

fn prompt_doq_config(existing: Option<&DoqTransportConfig>) -> Result<DoqTransportConfig> {
    let addr = Text::new("Address (host:port):")
        .with_help_message("e.g. 10.0.0.1:853 or dns.example.com:853")
        .with_default(
            existing
                .and_then(|e| e.addr.as_deref())
                .unwrap_or(""),
        )
        .prompt()
        .map_err(wizard_err)?;

    let server_name = optional_text(
        "TLS server name (SNI):",
        "Hostname for TLS certificate validation. Leave empty to use the hostname from address.",
        existing.and_then(|e| e.server_name.as_deref()),
    )?;

    let timeout_ms = optional_u64(
        "Timeout (ms):",
        "Query timeout in milliseconds, e.g. 2000. Leave empty to use the default.",
        existing.and_then(|e| e.timeout_ms),
    )?;

    let enabled = Confirm::new("Enable this endpoint?")
        .with_default(existing.map_or(true, |e| e.enabled))
        .prompt()
        .map_err(wizard_err)?;

    let addr = addr.trim().to_string();
    Ok(DoqTransportConfig {
        enabled,
        addr: Some(addr).filter(|a| !a.is_empty()),
        server_name,
        timeout_ms,
    })
}

/// If an existing config is present, ask the user whether to update or remove it.
/// If not present, go straight to the configure prompt.
fn configure_or_remove<T, F>(protocol: &str, existing: Option<&T>, configure: F) -> Result<Option<T>>
where
    F: FnOnce(Option<&T>) -> Result<T>,
{
    if existing.is_some() {
        let choices = vec![
            ActionChoice { action: EndpointAction::Configure, label: "configure / update" },
            ActionChoice { action: EndpointAction::Remove, label: "remove endpoint" },
        ];
        let chosen = Select::new(&format!("{protocol} endpoint:"), choices)
            .prompt()
            .map_err(wizard_err)?;

        if matches!(chosen.action, EndpointAction::Remove) {
            return Ok(None);
        }
    }

    configure(existing).map(Some)
}

// ─── Formatting helpers ───────────────────────────────────────────────────────

fn format_endpoint_label(protocol: &str, description: &str, status: String) -> String {
    format!("{protocol:<4}  {description:<30}  {status}")
}

/// Returns a short status string for an addr-based endpoint (dns/dot/doq).
/// When `is_url` is true, uses url instead of addr.
fn endpoint_addr_status<T: EndpointInfo>(endpoint: Option<&T>, is_url: bool) -> String {
    match endpoint {
        None => "not configured".to_string(),
        Some(ep) => {
            let target = if is_url {
                ep.url_str().unwrap_or_else(|| ep.addr_str().unwrap_or("?"))
            } else {
                ep.addr_str().unwrap_or("?")
            };
            let state = if ep.is_enabled() { "enabled" } else { "disabled" };
            format!("{state}{target}")
        }
    }
}

fn format_server_summary(server: &DnsServerConfig) -> String {
    let vendor = match server.vendor {
        crate::control_plane::config::VendorKind::Technitium => "technitium",
        crate::control_plane::config::VendorKind::Pangolin => "pangolin",
        crate::control_plane::config::VendorKind::Cloudflare => "cloudflare",
        crate::control_plane::config::VendorKind::Unifi => "unifi",
        crate::control_plane::config::VendorKind::Pihole => "pihole",
    };
    let url = server
        .base_url
        .as_deref()
        .unwrap_or("(default)");
    format!("{}  [{vendor}]  {url}", server.id)
}

// ─── Trait to unify transport config access for status formatting ─────────────

trait EndpointInfo {
    fn is_enabled(&self) -> bool;
    fn addr_str(&self) -> Option<&str>;
    fn url_str(&self) -> Option<&str> {
        None
    }
}

impl EndpointInfo for DnsTransportConfig {
    fn is_enabled(&self) -> bool { self.enabled }
    fn addr_str(&self) -> Option<&str> { self.addr.as_deref() }
}

impl EndpointInfo for DotTransportConfig {
    fn is_enabled(&self) -> bool { self.enabled }
    fn addr_str(&self) -> Option<&str> { self.addr.as_deref() }
}

impl EndpointInfo for DohTransportConfig {
    fn is_enabled(&self) -> bool { self.enabled }
    fn addr_str(&self) -> Option<&str> { self.addr.as_deref() }
    fn url_str(&self) -> Option<&str> { self.url.as_deref() }
}

impl EndpointInfo for DoqTransportConfig {
    fn is_enabled(&self) -> bool { self.enabled }
    fn addr_str(&self) -> Option<&str> { self.addr.as_deref() }
}

// ─── Prompt utilities ─────────────────────────────────────────────────────────

fn optional_text(label: &str, help: &str, default: Option<&str>) -> Result<Option<String>> {
    let mut builder = Text::new(label).with_help_message(help);
    if let Some(d) = default {
        builder = builder.with_default(d);
    }
    let val = builder.prompt().map_err(wizard_err)?;
    let val = val.trim();
    Ok(if val.is_empty() { None } else { Some(val.to_string()) })
}

fn optional_u64(label: &str, help: &str, current: Option<u64>) -> Result<Option<u64>> {
    let default = current.map(|n| n.to_string());
    let mut builder = Text::new(label)
        .with_help_message(help)
        .with_validator(|input: &str| {
            if input.is_empty() {
                return Ok(Validation::Valid);
            }
            if input.parse::<u64>().is_ok() {
                Ok(Validation::Valid)
            } else {
                Ok(Validation::Invalid("must be a non-negative integer".into()))
            }
        });
    if let Some(ref d) = default {
        builder = builder.with_default(d.as_str());
    }
    let val = builder.prompt().map_err(wizard_err)?;
    if val.is_empty() {
        Ok(None)
    } else {
        val.parse::<u64>()
            .map(Some)
            .map_err(|_| Error::parse(format!("'{val}' is not a valid integer")))
    }
}

fn wizard_err(e: inquire::InquireError) -> Error {
    match e {
        InquireError::OperationCanceled | InquireError::OperationInterrupted => Error::cancelled(),
        other => Error::io(
            format!("interactive prompt failed: {other}"),
            std::io::Error::other(other.to_string()),
        ),
    }
}

// ─── Display wrappers so Select/MultiSelect can render enum variants ──────────

struct VendorChoice {
    kind: VendorKind,
    label: &'static str,
}

impl std::fmt::Display for VendorChoice {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.label)
    }
}

struct LocationChoice {
    value: Option<ServerLocation>,
    label: &'static str,
}

impl std::fmt::Display for LocationChoice {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.label)
    }
}

struct AccessChoice {
    rule: PolicyRule,
    label: &'static str,
}

impl std::fmt::Display for AccessChoice {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.label)
    }
}

struct ProtocolChoice {
    id: u8,
    label: &'static str,
}

impl std::fmt::Display for ProtocolChoice {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.label)
    }
}

enum EndpointProtocol {
    Dns,
    Dot,
    Doh,
    Doq,
}

struct EndpointChoice {
    protocol: EndpointProtocol,
    label: String,
}

impl std::fmt::Display for EndpointChoice {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.label)
    }
}

enum EndpointAction {
    Configure,
    Remove,
}

struct ActionChoice {
    action: EndpointAction,
    label: &'static str,
}

impl std::fmt::Display for ActionChoice {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.label)
    }
}

struct ServerChoice {
    id: String,
    label: String,
}

impl std::fmt::Display for ServerChoice {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.label)
    }
}