Skip to content

Commit

Permalink
(MODULES-6895) Remove Win32 constants from Trigger
Browse files Browse the repository at this point in the history
 - Create a Flag class to scope the values and use them internally
   within the V1::Trigger class
  • Loading branch information
Iristyle committed Apr 17, 2018
1 parent 409df5a commit f445b6b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/puppet_x/puppetlabs/scheduled_task/trigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ class V1
'minutes_duration'
]

# https://msdn.microsoft.com/en-us/library/windows/desktop/aa383618(v=vs.85).aspx
class Flag
TASK_TRIGGER_FLAG_HAS_END_DATE = 0x1
TASK_TRIGGER_FLAG_KILL_AT_DURATION_END = 0x2
TASK_TRIGGER_FLAG_DISABLED = 0x4
end

class Day
TASK_SUNDAY = 0x1
TASK_MONDAY = 0x2
Expand Down Expand Up @@ -293,11 +300,10 @@ def self.canonicalize_and_validate(hash)

# iTrigger is a COM ITrigger instance
def self.from_iTrigger(iTrigger)
require 'puppet/util/windows/taskscheduler' # Needed for the WIN32::ScheduledTask flag constants
trigger_flags = 0
trigger_flags = trigger_flags | Win32::TaskScheduler::TASK_TRIGGER_FLAG_HAS_END_DATE unless iTrigger.Endboundary.empty?
trigger_flags = trigger_flags | Flag::TASK_TRIGGER_FLAG_HAS_END_DATE unless iTrigger.Endboundary.empty?
# There is no corresponding setting for the V1 flag TASK_TRIGGER_FLAG_KILL_AT_DURATION_END
trigger_flags = trigger_flags | Win32::TaskScheduler::TASK_TRIGGER_FLAG_DISABLED unless iTrigger.Enabled
trigger_flags = trigger_flags | Flag::TASK_TRIGGER_FLAG_DISABLED unless iTrigger.Enabled

start_boundary = Trigger.string_to_date(iTrigger.StartBoundary)
end_boundary = Trigger.string_to_date(iTrigger.EndBoundary)
Expand Down Expand Up @@ -376,9 +382,9 @@ def self.translate_hash_to_trigger(puppet_trigger)
trigger = time_trigger_once_now

if puppet_trigger['enabled'] == false
trigger['flags'] |= Win32::TaskScheduler::TASK_TRIGGER_FLAG_DISABLED
trigger['flags'] |= Flag::TASK_TRIGGER_FLAG_DISABLED
else
trigger['flags'] &= ~Win32::TaskScheduler::TASK_TRIGGER_FLAG_DISABLED
trigger['flags'] &= ~Flag::TASK_TRIGGER_FLAG_DISABLED
end

extra_keys = puppet_trigger.keys.sort - ValidManifestKeys
Expand Down

0 comments on commit f445b6b

Please sign in to comment.