Skip to content

Commit

Permalink
(IAC-732) - implement `Run only when user is logged on
Browse files Browse the repository at this point in the history
  • Loading branch information
David Swan committed Jul 29, 2020
1 parent 7ce1510 commit d8da04e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
4 changes: 4 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Please also note that Puppet must be running as a privileged user
in order to manage `scheduled_task` resources. Running as an
unprivileged user will result in 'access denied' errors.

If a user is specified without an accompanying password the
task will be created with `Run only when user is logged on`
specified.

Default value: system

##### `compatibility`
Expand Down
6 changes: 5 additions & 1 deletion lib/puppet/type/scheduled_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@
Please also note that Puppet must be running as a privileged user
in order to manage `scheduled_task` resources. Running as an
unprivileged user will result in 'access denied' errors."
unprivileged user will result in 'access denied' errors.
If a user is specified without an accompanying password the
task will be created with `Run only when user is logged on`
specified."

defaultto :system

Expand Down
6 changes: 5 additions & 1 deletion lib/puppet_x/puppetlabs/scheduled_task/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ def set_account_information(user, password)
@definition.Principal.LogonType = TASK_LOGON_TYPE::TASK_LOGON_SERVICE_ACCOUNT
else
@definition.Principal.UserId = user
@definition.Principal.LogonType = TASK_LOGON_TYPE::TASK_LOGON_PASSWORD
@definition.Principal.LogonType = if @task_password
TASK_LOGON_TYPE::TASK_LOGON_PASSWORD
else
TASK_LOGON_TYPE::TASK_LOGON_INTERACTIVE_TOKEN
end
end

true
Expand Down
47 changes: 47 additions & 0 deletions spec/acceptance/should_create_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,53 @@
end
end

it 'creates a task with a username: taskscheduler_api2' do
pp = <<-MANIFEST
scheduled_task {'#{taskname}':
ensure => present,
command => 'c:\\\\windows\\\\system32\\\\notepad.exe',
arguments => "foo bar baz",
working_dir => 'c:\\\\windows',
user => '#{username}',
trigger => {
schedule => daily,
start_time => '12:00',
},
}
MANIFEST
apply_manifest(pp, catch_failures: true)

# Verify the task exists
query_cmd = "schtasks.exe /query /v /fo list /tn #{taskname}"
run_shell(query_cmd) do |result|
expect(result.stdout).to match(%r{#{username}})
end
end

it 'creates a task with a username: win32_taskscheduler' do
pp = <<-MANIFEST
scheduled_task {'#{taskname}':
ensure => present,
command => 'c:\\\\windows\\\\system32\\\\notepad.exe',
arguments => "foo bar baz",
working_dir => 'c:\\\\windows',
user => '#{username}',
trigger => {
schedule => daily,
start_time => '12:00',
},
provider => 'win32_taskscheduler'
}
MANIFEST
apply_manifest(pp, catch_failures: true)

# Verify the task exists
query_cmd = "schtasks.exe /query /v /fo list /tn #{taskname}"
run_shell(query_cmd) do |result|
expect(result.stdout).to match(%r{#{username}})
end
end

it "updates a task's credentials: win32_taskscheduler" do
pp = <<-MANIFEST
scheduled_task {'#{taskname}':
Expand Down

0 comments on commit d8da04e

Please sign in to comment.