Compare commits

...

2 Commits

Author SHA1 Message Date
787f74e3ec break out module 2024-07-25 21:16:42 +02:00
9b68b32354 prefer box 2024-07-25 21:07:31 +02:00
4 changed files with 35 additions and 30 deletions

View File

@ -3,40 +3,14 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use log::{error, info}; use log::{error, info};
use reqwest::Client; use reqwest::Client;
use serde::{self, Deserialize, Serialize};
use std::{ use std::{
collections::HashMap,
fmt, fmt,
net::{IpAddr, Ipv4Addr}, net::{IpAddr, Ipv4Addr},
}; };
use super::cloudflare_responses::{CloudflareResponse, DnsRecord};
use crate::get_current_public_ipv4; use crate::get_current_public_ipv4;
#[derive(Serialize, Deserialize, Clone, Debug)]
struct DnsRecord {
id: String,
#[serde(rename = "type")]
record_type: Box<str>,
name: Box<str>,
content: Box<str>,
ttl: u32,
proxied: bool,
locked: bool,
zone_id: Box<str>,
zone_name: Box<str>,
modified_on: Box<str>,
created_on: Box<str>,
meta: HashMap<Box<str>, serde_json::Value>,
}
#[derive(Serialize, Deserialize, Debug)]
struct CloudflareResponse {
success: bool,
errors: Vec<HashMap<String, serde_json::Value>>,
messages: Vec<HashMap<String, serde_json::Value>>,
result: Option<Vec<DnsRecord>>,
}
pub struct CloudflareClient<A, Z> pub struct CloudflareClient<A, Z>
where where
A: fmt::Display, A: fmt::Display,

View File

@ -0,0 +1,27 @@
use std::collections::HashMap;
use serde;
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct DnsRecord {
pub id: Box<str>,
#[serde(rename = "type")]
pub record_type: Box<str>,
pub name: Box<str>,
pub content: Box<str>,
pub ttl: u32,
pub proxied: bool,
pub locked: bool,
pub zone_id: Box<str>,
pub zone_name: Box<str>,
pub modified_on: Box<str>,
pub created_on: Box<str>,
pub meta: HashMap<Box<str>, serde_json::Value>,
}
#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct CloudflareResponse {
pub success: bool,
pub errors: Box<[HashMap<Box<str>, serde_json::Value>]>,
pub messages: Box<[HashMap<Box<str>, serde_json::Value>]>,
pub result: Option<Vec<DnsRecord>>,
}

3
src/internet/mod.rs Normal file
View File

@ -0,0 +1,3 @@
mod cloudflare;
pub mod cloudflare_responses;
pub use cloudflare::CloudflareClient;

View File

@ -1,16 +1,17 @@
// SPDX: BSD-2-Clause // SPDX: BSD-2-Clause
mod cloudflare;
mod config; mod config;
mod exit_listener; mod exit_listener;
mod logging; mod logging;
mod message_handler; mod message_handler;
mod network_change_listener; mod network_change_listener;
mod public_ip; mod public_ip;
mod tests;
pub mod utils; pub mod utils;
pub use cloudflare::CloudflareClient; mod tests;
mod internet;
pub use internet::CloudflareClient;
pub use config::{get_config_path, read_config, Config}; pub use config::{get_config_path, read_config, Config};
pub use exit_listener::ExitListener; pub use exit_listener::ExitListener;
pub use logging::init_logger; pub use logging::init_logger;