Skip to content

Commit 31fec64

Browse files
author
David Swan
committed
(MODULES-10389) - Safeguard powershell provider loading
1 parent 3d33fb9 commit 31fec64

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/puppet/provider/exec/powershell.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
require 'puppet/provider/exec'
2-
begin
3-
require 'ruby-pwsh'
4-
rescue LoadError
5-
raise 'Could not load the "ruby-pwsh" library; is the dependency module puppetlabs-pwshlib installed in this environment?'
6-
end
72

83
Puppet::Type.type(:exec).provide :powershell, :parent => Puppet::Provider::Exec do
94
confine :operatingsystem => :windows
10-
11-
commands :powershell => Pwsh::Manager.powershell_path
5+
confine :feature => :pwshlib
6+
7+
def self.powershell_path
8+
begin
9+
require 'ruby-pwsh'
10+
Pwsh::Manager.powershell_path
11+
rescue
12+
nil
13+
end
14+
end
15+
commands :powershell => self.powershell_path
1216

1317
desc <<-EOT
1418
Executes Powershell commands. One of the `onlyif`, `unless`, or `creates`

lib/puppet/provider/exec/pwsh.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
require 'puppet/provider/exec'
2-
begin
3-
require 'ruby-pwsh'
4-
rescue LoadError
5-
raise 'Could not load the "ruby-pwsh" library; is the dependency module puppetlabs-pwshlib installed in this environment?'
6-
end
72

83
Puppet::Type.type(:exec).provide :pwsh, :parent => Puppet::Provider::Exec do
4+
confine :feature => :pwshlib
5+
96
desc <<-EOT
107
Executes PowerShell Core commands. One of the `onlyif`, `unless`, or `creates`
118
parameters should be specified to ensure the command is idempotent.

0 commit comments

Comments
 (0)