awsssh 2.1.2 → 2.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 648cbadb1d6c7dd15e713214c94844497c9adae2
4
- data.tar.gz: 185e202c3b0220887cd20aec177328e0b148b9c1
3
+ metadata.gz: 4b63fb129a41f40f706decc85cd615a650050d9c
4
+ data.tar.gz: 65d9e9f45738dd2a61dbc6340213e5306a7067fa
5
5
  SHA512:
6
- metadata.gz: 44e2a2bab75ce69015abc3082703b913beb56cb69169d05d5af7c6acd738ff4b236e01015cd6efe045babd5bba7cd63bf203e3989b528565cff7023613555812
7
- data.tar.gz: 9bb50ad0de96bc4b7fed678e856f1f323fdab85b718077f1f6ba6d6b316f1004041ec3069082bfbf6f5956f8ef7d42ccc0ec5fb43e8cf456b2547baccd6bb2cb
6
+ metadata.gz: 0c4f6daf66995d090eccdc8748f0485816a5153e494c2ceeceef62928b2247d1ff282ca913e614f89b44423d370ca3ed294b3fb0b2358d49e5b41531f5cba50a
7
+ data.tar.gz: 99afa2c0f438f16472e39162ca15fcfd292ca06f0560d32804c93f821ad9a04cefc250fb00c3fa35ff2d061508f889daf57d615ebe18cbb3302c106e11ca3873
data/.gitignore CHANGED
@@ -1 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
1
15
  *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in awsssh.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sebastian Thiele
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -34,6 +34,9 @@ Zeigt die Hilfe an
34
34
  Sebastian Thiele Twitter: (@sebat)
35
35
 
36
36
  ## Changelog
37
+ **2015-03-02 - v 2.2.0**
38
+ * [enh] Alias for list servers and accounts changed
39
+ * [fix] Build own punlic DNS if no public dns is set
37
40
 
38
41
  **2014-08-01 - v 2.1.2**
39
42
  * [enh] Alias for `--list-servers` and `--list-accounts`
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -1,19 +1,30 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'awsssh'
3
- s.version = '2.1.2'
4
- s.date = '2014-08-01'
5
- s.summary = "Connects you with OpsWorks EC2"
6
- s.description = "This will connects you with an EC2 instace"
7
- s.authors = ["Sebastian Thiele"]
8
- s.email = [%w(Sebastian.Thiele infopark.de).join('@')]
9
- s.license = "MIT"
10
- s.files = `git ls-files`.split("\n")
11
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
- s.homepage = "https://github.com/sethiele/awsssh"
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'awsssh/version'
13
5
 
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "awsssh"
8
+ spec.version = Awsssh::VERSION
9
+ spec.authors = ["Sebastian Thiele"]
10
+ spec.email = [%w(Sebastian.Thiele infopark.de).join('@')]
11
+ spec.summary = "Connects you with OpsWorks EC2"
12
+ spec.description = "This will connects you with an EC2 instace"
13
+ spec.homepage = "https://github.com/sethiele/awsssh"
14
+ spec.license = "MIT"
14
15
 
15
- s.add_runtime_dependency "net-ssh", "2.7.0"
16
- s.add_runtime_dependency "inifile", "2.0.2"
17
- s.add_runtime_dependency "aws-sdk", "1.35.0"
18
- s.add_runtime_dependency "thor", "0.18.1"
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8.3"
22
+ spec.add_development_dependency "rake", "~> 10.4.2"
23
+ spec.add_development_dependency "pry", "~> 0.10.1"
24
+ spec.add_development_dependency "rspec", "~> 2.6"
25
+
26
+ spec.add_runtime_dependency "net-ssh", "2.7.0"
27
+ spec.add_runtime_dependency "inifile", "2.0.2"
28
+ spec.add_runtime_dependency "aws-sdk", "1.35.0"
29
+ spec.add_runtime_dependency "thor", "0.18.1"
19
30
  end
data/bin/awsssh CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "awsssh"
4
4
 
5
- Awsssh.start(ARGV)
5
+ Awsssh::Awsssh.start(ARGV)
@@ -1,194 +1,208 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
1
+ require "awsssh/version"
3
2
  require 'net/ssh'
4
3
  require 'json'
5
4
  require "aws-sdk"
6
- # require "pry"
5
+ # Bundler.require(:default, :development)
7
6
  require "inifile"
8
7
  require "thor"
9
8
 
10
- class Awsssh < Thor
11
- CONFIG_DIR = ENV['AWSSSH_CONFIG_DIR'] || "/Users/#{ENV['USER']}/.aws/"
12
- CONF_FILE = ENV['AWSSSH_CONFIG_FILE'] || "aws_config_"
9
+ module Awsssh
10
+ class Awsssh < Thor
11
+ CONFIG_DIR = ENV['AWSSSH_CONFIG_DIR'] || "/Users/#{ENV['USER']}/.aws/"
12
+ CONF_FILE = ENV['AWSSSH_CONFIG_FILE'] || "aws_config_"
13
13
 
