capistrano-different-password 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -1
- data/lib/capistrano-different-password.rb +51 -49
- data/lib/capistrano-different-password/version.rb +1 -1
- metadata +2 -3
data/README.md
CHANGED
@@ -18,8 +18,9 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
*capfile*
|
22
22
|
|
23
|
+
```ruby
|
23
24
|
require 'capistrano-different-password'
|
24
25
|
|
25
26
|
set :user,'user'
|
@@ -27,6 +28,13 @@ set :password,"PasSworD"
|
|
27
28
|
|
28
29
|
role :admin,"127.0.0.1","127.0.0.2",["127.0.0.3","DifferentPasSwOrd"]
|
29
30
|
|
31
|
+
task :sometask,role: :admin do
|
32
|
+
run 'date'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
cap sometask
|
37
|
+
|
30
38
|
## Contributing
|
31
39
|
|
32
40
|
1. Fork it
|
@@ -1,69 +1,71 @@
|
|
1
1
|
require "capistrano-different-password/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module ::Capistrano
|
4
|
+
class ServerDefinition
|
5
|
+
attr_reader :password
|
6
|
+
def initialize(server, options={})
|
7
|
+
if server.is_a? Array
|
8
|
+
@password = server[1]
|
9
|
+
server = server[0]
|
10
|
+
end
|
11
|
+
@user, @host, @port = server.match(/^(?:([^;,:=]+)@|)(.*?)(?::(\d+)|)$/)[1,3]
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
@options = options.dup
|
14
|
+
user_opt, port_opt = @options.delete(:user), @options.delete(:port)
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
@user ||= user_opt
|
17
|
+
@port ||= port_opt
|
17
18
|
|
18
|
-
|
19
|
+
@port = @port.to_i if @port
|
20
|
+
end
|
19
21
|
end
|
20
|
-
end
|
21
22
|
|
22
|
-
class
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
class SSH
|
24
|
+
def self.connection_strategy(server, options={}, &block)
|
25
|
+
methods = [ %w(publickey hostbased), %w(password keyboard-interactive) ]
|
26
|
+
password_value = nil
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
# construct the hash of ssh options that should be passed more-or-less
|
29
|
+
# directly to Net::SSH. This will be the general ssh options, merged with
|
30
|
+
# the server-specific ssh-options.
|
31
|
+
ssh_options = (options[:ssh_options] || {}).merge(server.options[:ssh_options] || {})
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
# load any SSH configuration files that were specified in the SSH options. This
|
34
|
+
# will load from ~/.ssh/config and /etc/ssh_config by default (see Net::SSH
|
35
|
+
# for details). Merge the explicitly given ssh_options over the top of the info
|
36
|
+
# from the config file.
|
37
|
+
ssh_options = Net::SSH.configuration_for(server.host, ssh_options.fetch(:config, true)).merge(ssh_options)
|
37
38
|
|
38
|
-
|
39
|
-
|
39
|
+
# Once we've loaded the config, we don't need Net::SSH to do it again.
|
40
|
+
ssh_options[:config] = false
|
40
41
|
|
41
|
-
|
42
|
+
ssh_options[:verbose] = :debug if options[:verbose] && options[:verbose] > 0
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
user = server.user || options[:user] || ssh_options[:username] ||
|
45
|
+
ssh_options[:user] || ServerDefinition.default_user
|
46
|
+
port = server.port || options[:port] || ssh_options[:port]
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
# the .ssh/config file might have changed the host-name on us
|
49
|
+
host = ssh_options.fetch(:host_name, server.host)
|
49
50
|
|
50
|
-
|
51
|
+
ssh_options[:port] = port if port
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
# delete these, since we've determined which username to use by this point
|
54
|
+
ssh_options.delete(:username)
|
55
|
+
ssh_options.delete(:user)
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
begin
|
58
|
+
connection_options = ssh_options.merge(
|
59
|
+
:password => password_value,
|
60
|
+
:auth_methods => ssh_options[:auth_methods] || methods.shift
|
61
|
+
)
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
yield host, user, connection_options
|
64
|
+
rescue Net::SSH::AuthenticationFailed
|
65
|
+
raise if methods.empty? || ssh_options[:auth_methods]
|
66
|
+
password_value = server.password || options[:password]
|
67
|
+
retry
|
68
|
+
end
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-different-password
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: This gem make you can use different password with capistrano.
|
15
15
|
email:
|
@@ -51,4 +51,3 @@ signing_key:
|
|
51
51
|
specification_version: 3
|
52
52
|
summary: This gem make you can use different password with capistrano.
|
53
53
|
test_files: []
|
54
|
-
has_rdoc:
|