claws 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,7 +6,7 @@ account via the command line.
6
6
  It provides a configurable text based interface of the status of your hosts similar to the AWS web
7
7
  console. An example of its usage appears below:
8
8
 
9
- ![Instances](http://i.imgur.com/VEC8V.png)
9
+ ![Instances](http://i.imgur.com/xCr7x.png)
10
10
 
11
11
  It gives you a choice of which host to connect to and invokes the proper ssh command:
12
12
 
@@ -46,9 +46,11 @@ The full list of options includes:
46
46
 
47
47
  ```bash
48
48
  Usage: claws [options]
49
- -s, --status-only Display host status only and exit
49
+ -d, --display-only Display host status only and exit
50
50
  -c, --choice N Enter the number of the host to automatically connect to
51
51
  -i, --init Install the default configuration file for the application
52
+ -s, --source S define the AWS source - default is ec2
53
+ -v, --version Display the version number and exit
52
54
  ```
53
55
 
54
56
  ### To Do
@@ -33,7 +33,13 @@ module Claws
33
33
 
34
34
  puts 'connecting to server...'
35
35
 
36
- system "ssh #{config.ssh.user}@#{instances[selection.to_i].dns_name}"
36
+ identity = config.ssh.identity.nil? ? '' : "-i #{config.ssh.identity}"
37
+
38
+ instance = instances[selection.to_i]
39
+
40
+ hostname = instance.vpc? ? instance.private_ip_address : instance.dns_name
41
+
42
+ system "ssh #{identity} #{config.ssh.user}@#{hostname}"
37
43
  end
38
44
  end
39
45
  end
@@ -10,6 +10,7 @@ module Claws
10
10
  },
11
11
  'ssh' => {
12
12
  'user' => nil,
13
+ 'identity' => nil,
13
14
  },
14
15
  'aws' => {
15
16
  'access_key_id' => nil,
@@ -54,9 +55,16 @@ module Claws
54
55
  }
55
56
 
56
57
  conf = File.join(ENV['HOME'], '.claws.yml')
57
- puts "Creating configuration file: #{conf}\n..."
58
- File.open(conf, 'w').write(h.to_yaml)
59
- puts 'Complete!'
58
+
59
+ if File.exists?(conf)
60
+ puts "Configuration file #{conf} exists! Either remove or modify contents."
61
+ exit 1
62
+ else
63
+ print "Creating configuration file: #{conf}..."
64
+ File.open(conf, 'w').write(h.to_yaml)
65
+ puts "Complete!\nEnter your access key id and secret access key to access your AWS account."
66
+ exit 0
67
+ end
60
68
  end
61
69
  end
62
70
  end
data/lib/claws/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Claws
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -52,7 +52,7 @@ describe Claws::Command::EC2 do
52
52
  context 'instance collections' do
53
53
  it 'retrieves' do
54
54
  Claws::Collection::EC2.should_receive(:new).and_return(
55
- double(Claws::Collection::EC2, :get =>
55
+ double(Claws::Collection::EC2, :get =>
56
56
  [
57
57
  double(AWS::EC2::Instance, :id => 'test', :status => 'running', :dns_name => 'test.com'),
58
58
  ]
@@ -102,7 +102,9 @@ describe Claws::Command::EC2 do
102
102
  OpenStruct.new(
103
103
  {
104
104
  :ssh => OpenStruct.new(
105
- { :user => 'test' }
105
+ { :user => 'test',
106
+ :identity => 'my_id'
107
+ }
106
108
  ),
107
109
  :ec2 => OpenStruct.new(
108
110
  :fields => {
@@ -117,10 +119,32 @@ describe Claws::Command::EC2 do
117
119
  )
118
120
  end
119
121
 
122
+ context 'vpc' do
123
+ let(:instances) do
124
+ [
125
+ double(AWS::EC2::Instance, :id => 'test', :status => 'running', :private_ip_address => 'secret.com', :vpc? => true)
126
+ ]
127
+ end
128
+
129
+ it 'automatically connects to the server using private ip address' do
130
+ Claws::Collection::EC2.should_receive(:new).and_return(
131
+ double(Claws::Collection::EC2, :get => instances)
132
+ )
133
+
134
+ subject.should_receive(:puts).twice
135
+ subject.should_receive(:system).with('ssh -i my_id test@secret.com').and_return(0)
136
+
137
+ capture_stdout {
138
+ subject.exec options
139
+ }
140
+ end
141
+
142
+ end
143
+
120
144
  context 'single instance' do
121
145
  let(:instances) do
122
146
  [
123
- double(AWS::EC2::Instance, :id => 'test', :status => 'running', :dns_name => 'test.com')
147
+ double(AWS::EC2::Instance, :id => 'test', :status => 'running', :dns_name => 'test.com', :vpc? => false)
124
148
  ]
125
149
  end
126
150
 
@@ -130,7 +154,7 @@ describe Claws::Command::EC2 do
130
154
  )
131
155
 
132
156
  subject.should_receive(:puts).twice
133
- subject.should_receive(:system).with('ssh test@test.com').and_return(0)
157
+ subject.should_receive(:system).with('ssh -i my_id test@test.com').and_return(0)
134
158
 
135
159
  capture_stdout {
136
160
  subject.exec options
@@ -141,9 +165,9 @@ describe Claws::Command::EC2 do
141
165
  context 'multiple instances' do
142
166
  let(:instances) do
143
167
  [
144
- double(AWS::EC2::Instance, :id => 'test1', :status => 'running', :dns_name => 'test1.com'),
145
- double(AWS::EC2::Instance, :id => 'test2', :status => 'running', :dns_name => 'test2.com'),
146
- double(AWS::EC2::Instance, :id => 'test3', :status => 'running', :dns_name => 'test3.com'),
168
+ double(AWS::EC2::Instance, :id => 'test1', :status => 'running', :dns_name => 'test1.com', :vpc? => false),
169
+ double(AWS::EC2::Instance, :id => 'test2', :status => 'running', :dns_name => 'test2.com', :vpc? => false),
170
+ double(AWS::EC2::Instance, :id => 'test3', :status => 'running', :dns_name => 'test3.com', :vpc? => false),
147
171
  ]
148
172
  end
149
173
 
@@ -153,7 +177,7 @@ describe Claws::Command::EC2 do
153
177
  )
154
178
 
155
179
  subject.should_receive(:puts).twice
156
- subject.should_receive(:system).with('ssh test@test2.com').and_return(0)
180
+ subject.should_receive(:system).with('ssh -i my_id test@test2.com').and_return(0)
157
181
 
158
182
  capture_stdout {
159
183
  subject.exec OpenStruct.new( {:selection => 1, :config_file => nil, :connect => true} )
@@ -168,7 +192,7 @@ describe Claws::Command::EC2 do
168
192
 
169
193
  subject.should_receive(:gets).and_return('1\n')
170
194
  subject.should_receive(:puts).once
171
- subject.should_receive(:system).with('ssh test@test2.com').and_return(0)
195
+ subject.should_receive(:system).with('ssh -i my_id test@test2.com').and_return(0)
172
196
 
173
197
  capture_stdout {
174
198
  subject.exec options
@@ -5,14 +5,29 @@ describe Claws::Command::Initialize do
5
5
 
6
6
  let(:config) { 'test/.test.yml' }
7
7
 
8
- it 'works' do
8
+ it 'creates the configuration file' do
9
+ fh = double( File, :write => true )
10
+
9
11
  File.should_receive(:join).and_return(config)
10
- subject.should_receive(:puts)
12
+ File.should_receive(:exists?).and_return(false)
11
13
 
12
- fh = double( File, :write => true )
14
+ subject.should_receive(:print)
13
15
 
14
16
  File.should_receive(:open).with(config, 'w').and_return(fh)
17
+ fh.should_receive(:write)
18
+
19
+ subject.should_receive(:puts)
20
+ subject.should_receive(:exit).with(0)
21
+
22
+ subject.exec
23
+ end
24
+
25
+ it 'does not overwrite existing configuration file' do
26
+ File.should_receive(:join).and_return(config)
27
+ File.should_receive(:exists?).and_return(true)
28
+
15
29
  subject.should_receive(:puts)
30
+ subject.should_receive(:exit).with(1)
16
31
 
17
32
  subject.exec
18
33
  end
@@ -7,6 +7,10 @@ describe Claws::Configuration do
7
7
  'capistrano' => {
8
8
  'home' => 'test',
9
9
  },
10
+ 'ssh' => {
11
+ 'user' => 'test',
12
+ 'identity' => 'test/id_rsa',
13
+ },
10
14
  'aws' => {
11
15
  'access_key_id' => 'asdf',
12
16
  'secret_access_key' => 'qwer',
@@ -61,6 +65,20 @@ describe Claws::Configuration do
61
65
  end
62
66
  end
63
67
 
68
+ context 'SSH' do
69
+ before :each do
70
+ YAML.should_receive(:load_file).and_return(yaml)
71
+ end
72
+
73
+ it 'defines user' do
74
+ config.ssh.user.should == 'test'
75
+ end
76
+
77
+ it 'defines the identity file' do
78
+ config.ssh.identity.should == 'test/id_rsa'
79
+ end
80
+ end
81
+
64
82
  context 'AWS' do
65
83
  before :each do
66
84
  YAML.should_receive(:load_file).and_return(yaml)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: claws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-27 00:00:00.000000000 Z
13
+ date: 2012-06-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
- requirement: &2151922880 !ruby/object:Gem::Requirement
17
+ requirement: &2151925260 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2151922880
25
+ version_requirements: *2151925260
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: command_line_reporter
28
- requirement: &2151922140 !ruby/object:Gem::Requirement
28
+ requirement: &2151924480 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.2.1
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2151922140
36
+ version_requirements: *2151924480
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: aws-sdk
39
- requirement: &2151921480 !ruby/object:Gem::Requirement
39
+ requirement: &2151923780 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '1.0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2151921480
47
+ version_requirements: *2151923780
48
48
  description: A command line tool that provides a configurable report on the status
49
49
  of all of your EC2 hosts and provides trivial ssh access for connectivity. Never
50
50
  copy and paste the public dns for a host again!