14
- desc "-s SERVER [-a ACCOUNT]", "connect to a server"
15
- option :server, :aliases => '-s', :desc => "(required) The server name to connect with"
16
- option :account, :aliases => '-a', :desc => "Specify a account for a connection. Needet if the account don't came from the server name"
17
- option :list_accounts, :aliases => '-k', :type => :boolean, :desc => "List all Accounts"
18
- option :list_servers, :aliases => '-i', :desc => "List all Servers for a given Account", :banner => "ACCOUNT"
19
- # option :check_status, :alias => '-c', :type => :string, :desc => "Give information when the server status has changed to target.", :banner => "STATUS"
20
- long_desc <<-LONGDESC
21
- # Connect to a Server:
14
+ desc "-s SERVER [-a ACCOUNT]", "connect to a server"
15
+ option :server, :aliases => '-s', :desc => "(required) The server name to connect with"
16
+ option :account, :aliases => '-a', :desc => "Specify a account for a connection. Needet if the account don't came from the server name"
17
+ option :list, :aliases => '-l', :desc => "List any items use with -s for Servers or -a ACCOUNT for accounts", :type => :boolean
18
+ option :check, :aliases => '-c', :desc => "Alerts when -c STATE comes up for -s SERVER"
19
+ long_desc <<-LONGDESC
20
+ # Connect to a Server:
22
21
 
23
22
 
24
- > $ awsssh -s SERVER
25
- \x5 This will connect you to a Server. This will work only if the first part of the server name is the same as the account name.
23
+ > $ awsssh -s SERVER
24
+ \x5 This will connect you to a Server. This will work only if the first part of the server name is the same as the account name.
26
25
 
27
- > $ awsssh -s SERVER -a ACCOUNT
28
- \x5 With -a you can spezify a account to connect with. The server name don't play any role.
26
+ > $ awsssh -s SERVER -a ACCOUNT
27
+ \x5 With -a you can spezify a account to connect with. The server name don't play any role.
29
28
 
30
- # List all Account:
29
+ # List all Account:
31
30
 
32
- > $ awsssh [--list-accounts|-k]
33
- \x5 This will list all Accounts
31
+ > $ awsssh -l -a
32
+ \x5 This will list all Accounts
34
33
 
35
- # List all Servers for a Account
34
+ # List all Servers for a Account
36
35
 
37
- > $ awsssh [--list-servers|-i] ACCOUNT
38
- \x5 List all Servers vor Account ACCOUNT
36
+ > $ awsssh -l -a ACCOUNT
37
+ \x5 List all Servers vor Account ACCOUNT
39
38
 
40
- # Get notification when Server is in Status
39
+ # Check Server Status
41
40
 
42
- LONGDESC
43
- def connect
44
- if options[:server]
45
- connecting(options[:server], options[:account])
46
- elsif options[:list_accounts]
47
- list_accounts
48
- elsif options[:list_servers]
49
- list_servers(options[:list_servers])
50
- elsif options[:server]
51
- connecting(options[:server], options[:account])
52
- else
53
- help "connect"
41
+ LONGDESC
42
+ def connect
43
+ if options[:list] && options[:account]
44
+ list_accounts
45
+ elsif options[:list] && options[:server]
46
+ list_servers(options[:server])
47
+ elsif options[:server]
48
+ connecting(options[:server], options[:account])
49
+ else
50
+ help "connect"
51
+ end
54
52
  end
55
- end
56
53
 
57
- def help(*args)
58
- super("connect")
59
- end
54
+ def help(*args)
55
+ super("connect")
56
+ end
60
57
 
61
- private
62
- ##
63
- # List stacks for a account
64
- #
65
- # * *Args* :
66
- # - +account+ -> Account name
67
- #
68
- # * *Returns* :
69
- # - [Array] StackIDs
70
- def list_stacks(account)
71
- ow = awscfg(account)
72
- stacks = ow.client.describe_stacks[:stacks]
73
- stack_ids = []
74
- stacks.each do |stack|
75
- stack_ids << stack[:stack_id]
58
+ private
59
+
60
+ ##
61
+ # List stacks for a account
62
+ #
63
+ # * *Args* :
64
+ # - +account+ -> Account name
65
+ #
66
+ # * *Returns* :
67
+ # - [Array] StackIDs
68
+ def list_stacks(account)
69
+ ow = awscfg(account)
70
+ stacks = ow.client.describe_stacks[:stacks]
71
+ stack_ids = []
72
+ stacks.each do |stack|
73
+ stack_ids << stack[:stack_id]
74
+ end
75
+ return stack_ids
76
76
  end
