cloudflock 0.7.1 → 0.7.2

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: 421fa1e64759c72ef901ee7431000811e635e4d1
4
- data.tar.gz: 570f428da5e21ae71020b3eaf6d9e93a5c5a9e9c
3
+ metadata.gz: 5caf060aa6dffa12338aee4f8e6bc50a7d924ca0
4
+ data.tar.gz: 7dc01d5bb4c01a7037bc848e8d46911da697c5e3
5
5
  SHA512:
6
- metadata.gz: 444ea7d4d45b7d614f41005f69e606d32d8a92a0e44d0f75d7291e14770acf75af8799cd45d88b216f6c13f6dcb3f67495844c85393ddf3c799c83aab032a76a
7
- data.tar.gz: 30714d89645a257a8bc7481d05d5700a8d54f433d484335b7caabc24c3464a35d735e5d15d5f77fbd2e465c0bed6d00f60c2a5a4bdbe309911f8c9b0c0f2ed78
6
+ metadata.gz: 78c8c3e2a955ce7b0cbf0d201121f4ff3c8c6186079955657b23c4a5cbe53ffdbcab0e175805f068037a0a848c54d74b48973d098af4352c3888110126a37690
7
+ data.tar.gz: 77435605a9983bc72686a472b948a8ce061ba4387fe5f551dbd58cbe8de40d122c7f7742168296ae6af112101d5b5959d5a883fb6b63562bdc02f0149a57cd46
@@ -71,8 +71,8 @@ module CloudFlock; module App
71
71
  check_option(host, :hostname, "#{name} host")
72
72
  check_option(host, :port, "#{name} SSH port", default_answer: '22')
73
73
  check_option(host, :username, "#{name} username", default_answer: 'root')
74
- check_option(host, :password, "#{name} password",
75
- default_answer: '', allow_empty: true)
74
+ check_option_pw(host, :password, "#{name} password",
75
+ default_answer: '', allow_empty: true)
76
76
 
77
77
  key_path = File.join(Dir.home, '.ssh', 'id_rsa')
78
78
  key_path = '' unless File.exists?(key_path)
@@ -87,7 +87,7 @@ module CloudFlock; module App
87
87
  if host[:username] == 'root' || host[:sudo]
88
88
  host[:root_password] = host[:password]
89
89
  else
90
- check_option(host, :root_password, 'Password for root')
90
+ check_option_pw(host, :root_password, 'Password for root')
91
91
  end
92
92
 
93
93
  host
@@ -44,6 +44,24 @@ module CloudFlock
44
44
  options[name] = UI.prompt_filesystem(prompt, prompt_options)
45
45
  end
46
46
 
47
+ # Public: Wrap check_option, disabling local echo for password entry if the
48
+ # option is not set.
49
+ #
50
+ # options - Hash containing options to test against.
51
+ # name - The key in the options Hash expected to contain the
52
+ # response desired.
53
+ # prompt - Prompt to present to the user.
54
+ # prompt_options - Options to pass along to ConsoleGlitter::UI#prompt.
55
+ # (default: {})
56
+ #
57
+ # Returns the contents of the options[name] or else a String if
58
+ # options[name] is nil.
59
+ def check_option_pw(options, name, prompt, prompt_options = {})
60
+ return options[name] unless options[name].nil?
61
+
62
+ options[name] = UI.secure_prompt(prompt, prompt_options)
63
+ end
64
+
47
65
  # Public: Check if an option is set; return the value if so, otherwise
48
66
  # prompt the user for a response.
49
67
  #
@@ -7,7 +7,8 @@ module CloudFlock
7
7
 
8
8
  module Remote
9
9
  class SSH
10
- class InvalidHostname < StandardError; end
10
+ class InvalidHostname < StandardError; end
11
+ class SSHCannotConnect < StandardError; end
11
12
  end
12
13
  end
13
14
  end
