44require 'uri'
55require 'puppet/util'
66require 'puppet/parameter/boolean'
7- require 'pry'
87
98Puppet ::Type . newtype ( :archive ) do
109 @doc = 'Manage archive file download, extraction, and cleanup.'
@@ -264,9 +263,9 @@ def change_to_s(currentvalue, newvalue)
264263
265264 # Support both arrays and colon-separated fields.
266265 def value = ( *values )
267- @value = values . flatten . collect { |val |
266+ @value = values . flatten . map do |val |
268267 val . split ( File ::PATH_SEPARATOR )
269- } . flatten
268+ end . flatten
270269 end
271270 end
272271
@@ -280,29 +279,27 @@ def value=(*values)
280279 validate do |values |
281280 values = [ values ] unless values . is_a? Array
282281 values . each do |value |
283- unless value =~ /\w +=/
284- raise ArgumentError , _ ( "Invalid environment setting '%{value}'" ) % { value : value }
285- end
282+ raise ArgumentError , "Invalid environment setting '#{ value } '" unless value =~ %r{\w +=}
286283 end
287284 end
288285 end
289286
290- newcheck ( :creates , : parent => Puppet ::Parameter ::Path ) do
287+ newcheck ( :creates , parent : Puppet ::Parameter ::Path ) do
291288 desc 'if file/directory exists, will not download/extract archive.'
292289
293290 accept_arrays
294291
295292 # If the file exists, return false (i.e., don't run the command),
296293 # else return true
297294 def check ( value )
298- #TRANSLATORS 'creates' is a parameter name and should not be translated
299- debug ( _ ( "Checking that 'creates' path '%{creates_path }' exists" ) % { creates_path : value } )
295+ # TRANSLATORS 'creates' is a parameter name and should not be translated
296+ debug ( "Checking that 'creates' path '#{ value } ' exists" )
300297 Puppet ::FileSystem . exist? ( value )
301298 end
302299 end
303300
304301 newcheck ( :unless ) do
305- desc <<-' EOT'
302+ desc <<-EOT
306303 A test command that checks the state of the target system and restricts
307304 when the `archive` can run. If present, Puppet runs this test command
308305 first, then runs the main command unless the test has an exit code of 0
@@ -333,7 +330,7 @@ def check(value)
333330
334331 This `archive` would only run if every command in the array has a
335332 non-zero exit code.
336- EOT
333+ EOT
337334
338335 validate do |cmds |
339336 cmds = [ cmds ] unless cmds . is_a? Array
@@ -348,24 +345,24 @@ def check(value)
348345 begin
349346 output , status = provider . run ( value , true )
350347 rescue Timeout ::Error
351- err _ ( " Check %{value} exceeded timeout" ) % { value : value . inspect }
348+ err format ( ' Check %{value} exceeded timeout' , value : value . inspect )
352349 return false
353350 end
354351
355352 if sensitive
356- self . debug ( " [output redacted]" )
353+ debug ( ' [output redacted]' )
357354 else
358- output . split ( / \n / ) . each { |line |
359- self . debug ( line )
360- }
355+ output . split ( %r{ \n } ) . each do |line |
356+ debug ( line )
357+ end
361358 end
362359
363360 status . exitstatus != 0
364361 end
365362 end
366363
367364 newcheck ( :onlyif ) do
368- desc <<-' EOT'
365+ desc <<-EOT
369366 A test command that checks the state of the target system and restricts
370367 when the `archive` can run. If present, Puppet runs this test command
371368 first, and only runs the main command if the test has an exit code of 0
@@ -396,7 +393,7 @@ def check(value)
396393
397394 This `archive` would only run if every command in the array has an
398395 exit code of 0 (success).
399- EOT
396+ EOT
400397
401398 validate do |cmds |
402399 cmds = [ cmds ] unless cmds . is_a? Array
@@ -411,19 +408,19 @@ def check(value)
411408 begin
412409 output , status = provider . run ( value , true )
413410 rescue Timeout ::Error
414- err _ ( " Check %{value} exceeded timeout" ) % { value : value . inspect }
411+ err format ( ' Check %{value} exceeded timeout' , value : value . inspect )
415412 return false
416413 end
417414
418415 if sensitive
419- self . debug ( " [output redacted]" )
416+ debug ( ' [output redacted]' )
420417 else
421- output . split ( / \n / ) . each { |line |
422- self . debug ( line )
423- }
418+ output . split ( %r{ \n } ) . each do |line |
419+ debug ( line )
420+ end
424421 end
425422
426- status . exitstatus == 0
423+ status . exitstatus . zero?
427424 end
428425 end
429426
@@ -460,9 +457,8 @@ def check(value)
460457 # Verify that we pass all of the checks. The argument determines whether
461458 # we skip the :refreshonly check, which is necessary because we now check
462459 # within refresh
463- def check_all_attributes ( refreshing = false )
464- self . class . checks . each { |check |
465-
460+ def check_all_attributes ( _refreshing = false )
461+ self . class . checks . each do |check |
466462 next unless @parameters . include? ( check )
467463
468464 val = @parameters [ check ] . value
@@ -472,13 +468,13 @@ def check_all_attributes(refreshing = false)
472468
473469 # Give a debug message so users can figure out what command would have been
474470 # but don't print sensitive commands or parameters in the clear
475- sourcestring = @parameters [ :source ] . sensitive ? " [command redacted]" : @parameters [ :source ] . value
471+ sourcestring = @parameters [ :source ] . sensitive ? ' [command redacted]' : @parameters [ :source ] . value
476472
477- debug ( _ ( "'%{source}' won't be executed because of failed check '%{check}'" ) % { source : sourcestring , check : check } )
473+ debug ( format ( "'%{source}' won't be executed because of failed check '%{check}'" , source : sourcestring , check : check ) )
478474
479475 return false
480476 end
481- }
477+ end
482478 true
483479 end
484480
@@ -492,13 +488,13 @@ def output
492488
493489 # Run the command, or optionally run a separately-specified command.
494490 def refresh
495- if check_all_attributes ( true )
496- cmd = self [ :refresh ]
497- if cmd
498- provider . run ( cmd )
499- else
500- property ( :returns ) . sync
501- end
491+ return unless check_all_attributes ( true )
492+
493+ cmd = self [ :refresh ]
494+ if cmd
495+ provider . run ( cmd )
496+ else
497+ property ( :returns ) . sync
502498 end
503499 end
504500
@@ -507,7 +503,7 @@ def refresh
507503 def set_sensitive_parameters ( sensitive_parameters )
508504 # If any are sensitive, mark all as sensitive
509505 sensitive = false
510- parameters_to_check = [ : command, : unless, : onlyif]
506+ parameters_to_check = %i[ command unless onlyif ]
511507
512508 parameters_to_check . each do |p |
513509 if sensitive_parameters . include? ( p )
@@ -518,9 +514,7 @@ def set_sensitive_parameters(sensitive_parameters)
518514
519515 if sensitive
520516 parameters_to_check . each do |p |
521- if parameters . include? ( p )
522- parameter ( p ) . sensitive = true
523- end
517+ parameter ( p ) . sensitive = true if parameters . include? ( p )
524518 end
525519 end
526520
0 commit comments