77
- return stack_ids
78
- end
79
77
 
80
78
 
81
- ##
82
- # Read Stack
83
- #
84
- # * *Args* :
85
- # - +stackid+ -> Stack ID
86
- # - +account+ -> Account name
87
- #
88
- # * *Returns* :
89
- # - Stecks JSON
90
- #
91
- def read_stack(stackid, account)
92
- ow = awscfg(account)
93
- ow.client.describe_instances({:stack_id => stackid})
94
- # JSON.parse(`aws opsworks describe-instances --stack-id #{stackid}`)
95
- end
79
+ ##
80
+ # Read Stack
81
+ #
82
+ # * *Args* :
83
+ # - +stackid+ -> Stack ID
84
+ # - +account+ -> Account name
85
+ #
86
+ # * *Returns* :
87
+ # - Stecks JSON
88
+ #
89
+ def read_stack(stackid, account)
90
+ ow = awscfg(account)
91
+ ow.client.describe_instances({:stack_id => stackid})
92
+ # JSON.parse(`aws opsworks describe-instances --stack-id #{stackid}`)
93
+ end
96
94
 
97
- ##
98
- # Lists all AWS Accounts
99
- #
100
- # * *Returns* :
101
- # - [String]
102
- # This are the known AWS Accounts:
103
- # - account
104
- def list_accounts
105
- length = 30
106
- puts "This are the known AWS Accounts:"
107
- config_files = Dir.entries(CONFIG_DIR)
108
- config_files.each do |file|
109
- if file[0,CONF_FILE.length] == CONF_FILE
110
- file_part = file.split("_")
111
- unless file_part.last.nil?
112
- printf "\t- %-#{length}s\n", file_part[2]
95
+ ##
96
+ # Lists all AWS Accounts
97
+ #
98
+ # * *Returns* :
99
+ # - [String]
100
+ # This are the known AWS Accounts:
101
+ # - account
102
+ def list_accounts
103
+ length = 30
104
+ puts "This are the known AWS Accounts:"
105
+ config_files = Dir.entries(CONFIG_DIR)
106
+ config_files.each do |file|
107
+ if file[0,CONF_FILE.length] == CONF_FILE
108
+ file_part = file.split("_")
109
+ unless file_part.last.nil?
110
+ printf "\t- %-#{length}s\n", file_part[2]
111
+ end
113
112
  end
114
113
  end
115
114
  end
116
- end
117
115
 
118
- ##
119
- # Server Name
120
- #
121
- # * *Args* :
122
- # - +stack+ -> Stack as JSON
123
- #
124
- # * *Returns* :
125
- # - [String]
126
- # - <servername> (<status>)
127
- def server_name(stack)
128
- stack[:instances].each do |instance|
129
- printf "\t- %-20s %s\n", instance[:hostname], instance[:status]
116
+ ##
117
+ # Server Name
118
+ #
119
+ # * *Args* :
120
+ # - +stack+ -> Stack as JSON
121
+ #
122
+ # * *Returns* :
123
+ # - [String]
124
+ # - <servername> (<status>)
125
+ def server_name(stack)
126
+ stack[:instances].each do |instance|
127
+ host = build_hostname(instance)
128
+ printf "\t- %-20s %s \t %-15s \t %s\n", instance[:hostname], instance[:status], host[:ip], host[:hostname]
129
+ end
130
130
  end
131
- end
132
131
 
133
- ##
134
- # List all Servers for a given AWS Account
135
- #
136
- # * *Args* :
137
- # - +account+ -> AWS Account name
138
- #
139
- def list_servers(account)
140
- stacks = list_stacks account
141
- stacks.each do |stack_id|
142
- stack = read_stack stack_id, account
143
- server_name stack
132
+ ##
133
+ # List all Servers for a given AWS Account
134
+ #
135
+ # * *Args* :
136
+ # - +account+ -> AWS Account name
137
+ #
138
+ def list_servers(account)
139
+ stacks = list_stacks account
140
+ stacks.each do |stack_id|
141
+ stack = read_stack stack_id, account
142
+ server_name stack
143
+ end
144
144
  end
145
- end
146
145
 
147
- ##
148
- # Establish the connection
149
- #
150
- # * *Args* :
151
- # - +server+ -> Server name
152
- #
153
- def connecting(server, account=nil)
154
- public_dns = nil
155
- host = server.split("-")
156
- ac = account || host[0]
157
- stack_ids = list_stacks ac
158
- stack_ids.each do |stack_id|
159
- stack = read_stack(stack_id, ac)
160
- stack.instances.each do |i|
161
- if i[:hostname] == server
162
- public_dns = i[:public_dns]
163
- break
146
+ ##
147
+ # Establish the connection
148
+ #
149
+ # * *Args* :
150
+ # - +server+ -> Server name
151
+ #
152
+ def connecting(server, account=nil)
153
+ public_dns = nil
154
+ host = server.split("-")
155
+ ac = account || host[0]
156
+ stack_ids = list_stacks ac
157
+ stack_ids.each do |stack_id|
158
+ stack = read_stack(stack_id, ac)
159
+ stack.instances.each do |i|
160
+ if i[:hostname] == server
161
+ public_dns = build_hostname(i)[:hostname]
162
+ break
163
+ end
164
164
  end
