Module: Beaker::DSL::Wrappers
- Included in:
- Beaker::DSL, PSWindows::Exec
- Defined in:
- lib/beaker/dsl/wrappers.rb
Overview
These are wrappers to equivalent Command objects so that command line actions are executed within an appropriate and configurable environment.
I find most of these adapters of suspicious value and have deprecated many of them.
Instance Method Summary collapse
-
#cfacter(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
-
#encode_command(cmd) ⇒ String
private
Convert the provided command string to Base64.
-
#facter(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
-
#hiera(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
-
#powershell(command, args = {}) ⇒ Command
Returns a Command object for executing powershell commands on a host.
-
#puppet(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
Instance Method Details
#cfacter(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
27 28 29 30 31 32 |
# File 'lib/beaker/dsl/wrappers.rb', line 27 def cfacter(*args) = args.last.is_a?(Hash) ? args.pop : {} ['ENV'] ||= {} [:cmdexe] = true Command.new('cfacter', args, ) end |
#encode_command(cmd) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert the provided command string to Base64
169 170 171 172 173 174 175 |
# File 'lib/beaker/dsl/wrappers.rb', line 169 def encode_command(cmd) cmd = cmd.chars.to_a.join("\x00").chomp cmd << "\x00" unless cmd[-1].eql? "\x00" # use strict_encode because linefeeds are not correctly handled in our model cmd = Base64.strict_encode64(cmd).chomp cmd end |
#facter(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
16 17 18 19 20 21 |
# File 'lib/beaker/dsl/wrappers.rb', line 16 def facter(*args) = args.last.is_a?(Hash) ? args.pop : {} ['ENV'] ||= {} [:cmdexe] = true Command.new('facter', args, ) end |
#hiera(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
38 39 40 41 42 43 |
# File 'lib/beaker/dsl/wrappers.rb', line 38 def hiera(*args) = args.last.is_a?(Hash) ? args.pop : {} ['ENV'] ||= {} [:cmdexe] = true Command.new('hiera', args, ) end |
#powershell(command, args = {}) ⇒ Command
Returns a Command object for executing powershell commands on a host
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/beaker/dsl/wrappers.rb', line 126 def powershell(command, args={}) ps_opts = { 'ExecutionPolicy' => 'Bypass', 'InputFormat' => 'None', 'NoLogo' => '', 'NoProfile' => '', 'NonInteractive' => '' } encoded = false ps_opts.merge!(args) ps_args = [] # determine if the command should be encoded if ps_opts.has_key?('EncodedCommand') v = ps_opts.delete('EncodedCommand') # encode the commend if v is true, nil or empty encoded = v || v.eql?('') || v.nil? end ps_opts.each do |k, v| if v.eql?('') or v.nil? ps_args << "-#{k}" else ps_args << "-#{k} #{v}" end end # may not have a command if executing a file if command && !command.empty? if encoded ps_args << "-EncodedCommand #{encode_command(command)}" else ps_args << "-Command #{command}" end end Command.new("powershell.exe", ps_args) end |
#puppet(*args) ⇒ Object
This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.
58 59 60 61 62 63 64 65 66 |
# File 'lib/beaker/dsl/wrappers.rb', line 58 def puppet(*args) = args.last.is_a?(Hash) ? args.pop : {} ['ENV'] ||= {} [:cmdexe] = true # we assume that an invocation with `puppet()` will have it's first argument # a face or sub command cmd = "puppet #{args.shift}" Command.new( cmd, args, ) end |