ec2ssh 2.0.8 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +15 -5
- data/.travis.yml +1 -1
- data/ChangeLog.md +0 -5
- data/Gemfile +4 -2
- data/Guardfile +1 -5
- data/README.md +26 -90
- data/Rakefile +1 -0
- data/example/example.ec2ssh +17 -0
- data/lib/ec2ssh/builder.rb +29 -0
- data/lib/ec2ssh/cli.rb +66 -91
- data/lib/ec2ssh/command.rb +25 -0
- data/lib/ec2ssh/command/init.rb +72 -0
- data/lib/ec2ssh/command/migrate.rb +34 -0
- data/lib/ec2ssh/command/remove.rb +20 -0
- data/lib/ec2ssh/command/update.rb +39 -0
- data/lib/ec2ssh/dsl.rb +55 -0
- data/lib/ec2ssh/ec2_instances.rb +38 -0
- data/lib/ec2ssh/exceptions.rb +9 -0
- data/lib/ec2ssh/migrator.rb +74 -0
- data/lib/ec2ssh/ssh_config.rb +5 -6
- data/lib/ec2ssh/version.rb +1 -1
- data/spec/lib/ec2ssh/builder_spec.rb +67 -0
- data/spec/lib/ec2ssh/command/init_spec.rb +41 -0
- data/spec/lib/ec2ssh/command/migrate_spec.rb +108 -0
- data/spec/lib/ec2ssh/command/remove_spec.rb +68 -0
- data/spec/lib/ec2ssh/command/update_spec.rb +97 -0
- data/spec/lib/ec2ssh/dsl_spec.rb +33 -0
- data/spec/lib/ec2ssh/migrator_spec.rb +59 -0
- data/spec/lib/ec2ssh/ssh_config_spec.rb +70 -54
- data/spec/spec_helper.rb +10 -8
- metadata +30 -8
- data/lib/ec2ssh/dotfile.rb +0 -49
- data/lib/ec2ssh/hosts.rb +0 -42
- data/spec/lib/ec2ssh/cli_spec.rb +0 -171
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
Bundler.require
|
3
3
|
|
4
|
+
require 'fakefs/spec_helpers'
|
4
5
|
require 'webmock/rspec'
|
5
6
|
require 'pathname'
|
6
7
|
require 'stringio'
|
8
|
+
require 'fileutils'
|
7
9
|
|
8
10
|
RSpec.configure do |config|
|
9
11
|
def capture(stream)
|
@@ -19,19 +21,19 @@ RSpec.configure do |config|
|
|
19
21
|
result
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
23
|
-
|
24
|
+
def silence_stdout(&block)
|
25
|
+
capture(:stdout, &block)
|
24
26
|
end
|
25
27
|
|
26
28
|
def tmp_dir
|
27
|
-
|
29
|
+
@tmp_dir ||= begin
|
30
|
+
Pathname('/fakefs/ec2ssh').tap do |path|
|
31
|
+
FileUtils.mkdir_p path
|
32
|
+
end
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
alias :silence :capture
|
31
37
|
|
32
|
-
config.
|
33
|
-
unless tmp_dir.directory?
|
34
|
-
tmp_dir.mkdir
|
35
|
-
end
|
36
|
-
end
|
38
|
+
config.include FakeFS::SpecHelpers
|
37
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ec2ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Issei Naruta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -68,15 +68,31 @@ files:
|
|
68
68
|
- Guardfile
|
69
69
|
- MIT-LICENSE
|
70
70
|
- README.md
|
71
|
+
- Rakefile
|
71
72
|
- bin/ec2ssh
|
72
73
|
- ec2ssh.gemspec
|
74
|
+
- example/example.ec2ssh
|
73
75
|
- lib/ec2ssh.rb
|
76
|
+
- lib/ec2ssh/builder.rb
|
74
77
|
- lib/ec2ssh/cli.rb
|
75
|
-
- lib/ec2ssh/
|
76
|
-
- lib/ec2ssh/
|
78
|
+
- lib/ec2ssh/command.rb
|
79
|
+
- lib/ec2ssh/command/init.rb
|
80
|
+
- lib/ec2ssh/command/migrate.rb
|
81
|
+
- lib/ec2ssh/command/remove.rb
|
82
|
+
- lib/ec2ssh/command/update.rb
|
83
|
+
- lib/ec2ssh/dsl.rb
|
84
|
+
- lib/ec2ssh/ec2_instances.rb
|
85
|
+
- lib/ec2ssh/exceptions.rb
|
86
|
+
- lib/ec2ssh/migrator.rb
|
77
87
|
- lib/ec2ssh/ssh_config.rb
|
78
88
|
- lib/ec2ssh/version.rb
|
79
|
-
- spec/lib/ec2ssh/
|
89
|
+
- spec/lib/ec2ssh/builder_spec.rb
|
90
|
+
- spec/lib/ec2ssh/command/init_spec.rb
|
91
|
+
- spec/lib/ec2ssh/command/migrate_spec.rb
|
92
|
+
- spec/lib/ec2ssh/command/remove_spec.rb
|
93
|
+
- spec/lib/ec2ssh/command/update_spec.rb
|
94
|
+
- spec/lib/ec2ssh/dsl_spec.rb
|
95
|
+
- spec/lib/ec2ssh/migrator_spec.rb
|
80
96
|
- spec/lib/ec2ssh/ssh_config_spec.rb
|
81
97
|
- spec/spec_helper.rb
|
82
98
|
homepage: http://github.com/mirakui/ec2ssh
|
@@ -93,9 +109,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
109
|
version: '0'
|
94
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
111
|
requirements:
|
96
|
-
- - "
|
112
|
+
- - ">"
|
97
113
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
114
|
+
version: 1.3.1
|
99
115
|
requirements: []
|
100
116
|
rubyforge_project: ec2ssh
|
101
117
|
rubygems_version: 2.2.2
|
@@ -103,6 +119,12 @@ signing_key:
|
|
103
119
|
specification_version: 4
|
104
120
|
summary: A ssh_config manager for AWS EC2
|
105
121
|
test_files:
|
106
|
-
- spec/lib/ec2ssh/
|
122
|
+
- spec/lib/ec2ssh/builder_spec.rb
|
123
|
+
- spec/lib/ec2ssh/command/init_spec.rb
|
124
|
+
- spec/lib/ec2ssh/command/migrate_spec.rb
|
125
|
+
- spec/lib/ec2ssh/command/remove_spec.rb
|
126
|
+
- spec/lib/ec2ssh/command/update_spec.rb
|
127
|
+
- spec/lib/ec2ssh/dsl_spec.rb
|
128
|
+
- spec/lib/ec2ssh/migrator_spec.rb
|
107
129
|
- spec/lib/ec2ssh/ssh_config_spec.rb
|
108
130
|
- spec/spec_helper.rb
|
data/lib/ec2ssh/dotfile.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Ec2ssh
|
4
|
-
class AwsKeyNotFound < StandardError; end
|
5
|
-
class Dotfile
|
6
|
-
def initialize(config={})
|
7
|
-
@config = {
|
8
|
-
'path' => "#{ENV['HOME']}/.ssh/config",
|
9
|
-
'aws_keys' => {
|
10
|
-
'default' => {
|
11
|
-
'access_key_id' => ENV['AMAZON_ACCESS_KEY_ID'],
|
12
|
-
'secret_access_key' => ENV['AMAZON_SECRET_ACCESS_KEY']
|
13
|
-
}
|
14
|
-
},
|
15
|
-
'regions' => %w(ap-northeast-1),
|
16
|
-
}.merge(config)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.load(path)
|
20
|
-
new YAML.load(open(path).read)
|
21
|
-
end
|
22
|
-
|
23
|
-
def save(path)
|
24
|
-
open(path, 'w') {|f| f.write @config.to_yaml }
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.update_or_create(path, config={})
|
28
|
-
dotfile = if File.exist?(path)
|
29
|
-
Dotfile.load(path)
|
30
|
-
else
|
31
|
-
new
|
32
|
-
end
|
33
|
-
dotfile.update(config)
|
34
|
-
dotfile.save(path)
|
35
|
-
end
|
36
|
-
|
37
|
-
def [](key)
|
38
|
-
@config[key]
|
39
|
-
end
|
40
|
-
|
41
|
-
def aws_key(keyname)
|
42
|
-
self['aws_keys'][keyname] or raise AwsKeyNotFound
|
43
|
-
end
|
44
|
-
|
45
|
-
def update(config)
|
46
|
-
@config = @config.merge config
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/ec2ssh/hosts.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'aws-sdk'
|
2
|
-
require 'ec2ssh/dotfile'
|
3
|
-
|
4
|
-
module Ec2ssh
|
5
|
-
class AwsEnvNotDefined < StandardError; end
|
6
|
-
class Hosts
|
7
|
-
def initialize(dotfile, keyname)
|
8
|
-
@dotfile = dotfile
|
9
|
-
@ec2 = Hash.new do |h,region|
|
10
|
-
key = dotfile.aws_key(keyname)
|
11
|
-
raise AwsEnvNotDefined if key['access_key_id'].nil? || key['secret_access_key'].nil?
|
12
|
-
h[region] = AWS::EC2.new(
|
13
|
-
:region => region,
|
14
|
-
:access_key_id => key['access_key_id'],
|
15
|
-
:secret_access_key => key['secret_access_key']
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def all
|
21
|
-
@dotfile['regions'].map {|region|
|
22
|
-
process_region region
|
23
|
-
}.flatten
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
def process_region(region)
|
28
|
-
instances(region).map {|instance|
|
29
|
-
name_tag = instance[:tag_set].find {|tag| tag[:key] == 'Name' }
|
30
|
-
next nil if name_tag.nil? || name_tag[:value].nil?
|
31
|
-
name = name_tag[:value]
|
32
|
-
dns_name = instance[:dns_name] or next nil
|
33
|
-
{:host => "#{name}.#{region}", :dns_name => dns_name}
|
34
|
-
}.compact.sort {|a,b| a[:host] <=> b[:host] }
|
35
|
-
end
|
36
|
-
|
37
|
-
def instances(region)
|
38
|
-
response = @ec2[region].instances.tagged('Name').filtered_request(:describe_instances)
|
39
|
-
response[:instance_index].values
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/spec/lib/ec2ssh/cli_spec.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'ec2ssh/cli'
|
3
|
-
require 'ec2ssh/dotfile'
|
4
|
-
|
5
|
-
describe Ec2ssh::CLI do
|
6
|
-
before(:all) do
|
7
|
-
Ec2ssh::Hosts.tap do |cls|
|
8
|
-
cls.class_eval do
|
9
|
-
def all
|
10
|
-
[
|
11
|
-
{:host => 'db-01.ap-northeast-1', :dns_name => 'ec2-1-1-1-1.ap-northeast-1.ec2.amazonaws.com'},
|
12
|
-
{:host => 'db-02.ap-northeast-1', :dns_name => 'ec2-1-1-1-2.ap-northeast-1.ec2.amazonaws.com'},
|
13
|
-
]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
before do
|
19
|
-
File.delete(dotfile_path) if File.exist?(dotfile_path)
|
20
|
-
end
|
21
|
-
let(:cli) { described_class }
|
22
|
-
let(:ssh_config_path) do
|
23
|
-
path = tmp_dir.join('ssh_config')
|
24
|
-
path.open('w') {|f| f.write <<-END }
|
25
|
-
Host foo.bar.com
|
26
|
-
HostName 1.2.3.4
|
27
|
-
END
|
28
|
-
path
|
29
|
-
end
|
30
|
-
let(:ssh_config_string) { ssh_config_path.read }
|
31
|
-
let(:dotfile_path) do
|
32
|
-
tmp_dir.join('dot.ec2ssh')
|
33
|
-
end
|
34
|
-
|
35
|
-
around do |example|
|
36
|
-
tz = ENV['TZ']
|
37
|
-
ENV['TZ'] = 'UTC'
|
38
|
-
Timecop.freeze(Time.local(2013,1,1,0,0,0)) { example.call }
|
39
|
-
ENV['TZ'] = tz
|
40
|
-
end
|
41
|
-
|
42
|
-
subject { ssh_config_string }
|
43
|
-
|
44
|
-
describe '#init' do
|
45
|
-
before do
|
46
|
-
silence(:stdout) { cli.start %W[init --path #{ssh_config_path} --dotfile #{dotfile_path}] }
|
47
|
-
end
|
48
|
-
|
49
|
-
it { should eq(<<-END) }
|
50
|
-
Host foo.bar.com
|
51
|
-
HostName 1.2.3.4
|
52
|
-
### EC2SSH BEGIN ###
|
53
|
-
# Generated by ec2ssh http://github.com/mirakui/ec2ssh
|
54
|
-
# DO NOT edit this block!
|
55
|
-
# Updated 2013-01-01T00:00:00+00:00
|
56
|
-
|
57
|
-
### EC2SSH END ###
|
58
|
-
END
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#update' do
|
62
|
-
before do
|
63
|
-
silence(:stdout) do
|
64
|
-
cli.start %W[init --path #{ssh_config_path} --dotfile #{dotfile_path}]
|
65
|
-
cli.start %W[update --path #{ssh_config_path} --dotfile #{dotfile_path}]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it { should eq(<<-END) }
|
70
|
-
Host foo.bar.com
|
71
|
-
HostName 1.2.3.4
|
72
|
-
### EC2SSH BEGIN ###
|
73
|
-
# Generated by ec2ssh http://github.com/mirakui/ec2ssh
|
74
|
-
# DO NOT edit this block!
|
75
|
-
# Updated 2013-01-01T00:00:00+00:00
|
76
|
-
# section: default
|
77
|
-
Host db-01.ap-northeast-1
|
78
|
-
HostName ec2-1-1-1-1.ap-northeast-1.ec2.amazonaws.com
|
79
|
-
Host db-02.ap-northeast-1
|
80
|
-
HostName ec2-1-1-1-2.ap-northeast-1.ec2.amazonaws.com
|
81
|
-
|
82
|
-
|
83
|
-
### EC2SSH END ###
|
84
|
-
END
|
85
|
-
end
|
86
|
-
|
87
|
-
describe '#update with aws-keys option' do
|
88
|
-
before do
|
89
|
-
silence(:stdout) do
|
90
|
-
cli.start %W[init --path #{ssh_config_path} --dotfile #{dotfile_path}]
|
91
|
-
end
|
92
|
-
dotfile = Ec2ssh::Dotfile.load(dotfile_path)
|
93
|
-
dotfile['aws_keys']['key1'] = {
|
94
|
-
'access_key_id' => 'ACCESS_KEY_ID',
|
95
|
-
'secret_access_key' => 'SECRET_ACCESS_KEY'
|
96
|
-
}
|
97
|
-
@output = capture(:stdout) do
|
98
|
-
cli.start %W[update --path #{ssh_config_path} --dotfile #{dotfile_path} --aws-key #{keyname}]
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
subject { @output }
|
103
|
-
|
104
|
-
context do
|
105
|
-
let(:keyname) { 'default' }
|
106
|
-
it { should =~ /Updated 2 hosts/ }
|
107
|
-
it { should =~ /# section: default/ }
|
108
|
-
end
|
109
|
-
|
110
|
-
context do
|
111
|
-
let(:keyname) { 'key1' }
|
112
|
-
it { should =~ /Updated 2 hosts/ }
|
113
|
-
it { should =~ /# section: key1/ }
|
114
|
-
end
|
115
|
-
|
116
|
-
context do
|
117
|
-
let(:keyname) { 'key2' }
|
118
|
-
it { should_not =~ /^Updated 2 hosts/ }
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe '#update with aws-keys option in multiple times' do
|
123
|
-
before do
|
124
|
-
silence(:stdout) do
|
125
|
-
cli.start %W[init --path #{ssh_config_path} --dotfile #{dotfile_path}]
|
126
|
-
end
|
127
|
-
dotfile = Ec2ssh::Dotfile.load(dotfile_path)
|
128
|
-
dotfile['aws_keys']['key1'] = {
|
129
|
-
'access_key_id' => 'ACCESS_KEY_ID',
|
130
|
-
'secret_access_key' => 'SECRET_ACCESS_KEY'
|
131
|
-
}
|
132
|
-
dotfile['aws_keys']['key2'] = {
|
133
|
-
'access_key_id' => 'ACCESS_KEY_ID',
|
134
|
-
'secret_access_key' => 'SECRET_ACCESS_KEY'
|
135
|
-
}
|
136
|
-
@output = capture(:stdout) do
|
137
|
-
cli.start %W[update --path #{ssh_config_path} --dotfile #{dotfile_path} --aws-key key1]
|
138
|
-
cli.start %W[update --path #{ssh_config_path} --dotfile #{dotfile_path} --aws-key #{keyname}]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
subject { @output }
|
143
|
-
|
144
|
-
context 'when updated by the same key' do
|
145
|
-
let(:keyname) { 'key1' }
|
146
|
-
it { subject.should =~ /# section: key1/ }
|
147
|
-
it { subject.should_not =~ /# section: key2/ }
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'when updated by different key' do
|
151
|
-
let(:keyname) { 'key2' }
|
152
|
-
it { subject.should =~ /# section: key1/ }
|
153
|
-
it { subject.should =~ /# section: key2/ }
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe '#remove' do
|
158
|
-
before do
|
159
|
-
silence(:stdout) do
|
160
|
-
cli.start %W[init --path #{ssh_config_path} --dotfile #{dotfile_path}]
|
161
|
-
cli.start %W[update --path #{ssh_config_path} --dotfile #{dotfile_path}]
|
162
|
-
cli.start %W[remove --path #{ssh_config_path} --dotfile #{dotfile_path}]
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
it { should eq(<<-END) }
|
167
|
-
Host foo.bar.com
|
168
|
-
HostName 1.2.3.4
|
169
|
-
END
|
170
|
-
end
|
171
|
-
end
|