smart_proxy_remote_execution_ssh 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/smart_proxy_remote_execution_ssh/command_action.rb +9 -8
- data/lib/smart_proxy_remote_execution_ssh/connector.rb +2 -0
- data/lib/smart_proxy_remote_execution_ssh/dispatcher.rb +9 -8
- data/lib/smart_proxy_remote_execution_ssh/session.rb +13 -3
- data/lib/smart_proxy_remote_execution_ssh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1ead2e0c7291668c08d8c00301f82011bddd74d
|
4
|
+
data.tar.gz: 6fea98dc76b79bce6725a6cb208ad89e7bf21896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ec16052339edbfbe8e427944aa7016a6221c24414a1a49f85cb8070001337111276c50a473780f793181f80102b871a485eda2a473e2d9cd740f0202363b0bf
|
7
|
+
data.tar.gz: 71e75aa680faf8dc450b13f36de22a1a82c92bcba88d49a016ba0be22c0455e692e08cbbf52152722190b215c0fbe142425c28df529607af0074f80ef5e7d59d
|
data/README.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
[![Build Status](https://img.shields.io/jenkins/s/http/ci.theforeman.org/test_plugin_smart_proxy_remote_execution_ssh_master.svg)](http://ci.theforeman.org/job/test_plugin_smart_proxy_remote_execution_ssh_master)
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/smart_proxy_remote_execution_ssh.svg)](https://rubygems.org/gems/smart_proxy_remote_execution_ssh)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/theforeman/smart_proxy_remote_execution_ssh/badges/gpa.svg)](https://codeclimate.com/github/theforeman/smart_proxy_remote_execution_ssh)
|
4
|
+
[![GPL License](https://img.shields.io/github/license/theforeman/smart_proxy_remote_execution_ssh.svg)](https://github.com/theforeman/smart_proxy_remote_execution_ssh/blob/master/LICENSE)
|
5
|
+
|
1
6
|
# Smart-proxy Ssh plugin
|
2
7
|
|
3
8
|
This a plugin for foreman smart-proxy allowing using ssh for the
|
@@ -40,14 +40,15 @@ module Proxy::RemoteExecution::Ssh
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def command
|
43
|
-
@command ||= Dispatcher::Command.new(:id
|
44
|
-
:host
|
45
|
-
:ssh_user
|
46
|
-
:effective_user
|
47
|
-
:script
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
43
|
+
@command ||= Dispatcher::Command.new(:id => input[:task_id],
|
44
|
+
:host => input[:hostname],
|
45
|
+
:ssh_user => input[:ssh_user] || 'root',
|
46
|
+
:effective_user => input[:effective_user],
|
47
|
+
:script => input[:script],
|
48
|
+
:effective_user_method => input[:effective_user_method],
|
49
|
+
:host_public_key => input[:host_public_key],
|
50
|
+
:verify_host => input[:verify_host],
|
51
|
+
:suspended_action => suspended_action)
|
51
52
|
end
|
52
53
|
|
53
54
|
def init_run
|
@@ -22,6 +22,8 @@ module Proxy::RemoteExecution::Ssh
|
|
22
22
|
def async_run(command)
|
23
23
|
started = false
|
24
24
|
session.open_channel do |channel|
|
25
|
+
channel.request_pty
|
26
|
+
|
25
27
|
channel.on_data { |ch, data| yield CommandUpdate::StdoutData.new(data) }
|
26
28
|
|
27
29
|
channel.on_extended_data { |ch, type, data| yield CommandUpdate::StderrData.new(data) }
|
@@ -7,18 +7,19 @@ module Proxy::RemoteExecution::Ssh
|
|
7
7
|
class Dispatcher < ::Dynflow::Actor
|
8
8
|
# command comming from action
|
9
9
|
class Command
|
10
|
-
attr_reader :id, :host, :ssh_user, :effective_user, :script, :host_public_key, :suspended_action
|
10
|
+
attr_reader :id, :host, :ssh_user, :effective_user, :effective_user_method, :script, :host_public_key, :suspended_action
|
11
11
|
|
12
12
|
def initialize(data)
|
13
13
|
validate!(data)
|
14
14
|
|
15
|
-
@id
|
16
|
-
@host
|
17
|
-
@ssh_user
|
18
|
-
@effective_user
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@
|
15
|
+
@id = data[:id]
|
16
|
+
@host = data[:host]
|
17
|
+
@ssh_user = data[:ssh_user]
|
18
|
+
@effective_user = data[:effective_user]
|
19
|
+
@effective_user_method = data[:effective_user_method] || 'su'
|
20
|
+
@script = data[:script]
|
21
|
+
@host_public_key = data[:host_public_key]
|
22
|
+
@suspended_action = data[:suspended_action]
|
22
23
|
end
|
23
24
|
|
24
25
|
def validate!(data)
|
@@ -25,9 +25,6 @@ module Proxy::RemoteExecution::Ssh
|
|
25
25
|
@logger.debug("initalizing command [#{@command}]")
|
26
26
|
open_connector
|
27
27
|
remote_script = cp_script_to_remote
|
28
|
-
if @command.effective_user && @command.effective_user != @command.ssh_user
|
29
|
-
su_prefix = "su - #{@command.effective_user} -c "
|
30
|
-
end
|
31
28
|
output_path = File.join(File.dirname(remote_script), 'output')
|
32
29
|
|
33
30
|
# pipe the output to tee while capturing the exit code
|
@@ -37,6 +34,7 @@ module Proxy::RemoteExecution::Ssh
|
|
37
34
|
exec 4>&-
|
38
35
|
exit $exit_code
|
39
36
|
SCRIPT
|
37
|
+
@logger.debug("executing script:\n#{script.lines.map { |line| " | #{line}" }.join}")
|
40
38
|
@connector.async_run(script) do |data|
|
41
39
|
@command_buffer << data
|
42
40
|
end
|
@@ -104,6 +102,18 @@ module Proxy::RemoteExecution::Ssh
|
|
104
102
|
|
105
103
|
private
|
106
104
|
|
105
|
+
def su_prefix
|
106
|
+
return if @command.effective_user.nil? || @command.effective_user == @command.ssh_user
|
107
|
+
case @command.effective_user_method
|
108
|
+
when 'sudo'
|
109
|
+
"sudo -n -u #{@command.effective_user} "
|
110
|
+
when 'su'
|
111
|
+
"su - #{@command.effective_user} -c "
|
112
|
+
else
|
113
|
+
raise "effective_user_method ''#{@command.effective_user_method}'' not supported"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
107
117
|
def open_connector
|
108
118
|
raise 'Connector already opened' if @connector
|
109
119
|
options = { :logger => @logger }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_remote_execution_ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|