Class: Inspec::Resources::Powershell
- Defined in:
- lib/inspec/resources/powershell.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Cmd
Instance Method Summary collapse
-
#exist? ⇒ Boolean
we cannot determine if a command exists, because that does not work for scripts.
-
#initialize(script) ⇒ Powershell
constructor
A new instance of Powershell.
- #resource_id ⇒ Object
-
#strip ⇒ Object
Removes leading and trailing whitespace from stdout.
- #to_s ⇒ Object
Methods inherited from Cmd
#exit_status, #result, #stderr, #stdout
Constructor Details
#initialize(script) ⇒ Powershell
Returns a new instance of Powershell.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/inspec/resources/powershell.rb', line 20 def initialize(script) # PowerShell is the default shell on Windows, use the `command` resource return super(script) if inspec.os.windows? unless inspec.command("pwsh").exist? raise Inspec::Exceptions::ResourceSkipped, "Can not find `pwsh` command" end # Prevent progress stream from leaking into stderr command = "$ProgressPreference='SilentlyContinue';" + script # Encode as Base64 to remove any quotes/escapes/etc issues command = command.encode("UTF-16LE", "UTF-8") command = Base64.strict_encode64(command) # Use the `command` resource to execute the command via `pwsh` super("pwsh -encodedCommand '#{command}'") end |
Instance Method Details
#exist? ⇒ Boolean
we cannot determine if a command exists, because that does not work for scripts
40 41 42 |
# File 'lib/inspec/resources/powershell.rb', line 40 def exist? nil end |
#resource_id ⇒ Object
53 54 55 |
# File 'lib/inspec/resources/powershell.rb', line 53 def resource_id "Powershell" end |
#strip ⇒ Object
Removes leading and trailing whitespace from stdout
45 46 47 |
# File 'lib/inspec/resources/powershell.rb', line 45 def strip result.stdout&.strip end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/inspec/resources/powershell.rb', line 49 def to_s "Powershell" end |