1use clap::Args;
2use schemars::JsonSchema;
3use serde::Deserialize;
4use serde_json::Value;
5
6use crate::core::{
7 dns::service::{ZoneExport, ZoneImport, ZoneRead, ZoneWrite},
8 error::Result,
9};
10
11#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct ZoneSummary {
14 pub name: String,
15 pub zone_type: String,
16 pub disabled: bool,
17}
18
19#[derive(Debug, Clone, Args, Deserialize, JsonSchema)]
21pub struct ZoneImportOptions {
22 #[arg(long, default_value_t = true)]
24 #[serde(default = "default_overwrite")]
25 pub overwrite: bool,
26 #[arg(long, default_value_t = false)]
28 #[serde(default)]
29 pub overwrite_zone: bool,
30 #[arg(long, default_value_t = false)]
32 #[serde(default)]
33 pub overwrite_soa_serial: bool,
34}
35
36fn default_overwrite() -> bool {
37 true
38}
39
40pub async fn list_zones<C: ZoneRead + ?Sized>(
46 client: &C,
47 page: u32,
48 per_page: u32,
49) -> Result<Value> {
50 client.list_zones(page, per_page).await
51}
52
53pub async fn create_zone<C: ZoneWrite + ?Sized>(
59 client: &C,
60 zone: &str,
61 zone_type: &str,
62) -> Result<Value> {
63 client.create_zone(zone, zone_type).await
64}
65
66pub async fn delete_zone<C: ZoneWrite + ?Sized>(client: &C, zone: &str) -> Result<Value> {
72 client.delete_zone(zone).await
73}
74
75pub async fn enable_zone<C: ZoneWrite + ?Sized>(client: &C, zone: &str) -> Result<Value> {
81 client.enable_zone(zone).await
82}
83
84pub async fn disable_zone<C: ZoneWrite + ?Sized>(client: &C, zone: &str) -> Result<Value> {
90 client.disable_zone(zone).await
91}
92
93pub async fn import_zone_file<C: ZoneImport + ?Sized>(
99 client: &C,
100 zone: &str,
101 file_name: String,
102 file_bytes: Vec<u8>,
103 overwrite: bool,
104 overwrite_zone: bool,
105 overwrite_soa_serial: bool,
106) -> Result<Value> {
107 client
108 .import_zone_file(
109 zone,
110 file_name,
111 file_bytes,
112 overwrite,
113 overwrite_zone,
114 overwrite_soa_serial,
115 )
116 .await
117}
118
119pub async fn export_zone_file<C: ZoneExport + ?Sized>(client: &C, zone: &str) -> Result<String> {
125 client.export_zone_file(zone).await
126}