eb-connect 0.1.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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/bin/eb-connect +6 -0
- data/eb-connect.gemspec +22 -0
- data/lib/eb-connect.rb +113 -0
- data/lib/eb-connect/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18ebd6a23005d0f0b1faaa3b6187fde3ed38187e
|
4
|
+
data.tar.gz: 10ccbbd962301d5585171d6a8d200b8864c99353
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ad22f7a558cabf3abd38647009f7fe731ad32d7014b41c8ed4ec8ff4c75f312225e1b5f75eac748a92ba1db5e8e1850697cd6ecdc01c6a0db813c50f7cc6d3d
|
7
|
+
data.tar.gz: 5f99df966914941f8be32fcf61e97fd2c6fdc563c71c1f876a3a7ccdff5fa557af20e7c1c9aec24c93b055b6f9dba12c8709920a49220a7c0ed744dd656372b2
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Spencer Ellinor
|
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,25 @@
|
|
1
|
+
# ElasticBeanstalk-Connect
|
2
|
+
|
3
|
+
Ease ElasticBeanstalk instance SSH connections
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it yourself as:
|
8
|
+
|
9
|
+
$ gem install eb-connect
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Run command:
|
14
|
+
|
15
|
+
$ eb-connect
|
16
|
+
|
17
|
+
And it'll handle the rest!
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it ( https://github.com/zpencerq/eb-connect/fork )
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/eb-connect
ADDED
data/eb-connect.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'eb-connect/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eb-connect"
|
8
|
+
spec.version = ElasticBeanstalk::VERSION
|
9
|
+
spec.authors = ["Spencer Ellinor"]
|
10
|
+
spec.summary = %q{Ease EB instance SSH connections}
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "aws-sdk", "~> 2"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
22
|
+
end
|
data/lib/eb-connect.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'eb-connect/version'
|
2
|
+
require 'aws-sdk'
|
3
|
+
|
4
|
+
module ElasticBeanstalk
|
5
|
+
class Driver
|
6
|
+
def initialize
|
7
|
+
Aws.config.update(region: 'us-east-1')
|
8
|
+
end
|
9
|
+
|
10
|
+
def ask?(question, options)
|
11
|
+
answer = nil
|
12
|
+
answer = options[0] if options.length == 1
|
13
|
+
|
14
|
+
while answer == nil
|
15
|
+
puts "",question
|
16
|
+
options
|
17
|
+
.each.with_index(1) do |option, idx|
|
18
|
+
puts "[#{idx}] #{option[:name]}"
|
19
|
+
end
|
20
|
+
print "Choose: "
|
21
|
+
input = gets.chomp.to_i
|
22
|
+
begin
|
23
|
+
answer = options[input-1]
|
24
|
+
rescue
|
25
|
+
puts "Invalid choice, please try again.\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
answer
|
29
|
+
end
|
30
|
+
|
31
|
+
def connect
|
32
|
+
begin
|
33
|
+
user = Aws::IAM::Client.new.get_user[:user]
|
34
|
+
rescue Aws::Errors::MissingCredentialsError
|
35
|
+
puts "Uh oh. AWS Credentials could not be found!", ""
|
36
|
+
puts "Do one of the following, then try eb-connect again:"
|
37
|
+
puts " * Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV"
|
38
|
+
puts " * Setup ~/.aws/credentials file"
|
39
|
+
return
|
40
|
+
rescue Errno::EHOSTDOWN
|
41
|
+
puts "AWS API is not responding, please wait and try again."
|
42
|
+
puts "You may be rate-limited."
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
puts "Welcome to EB-Connect!"
|
47
|
+
|
48
|
+
client = Aws::ElasticBeanstalk::Client.new
|
49
|
+
applications = client.describe_applications[:applications].map do |app|
|
50
|
+
{application_name: app[:application_name], name: app[:application_name]}
|
51
|
+
end.sort_by { |option| option[:name] }
|
52
|
+
|
53
|
+
application = ask?("Applications", applications)
|
54
|
+
environments = client.describe_environments(application_name: application[:application_name])[:environments].map do |environment|
|
55
|
+
{
|
56
|
+
environment_name: environment[:environment_name],
|
57
|
+
environment_id: environment[:environment_id],
|
58
|
+
name: environment[:environment_name]
|
59
|
+
}
|
60
|
+
end.sort_by { |option| option[:name] }
|
61
|
+
|
62
|
+
environment = ask?("Environments", environments)
|
63
|
+
instances = Aws::EC2::Client.new.describe_instances(
|
64
|
+
instance_ids: client.describe_environment_resources(
|
65
|
+
environment_id: environment[:environment_id],
|
66
|
+
environment_name: environment[:environment_name],
|
67
|
+
)[:environment_resources][:instances].map(&:id)
|
68
|
+
).flat_map(&:reservations).flat_map(&:instances)
|
69
|
+
.select do |instance|
|
70
|
+
instance.state.name == "running"
|
71
|
+
end
|
72
|
+
.each_with_index.map do |instance, idx|
|
73
|
+
name_tag = instance.tags.select do |tag| tag.key == "Name" end.first
|
74
|
+
ip = instance[:public_ip_address] ? instance[:public_ip_address] : instance[:private_ip_address]
|
75
|
+
|
76
|
+
{
|
77
|
+
instance_id: instance[:instance_id],
|
78
|
+
name: "#{name_tag ? name_tag.value : ""} (#{ip})",
|
79
|
+
ip: ip,
|
80
|
+
key_name: instance[:key_name],
|
81
|
+
}
|
82
|
+
end.sort_by { |option| option[:name] }
|
83
|
+
|
84
|
+
instance = ask?("Instances", instances)
|
85
|
+
|
86
|
+
present_pems = Dir.glob("*.pem")
|
87
|
+
pem_filename = "#{instance[:key_name]}.pem"
|
88
|
+
|
89
|
+
if instance[:key_name] && !ENV['KEY_DIR'] && !present_pems.include?(pem_filename)
|
90
|
+
puts "\n\nWhere are your keys located?"
|
91
|
+
ENV['KEY_DIR'] = gets.chomp
|
92
|
+
end
|
93
|
+
|
94
|
+
cmd = ["ssh"]
|
95
|
+
|
96
|
+
if present_pems.include?(pem_filename)
|
97
|
+
cmd << "-i #{pem_filename}"
|
98
|
+
elsif !ENV['KEY_DIR'].nil? && !ENV['KEY_DIR'].empty? && !instance[:key_name].nil?
|
99
|
+
cmd << "-i #{ENV['KEY_DIR']}/#{pem_filename}"
|
100
|
+
end
|
101
|
+
|
102
|
+
cmd << "#{"ec2-user@" if instance[:key_name]}#{instance[:ip]}"
|
103
|
+
|
104
|
+
ssh_cmd = cmd.join(" ")
|
105
|
+
|
106
|
+
puts "", ssh_cmd
|
107
|
+
system "#{ssh_cmd}"
|
108
|
+
if $?.exitstatus == 255
|
109
|
+
puts "","Did you properly set ENV['KEY_DIR']? (= #{ENV['KEY_DIR'] or "nil"})"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eb-connect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spencer Ellinor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.4'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
executables:
|
58
|
+
- eb-connect
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/eb-connect
|
68
|
+
- eb-connect.gemspec
|
69
|
+
- lib/eb-connect.rb
|
70
|
+
- lib/eb-connect/version.rb
|
71
|
+
homepage:
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.4.5.1
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Ease EB instance SSH connections
|
95
|
+
test_files: []
|