@@ -10,8 +10,9 @@ module CloudFlock
10
10
  module Remote
11
11
  class SSH
12
12
  module Errstr
13
- NOHOST = 'No host specified'
14
- INVALID_HOST = 'Unable to look up host: %s'
13
+ NOHOST = 'No host specified'
14
+ INVALID_HOST = 'Unable to look up host: %s'
15
+ CANNOT_CONNECT = 'Unable to connect to host: %s'
15
16
  end
16
17
  end
17
18
  end
@@ -21,6 +21,9 @@ module CloudFlock; module Remote
21
21
  '-o ConnectTimeout=15 ' \
22
22
  '-o ServerAliveInterval=30'
23
23
 
24
+ # Public: Hash containing always-set options for Net::SSH
25
+ NET_SSH_OPTIONS = { user_known_hosts_file: '/dev/null', paranoid: false }
26
+
24
27
  # Public: Prompt to be set on a host upon successful login.
25
28
  PROMPT = '@@CLOUDFLOCK@@'
26
29
 
@@ -57,6 +60,7 @@ module CloudFlock; module Remote
57
60
  def initialize(args = {})
58
61
  @options = sanitize_arguments(DEFAULT_ARGS.merge(args))
59
62
  start_session
63
+ start_keepalive_thread
60
64
  end
61
65
 
62
66
  # Public: Return the hostname of the host.
@@ -236,7 +240,7 @@ module CloudFlock; module Remote
236
240
  # :key_passphrase defined.
237
241
  def filter_ssh_options(args)
238
242
  valid_arguments = [:port, :password, :key_data, :key_passphrase]
239
- args.select { |opt| valid_arguments.include? opt }
243
+ args.select { |opt| valid_arguments.include? opt }.merge(NET_SSH_OPTIONS)
240
244
  end
241
245
 
242
246
  # Internal: Resolve the hostname provided and return the network address to
@@ -259,9 +263,31 @@ module CloudFlock; module Remote
259
263
  # Sets @ssh.
260
264
  #
261
265
  # Returns nothing.
266
+ #
267
+ # Raises TooManyRetries if retry_count is greater than 4.
262
268
  def start_session
263
269
  ssh_opts = filter_ssh_options(options)
264
270
  @ssh = Net::SSH.start(options[:hostname], options[:username], ssh_opts)
271
+ rescue Net::SSH::Disconnect
272
+ retry_count = retry_count.to_i + 1
273
+ sleep 30 and retry if retry_count < 5
274
+ raise(SSHCannotConnect, Errstr::CANNOT_CONNECT % options[:hostname])
275
+ end
276
+
277
+ # Internal: Creates a thread which sends a keepalive message every 10
278
+ # seconds.
279
+ #
280
+ # Sets @keepalive.
281
+ #
282
+ # Returns nothing.
283
+ def start_keepalive_thread
284
+ @keepalive.kill if @keepalive.is_a?(Thread)
285
+ @keepalive = Thread.new do
286
+ loop do
287
+ sleep 10
288
+ @ssh.send_global_request('keepalive@openssh.com')
289
+ end
290
+ end
265
291
  end
266
292
  end
267
293
  end; end
data/lib/cloudflock.rb CHANGED
@@ -4,5 +4,5 @@ require 'cloudflock/errstr'
4
4
  # Public: Encapsulate all functionality related to the CloudFlock API and any
5
5
  # apps built with such.
6
6
  module CloudFlock
7
- VERSION = '0.7.1'
7
+ VERSION = '0.7.2'
8
8
  end
metadata CHANGED
@@ -1,29 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudflock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wuest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-07 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog-json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: fog
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.21'
33
+ version: '1.22'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.22.1
20
37
  type: :runtime
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
24
41
  - - "~>"
25
42
  - !ruby/object:Gem::Version
26
- version: '1.21'
43
+ version: '1.22'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.22.1
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: cpe
29
49
  requirement: !ruby/object:Gem::Requirement