165
+ break unless public_dns.nil?
165
166
  end
166
- break unless public_dns.nil?
167
- end
168
167
 
169
- if public_dns.nil?
170
- puts "Server '#{server}' not found. Try ssh"
171
- exec "ssh #{server}"
172
- exit -1
173
- end
168
+ if public_dns.nil?
169
+ puts "Server '#{server}' not found. Try ssh"
170
+ exec "ssh #{server}"
171
+ exit -1
172
+ end
174
173
 
175
- puts "Connecting to #{server} (#{public_dns})"
176
- exec "ssh #{public_dns}"
174
+ puts "Connecting to #{server} (#{public_dns})"
175
+ exec "ssh #{public_dns}"
177
176
 
178
- end
177
+ end
179
178
 
180
- def awscfg(account)
181
- if cnf = IniFile.load(CONFIG_DIR + CONF_FILE + account)
182
- cnf = cnf['default']
183
- return AWS::OpsWorks.new(
184
- access_key_id: cnf['aws_access_key_id'],
185
- secret_access_key: cnf['aws_secret_access_key'],
186
- region: cnf['region']
187
- )
188
- else
189
- puts "No config #{CONF_FILE}#{account} found. Maybe use -a to specify a account."
190
- exit -1
179
+ def build_hostname(instance)
180
+ host = {}
181
+ if instance[:status] != 'online'
182
+ host[:ip] = host[:hostname] = nil
183
+ return host
184
+ end
185
+ az = (instance[:availability_zone][-1].match(/[a-z]/)) ?
186
+ instance[:availability_zone][0..-2] :
187
+ instance[:availability_zone]
188
+ host[:ip] = instance[:public_ip] || instance[:elastic_ip]
189
+ host[:hostname] = "ec2-#{host[:ip].gsub("\.", "\-")}.#{az}.compute.amazonaws.com"
190
+ host
191
191
  end
192
- end
193
- default_task :connect
192
+
193
+ def awscfg(account)
194
+ if cnf = IniFile.load(CONFIG_DIR + CONF_FILE + account)
195
+ cnf = cnf['default']
196
+ return AWS::OpsWorks.new(
197
+ access_key_id: cnf['aws_access_key_id'],
198
+ secret_access_key: cnf['aws_secret_access_key'],
199
+ region: cnf['region']
200
+ )
201
+ else
202
+ puts "No config #{CONF_FILE}#{account} found. Maybe use -a to specify a account."
203
+ exit -1
204
+ end
205
+ end
206
+ default_task :connect
207
+ end
194
208
  end
@@ -0,0 +1,3 @@
1
+ module Awsssh
2
+ VERSION = "2.2.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ require "awsssh"
2
+ describe Awsssh::Awsssh do
3
+ def runner(options = {})
4
+ @runner ||= Awsssh::Awsssh.new([1], options, :destination_root => destination_root)
5
+ end
6
+
7
+ def action(*args, &block)
8
+ capture(:stdout) { runner.send(*args, &block) }
9
+ end
10
+
11
+ describe "on list stacks" do
12
+ it "lists all stacks" do
13
+ base = Awsssh::Awsssh.new ["-s"]
14
+ base.send(:list_stacks, 'trox').class.should eq [].class
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Thiele
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 10.4.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.4.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.6'
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: net-ssh
15
71
  requirement: !ruby/object:Gem::Requirement
@@ -75,10 +131,15 @@ extensions: []
75
131
  extra_rdoc_files: []
76
132
  files:
77
133
  - ".gitignore"
134
+ - Gemfile
135
+ - LICENSE.txt
78
136
  - README.md
137
+ - Rakefile
79
138
  - awsssh.gemspec
80
139
  - bin/awsssh
81
140
  - lib/awsssh.rb
141
+ - lib/awsssh/version.rb
142
+ - spec/awsssh_spec.rb
82
143
  homepage: https://github.com/sethiele/awsssh
83
144
  licenses:
84
145
  - MIT
@@ -99,8 +160,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
160
  version: '0'
100
161
  requirements: []
101
162
  rubyforge_project:
102
- rubygems_version: 2.4.1
163
+ rubygems_version: 2.2.2
103
164
  signing_key:
104
165
  specification_version: 4
105
166
  summary: Connects you with OpsWorks EC2
106
- test_files: []
167
+ test_files:
168
+ - spec/awsssh_spec.rb