Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(IAC-732) - implement `Run only when user is logged on #150

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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