awsssh 3.0.0 → 3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b969975c60d12fb9fd8ca034d1ffb0d7621246b
4
- data.tar.gz: 769bfd7c5de0f13466dcf0d595158741a920f2f9
3
+ metadata.gz: 71e530b89ccea7c6954872d846d25a9fa50f1827
4
+ data.tar.gz: 461fb7bbe46bb14a47d01ea81e18fb6067b7978b
5
5
  SHA512:
6
- metadata.gz: 6cb828c344ab11d3d8e8ff0046bca635cfe4c5a0cec735b544cacfef1b82cbd2615825f3322952cc9f4dbd0336e8cd7a0f6267a432f2df21d4bef0aebc2c592f
7
- data.tar.gz: e8ee0bd457af118a8036bec8ed7a637b6177c9ff43244ae41915ccc713d2043dc2d6abebcffe10f46e2f737afd7d470d7c37dd5f8ee9e1bac30fcbfdabb25b2c
6
+ metadata.gz: 9f29fc4c05cbe9da050d7dc0efa8dae84a2b80da3d1a561eedcd1cdfbce1f7765833dae7315677ccc47c83c2450b8c2d9d1e62ca7e298cdc3c441f584a04c775
7
+ data.tar.gz: 95383297c9c9f82410e0b576cb6dc56b0e093b497344894e88374c20680ae4f0b64f12921759381a4ecc4ad1a2c9749fa1132721b807dfc8268b9bddb7be4fd5
data/README.md CHANGED
@@ -61,6 +61,12 @@ issues:
61
61
  [github](https://github.com/sethiele/awsssh)
62
62
 
63
63
  ## Changelog
64
+ **2016-02-24 - v 3.1.0**
65
+ * [enh] Show only online Server
66
+ * [enh] colors in output
67
+ * [enh] connect to server from list_server
68
+ * [fix] error message for list_servers with unkown profile
69
+
64
70
  **2016-02-18 - v 3.0.0**
65
71
  * readme in english
66
72
  * Tests
data/awsssh.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_runtime_dependency "inifile", "~> 3.0.0", ">= 3.0.0"
29
29
  spec.add_runtime_dependency "aws-sdk", "~> 2.2.0", ">= 2.2.0"
30
30
  spec.add_runtime_dependency "thor", "~> 0.19.1", ">= 0.19.1"
31
+ spec.add_runtime_dependency "colorize", "~> 0.7.7"
31
32
  end
@@ -8,36 +8,3 @@ Feature: Running the program
8
8
  When I run `awsssh version`
9
9
  Then the exit status should be 0
10
10
  And the output should contain "version"
11
-
12
- Scenario: User runs the program with list_profiles parameter
13
- Given a file named "bla" with:
14
- """
15
- [testprofile]
16
- aws_access_key_id=ABC
17
- aws_secret_access_key=XYZ
18
- region=us-east-1
19
- """
20
- When I run `awsssh list_profiles`
21
- Then the output should contain "testprofile"
22
-
23
- Scenario: User runs the program with list_server parameter
24
- When I run `awsssh list_server`
25
- Then the exit status should be 0
26
- And the output should contain "ERROR"
27
- And the output should contain "Usage"
28
-
29
- Scenario: User runs the programm without `AWS_CREDENTIAL_FILE`
30
- Given I set the environment variables to:
31
- | variable | value |
32
- | AWS_CREDENTIAL_FILE | |
33
- When I run `awsssh list_profiles`
34
- Then the output should contain "$AWS_CREDENTIAL_FILE not set"
35
- And the exit status should not be 0
36
-
37
- Scenario: User runs the programm woth wrong `AWS_CREDENTIAL_FILE`
38
- Given I set the environment variables to:
39
- | variable | value |
40
- | AWS_CREDENTIAL_FILE | ./test.txt |
41
- When I run `awsssh list_profiles`
42
- Then the output should contain "Credential File not found."
43
- And the exit status should not be 0
@@ -0,0 +1,27 @@
1
+ Feature: Running the program with list_profiles
2
+ Scenario: User runs the program
3
+ Given a file named "credentials" with:
4
+ """
5
+ [testprofile]
6
+ aws_access_key_id=ABC
7
+ aws_secret_access_key=XYZ
8
+ region=us-east-1
9
+ """
10
+ When I run `awsssh list_profiles`
11
+ Then the output should contain "testprofile"
12
+
13
+ Scenario: User runs without `AWS_CREDENTIAL_FILE`
14
+ Given I set the environment variables to:
15
+ | variable | value |
16
+ | AWS_CREDENTIAL_FILE | |
17
+ When I run `awsssh list_profiles`
18
+ Then the output should contain "$AWS_CREDENTIAL_FILE not set"
19
+ And the exit status should not be 0
20
+
21
+ Scenario: User runs with wrong `AWS_CREDENTIAL_FILE`
22
+ Given I set the environment variables to:
23
+ | variable | value |
24
+ | AWS_CREDENTIAL_FILE | ./test.txt |
25
+ When I run `awsssh list_profiles`
26
+ Then the output should contain "Credential File not found."
27
+ And the exit status should not be 0
@@ -0,0 +1,18 @@
1
+ Feature: Running the program with list_server
2
+ Scenario: User runs the program without profile
3
+ When I run `awsssh list_server`
4
+ Then the exit status should be 0
5
+ And the output should contain "ERROR"
6
+ And the output should contain "Usage"
7
+
8
+ Scenario: User runs the program with unknown profile
9
+ Given a file named "credentials" with:
10
+ """
11
+ [testprofile]
12
+ aws_access_key_id=ABC
13
+ aws_secret_access_key=XYZ
14
+ region=us-east-1
15
+ """
16
+ When I run `awsssh list_server unkown`
17
+ Then the output should contain "Profile `unkown` not found. Try `awsssh list_profiles`"
18
+ And the exit status should not be 0
@@ -1,4 +1,4 @@
1
1
  ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
2
- ENV['AWS_CREDENTIAL_FILE'] = "bla"
2
+ ENV['AWS_CREDENTIAL_FILE'] = "credentials"
3
3
 
4
4
  require 'aruba/cucumber'
@@ -1,3 +1,3 @@
1
1
  module Awsssh
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
data/lib/awsssh.rb CHANGED
@@ -2,11 +2,24 @@ require "awsssh/version"
2
2
  require "thor"
3
3
  require "inifile"
4
4
  require "aws-sdk"
5
+ require "colorize"
5
6
 
6
7
 
7
8
  module Awsssh
8
9
  class Awsssh < Thor
9
10
 
11
+ def initialize(*args)
12
+ super
13
+ @text_colors = {
14
+ :infotext => :cyan,
15
+ :infotext_sub => :yellow,
16
+ :status => {
17
+ :online => :green,
18
+ :stopped => :light_red
19
+ }
20
+ }
21
+ end
22
+
10
23
  desc "list_profiles", "List all your avavible profiles"
11
24
  def list_profiles()
12
25
  credentials = open_credantial_file
@@ -18,30 +31,61 @@ module Awsssh
18
31
  end
19
32
 
20
33
  desc "list_server PROFILE", "List all Server for given profile"
34
+ method_option :all, :type => :boolean, :aliases => "-a", :default => false, :desc => "Show all Server"
21
35
  def list_server(profile)
22
36
  credentials = open_credantial_file
23
- raise "Profile `#{profile}` not found. Please try `awsssh list_profiles`" if credentials[profile].empty?
37
+
38
+ puts "Profile `#{profile}` not found. Try `awsssh list_profiles`" if credentials[profile].empty?
39
+ exit -1 if credentials[profile].empty?
40
+
24
41
  aws_connection(profile, credentials)
25
42
 
26
- puts "Stacks and instances for profile `#{profile}`"
43
+ puts "Stacks and instances for profile `#{profile}`".colorize(@text_colors[:infotext])
44
+ puts "only online server".colorize(@text_colors[:infotext_sub]) unless options[:all]
27
45
  puts
28
46
 
47
+ server_number = 0
48
+ server_online = []
49
+
29
50
  @client.describe_stacks.stacks.each do |stack|
30
51
  puts "##### Stack: #{stack.name}"
31
52
  @client.describe_instances({stack_id: stack.stack_id}).instances.each do |instance|
32
- printf " %-20s status: %-11s %s\n" % [instance.hostname, instance.status, public_dns(instance)]
53
+ if instance.status == "online"
54
+ server_number+=1
55
+ server_online[server_number] = public_dns = public_dns(instance)
56
+ printf("[%02d]" % [server_number])
57
+ else
58
+ print " "
59
+ public_dns = "-"
60
+ end
61
+ printf " %-20s status: %-11s %s\n".colorize(@text_colors[:status][instance.status.to_sym]) % [instance.hostname, instance.status, public_dns] if instance.status == "online" or options[:all]
33
62
  end
34
63
  puts ""
35
64
  end
65
+ while true
66
+ print "Would you like to connect to any server directly? Please enter Server number (Enter to exit): "
67
+ server_to_connect = STDIN.gets.chomp
68
+ if server_to_connect.to_i != 0 and !server_online[server_to_connect.to_i].nil?
69
+ puts "connecting to #{server_online[server_to_connect.to_i]}"
70
+ puts
71
+ puts
72
+ connect_server server_online[server_to_connect.to_i]
73
+ elsif server_to_connect.to_i > server_online.length+1
74
+ puts "No Server sellected"
75
+ puts
76
+ else
77
+ break;
78
+ end
79
+ end
36
80
  end
37
81
 
38
82
  desc "connect SERVERNAME", "Connect to Hostname"
39
- option :profile, :desc => "specify a profile - see `awsssh list_profiles`"
83
+ method_option :profile, :desc => "specify a profile - see `awsssh list_profiles`"
40
84
  def connect (hostname)
41
85
  hostname_parts = hostname.split("-")
42
86
  profile = options[:profile] || hostname_parts[0]
43
87
  credentials = open_credantial_file
44
- puts "Profile `#{profile}` not found. Try `awsssh SERVERNAME --profile PROFILE`" if credentials[profile].empty?
88
+ puts "Profile `#{profile}` not found. Try `awsssh connect SERVERNAME --profile PROFILE`" if credentials[profile].empty?
45
89
  exit -1 if credentials[profile].empty?
46
90
 
47
91
  aws_connection(profile, credentials)
@@ -53,13 +97,11 @@ module Awsssh
53
97
  puts "Try `awsssh list_server PROFILE`"
54
98
  puts "checking your local ssh config..."
55
99
  puts
56
- exec "ssh #{hostname}"
57
- exit -1
100
+ connect_server hostname
58
101
  else
59
102
  puts "start ssh connection to `#{hostname}`..."
60
103
  puts
61
- exec "ssh #{public_dns}"
62
- exit 0
104
+ connect_server public_dns
63
105
  end
64
106
  end
65
107
 
@@ -122,5 +164,10 @@ module Awsssh
122
164
  end
123
165
  return nil
124
166
  end
167
+
168
+ def connect_server(hostname)
169
+ exec "ssh #{hostname}"
170
+ exit 0
171
+ end
125
172
  end
126
173
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.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: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,6 +140,20 @@ dependencies:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: 0.19.1
143
+ - !ruby/object:Gem::Dependency
144
+ name: colorize
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: 0.7.7
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: 0.7.7
143
157
  description: This will connects you with an EC2 instace
144
158
  email: Sebastian.Thiele@infopark.de
145
159
  executables:
@@ -156,6 +170,8 @@ files:
156
170
  - awsssh.gemspec
157
171
  - bin/awsssh
158
172
  - features/running.feature
173
+ - features/running_list_profiles.feature
174
+ - features/running_list_server.feature
159
175
  - features/step_definitions/running_steps.rb
160
176
  - features/support/env.rb
161
177
  - lib/awsssh.rb
@@ -187,6 +203,8 @@ specification_version: 4
187
203
  summary: Connects you with OpsWorks EC2
188
204
  test_files:
189
205
  - features/running.feature
206
+ - features/running_list_profiles.feature
207
+ - features/running_list_server.feature
190
208
  - features/step_definitions/running_steps.rb
191
209
  - features/support/env.rb
192
210
  has_rdoc: