knife-pkg 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 430cb5229929d0abcef9ba104bf70aca67b7e06a
|
4
|
+
data.tar.gz: 50cb20d7b4ee75361a572c05da9ba4c26b7daad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 770257268b2797af8a5d2d120896a78818013ba09cc158126c12872d55eb4433df0f4ce3dcc35cb8e47297f6414b4701b4a42a303211011d10c519460038bfb8
|
7
|
+
data.tar.gz: d2bf596d92084d0fe841f36fed886e75b9d821332bb181b4869cae6d542324bc5793c1e026370d3f4abdd5971ff61162f8b8b5c15d7639c7f311971da151542f
|
data/lib/chef/knife/pkg_base.rb
CHANGED
@@ -151,13 +151,20 @@ module Knife
|
|
151
151
|
|
152
152
|
## ++ methods to implement
|
153
153
|
|
154
|
-
|
155
154
|
def sudo
|
156
|
-
@options[:sudo] ? 'sudo ' : ''
|
155
|
+
@options[:sudo] ? 'sudo -p \'knife sudo password: \' ' : ''
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_password
|
159
|
+
@@password ||= prompt_for_password
|
160
|
+
end
|
161
|
+
|
162
|
+
def prompt_for_password(prompt = "Enter your password: ")
|
163
|
+
@ui.ask(prompt) { |q| q.echo = false }
|
157
164
|
end
|
158
165
|
|
159
166
|
def exec(cmd)
|
160
|
-
ShellCommand.exec(cmd, @session)
|
167
|
+
ShellCommand.exec(cmd, @session, get_password)
|
161
168
|
end
|
162
169
|
|
163
170
|
def max_pkg_cache_age
|
@@ -18,16 +18,21 @@ module Knife
|
|
18
18
|
module Pkg
|
19
19
|
class ShellCommand
|
20
20
|
|
21
|
-
def self.exec(cmd, session)
|
21
|
+
def self.exec(cmd, session, password = '')
|
22
22
|
|
23
23
|
stdout_data, stderr_data = "", ""
|
24
24
|
exit_code, exit_signal = nil, nil
|
25
25
|
session.open_channel do |channel|
|
26
|
+
channel.request_pty
|
26
27
|
channel.exec(cmd) do |_, success|
|
27
28
|
raise RuntimeError, "Command \"#{@cmd}\" could not be executed!" if !success
|
28
|
-
|
29
29
|
channel.on_data do |_, data|
|
30
|
-
|
30
|
+
if data =~ /^knife sudo password: /
|
31
|
+
Chef::Log.debug("sudo password required, sending password")
|
32
|
+
channel.send_data(password + "\n")
|
33
|
+
else
|
34
|
+
stdout_data += data
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
channel.on_extended_data do |_,_,data|
|
data/lib/knife-pkg/version.rb
CHANGED
@@ -15,7 +15,7 @@ describe 'PackageController' do
|
|
15
15
|
describe '#sudo' do
|
16
16
|
it 'should return sudo prefix' do
|
17
17
|
p = PackageController.new(nil, nil, :sudo => true)
|
18
|
-
expect(p.sudo).to eq("sudo ")
|
18
|
+
expect(p.sudo).to eq("sudo -p 'knife sudo password: ' ")
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should return no sudo prefix' do
|
@@ -27,15 +27,27 @@ describe 'PackageController' do
|
|
27
27
|
describe '#exec' do
|
28
28
|
it 'should call ShellCommand and return a ShellCommandResult' do
|
29
29
|
p = PackageController.new(nil, 'a')
|
30
|
+
p.ui = @ui
|
30
31
|
cmd = "ls -l"
|
31
32
|
r = Struct.new(:stdout, :stderr)
|
32
33
|
result = r.new('a', 'b')
|
33
|
-
|
34
|
-
|
34
|
+
p.stub(:get_password).and_return('test')
|
35
|
+
ShellCommand.stub(:exec).with(cmd, p.session, p.get_password).and_return(r)
|
36
|
+
expect(ShellCommand).to receive(:exec).with(cmd, p.session, p.get_password)
|
35
37
|
expect(p.exec(cmd)).to eq(r)
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
41
|
+
describe '#get_password' do
|
42
|
+
it 'should prompt for password only the first time' do
|
43
|
+
p = PackageController.new(nil, 'a')
|
44
|
+
p.ui = @ui
|
45
|
+
p.ui.stub(:ask).and_return('test')
|
46
|
+
expect(p).to receive(:prompt_for_password).exactly(1).times
|
47
|
+
p.get_password
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
39
51
|
describe '.init_controller' do
|
40
52
|
it 'should initialize the right package controller if node[:platform_family] is not set' do
|
41
53
|
node = Hash.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-pkg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Holger Amann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|