parent
31892b27fc
commit
bd7514ea84
3 changed files with 28 additions and 29 deletions
|
@ -60,7 +60,7 @@ impl CloudflareZone {
|
|||
|
||||
match self.get(&endpoint) {
|
||||
Ok(response) => {
|
||||
return if response.status().is_success() {
|
||||
if response.status().is_success() {
|
||||
let entries = match response.json::<CloudflareApiResults>() {
|
||||
Ok(data) => data,
|
||||
Err(e) => {
|
||||
|
@ -97,9 +97,9 @@ impl CloudflareZone {
|
|||
pub(crate) fn update(&self, entry: &ZoneEntry, r#type: &DnsRecordType, id: &String, ipv6: Option<Ipv6Addr>, ipv4: Option<Ipv4Addr>) -> Result<(), ()> {
|
||||
let endpoint = format!("{}/zones/{}/dns_records/{}", API_BASE, self.id, id);
|
||||
|
||||
match r#type {
|
||||
return match r#type {
|
||||
DnsRecordType::A => {
|
||||
return if let Some(ip) = ipv4 {
|
||||
if let Some(ip) = ipv4 {
|
||||
let json_body = self.create_body("A", &entry.name, ip.to_string().as_str());
|
||||
|
||||
match self.put(&endpoint, &json_body) {
|
||||
|
@ -125,7 +125,7 @@ impl CloudflareZone {
|
|||
}
|
||||
},
|
||||
DnsRecordType::AAAA => {
|
||||
return if let Some(ip) = ipv6 {
|
||||
if let Some(ip) = ipv6 {
|
||||
let json_body = self.create_body("AAAA", &entry.name, ip.to_string().as_str());
|
||||
|
||||
match self.put(&endpoint, &json_body) {
|
||||
|
@ -156,7 +156,7 @@ impl CloudflareZone {
|
|||
true => warn!("[WARN] {warn_msg}"),
|
||||
false => println!("[WARN] {warn_msg}"),
|
||||
}
|
||||
return Err(())
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,9 +164,9 @@ impl CloudflareZone {
|
|||
pub(crate) fn create(&self, entry: &ZoneEntry, r#type: &DnsRecordType, ipv6: Option<Ipv6Addr>, ipv4: Option<Ipv4Addr>) -> Result<(), ()> {
|
||||
let endpoint = format!("{}/zones/{}/dns_records", API_BASE, self.id);
|
||||
|
||||
match r#type {
|
||||
return match r#type {
|
||||
DnsRecordType::A => {
|
||||
return if let Some(ip) = ipv4 {
|
||||
if let Some(ip) = ipv4 {
|
||||
let json_body = self.create_body("A", &entry.name, ip.to_string().as_str());
|
||||
|
||||
match self.post(&endpoint, &json_body) {
|
||||
|
@ -192,7 +192,7 @@ impl CloudflareZone {
|
|||
}
|
||||
},
|
||||
DnsRecordType::AAAA => {
|
||||
return if let Some(ip) = ipv6 {
|
||||
if let Some(ip) = ipv6 {
|
||||
let json_body = self.create_body("AAAA", &entry.name, ip.to_string().as_str());
|
||||
|
||||
match self.post(&endpoint, &json_body) {
|
||||
|
@ -223,7 +223,7 @@ impl CloudflareZone {
|
|||
true => warn!("[WARN] {warn_msg}"),
|
||||
false => println!("[WARN] {warn_msg}"),
|
||||
}
|
||||
return Err(())
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -275,16 +275,16 @@ impl CloudflareZone {
|
|||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
}
|
||||
return Err(e)
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_body(&self, r#type: &str, name: &String, ip: &str) -> HashMap<String, String> {
|
||||
fn create_body(&self, r#type: &str, name: &str, ip: &str) -> HashMap<String, String> {
|
||||
let mut body = HashMap::new();
|
||||
body.insert("type".to_string(), r#type.to_string());
|
||||
body.insert("name".to_string(), name.clone());
|
||||
body.insert("content".to_string(), ip.to_string());
|
||||
body.insert("type".to_owned(), r#type.to_owned());
|
||||
body.insert("name".to_owned(), name.to_owned());
|
||||
body.insert("content".to_owned(), ip.to_owned());
|
||||
body
|
||||
}
|
||||
|
||||
|
@ -303,14 +303,14 @@ impl CloudflareZone {
|
|||
};
|
||||
|
||||
match data.success {
|
||||
true => return Ok(()),
|
||||
true => Ok(()),
|
||||
false => {
|
||||
let err_msg = format!("Unexpected error while updating DNS record. Info: {:?}", data);
|
||||
match connected_to_journal() {
|
||||
true => error!("[ERROR] {err_msg}"),
|
||||
false => eprintln!("[ERROR] {err_msg}"),
|
||||
}
|
||||
return Err(())
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -325,6 +325,7 @@ impl CloudflareZone {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Copy, Display, IntoStaticStr)]
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub(crate) enum DnsRecordType {
|
||||
A,
|
||||
AAAA,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue