aws_ssh 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 +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +21 -0
- data/README.md +65 -0
- data/aws_ssh.gemspec +28 -0
- data/bin/aws_ssh_generate +9 -0
- data/bin/aws_ssh_setup +21 -0
- data/bin/aws_ssh_teardown +21 -0
- data/lib/aws_ssh/cmds.rb +7 -0
- data/lib/aws_ssh/ec2.rb +114 -0
- data/lib/aws_ssh/exceptions.rb +4 -0
- data/lib/aws_ssh/files.rb +5 -0
- data/lib/aws_ssh/runner.rb +21 -0
- data/lib/aws_ssh/setup.rb +103 -0
- data/lib/aws_ssh/teardown.rb +84 -0
- data/lib/aws_ssh/terminal_formats.rb +5 -0
- data/lib/aws_ssh/version.rb +3 -0
- data/lib/aws_ssh.rb +14 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 309d8060f416544bfc2f694b9e52e9a1d0959c88
|
4
|
+
data.tar.gz: f10639efda3bfb3d036886b865559320471dba4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 08db6a7f98e7e501c61c84dddf558c3614f46866d0d1a634750a85811d8b3f57abaef5cef29a062f7be69cb4b1674b248e9836e68709578ab73b92feffbf756c
|
7
|
+
data.tar.gz: 44c0e9cb3d52f917c6d548c96650ec837352067ddc96cb244b3ee68d23d578f628285fa4a6bbae313ce3a49d6fc34627fc633da8bd542701c20ce4f5b96ff4c9
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
aws-sdk (1.56.0)
|
5
|
+
aws-sdk-v1 (= 1.56.0)
|
6
|
+
aws-sdk-v1 (1.56.0)
|
7
|
+
json (~> 1.4)
|
8
|
+
nokogiri (>= 1.4.4)
|
9
|
+
colorize (0.7.3)
|
10
|
+
json (1.8.1)
|
11
|
+
mini_portile (0.6.0)
|
12
|
+
nokogiri (1.6.3.1)
|
13
|
+
mini_portile (= 0.6.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
aws-sdk
|
20
|
+
colorize
|
21
|
+
json
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# AWS SSH Extension #
|
2
|
+
|
3
|
+
If you have a lot of services running over a multitude of instances, or if you just don't want to have to remember IP addresses, this tool will work for you.
|
4
|
+
|
5
|
+
## Requirements ##
|
6
|
+
|
7
|
+
It does assume that you are using SSH key based authentication to access the servers and have a correctly configured environment. This means a current ~/.ssh/config that has relevant proxy settings etc along with AWS environment vars (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
|
8
|
+
|
9
|
+
Ruby, version 2.0 onwards, is required along with the standard bundler gem.
|
10
|
+
|
11
|
+
At the moment, this code is only tested with bash based shells.
|
12
|
+
|
13
|
+
## AWS Configuration ##
|
14
|
+
|
15
|
+
Before you install this code, please be aware you may need to add some information to your ec2 instances. This code makes use of the "tags" key / value data available for each instance.
|
16
|
+
|
17
|
+
I think this will be easier to explain by example:
|
18
|
+
|
19
|
+
<img src="http://i.imgur.com/kvgHbr1.png" width="100%">
|
20
|
+
Above is an ec2 instance setup to run both website and blog services (website.blog) in production and staging (production.staging).
|
21
|
+
|
22
|
+
<img src="http://i.imgur.com/2psCejI.png" width="100%">
|
23
|
+
This ec2 instance is just the website running in production.
|
24
|
+
|
25
|
+
What values you have for environment and service are free form, so if you prefer to use "prod" instead of "production", you can.
|
26
|
+
|
27
|
+
You can also have as many services and environments as you like, they just have to be seperated by a full stop (.).
|
28
|
+
|
29
|
+
## Install ##
|
30
|
+
|
31
|
+
|
32
|
+
### Uninstall ###
|
33
|
+
|
34
|
+
|
35
|
+
## Usage ##
|
36
|
+
|
37
|
+
Once installed you will need to make an SSH call to a service like:
|
38
|
+
|
39
|
+
ssh $environment_$service
|
40
|
+
or
|
41
|
+
ssh $service_$environment
|
42
|
+
|
43
|
+
In the case or examples above, that would be:
|
44
|
+
|
45
|
+
ssh production_website
|
46
|
+
or
|
47
|
+
ssh website_production
|
48
|
+
|
49
|
+
To be even more useful, it will also add the instance name, so:
|
50
|
+
|
51
|
+
ssh websites
|
52
|
+
|
53
|
+
would work as well
|
54
|
+
|
55
|
+
If you have tab completion available, even better.
|
56
|
+
|
57
|
+
### SSH User ###
|
58
|
+
|
59
|
+
By default "deploy" is used as the ssh user. You can override this in the command as you are running it:
|
60
|
+
|
61
|
+
ssh my-user@website_production
|
62
|
+
|
63
|
+
Or, to save remembering, you can add a "user" tag to your instance and that will be loaded in
|
64
|
+
|
65
|
+
|
data/aws_ssh.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "aws_ssh/version"
|
5
|
+
require "aws_ssh/cmds"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "aws_ssh"
|
9
|
+
spec.version = AWS_SSH::VERSION
|
10
|
+
spec.authors = ["Charles Marshall"]
|
11
|
+
spec.email = ["cm56marshall@gmail.com"]
|
12
|
+
spec.summary = %q{ Autogenerates an SSH config file built from and AWS environment }
|
13
|
+
spec.description = %q{ Autogenerates an SSH config file built from and AWS environment }
|
14
|
+
spec.homepage = "https://github.com/charlesmarshall/aws_ssh"
|
15
|
+
spec.license = "MIT"
|
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_dependency "colorize", "~> 0.7"
|
22
|
+
spec.add_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_dependency "json", "~> 1.8"
|
24
|
+
spec.add_dependency "aws-sdk", "~> 1.5"
|
25
|
+
|
26
|
+
spec.post_install_message = "Gem installed.\nTo configure for use, run: #{AWS_SSH::SETUP_CMD}\nBefore removing gem, run: #{AWS_SSH::TEARDOWN_CMD}\n\nThank you!"
|
27
|
+
|
28
|
+
end
|
data/bin/aws_ssh_setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'aws_ssh'
|
7
|
+
require "colorize"
|
8
|
+
# run the config setup
|
9
|
+
runner = AWS_SSH::Setup.new
|
10
|
+
puts ""
|
11
|
+
puts "Configuring...".colorize(:green)
|
12
|
+
result = runner.run
|
13
|
+
if ! result.nil?
|
14
|
+
puts ""
|
15
|
+
puts "Configuration completed.".colorize(:green)
|
16
|
+
puts ""
|
17
|
+
else
|
18
|
+
puts ""
|
19
|
+
puts "Configuration failed.".colorize(:red)
|
20
|
+
puts ""
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'aws_ssh'
|
7
|
+
require "colorize"
|
8
|
+
# run the config setup
|
9
|
+
runner = AWS_SSH::Teardown.new
|
10
|
+
puts ""
|
11
|
+
puts "Removing...".colorize(:green)
|
12
|
+
result = runner.run
|
13
|
+
if ! result.nil?
|
14
|
+
puts ""
|
15
|
+
puts "Removal completed, you can uninstall the gem.".colorize(:green)
|
16
|
+
puts ""
|
17
|
+
else
|
18
|
+
puts ""
|
19
|
+
puts "Removal failed.".colorize(:red)
|
20
|
+
puts ""
|
21
|
+
end
|
data/lib/aws_ssh/cmds.rb
ADDED
data/lib/aws_ssh/ec2.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'aws-sdk'
|
3
|
+
|
4
|
+
module AWS_SSH
|
5
|
+
class EC2
|
6
|
+
### ssh config file values
|
7
|
+
attr_accessor :User
|
8
|
+
attr_accessor :StrictHostKeyChecking
|
9
|
+
attr_accessor :UserKnownHostsFile
|
10
|
+
attr_accessor :LogLevel
|
11
|
+
### class values
|
12
|
+
# aws api object
|
13
|
+
attr_accessor :api
|
14
|
+
# suffix of the key to use
|
15
|
+
attr_accessor :ssh_key_suffix
|
16
|
+
# auto generated ssh config_file
|
17
|
+
attr_accessor :ssh_config_file
|
18
|
+
# value used as seperater in the tags
|
19
|
+
attr_accessor :seperator
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
self.env_error_check
|
23
|
+
self.default_values
|
24
|
+
end
|
25
|
+
|
26
|
+
def env_error_check
|
27
|
+
if ENV['AWS_ACCESS_KEY_ID'].nil? || ENV['AWS_SECRET_ACCESS_KEY'].nil? || ENV['AWS_REGION'].nil?
|
28
|
+
raise MissingAWS_CONFIG, "Missing AWS config data from the ENV."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_values
|
33
|
+
@User = "deploy"
|
34
|
+
@StrictHostKeyChecking = "no"
|
35
|
+
@UserKnownHostsFile = "/dev/null"
|
36
|
+
@LogLevel = "quiet"
|
37
|
+
|
38
|
+
@seperator = "."
|
39
|
+
@ssh_key_suffix = "pem"
|
40
|
+
@api = AWS::EC2.new(access_key_id: ENV['AWS_ACCESS_KEY_ID'], secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], region: ENV['AWS_REGION'])
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def instances
|
45
|
+
instances = []
|
46
|
+
# normal instances
|
47
|
+
@api.instances.each{|i| instances.push(i)}
|
48
|
+
# vpc based insatnces
|
49
|
+
@api.vpcs.each{|v| v.instances.each{|vi| instances.push(vi)} }
|
50
|
+
return instances
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def instance_data(instance)
|
55
|
+
tags = instance.tags.to_h
|
56
|
+
return {
|
57
|
+
:name => if tags["Name"].nil? then nil else tags["Name"].to_s.strip end,
|
58
|
+
:user => if tags["user"].nil? then @User else tags["user"].to_s.strip end,
|
59
|
+
:envs => if tags["environment"].nil? then nil else tags["environment"].split(@seperator) end,
|
60
|
+
:services => if tags["service"].nil? then nil else tags["service"].split(@seperator) end,
|
61
|
+
:ip => instance.private_ip_address,
|
62
|
+
:key => instance.key_name,
|
63
|
+
:key_file => ENV['HOME']+"/.ssh/"+instance.key_name+"."+@ssh_key_suffix
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def instance_names(info)
|
68
|
+
names = []
|
69
|
+
if ! info[:name].nil? then names.push(info[:name]) end
|
70
|
+
if ! info[:envs].nil? && ! info[:services].nil?
|
71
|
+
info[:envs].each do |e|
|
72
|
+
info[:services].each do |s|
|
73
|
+
names.push("#{e}_#{s}")
|
74
|
+
names.push("#{s}_#{e}")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
return names
|
79
|
+
end
|
80
|
+
|
81
|
+
def hosts
|
82
|
+
hosts = {}
|
83
|
+
self.instances.select!{|i| i.status.to_s == "running"}.each do |i|
|
84
|
+
info = self.instance_data(i)
|
85
|
+
if File.exists?(info[:key_file])
|
86
|
+
self.instance_names(info).each{ |h| hosts[h] = info}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return hosts
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def write
|
94
|
+
# loop over hash and generate string
|
95
|
+
config = "\n\n# Custom generated list from AWS on #{Time.now}\n\n"
|
96
|
+
dir = ENV['HOME']+"/.ssh/"
|
97
|
+
sshfile = dir+AWS_SSH::HOSTS_FILE
|
98
|
+
File.open(sshfile, "w"){ |file| file.write(config)}
|
99
|
+
self.hosts.each do |name, host|
|
100
|
+
config += "Host #{name}\n"
|
101
|
+
config += " HostName #{host[:ip].to_s}\n"
|
102
|
+
config += " User #{host[:user].to_s}\n"
|
103
|
+
config += " IdentityFile ~/.ssh/#{host[:key].to_s}.#{@ssh_key_suffix}\n"
|
104
|
+
config += " StrictHostKeyChecking #{@StrictHostKeyChecking}\n"
|
105
|
+
config += " UserKnownHostsFile #{@UserKnownHostsFile}\n"
|
106
|
+
config += " LogLevel #{@LogLevel}\n"
|
107
|
+
config += "\n\n"
|
108
|
+
end
|
109
|
+
# write to file
|
110
|
+
File.open(sshfile, "w"){ |file| file.write(config)}
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "aws_ssh/files"
|
2
|
+
module AWS_SSH
|
3
|
+
class Run
|
4
|
+
def generate
|
5
|
+
config = AWS_SSH::HOSTS_FILE
|
6
|
+
# 4 hour cache
|
7
|
+
if (File.exists?(config) && File.mtime(config) < (Time.now - (60*60*4) )) || ! File.exists?(config)
|
8
|
+
self.force
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def force
|
13
|
+
ec2 = EC2.new
|
14
|
+
ec2.write
|
15
|
+
end
|
16
|
+
|
17
|
+
def merge
|
18
|
+
`#{AWS_SSH::MERGE_CMD}`
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require "aws_ssh/files"
|
3
|
+
require "aws_ssh/terminal_formats"
|
4
|
+
require "aws_ssh/version"
|
5
|
+
require 'fileutils'
|
6
|
+
require "aws_ssh/runner"
|
7
|
+
|
8
|
+
module AWS_SSH
|
9
|
+
class Setup
|
10
|
+
attr_accessor :profile
|
11
|
+
|
12
|
+
# all vars are required
|
13
|
+
def env
|
14
|
+
return ( ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_REGION'] && ENV['SHELL'] && ENV['HOME'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def shell
|
18
|
+
shell = ENV['SHELL']
|
19
|
+
last = shell.rindex("/")+1
|
20
|
+
len = shell.length-1
|
21
|
+
return shell[last..len]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.shells(home, shell)
|
25
|
+
["#{home}/.#{shell}rc", "#{home}/.#{shell}_profile", "#{home}/.profile"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def profile
|
29
|
+
home = ENV['HOME']
|
30
|
+
shell = self.shell
|
31
|
+
@profile = nil
|
32
|
+
# check for automated locations
|
33
|
+
if ! shell.nil?
|
34
|
+
possibles = AWS_SSH::Setup.shells(home, shell)
|
35
|
+
possibles.each {|p| if @profile.nil? && File.exists?(p) then @profile = p end }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# create the alias file
|
41
|
+
def alias
|
42
|
+
msg = "# This is an automatically generated file; do not edit.\n# Created at #{Time.now}\n# Created by aws_ssh #{AWS_SSH::VERSION}\n"
|
43
|
+
cmd = 'alias ssh="' + AWS_SSH::GENERATE_CMD + ' ; '+AWS_SSH::MERGE_CMD+ '; ssh"'
|
44
|
+
filename=ENV['HOME']+"/"+AWS_SSH::ALIAS_FILE
|
45
|
+
File.open(filename, 'w') { |file| file.write(msg+cmd) }
|
46
|
+
return File.exists?(filename)
|
47
|
+
end
|
48
|
+
# move any current ssh config file to a base file
|
49
|
+
def create_base
|
50
|
+
origin = "#{ENV['HOME']}/.ssh/config"
|
51
|
+
dest = "#{ENV['HOME']}/.ssh/#{AWS_SSH::BASE_HOSTS_FILE}"
|
52
|
+
if File.exists?(origin)
|
53
|
+
FileUtils.mv(origin, dest)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_to_profile
|
58
|
+
if ! @profile.nil?
|
59
|
+
contents = File.open(@profile, 'rb') {|file| file.read}
|
60
|
+
# remove any current references and add new one in
|
61
|
+
contents = contents.gsub(". ~/#{AWS_SSH::ALIAS_FILE}", "").chomp + "\n" + ". ~/#{AWS_SSH::ALIAS_FILE}"
|
62
|
+
File.open(@profile, 'w') { |file| file.write(contents) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def run
|
67
|
+
|
68
|
+
if !self.env
|
69
|
+
printf(AWS_SSH::FORMAT_FATAL, "Environment failed", "\u2620")
|
70
|
+
return nil
|
71
|
+
else
|
72
|
+
printf(AWS_SSH::FORMAT_OK, "Environment vars", "\u2713")
|
73
|
+
end
|
74
|
+
|
75
|
+
self.profile
|
76
|
+
if @profile.nil?
|
77
|
+
printf(AWS_SSH::FORMAT_FATAL, "Shell profile failed", "\u2620")
|
78
|
+
return nil
|
79
|
+
else
|
80
|
+
printf(AWS_SSH::FORMAT_OK, "Shell profile found", "\u2713")
|
81
|
+
end
|
82
|
+
|
83
|
+
if self.alias
|
84
|
+
printf(AWS_SSH::FORMAT_OK, "Alias file created ", "\u2713")
|
85
|
+
else
|
86
|
+
printf(AWS_SSH::FORMAT_FATAL, "Alias file creation failed", "\u2620")
|
87
|
+
return nil
|
88
|
+
end
|
89
|
+
|
90
|
+
self.create_base
|
91
|
+
printf(AWS_SSH::FORMAT_OK, "Base SSH file created ", "\u2713")
|
92
|
+
self.add_to_profile
|
93
|
+
printf(AWS_SSH::FORMAT_OK, "Alias added to shell ", "\u2713")
|
94
|
+
|
95
|
+
run = AWS_SSH::Run.new
|
96
|
+
run.force
|
97
|
+
run.merge
|
98
|
+
printf(AWS_SSH::FORMAT_OK, "Completed first run", "\u2713")
|
99
|
+
return true
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require "aws_ssh/files"
|
3
|
+
require "aws_ssh/terminal_formats"
|
4
|
+
require "aws_ssh/version"
|
5
|
+
require 'fileutils'
|
6
|
+
require "aws_ssh/runner"
|
7
|
+
|
8
|
+
module AWS_SSH
|
9
|
+
class Teardown < Setup
|
10
|
+
attr_accessor :profile
|
11
|
+
|
12
|
+
|
13
|
+
def self.shells(home, shell)
|
14
|
+
["#{home}/.#{shell}rc", "#{home}/.#{shell}_profile", "#{home}/.profile"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def profile
|
18
|
+
home = ENV['HOME']
|
19
|
+
shell = self.shell
|
20
|
+
@profile = nil
|
21
|
+
# check for automated locations
|
22
|
+
if ! shell.nil?
|
23
|
+
possibles = AWS_SSH::Setup.shells(home, shell)
|
24
|
+
possibles.each {|p| if @profile.nil? && File.exists?(p) then @profile = p end }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
# create the alias file
|
30
|
+
def alias
|
31
|
+
filename=ENV['HOME']+"/"+AWS_SSH::ALIAS_FILE
|
32
|
+
if File.exists?(filename)
|
33
|
+
FileUtils.rm(filename)
|
34
|
+
end
|
35
|
+
return !File.exists?(filename)
|
36
|
+
end
|
37
|
+
#
|
38
|
+
def swap_base
|
39
|
+
origin = "#{ENV['HOME']}/.ssh/config"
|
40
|
+
dest = "#{ENV['HOME']}/.ssh/#{AWS_SSH::BASE_HOSTS_FILE}"
|
41
|
+
if File.exists?(dest)
|
42
|
+
FileUtils.mv(dest, origin)
|
43
|
+
end
|
44
|
+
extra = "#{ENV['HOME']}/.ssh/#{AWS_SSH::HOSTS_FILE}"
|
45
|
+
if File.exists?(extra)
|
46
|
+
FileUtils.rm(extra)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove_from_profile
|
51
|
+
if ! @profile.nil?
|
52
|
+
contents = File.open(@profile, 'rb') {|file| file.read}
|
53
|
+
# remove any current references and add new one in
|
54
|
+
contents = contents.gsub(". ~/#{AWS_SSH::ALIAS_FILE}", "").chomp + "\n"
|
55
|
+
File.open(@profile, 'w') { |file| file.write(contents) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def run
|
60
|
+
self.profile
|
61
|
+
if @profile.nil?
|
62
|
+
printf(AWS_SSH::FORMAT_FATAL, "Shell profile failed", "\u2620")
|
63
|
+
return nil
|
64
|
+
else
|
65
|
+
printf(AWS_SSH::FORMAT_OK, "Shell profile found", "\u2713")
|
66
|
+
end
|
67
|
+
|
68
|
+
if self.alias
|
69
|
+
printf(AWS_SSH::FORMAT_OK, "Alias file removed ", "\u2713")
|
70
|
+
else
|
71
|
+
printf(AWS_SSH::FORMAT_FATAL, "Alias removal failed", "\u2620")
|
72
|
+
return nil
|
73
|
+
end
|
74
|
+
|
75
|
+
self.swap_base
|
76
|
+
printf(AWS_SSH::FORMAT_OK, "Base SSH file reverted ", "\u2713")
|
77
|
+
self.remove_from_profile
|
78
|
+
printf(AWS_SSH::FORMAT_OK, "Alias removed from shell ", "\u2713")
|
79
|
+
|
80
|
+
return true
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
data/lib/aws_ssh.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "aws_ssh/version"
|
2
|
+
|
3
|
+
|
4
|
+
module AWS_SSH
|
5
|
+
require "aws_ssh/exceptions"
|
6
|
+
require "aws_ssh/files"
|
7
|
+
require "aws_ssh/cmds"
|
8
|
+
require "aws_ssh/terminal_formats"
|
9
|
+
require "aws_ssh/ec2"
|
10
|
+
require "aws_ssh/setup"
|
11
|
+
require "aws_ssh/teardown"
|
12
|
+
require "aws_ssh/runner"
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_ssh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Marshall
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
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.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.5'
|
69
|
+
description: " Autogenerates an SSH config file built from and AWS environment "
|
70
|
+
email:
|
71
|
+
- cm56marshall@gmail.com
|
72
|
+
executables:
|
73
|
+
- aws_ssh_generate
|
74
|
+
- aws_ssh_setup
|
75
|
+
- aws_ssh_teardown
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- README.md
|
83
|
+
- aws_ssh.gemspec
|
84
|
+
- bin/aws_ssh_generate
|
85
|
+
- bin/aws_ssh_setup
|
86
|
+
- bin/aws_ssh_teardown
|
87
|
+
- lib/aws_ssh.rb
|
88
|
+
- lib/aws_ssh/cmds.rb
|
89
|
+
- lib/aws_ssh/ec2.rb
|
90
|
+
- lib/aws_ssh/exceptions.rb
|
91
|
+
- lib/aws_ssh/files.rb
|
92
|
+
- lib/aws_ssh/runner.rb
|
93
|
+
- lib/aws_ssh/setup.rb
|
94
|
+
- lib/aws_ssh/teardown.rb
|
95
|
+
- lib/aws_ssh/terminal_formats.rb
|
96
|
+
- lib/aws_ssh/version.rb
|
97
|
+
homepage: https://github.com/charlesmarshall/aws_ssh
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message: |-
|
102
|
+
Gem installed.
|
103
|
+
To configure for use, run: aws_ssh_setup
|
104
|
+
Before removing gem, run: aws_ssh_teardown
|
105
|
+
|
106
|
+
Thank you!
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Autogenerates an SSH config file built from and AWS environment
|
126
|
+
test_files: []
|