Class: Bolt::Transport::Local::Connection
- Inherits:
-
Object
- Object
- Bolt::Transport::Local::Connection
- Defined in:
- lib/bolt/transport/local/connection.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#target ⇒ Object
Returns the value of attribute target.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #copy_file(source, dest) ⇒ Object
- #execute(command) ⇒ Object
-
#initialize(target) ⇒ Connection
constructor
A new instance of Connection.
-
#reset_cwd? ⇒ Boolean
This is used by the Bash shell to decide whether to ‘cd` before executing commands as a run-as user.
- #shell ⇒ Object
Constructor Details
#initialize(target) ⇒ Connection
Returns a new instance of Connection.
14 15 16 17 18 19 |
# File 'lib/bolt/transport/local/connection.rb', line 14 def initialize(target) @target = target # The familiar problem: Etc.getlogin is broken on osx @user = ENV['USER'] || Etc.getlogin @logger = Logging.logger[self] end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/bolt/transport/local/connection.rb', line 12 def logger @logger end |
#target ⇒ Object
Returns the value of attribute target.
12 13 14 |
# File 'lib/bolt/transport/local/connection.rb', line 12 def target @target end |
#user ⇒ Object
Returns the value of attribute user.
12 13 14 |
# File 'lib/bolt/transport/local/connection.rb', line 12 def user @user end |
Instance Method Details
#copy_file(source, dest) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bolt/transport/local/connection.rb', line 29 def copy_file(source, dest) @logger.debug { "Uploading #{source}, to #{dest}" } if source.is_a?(StringIO) Tempfile.create(File.basename(dest)) do |f| f.write(source.read) FileUtils.mv(t, dest) end else # Mimic the behavior of `cp --remove-destination` # since the flag isn't supported on MacOS FileUtils.cp_r(source, dest, remove_destination: true) end rescue StandardError => e = "Could not copy file to #{dest}: #{e}" raise Bolt::Node::FileError.new(, 'COPY_ERROR') end |
#execute(command) ⇒ Object
46 47 48 |
# File 'lib/bolt/transport/local/connection.rb', line 46 def execute(command) Open3.popen3(command) end |
#reset_cwd? ⇒ Boolean
This is used by the Bash shell to decide whether to ‘cd` before executing commands as a run-as user
52 53 54 |
# File 'lib/bolt/transport/local/connection.rb', line 52 def reset_cwd? false end |