mmotw 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/bang.gemspec +24 -0
- data/bin/bang +178 -0
- data/lib/bang.rb +5 -0
- data/lib/bang/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1321310b4fb00182be9be4a58adcd9c394f64e17
|
4
|
+
data.tar.gz: 15daf0e085d684e916641a195e73c9884b3c42fd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d63e5eb0a0735fd7303883617c67ef837efc0827e235450bfcbe25c700ecf6f84ce5b8117f6e4c3d3700ec9b46623c93c2767ad8186f5dedd973b077da67fb3e
|
7
|
+
data.tar.gz: 018011e44f4ecd3427b04f8482e4aeee404b263a431b70498681248a61f083ff72bb3461ec21cc5f58e1f704925e2799006e72c4b45f39809f045aaf6b9e12ee
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Marc Held
|
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
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Bang
|
2
|
+
|
3
|
+
Queries AWS for running instances, then connects you to the one you want (via ssh or mosh) so that you don't have to keep everything in your head
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bang'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bang
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Make sure that these three environment variables are set
|
22
|
+
export AWS_ACCESS_KEY_ID='...''
|
23
|
+
export AWS_SECRET_ACCESS_KEY='...'
|
24
|
+
export AWS_IDENTITY='...' (your pem file)
|
25
|
+
|
26
|
+
We also look at AWS_REGION, but it's not mandatory to set (us-west-2 by default)
|
27
|
+
|
28
|
+
Then just run 'bang'
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
37
|
+
|
38
|
+
|
39
|
+
## Features/problems:
|
40
|
+
|
41
|
+
- 'm' when highlighting a machine will mosh you to it.
|
42
|
+
- 's' or enter will ssh you to that machine.
|
43
|
+
- 'q' will close bang.
|
44
|
+
|
45
|
+
- Only looks at one PEM at a time
|
46
|
+
- Only looks at one region at a time
|
47
|
+
- Only does ubuntu@IP_ADDRESS machines
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bang.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bang/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mmotw"
|
8
|
+
spec.version = Bang::VERSION
|
9
|
+
spec.authors = ["Marc Held"]
|
10
|
+
spec.email = ["marc@weft.io"]
|
11
|
+
spec.description = %q{Queries AWS for running instances, then connects you to the one you want (via ssh or mosh) so that you don't have to keep everything in your head}
|
12
|
+
spec.summary = %q{ssh/mosh to a list of your running AWS instances}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = ["bang"]
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "aws"
|
24
|
+
end
|
data/bin/bang
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
puts "running BANG"
|
4
|
+
require 'bang'
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'ostruct'
|
8
|
+
require 'date'
|
9
|
+
|
10
|
+
require 'aws'
|
11
|
+
require 'curses'
|
12
|
+
|
13
|
+
include Curses
|
14
|
+
|
15
|
+
noecho
|
16
|
+
init_screen
|
17
|
+
start_color
|
18
|
+
stdscr.keypad(true)
|
19
|
+
|
20
|
+
class App
|
21
|
+
VERSION = '0.0.1'
|
22
|
+
|
23
|
+
attr_reader :options
|
24
|
+
|
25
|
+
def initialize(arguments, stdin)
|
26
|
+
@arguments = arguments
|
27
|
+
@stdin = stdin
|
28
|
+
|
29
|
+
@position = 0
|
30
|
+
@instances = []
|
31
|
+
@machines = []
|
32
|
+
|
33
|
+
@options = OpenStruct.new
|
34
|
+
@options.verbose = false
|
35
|
+
@options.quiet = false
|
36
|
+
@options.access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
37
|
+
@options.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
38
|
+
@options.region = ENV['AWS_REGION'] || "us-west-2"
|
39
|
+
@options.identity = ENV['AWS_IDENTITY']
|
40
|
+
end
|
41
|
+
|
42
|
+
# Parse options, check arguments, then process the command
|
43
|
+
def run
|
44
|
+
if parsed_options? && arguments_valid?
|
45
|
+
puts "Start at #{DateTime.now}\n\n" if @options.verbose
|
46
|
+
|
47
|
+
output_options if @options.verbose # [Optional]
|
48
|
+
|
49
|
+
process_arguments
|
50
|
+
process_command
|
51
|
+
|
52
|
+
puts "\nFinished at #{DateTime.now}" if @options.verbose
|
53
|
+
else
|
54
|
+
output_usage
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def draw_menu(menu, active_index=nil)
|
61
|
+
@machines.each_with_index do |machine, i|
|
62
|
+
menu.setpos(i + 1, 1)
|
63
|
+
menu.attrset(i == active_index ? A_STANDOUT : A_NORMAL)
|
64
|
+
menu.addstr machine[:name]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def draw_info(menu, text)
|
69
|
+
menu.setpos(1, 10)
|
70
|
+
menu.attrset(A_NORMAL)
|
71
|
+
menu.addstr text
|
72
|
+
end
|
73
|
+
|
74
|
+
def parsed_options?
|
75
|
+
opts = OptionParser.new
|
76
|
+
opts.on('-v', '--version') { output_version ; exit 0 }
|
77
|
+
opts.on('-h', '--help') { output_help }
|
78
|
+
opts.on('-V', '--verbose') { @options.verbose = true }
|
79
|
+
opts.on('-q', '--quiet') { @options.quiet = true }
|
80
|
+
|
81
|
+
opts.parse!(@arguments) rescue return false
|
82
|
+
|
83
|
+
process_options
|
84
|
+
true
|
85
|
+
end
|
86
|
+
|
87
|
+
# Performs post-parse processing on options
|
88
|
+
def process_options
|
89
|
+
@options.verbose = false if @options.quiet
|
90
|
+
end
|
91
|
+
|
92
|
+
def output_options
|
93
|
+
puts "Options:\n"
|
94
|
+
|
95
|
+
@options.marshal_dump.each do |name, val|
|
96
|
+
puts " #{name} = #{val}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# True if required arguments were provided
|
101
|
+
def arguments_valid?
|
102
|
+
true if (@arguments.length == 0 && @options.identity)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Setup the arguments
|
106
|
+
def process_arguments
|
107
|
+
AWS.config(
|
108
|
+
access_key_id: @options.access_key_id,
|
109
|
+
secret_access_key: @options.secret_access_key,
|
110
|
+
region: @options.region
|
111
|
+
)
|
112
|
+
@ec2 = AWS.ec2
|
113
|
+
@instances = @ec2.instances
|
114
|
+
@machines = @instances.map do |i|
|
115
|
+
ip = i.public_ip_address
|
116
|
+
{
|
117
|
+
name: "#{ip} - #{i.tags.first[1]}",
|
118
|
+
ip: ip
|
119
|
+
}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def output_help
|
124
|
+
output_version
|
125
|
+
puts "make sure you have AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_IDENTITY set"
|
126
|
+
exit
|
127
|
+
end
|
128
|
+
|
129
|
+
def output_usage
|
130
|
+
#RDoc::usage('usage') # gets usage from comments above
|
131
|
+
puts "make sure you have AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_IDENTITY set"
|
132
|
+
end
|
133
|
+
|
134
|
+
def output_version
|
135
|
+
puts "#{File.basename(__FILE__)} version #{VERSION}"
|
136
|
+
end
|
137
|
+
|
138
|
+
def mosh(pos)
|
139
|
+
clear
|
140
|
+
close_screen
|
141
|
+
exec "mosh --ssh=\"ssh -i #{@options.identity}\" ubuntu@#{@machines[pos][:ip]}"
|
142
|
+
end
|
143
|
+
|
144
|
+
def ssh(pos)
|
145
|
+
clear
|
146
|
+
close_screen
|
147
|
+
exec "ssh -i #{@options.identity} ubuntu@#{@machines[pos][:ip]}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def process_command
|
151
|
+
menu = Window.new(@machines.count+1, 80, 0, 0)
|
152
|
+
draw_menu(menu, @position)
|
153
|
+
|
154
|
+
while ch = menu.getch
|
155
|
+
case ch
|
156
|
+
when Curses::Key::UP, 'A', 'p' # WTF?
|
157
|
+
@position -= 1
|
158
|
+
when Curses::Key::DOWN, 'B', 'n'
|
159
|
+
@position += 1
|
160
|
+
when Curses::Key::ENTER, 343, 10
|
161
|
+
ssh @position
|
162
|
+
when 'm'
|
163
|
+
mosh @position
|
164
|
+
when 's'
|
165
|
+
ssh @position
|
166
|
+
when 'x', 'q'
|
167
|
+
exit
|
168
|
+
end
|
169
|
+
@position = @machines.count-1 if @position < 0
|
170
|
+
@position = 0 if @position > @machines.count-1
|
171
|
+
|
172
|
+
draw_menu(menu, @position)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
app = App.new(ARGV, STDIN)
|
178
|
+
app.run
|
data/lib/bang/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mmotw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marc Held
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
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.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.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: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Queries AWS for running instances, then connects you to the one you want
|
56
|
+
(via ssh or mosh) so that you don't have to keep everything in your head
|
57
|
+
email:
|
58
|
+
- marc@weft.io
|
59
|
+
executables:
|
60
|
+
- bang
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bang.gemspec
|
70
|
+
- bin/bang
|
71
|
+
- lib/bang.rb
|
72
|
+
- lib/bang/version.rb
|
73
|
+
homepage: ''
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: ssh/mosh to a list of your running AWS instances
|
97
|
+
test_files: []
|