Module: Chef::Goiardi::Gel::KnifeHelpers
- Included in:
- Knife::GoiardiGelDelete, Knife::GoiardiGelList, Knife::GoiardiGelPurge, Knife::GoiardiGelShow
- Defined in:
- lib/chef/goiardi/knife_helpers.rb
Instance Method Summary collapse
-
#apply_time_args ⇒ Object
Code below adapted from the knife-reporting plugin.
- #convert_to_unix_timestamps(time_to_change) ⇒ Object
- #format_event(gel) ⇒ Object
- #format_object_type(obj) ⇒ Object
- #format_time(timestamp) ⇒ Object
Instance Method Details
#apply_time_args ⇒ Object
Code below adapted from the knife-reporting plugin
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chef/goiardi/knife_helpers.rb', line 26 def apply_time_args() if config[:start_time] start_time = (config[:start_time]) else start_time = nil end if config[:end_time] end_time = (config[:end_time]) else end_time = nil end return start_time, end_time end |
#convert_to_unix_timestamps(time_to_change) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/goiardi/knife_helpers.rb', line 44 def (time_to_change) if config[:unix_timestamps] new_time = time_to_change.to_i else # Take user supplied input, assumes it is in a valid date format, # convert to a date object to ensure we have the proper date format for # passing to the time object (but converting is not a validation step, # so bad user input will still be bad) # then convert to a time object, and then convert to a unix timestamp # An error could potentially be thrown if the conversions don't work # This does work on windows - to_i on time even on windows still returns a unix timestamp # Verified on ruby 1.9.3 on a windows 2000 ami on aws new_time = Time.parse(Date.strptime(time_to_change, '%m-%d-%Y').to_s).to_i end return new_time end |
#format_event(gel) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/chef/goiardi/knife_helpers.rb', line 17 def format_event(gel) gel["object_type"] = format_object_type(gel["object_type"]) gel["actor_info"] = JSON.parse(gel["actor_info"]) gel["extended_info"] = JSON.parse(gel["extended_info"]) gel["time"] = format_time(gel["time"]) gel end |
#format_object_type(obj) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/chef/goiardi/knife_helpers.rb', line 5 def format_object_type(obj) if obj == "*cookbook.CookbookVersion" "cookbook_version" else obj =~ /^\*?(\w+)\.?/ $1 || obj end end |
#format_time(timestamp) ⇒ Object
13 14 15 |
# File 'lib/chef/goiardi/knife_helpers.rb', line 13 def format_time() Time.parse().strftime("%c") end |