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
// Copyright (c) 2025 Erick Bourgeois, firestoned
// SPDX-License-Identifier: MIT
//! bindcar - HTTP REST API for managing BIND9 zones via RNDC
//!
//! A lightweight library that provides programmatic control over BIND9 DNS zones
//! using the RNDC (Remote Name Daemon Control) protocol.
//!
//! # Features
//!
//! - Create, delete, and manage BIND9 zones dynamically
//! - Execute RNDC commands asynchronously
//! - Zone file generation and management
//! - Shared request/response types for API operations
//! - Authentication support (Bearer tokens and Kubernetes ServiceAccounts)
//! - Prometheus metrics integration
//!
//! # Usage
//!
//! This crate can be used as both a library and a standalone binary:
//!
//! ## As a Library
//!
//! ### Using RNDC Executor
//!
//! ```rust,no_run
//! use bindcar::RndcExecutor;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let executor = RndcExecutor::new(
//! "127.0.0.1:953".to_string(),
//! "sha256".to_string(),
//! "dGVzdC1zZWNyZXQtaGVyZQ==".to_string(), // base64 encoded secret
//! )?;
//!
//! // Execute RNDC commands
//! let status = executor.status().await?;
//! println!("BIND9 Status: {}", status);
//!
//! Ok(())
//! }
//! ```
//!
//! ### Using Shared Types (for API clients)
//!
//! ```rust
//! use bindcar::{CreateZoneRequest, ZoneConfig, SoaRecord, DnsRecord};
//! use std::collections::HashMap;
//!
//! // Create nameserver glue records
//! let mut ns_ips = HashMap::new();
//! ns_ips.insert("ns1.example.com.".to_string(), "192.0.2.10".to_string());
//!
//! // Create a zone creation request
//! let request = CreateZoneRequest {
//! zone_name: "example.com".to_string(),
//! zone_type: "primary".to_string(),
//! zone_config: ZoneConfig {
//! ttl: 3600,
//! soa: SoaRecord {
//! primary_ns: "ns1.example.com.".to_string(),
//! admin_email: "admin.example.com.".to_string(),
//! serial: 2025010101,
//! refresh: 3600,
//! retry: 600,
//! expire: 604800,
//! negative_ttl: 86400,
//! },
//! name_servers: vec!["ns1.example.com.".to_string()],
//! name_server_ips: ns_ips,
//! records: vec![
//! DnsRecord {
//! name: "@".to_string(),
//! record_type: "A".to_string(),
//! value: "192.0.2.1".to_string(),
//! ttl: None,
//! priority: None,
//! },
//! ],
//! also_notify: None,
//! allow_transfer: None,
//! primaries: None,
//! dnssec_policy: None,
//! inline_signing: None,
//! },
//! update_key_name: None,
//! };
//!
//! // Serialize to JSON for API requests
//! let json = serde_json::to_string(&request).unwrap();
//! ```
//!
//! ## As a Binary
//!
//! ```bash
//! cargo install bindcar
//! bindcar
//! ```
//!
//! ## Zone File Generation
//!
//! The `serial` field in SoaRecord will auto-generate in YYYYMMDD01 format if omitted from JSON.
//!
//! ```rust
//! use bindcar::{ZoneConfig, SoaRecord, DnsRecord};
//! use std::collections::HashMap;
//!
//! // Example JSON can omit serial for auto-generation:
//! let json = r#"{
//! "ttl": 3600,
//! "soa": {
//! "primaryNs": "ns1.example.com.",
//! "adminEmail": "admin.example.com."
//! },
//! "nameServers": ["ns1.example.com."],
//! "nameServerIps": {
//! "ns1.example.com.": "192.0.2.10"
//! },
//! "records": []
//! }"#;
//!
//! let zone_config: ZoneConfig = serde_json::from_str(json).unwrap();
//! let zone_file_content = zone_config.to_zone_file();
//! println!("{}", zone_file_content);
//! ```
//!
//! # Integration with Other Projects
//!
//! This library is designed to be used by other projects (like bindy) that need to
//! interact with the bindcar API. By importing this crate, you get:
//!
//! - Type-safe request/response structures
//! - Automatic JSON serialization/deserialization
//! - OpenAPI schema compatibility
//! - No need to maintain duplicate type definitions
// Re-export public modules
// Re-export commonly used types
// RNDC executor
pub use RndcExecutor;
// nsupdate executor
pub use NsupdateExecutor;
// Error types
pub use ;
// Zone configuration types
pub use ;
// Request/Response types for API operations
pub use ;
// Record management types
pub use ;
// RNDC configuration
pub use ;
// RNDC configuration parser
pub use ;
// RNDC configuration types
pub use ;
// Test modules