Skip to content

Commit ec262a4

Browse files
committed
Merge branch 'dev'
2 parents 38dc753 + a145a23 commit ec262a4

File tree

7 files changed

+34
-35
lines changed

7 files changed

+34
-35
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cloudflare-ddns-rust"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

settings.example.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
"domain_settings": [
99
{
1010
"enabled": false,
11-
"domainName": "example.com",
11+
"domain_name": "example.com",
1212
"service_provider": {
1313
"provider_name": "cloudflare",
1414
"zone_id": "your_zone_ID",
1515
"api_token": "your_api_token"
1616
},
17-
"recordType": "AAAA",
18-
"createNewRecord": true,
17+
"record_type": "AAAA",
18+
"create_new_record": true,
1919
"subdomains": [
2020
{
2121
"name": "test",
22-
"interfaceID": "::2903"
22+
"interface_id": "::2903"
2323
}
2424
]
2525
},
@@ -31,8 +31,8 @@
3131
"zone_id": "your_zone_ID",
3232
"api_token": "your_api_token"
3333
},
34-
"recordType": "A",
35-
"createNewRecord": false,
34+
"record_type": "A",
35+
"create_new_record": false,
3636
"subdomains": [
3737
{
3838
"name": "test",

src/api/cloudflare/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct CloudflareInterface {
2525

2626
impl CloudflareInterface {
2727
fn get_full_domain(subdomain: &str, base_domain: &str) -> String {
28-
if subdomain == "@" || subdomain == "" {
28+
if subdomain == "@" || subdomain.is_empty() {
2929
base_domain.to_string()
3030
} else {
3131
format!("{}.{}", subdomain, base_domain)

src/config/cmd.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ impl std::fmt::Display for LogLevel {
2222
}
2323
}
2424

25-
impl std::convert::Into<LevelFilter> for LogLevel {
26-
fn into(self) -> LevelFilter {
27-
match self {
28-
Self::Trace => LevelFilter::Trace,
29-
Self::Debug => LevelFilter::Debug,
30-
Self::Info => LevelFilter::Info,
31-
Self::Warn => LevelFilter::Warn,
32-
Self::Error => LevelFilter::Error,
25+
impl std::convert::From<LogLevel> for LevelFilter {
26+
fn from(val: LogLevel) -> Self {
27+
match val {
28+
LogLevel::Trace => LevelFilter::Trace,
29+
LogLevel::Debug => LevelFilter::Debug,
30+
LogLevel::Info => LevelFilter::Info,
31+
LogLevel::Warn => LevelFilter::Warn,
32+
LogLevel::Error => LevelFilter::Error,
3333
}
3434
}
3535
}

src/config/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ use serde::{Deserialize, Serialize};
88
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
99
pub enum RecordType {
1010
A,
11-
AAAA,
11+
#[serde(rename = "AAAA")]
12+
Aaaa,
1213
}
1314

1415
impl std::fmt::Display for RecordType {
1516
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1617
match self {
1718
RecordType::A => write!(f, "A"),
18-
RecordType::AAAA => write!(f, "AAAA"),
19+
RecordType::Aaaa => write!(f, "AAAA"),
1920
}
2021
}
2122
}
@@ -24,7 +25,7 @@ impl From<IpAddr> for RecordType {
2425
fn from(value: IpAddr) -> Self {
2526
match value {
2627
IpAddr::V4(_) => Self::A,
27-
IpAddr::V6(_) => Self::AAAA,
28+
IpAddr::V6(_) => Self::Aaaa,
2829
}
2930
}
3031
}

src/domain_record_changer.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,16 @@ where
5959
Err(message) => {
6060
log::error!("Authorize api failed: {}", message);
6161
return;
62-
},
62+
}
6363
}
6464

6565
'subdomain_iter: for subdomain_settings in &self.subdomains {
66-
let full_domain_name: String;
67-
68-
if subdomain_settings.name == "@" || subdomain_settings.name == "" {
69-
full_domain_name = self.domain_name.clone();
70-
} else {
71-
full_domain_name = format!("{}.{}", subdomain_settings.name, &self.domain_name);
72-
}
66+
let full_domain_name =
67+
if subdomain_settings.name == "@" || subdomain_settings.name.is_empty() {
68+
self.domain_name.clone()
69+
} else {
70+
format!("{}.{}", subdomain_settings.name, &self.domain_name)
71+
};
7372
log::debug!("Start DDNS for {}", full_domain_name);
7473

7574
// Convert the ip address to ip to be sent by api request.
@@ -97,8 +96,7 @@ where
9796
if interface_addr_arr
9897
.iter()
9998
.take(4)
100-
.fold(0, |accu, cur| accu + cur)
101-
!= 0
99+
.sum::<u16>() != 0
102100
{
103101
log::warn!(
104102
"The first 64 bits of the interface id are not 0. They are ignored."

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn main() {
117117
return Err(());
118118
}
119119
};
120-
return Ok(result);
120+
Ok(result)
121121
});
122122

123123
let ipv6_address = thread::spawn(|| {
@@ -141,17 +141,17 @@ fn main() {
141141
return Err(());
142142
}
143143
};
144-
return Ok(result);
144+
Ok(result)
145145
});
146146

147147
let ipv4_address = ipv4_address.join().unwrap_or_else(|_| {
148148
log::error!("Get ipv4 address failed: thread exited abnormally.");
149-
return Err(());
149+
Err(())
150150
});
151151

152152
let ipv6_address = ipv6_address.join().unwrap_or_else(|_| {
153153
log::error!("Get ipv6 address failed: thread exited abnormally.");
154-
return Err(());
154+
Err(())
155155
});
156156

157157
let ipv4_address = match ipv4_address {
@@ -210,7 +210,7 @@ fn main() {
210210
continue;
211211
}
212212
},
213-
RecordType::AAAA => match &ipv6_address {
213+
RecordType::Aaaa => match &ipv6_address {
214214
Ok(address) => IpAddr::V6(*address),
215215
Err(_) => {
216216
log::error!("Skipping AAAA record update for {} as a result of previously failed ip address aquisition.", single_domain_settings.domain_name);
@@ -219,7 +219,7 @@ fn main() {
219219
},
220220
};
221221
let mut changer = match single_domain_settings.service_provider.clone() {
222-
ServiceProvider::Cloudflare(build_config) => DomainRecordChanger::new(single_domain_settings, current_ip_address.clone(), CloudflareInterface::new(build_config))
222+
ServiceProvider::Cloudflare(build_config) => DomainRecordChanger::new(single_domain_settings, current_ip_address, CloudflareInterface::new(build_config))
223223
};
224224
s.spawn(move |_| {changer.start_ddns();});
225225
}

0 commit comments

Comments
 (0)