awssh 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/awssh/command.rb +71 -29
- data/lib/awssh/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7813fbd643c47e30330aa13e8df8c830694833a2
|
4
|
+
data.tar.gz: fa612f8c10bfc39b2b111ff8c89e702594c61071
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc4a46a8e7e69672c8165af90b92ea1c5f9b7dcfc3c76bbeac97737318ca60424dc27fd1a4ee12011bae3b63aaa8e394d1411e4453ce5fb45893638a6bc8cd80
|
7
|
+
data.tar.gz: 77f3cd627766fe012459567f412ee9f6030ecb01501cd1ded42fa1c121435b92a80b5fc088522609040beb4062c45305b690bc1f2160bcc5a422d21fba466b35
|
data/lib/awssh/command.rb
CHANGED
@@ -6,6 +6,7 @@ module Awssh
|
|
6
6
|
config: '~/.awssh',
|
7
7
|
multi: false,
|
8
8
|
test: false,
|
9
|
+
list: false,
|
9
10
|
}
|
10
11
|
@config = {
|
11
12
|
multi: 'csshX',
|
@@ -14,7 +15,9 @@ module Awssh
|
|
14
15
|
user: nil,
|
15
16
|
key: 'AWS ACCESS KEY ID',
|
16
17
|
secret: 'AWS SECRET ACCESS KEY',
|
17
|
-
domain: 'example.com'
|
18
|
+
domain: 'example.com',
|
19
|
+
cache: '~/.awssh.cache',
|
20
|
+
expires: 1.day
|
18
21
|
}.stringify_keys
|
19
22
|
|
20
23
|
@config_file = File.expand_path(@options[:config])
|
@@ -58,6 +61,14 @@ module Awssh
|
|
58
61
|
opts.on('-u', '--user', 'override user setting') do |u|
|
59
62
|
@config['user'] = u
|
60
63
|
end
|
64
|
+
opts.on('-l', '--list', 'just list servers') do |l|
|
65
|
+
@options[:list] = true
|
66
|
+
end
|
67
|
+
opts.on('-U', '--update', 'just update the cache') do |u|
|
68
|
+
@options[:update] = true
|
69
|
+
get_servers
|
70
|
+
exit 0
|
71
|
+
end
|
61
72
|
end.parse!(argv)
|
62
73
|
|
63
74
|
@search = argv
|
@@ -70,22 +81,22 @@ module Awssh
|
|
70
81
|
end
|
71
82
|
|
72
83
|
def connect
|
73
|
-
@servers =
|
84
|
+
@servers = find_servers
|
74
85
|
|
75
|
-
|
76
|
-
|
77
|
-
puts "- #{s}"
|
78
|
-
end if @options[:verbose]
|
79
|
-
|
80
|
-
if @servers.count == 0
|
81
|
-
puts "no servers found"
|
82
|
-
exit 1
|
86
|
+
if @options[:verbose] || @options[:list]
|
87
|
+
print_list
|
83
88
|
end
|
89
|
+
return if @options[:list]
|
84
90
|
|
85
91
|
if @servers.count > 1 && !@options[:multi]
|
92
|
+
print_list
|
86
93
|
puts "more than one server found, and multi is false"
|
87
94
|
puts "set the -m flag to connect to more than one matched server"
|
88
|
-
|
95
|
+
exit 1
|
96
|
+
end
|
97
|
+
|
98
|
+
if @servers.count == 0
|
99
|
+
puts "no servers found"
|
89
100
|
exit 1
|
90
101
|
end
|
91
102
|
|
@@ -97,31 +108,62 @@ module Awssh
|
|
97
108
|
|
98
109
|
private
|
99
110
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
111
|
+
def print_list
|
112
|
+
puts "found: #{@servers.count}"
|
113
|
+
@servers.each do |s|
|
114
|
+
puts "- #{s}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def find_servers
|
119
|
+
servers = []
|
120
|
+
get_servers.each do |n|
|
121
|
+
fail = false
|
122
|
+
@search.each do |v|
|
123
|
+
if v =~ /^\^/
|
124
|
+
fail = true if n =~ /#{v.gsub(/^\^/, '')}/
|
125
|
+
else
|
126
|
+
fail = true unless n =~ /#{v}/
|
127
|
+
end
|
128
|
+
end
|
129
|
+
next if fail
|
130
|
+
servers << n
|
131
|
+
end
|
132
|
+
servers
|
133
|
+
end
|
103
134
|
|
135
|
+
def get_servers
|
136
|
+
list = get_cache do
|
137
|
+
server_names
|
138
|
+
end
|
104
139
|
puts "total servers: #{list.count}" if @options[:verbose]
|
140
|
+
list.sort
|
141
|
+
end
|
105
142
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
if
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
fail = true if n =~ /#{v.gsub(/^\^/, '')}/
|
114
|
-
else
|
115
|
-
fail = true unless n =~ /#{v}/
|
143
|
+
def get_cache
|
144
|
+
if @config['cache']
|
145
|
+
file = File.expand_path(@config['cache'])
|
146
|
+
if File.exists?(file)
|
147
|
+
unless @options[:update]
|
148
|
+
if Time.now - File.mtime(file) < @config['expires']
|
149
|
+
return YAML.load_file(file)
|
116
150
|
end
|
117
151
|
end
|
118
|
-
next if fail
|
119
|
-
servers << n
|
120
|
-
else
|
121
|
-
puts "server #{s.id} does not have a name"
|
122
152
|
end
|
153
|
+
puts "updating cache ..."
|
154
|
+
list = yield
|
155
|
+
File.open(file, "w+") { |f| f.write list.to_yaml }
|
156
|
+
return list
|
123
157
|
end
|
124
|
-
|
158
|
+
list = yield
|
159
|
+
return list
|
160
|
+
end
|
161
|
+
|
162
|
+
def server_names
|
163
|
+
puts "requesting servers ..."
|
164
|
+
@fog = Fog::Compute.new(provider: 'AWS', aws_access_key_id: @config['key'], aws_secret_access_key: @config['secret'], region: @config["region"])
|
165
|
+
list = @fog.servers.all
|
166
|
+
list.inject([]) { |a, e| a << e.tags['Name'] }
|
125
167
|
end
|
126
168
|
|
127
169
|
def get_command(servers)
|
data/lib/awssh/version.rb
CHANGED