awssh 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7769be2866aa2ea80787123093fd4415f8fd3c61
4
+ data.tar.gz: 96abfdf069e75350044a20802434e2cd3072005a
5
+ SHA512:
6
+ metadata.gz: 7b0e70860e2bd0faba3d09275d7894af5c36eb7ec17e0653793935f79e4809c7362ebc4d0152270ed98b196974a405509669e560766b39243a1adb3e3f4a0171
7
+ data.tar.gz: fcefa9565d2271eb26217c0352e726d4a7dec14e1a9b1412c719f4c1fb3fbe0190b5ecc223e171efae411e095973bf85ad59b0ef0ed29fa80426fe36b17dd552
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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in awssh.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Shawn Catanzarite
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,50 @@
1
+ # Awssh
2
+
3
+ Hacky way to handle ssh to AWS servers
4
+
5
+ - Searches for servers based on AWS tag Name.
6
+ - Provides the ability to use single ssh and multiple ssh access.
7
+ - Multiple can use cssh or csshX (configurable)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'awssh'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install awssh
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ Usage: awssh [options] [search terms]
27
+
28
+ Search Terms:
29
+ matches against AWS Tag "Name"
30
+ positive check for each entry
31
+ name =~ /term/
32
+ negative check if the term starts with ^
33
+ name !~ /term/ if term[0] == "^"
34
+
35
+ Options:
36
+ -n, --test just output ssh command
37
+ -v, --[no-]verbose Run verbosely
38
+ -V, --version print version
39
+ -c, --config config file (default: ~/.awssh)
40
+ -m, --[no-]multi connect to multiple servers
41
+ -i, --init initialize config
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/[my-github-username]/awssh/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/awssh.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'awssh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "awssh"
8
+ spec.version = Awssh::Version::STRING
9
+ spec.authors = ["Shawn Catanzarite"]
10
+ spec.email = ["me@shawncatz.com"]
11
+ spec.summary = %q{aws ssh wrapper}
12
+ spec.description = %q{aws ssh wrapper}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
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 'fog', '~> 1.23.0'
22
+ spec.add_dependency 'dotenv', '~> 0.11.1'
23
+ spec.add_dependency 'activesupport'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ end
data/bin/awssh ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fog'
4
+ require 'optparse'
5
+ require 'active_support/all'
6
+ require 'awssh'
7
+
8
+ Awssh::Command.new(ARGV).connect
@@ -0,0 +1,139 @@
1
+ module Awssh
2
+ class Command
3
+ def initialize(argv)
4
+ @options = {
5
+ verbose: false,
6
+ config: '~/.awssh',
7
+ multi: false,
8
+ test: true,
9
+ }
10
+ @config = {
11
+ multi: 'csshX',
12
+ single: 'ssh',
13
+ region: 'us-east-1',
14
+ user: nil,
15
+ key: 'AWS ACCESS KEY ID',
16
+ secret: 'AWS SECRET ACCESS KEY',
17
+ domain: 'example.com'
18
+ }.stringify_keys
19
+
20
+ OptionParser.new do |opts|
21
+ opts.banner = "Usage: awssh [options] [search terms]"
22
+
23
+ opts.separator ''
24
+ opts.separator 'Search Terms:'
25
+ opts.separator ' matches against AWS Tag "Name"'
26
+ opts.separator ' positive check for each entry'
27
+ opts.separator ' name =~ /term/'
28
+ opts.separator ' negative check if the term starts with ^'
29
+ opts.separator ' name !~ /term/ if term[0] == "^"'
30
+ opts.separator ''
31
+ opts.separator 'Options:'
32
+
33
+ opts.on('-n', '--test', 'just output ssh command') do |n|
34
+ @options[:test] = n
35
+ end
36
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
37
+ @options[:verbose] = v
38
+ end
39
+ opts.on('-V', '--version', 'print version') do |v|
40
+ puts "awssh version: #{Awssh::Version::STRING}"
41
+ exit 0
42
+ end
43
+ opts.on('-c', "--config", "config file (default: ~/.awssh)") do |c|
44
+ @options[:config] = c
45
+ end
46
+ opts.on('-m', '--[no-]multi', 'connect to multiple servers') do |m|
47
+ @options[:multi] = m
48
+ end
49
+ opts.on('-i', '--init', 'initialize config') do |i|
50
+ path = File.expand_path("~/.awssh")
51
+ File.open(path, "w+") {|f| f.write config.to_yaml}
52
+ puts "created config file: #{path}"
53
+ exit 0
54
+ end
55
+ end.parse!(argv)
56
+
57
+ @search = argv
58
+ @config_file = File.expand_path(@options[:config])
59
+ @config.merge!(YAML.load_file(@config_file)) if File.exists?(@config_file)
60
+
61
+ if @options[:verbose]
62
+ p @search
63
+ p @options
64
+ p @config
65
+ end
66
+ end
67
+
68
+ def connect
69
+ @servers = get_servers
70
+
71
+ puts "found: #{@servers.count}" if @options[:verbose]
72
+ @servers.each do |s|
73
+ puts "- #{s}"
74
+ end if @options[:verbose]
75
+
76
+ if @servers.count > 1 && !@options[:multi]
77
+ puts "more than one server found, and multi is false"
78
+ puts "set the -m flag to connect to more than one matched server"
79
+ puts "servers: #{@servers.join(',')}" unless @options[:verbose]
80
+ exit 1
81
+ end
82
+
83
+ @command = get_command(@servers)
84
+
85
+ if @options[:test]
86
+ puts "command: #{@command}"
87
+ else
88
+ exec @command
89
+ end
90
+ end
91
+
92
+ private
93
+
94
+ def get_servers
95
+ @fog = Fog::Compute.new(provider: 'AWS', aws_access_key_id: @config['key'], aws_secret_access_key: @config['secret'], region: @config["region"])
96
+ list = @fog.servers.all
97
+
98
+ puts "total servers: #{list.count}" if @options[:verbose]
99
+
100
+ servers = []
101
+ list.each do |s|
102
+ n = s.tags['Name']
103
+ if n
104
+ fail = false
105
+ @search.each do |v|
106
+ if v =~ /^\^/
107
+ v.gsub!(/^\^/, '')
108
+ fail = true if n =~ /#{v}/
109
+ else
110
+ fail = true unless n =~ /#{v}/
111
+ end
112
+ end
113
+ next if fail
114
+ servers << n
115
+ else
116
+ puts "server #{s.id} does not have a name"
117
+ end
118
+ end
119
+ servers.sort
120
+ end
121
+
122
+ def get_command(servers)
123
+ if @options[:multi]
124
+ command = "#{@config["multi"]} #{servers.map {|e| server_url(e) }.join(' ')}"
125
+ else
126
+ command = "#{@config["single"]} #{server_url(e)}"
127
+ end
128
+ command
129
+ end
130
+
131
+ def server_url(server)
132
+ out = []
133
+ out << "#{@config["user"]}@" if @config["user"]
134
+ out << server
135
+ out << ".#{@config["domain"]}" if @config["domain"]
136
+ out.join('')
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,10 @@
1
+ module Awssh
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+ TAG = nil
7
+ LIST = [MAJOR, MINOR, TINY, TAG].compact
8
+ STRING = LIST.join('.')
9
+ end
10
+ end
data/lib/awssh.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "awssh/version"
2
+ require "awssh/command"
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awssh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shawn Catanzarite
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.23.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.23.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.11.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.11.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: aws ssh wrapper
84
+ email:
85
+ - me@shawncatz.com
86
+ executables:
87
+ - awssh
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - awssh.gemspec
97
+ - bin/awssh
98
+ - lib/awssh.rb
99
+ - lib/awssh/command.rb
100
+ - lib/awssh/version.rb
101
+ homepage: ''
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: aws ssh wrapper
125
+ test_files: []