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: 693eb26a2679a69e02ec7c5e401f658fe0bf1f7a
4
- data.tar.gz: 234e8b042f480d0b6b9f25ce67a5c3a623b6a059
3
+ metadata.gz: 430cb5229929d0abcef9ba104bf70aca67b7e06a
4
+ data.tar.gz: 50cb20d7b4ee75361a572c05da9ba4c26b7daad0
5
5
  SHA512:
6
- metadata.gz: 43f34e39548c1a7e3c06e6e916a0b1207047b06443d29bd27ff5a017b0a8d964a58389d081d5dc2b774bfc620e0f74f010d52aceffbede87687f6342380d6357
7
- data.tar.gz: 4ea377499214e59d5e453caed9cd68f13f45e053cf35c4dd0e2f8fa2b2cc176fc0a80677b2427a3f164701b5b622fd56d6eb75c59177b60adf3d3d068e575bfe
6
+ metadata.gz: 770257268b2797af8a5d2d120896a78818013ba09cc158126c12872d55eb4433df0f4ce3dcc35cb8e47297f6414b4701b4a42a303211011d10c519460038bfb8
7
+ data.tar.gz: d2bf596d92084d0fe841f36fed886e75b9d821332bb181b4869cae6d542324bc5793c1e026370d3f4abdd5971ff61162f8b8b5c15d7639c7f311971da151542f
@@ -44,6 +44,7 @@ class Chef
44
44
  pkg_options[:verbose] = config[:verbose] || config[:dry_run] || config[:pkg_verbose]
45
45
  pkg_options[:dry_run] = config[:dry_run]
46
46
  pkg_options[:yes] = config[:yes]
47
+ pkg_options[:password] = config[:ssh_password]
47
48
  pkg_options
48
49
  end
49
50
 
@@ -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
- stdout_data += data
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|
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Pkg
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -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
- ShellCommand.stub(:exec).with(cmd, p.session).and_return(r)
34
- expect(ShellCommand).to receive(:exec).with(cmd, p.session)
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.2.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-19 00:00:00.000000000 Z
11
+ date: 2013-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef