app/cyclid/plugins/transport/ssh.rb in cyclid-0.3.3 vs app/cyclid/plugins/transport/ssh.rb in cyclid-0.4.0

- old
+ new

@@ -64,12 +64,15 @@ if (Time.now - start) >= 30 end end # Execute a command via. SSH - def exec(cmd, path = nil) - command = build_command(cmd, path, @env) + def exec(cmd, args = {}) + sudo = args[:sudo] || false + path = args[:path] + + command = build_command(cmd, sudo, path, @env) Cyclid.logger.debug "command=#{command}" @session.open_channel do |channel| channel.on_open_failed do |_ch, _code, desc| # XXX raise @@ -123,13 +126,21 @@ # Close the SSH connection def close @session.close end + # Plugin metadata + def self.metadata + super.merge!(version: Cyclid::Api::VERSION, + license: 'Apache-2.0', + author: 'Liqwyd Ltd.', + homepage: 'http://docs.cyclid.io') + end + private - def build_command(cmd, path = nil, env = {}) + def build_command(cmd, sudo, path = nil, env = {}) command = [] if env vars = env.map do |k, value| key = k.upcase key.gsub!(/\s/, '_') @@ -139,11 +150,13 @@ end command << "cd #{path}" if path command << if @username == 'root' cmd + elsif sudo + "sudo -E -n $SHELL -l -c '#{cmd}'" else - "sudo -E #{cmd}" + cmd end command.join(';') end # Register this plugin