@@ -88,13 +88,7 @@ impl CloudflareDDNS {
8888 }
8989
9090 match Config :: builder ( )
91- . set_default (
92- "ip_src" ,
93- DEFAULT_IPS
94- . into_iter ( )
95- . map ( String :: from)
96- . collect :: < Vec < _ > > ( ) ,
97- )
91+ . set_default ( "ip_src" , DEFAULT_IPS . into_iter ( ) . map ( String :: from) . collect :: < Vec < _ > > ( ) )
9892 . unwrap ( )
9993 . set_default ( "http_timeout_s" , 10 )
10094 . unwrap ( )
@@ -141,14 +135,8 @@ impl CloudflareDDNS {
141135
142136 fn get_client ( & self ) -> Agent {
143137 Agent :: config_builder ( )
144- . user_agent ( concat ! (
145- env!( "CARGO_PKG_NAME" ) ,
146- "/" ,
147- env!( "CARGO_PKG_VERSION" )
148- ) )
149- . timeout_global ( Some ( std:: time:: Duration :: from_secs (
150- self . http_timeout_s . unwrap ( ) ,
151- ) ) )
138+ . user_agent ( concat ! ( env!( "CARGO_PKG_NAME" ) , "/" , env!( "CARGO_PKG_VERSION" ) ) )
139+ . timeout_global ( Some ( std:: time:: Duration :: from_secs ( self . http_timeout_s . unwrap ( ) ) ) )
152140 . https_only ( true )
153141 . ip_family ( Ipv4Only )
154142 . build ( )
@@ -214,81 +202,67 @@ impl CloudflareDDNS {
214202 . header ( "Authorization" , format ! ( "Bearer {}" , self . auth_key) )
215203 . call ( )
216204 {
217- Ok ( resp) => {
218- match resp
219- . into_body ( )
220- . read_json :: < CloudflareDnsResponse < CloudflareDnsRecord > > ( )
221- {
222- Ok ( resp) => {
223- if !resp. success {
224- println ! ( "cloudflare api error(s):\n {}" , resp. errors. join( "\n " ) ) ;
225- exit ( 1 ) ;
226- }
227- let mut a_records = resp
228- . entries
205+ Ok ( resp) => match resp. into_body ( ) . read_json :: < CloudflareDnsResponse < CloudflareDnsRecord > > ( ) {
206+ Ok ( resp) => {
207+ if !resp. success {
208+ println ! ( "cloudflare api error(s):\n {}" , resp. errors. join( "\n " ) ) ;
209+ exit ( 1 ) ;
210+ }
211+ let mut a_records = resp
212+ . entries
213+ . iter ( )
214+ . filter ( |x| x. r#type == "A" )
215+ . map ( |x| x. to_owned ( ) )
216+ . collect :: < Vec < _ > > ( ) ;
217+
218+ let total_records = a_records. len ( ) ;
219+ if total_records == 0 {
220+ println ! ( "none found" ) ;
221+ exit ( 0 ) ;
222+ }
223+
224+ if let Some ( patterns) = self . patterns . as_ref ( ) {
225+ let matchers = patterns
229226 . iter ( )
230- . filter ( |x| x. r#type == "A" )
231- . map ( |x| x. to_owned ( ) )
227+ . map ( |p| globset:: Glob :: new ( p) . expect ( "invalid pattern" ) . compile_matcher ( ) )
232228 . collect :: < Vec < _ > > ( ) ;
233229
234- let total_records = a_records. len ( ) ;
235- if total_records == 0 {
236- println ! ( "none found" ) ;
237- exit ( 0 ) ;
238- }
239-
240- if let Some ( patterns) = self . patterns . as_ref ( ) {
241- let matchers = patterns
242- . iter ( )
243- . map ( |p| {
244- globset:: Glob :: new ( p)
245- . expect ( "invalid pattern" )
246- . compile_matcher ( )
247- } )
248- . collect :: < Vec < _ > > ( ) ;
249-
250- a_records. retain ( |x| {
251- let matched = matchers. iter ( ) . any ( |m| m. is_match ( & x. name ) ) ;
252- if self . invert_patterns . unwrap_or ( true ) {
253- !matched
254- } else {
255- matched
256- }
257- } ) ;
258- }
259-
260- let filtered_records = a_records. len ( ) ;
261- if filtered_records == 0 {
262- println ! ( "all records were filtered" ) ;
263- exit ( 0 ) ;
264- }
265-
266- print ! ( "{} found" , total_records) ;
267- if total_records > filtered_records {
268- print ! ( ", {} filtered" , total_records - filtered_records) ;
269- }
230+ a_records. retain ( |x| {
231+ let matched = matchers. iter ( ) . any ( |m| m. is_match ( & x. name ) ) ;
232+ if self . invert_patterns . unwrap_or ( true ) {
233+ !matched
234+ } else {
235+ matched
236+ }
237+ } ) ;
238+ }
270239
271- return a_records;
240+ let filtered_records = a_records. len ( ) ;
241+ if filtered_records == 0 {
242+ println ! ( "all records were filtered" ) ;
243+ exit ( 0 ) ;
272244 }
273- Err ( e) => {
274- println ! ( "failed:\n {e}" ) ;
275- exit ( 1 ) ;
245+
246+ print ! ( "{} found" , total_records) ;
247+ if total_records > filtered_records {
248+ print ! ( ", {} filtered" , total_records - filtered_records) ;
276249 }
250+
251+ return a_records;
277252 }
278- }
253+ Err ( e) => {
254+ println ! ( "failed:\n {e}" ) ;
255+ exit ( 1 ) ;
256+ }
257+ } ,
279258 Err ( e) => {
280259 println ! ( "failed:\n {e}" ) ;
281260 exit ( 1 ) ;
282261 }
283262 }
284263 }
285264
286- fn patch_records (
287- & self ,
288- client : & Agent ,
289- current_ip : & Ipv4Addr ,
290- a_records : Vec < CloudflareDnsRecord > ,
291- ) {
265+ fn patch_records ( & self , client : & Agent , current_ip : & Ipv4Addr , a_records : Vec < CloudflareDnsRecord > ) {
292266 let mut errors = false ;
293267
294268 for ( i, record) in a_records. into_iter ( ) . enumerate ( ) {
@@ -314,10 +288,7 @@ impl CloudflareDDNS {
314288 let status = resp. status ( ) ;
315289 println ! ( "failed (http {})" , status) ;
316290
317- let data = resp
318- . into_body ( )
319- . read_json :: < CloudflareDnsResponse < ( ) > > ( )
320- . unwrap_or_default ( ) ;
291+ let data = resp. into_body ( ) . read_json :: < CloudflareDnsResponse < ( ) > > ( ) . unwrap_or_default ( ) ;
321292 if !data. errors . is_empty ( ) {
322293 println ! ( "error(s):\n {}" , data. errors. join( "\n " ) ) ;
323294 }
0 commit comments