ec2ssh 3.0.3 → 3.1.0.rc1
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 +4 -4
- data/ChangeLog.md +3 -0
- data/README.md +21 -12
- data/ec2ssh.gemspec +1 -0
- data/example/example.ec2ssh +4 -12
- data/lib/ec2ssh/builder.rb +14 -2
- data/lib/ec2ssh/cli.rb +0 -1
- data/lib/ec2ssh/dsl.rb +12 -1
- data/lib/ec2ssh/ec2_instances.rb +6 -1
- data/lib/ec2ssh/exceptions.rb +1 -0
- data/lib/ec2ssh/version.rb +1 -1
- data/spec/lib/ec2ssh/dsl_spec.rb +55 -11
- data/spec/lib/ec2ssh/ec2_instances_spec.rb +2 -2
- data/zsh/_ec2ssh +32 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fed04d98aec0c6bc32e228fec63e1a7040d7f3e
|
4
|
+
data.tar.gz: 778787d2041ac64d967d03a6bfd07515038308fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac818f9832e2c5f51c754ddad8c6004a16714bd651913062c35874c1be3282cfccf17740a480069355551e71149bc4181f3179c4dece7e6e404b93af21966f7
|
7
|
+
data.tar.gz: 81122aef18a18b74f062e6f2b16aab5f1c84f5c275b82192307c40176823171c1b08ba58e7ad3cbc0097d0d70300cb6a47f6390bc6a8e01a13348b2fbf1a2a33
|
data/ChangeLog.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Change Log
|
2
|
+
## 3.1.0
|
3
|
+
* Use credentials from `~/.aws/credentials` as default. Credential profiles are set as `profiles` in dotfile.
|
4
|
+
|
2
5
|
## 3.0.3
|
3
6
|
* Use "%-" for ERB's trim\_mode at `host\_line` in dotfile (#29)
|
4
7
|
* Add 'shellcomp' command: loading completion functions easily in bash/zsh (#27)
|
data/README.md
CHANGED
@@ -9,30 +9,39 @@ ec2ssh is a ssh_config manager for Amazon EC2.
|
|
9
9
|
### 1. Set 'Name' tag to your instances
|
10
10
|
eg. Tag 'app-server-1' as 'Name' to an instance i-xxxxx in us-west-1 region.
|
11
11
|
|
12
|
-
### 2.
|
12
|
+
### 2. Write ~/.aws/credentials
|
13
|
+
```
|
14
|
+
# ~/.aws/credentials
|
15
|
+
|
16
|
+
[default]
|
17
|
+
aws_access_key_id=...
|
18
|
+
aws_secret_access_key=...
|
19
|
+
|
20
|
+
[myprofile]
|
21
|
+
aws_access_key_id=...
|
22
|
+
aws_secret_access_key=...
|
23
|
+
```
|
24
|
+
|
25
|
+
If you need more details about `~/.aws/credentials`, check [A New and Standardized Way to Manage Credentials in the AWS SDKs](http://blogs.aws.amazon.com/security/post/Tx3D6U6WSFGOK2H/A-New-and-Standardized-Way-to-Manage-Credentials-in-the-AWS-SDKs)
|
26
|
+
|
27
|
+
### 3. Install ec2ssh
|
13
28
|
|
14
29
|
```
|
15
30
|
$ gem install ec2ssh
|
16
31
|
```
|
17
32
|
|
18
|
-
###
|
33
|
+
### 4. Execute `ec2ssh init`
|
19
34
|
|
20
35
|
```
|
21
36
|
$ ec2ssh init
|
22
37
|
```
|
23
38
|
|
24
|
-
###
|
39
|
+
### 5. Edit `.ec2ssh`
|
25
40
|
|
26
41
|
```
|
27
42
|
$ vi ~/.ec2ssh
|
28
43
|
---
|
29
|
-
|
30
|
-
default: {
|
31
|
-
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
32
|
-
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
33
|
-
},
|
34
|
-
# my_key1: { access_key_id: '...', secret_access_key: '...' }, ...
|
35
|
-
)
|
44
|
+
profiles 'default', 'myprofile'
|
36
45
|
regions 'us-east-1'
|
37
46
|
|
38
47
|
# Ignore unnamed instances
|
@@ -46,14 +55,14 @@ Host <%= tags['Name'] %>.<%= availability_zone %>
|
|
46
55
|
END
|
47
56
|
```
|
48
57
|
|
49
|
-
###
|
58
|
+
### 6. Execute `ec2ssh update`
|
50
59
|
|
51
60
|
```
|
52
61
|
$ ec2ssh update
|
53
62
|
```
|
54
63
|
Then host-names of your instances are generated and wrote to .ssh/config
|
55
64
|
|
56
|
-
###
|
65
|
+
### 7. And you can ssh to your instances with your tagged name.
|
57
66
|
|
58
67
|
```
|
59
68
|
$ ssh app-server-1.us-east-1a
|
data/ec2ssh.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "http://github.com/mirakui/ec2ssh"
|
12
12
|
s.summary = %q{A ssh_config manager for AWS EC2}
|
13
13
|
s.description = %q{ec2ssh is a ssh_config manager for AWS EC2}
|
14
|
+
s.required_ruby_version = ">= 2.0.0"
|
14
15
|
|
15
16
|
s.rubyforge_project = "ec2ssh"
|
16
17
|
s.add_dependency "thor", "~> 0.14"
|
data/example/example.ec2ssh
CHANGED
@@ -1,17 +1,9 @@
|
|
1
|
-
path '
|
2
|
-
|
3
|
-
{
|
4
|
-
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
5
|
-
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
6
|
-
},
|
7
|
-
#{
|
8
|
-
# access_key_id: '...'
|
9
|
-
# secret_access_key: '...'
|
10
|
-
#}
|
11
|
-
)
|
1
|
+
path "#{ENV['HOME']}/.ssh/config"
|
2
|
+
profiles 'default', 'myprofile'
|
12
3
|
regions 'ap-northeast-1', 'us-east-1'
|
13
4
|
reject {|instance| instance.tags['Name'] =~ /.../ }
|
14
|
-
|
5
|
+
|
6
|
+
host_line <<END
|
15
7
|
Host <%= tags['Name'] %>
|
16
8
|
HostName <%= private_ip_address %>
|
17
9
|
END
|
data/lib/ec2ssh/builder.rb
CHANGED
@@ -13,7 +13,7 @@ module Ec2ssh
|
|
13
13
|
|
14
14
|
def build_host_lines
|
15
15
|
out = StringIO.new
|
16
|
-
|
16
|
+
aws_keys.each do |name, key|
|
17
17
|
out.puts "# section: #{name}"
|
18
18
|
ec2s.instances(name).each do |instance|
|
19
19
|
bind = instance.instance_eval { binding }
|
@@ -26,7 +26,19 @@ module Ec2ssh
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def ec2s
|
29
|
-
@ec2s ||= Ec2Instances.new
|
29
|
+
@ec2s ||= Ec2Instances.new aws_keys, @container.regions
|
30
|
+
end
|
31
|
+
|
32
|
+
def aws_keys
|
33
|
+
@aws_keys ||= if @container.profiles
|
34
|
+
keys = {}
|
35
|
+
@container.profiles.each do |profile_name|
|
36
|
+
keys[profile_name] = Ec2Instances.expand_profile_name_to_credential profile_name
|
37
|
+
end
|
38
|
+
keys
|
39
|
+
else
|
40
|
+
@container.aws_keys
|
41
|
+
end
|
30
42
|
end
|
31
43
|
end
|
32
44
|
end
|
data/lib/ec2ssh/cli.rb
CHANGED
data/lib/ec2ssh/dsl.rb
CHANGED
@@ -12,6 +12,10 @@ module Ec2ssh
|
|
12
12
|
@_result.aws_keys = keys
|
13
13
|
end
|
14
14
|
|
15
|
+
def profiles(*profiles)
|
16
|
+
@_result.profiles = profiles
|
17
|
+
end
|
18
|
+
|
15
19
|
def regions(*regions)
|
16
20
|
@_result.regions = regions
|
17
21
|
end
|
@@ -30,6 +34,7 @@ module Ec2ssh
|
|
30
34
|
|
31
35
|
class Container < Struct.new(*%i[
|
32
36
|
aws_keys
|
37
|
+
profiles
|
33
38
|
regions
|
34
39
|
host_line
|
35
40
|
reject
|
@@ -41,7 +46,7 @@ module Ec2ssh
|
|
41
46
|
def self.parse(dsl_str)
|
42
47
|
dsl = Dsl.new
|
43
48
|
dsl.instance_eval dsl_str
|
44
|
-
dsl._result
|
49
|
+
dsl._result.tap {|result| validate result }
|
45
50
|
rescue SyntaxError => e
|
46
51
|
raise DotfileSyntaxError, e.to_s
|
47
52
|
end
|
@@ -50,6 +55,12 @@ module Ec2ssh
|
|
50
55
|
raise DotfileNotFound, path.to_s unless File.exist?(path)
|
51
56
|
parse File.read(path)
|
52
57
|
end
|
58
|
+
|
59
|
+
def self.validate(result)
|
60
|
+
if result.aws_keys && result.profiles
|
61
|
+
raise DotfileValidationError, "`aws_keys` and `profiles` doesn't work together in dotfile."
|
62
|
+
end
|
63
|
+
end
|
53
64
|
end
|
54
65
|
end
|
55
66
|
end
|
data/lib/ec2ssh/ec2_instances.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aws-sdk'
|
1
|
+
require 'aws-sdk-v1'
|
2
2
|
|
3
3
|
module Ec2ssh
|
4
4
|
class Ec2Instances
|
@@ -34,5 +34,10 @@ module Ec2ssh
|
|
34
34
|
sort_by {|ins| ins.tags['Name'].to_s }
|
35
35
|
}.flatten
|
36
36
|
end
|
37
|
+
|
38
|
+
def self.expand_profile_name_to_credential(profile_name)
|
39
|
+
provider = AWS::Core::CredentialProviders::SharedCredentialFileProvider.new(profile_name: profile_name)
|
40
|
+
provider.credentials
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
data/lib/ec2ssh/exceptions.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Ec2ssh
|
2
2
|
class DotfileNotFound < StandardError; end
|
3
3
|
class DotfileSyntaxError < StandardError; end
|
4
|
+
class DotfileValidationError < StandardError; end
|
4
5
|
class ObsoleteDotfile < StandardError; end
|
5
6
|
class InvalidDotfile < StandardError; end
|
6
7
|
class MarkNotFound < StandardError; end
|
data/lib/ec2ssh/version.rb
CHANGED
data/spec/lib/ec2ssh/dsl_spec.rb
CHANGED
@@ -2,7 +2,29 @@ require 'spec_helper'
|
|
2
2
|
require 'ec2ssh/dsl'
|
3
3
|
|
4
4
|
describe Ec2ssh::Dsl do
|
5
|
-
|
5
|
+
context 'with profiles' do
|
6
|
+
let(:dsl_str) do
|
7
|
+
<<-END
|
8
|
+
profiles 'default', 'myprofile'
|
9
|
+
regions 'ap-northeast-1', 'us-east-1'
|
10
|
+
host_line 'host lines'
|
11
|
+
reject {|instance| instance }
|
12
|
+
path 'path'
|
13
|
+
END
|
14
|
+
end
|
15
|
+
|
16
|
+
subject(:result) { Ec2ssh::Dsl::Parser.parse dsl_str }
|
17
|
+
|
18
|
+
its(:profiles) { should == ['default', 'myprofile'] }
|
19
|
+
its(:aws_keys) { should be_nil }
|
20
|
+
its(:regions) { should == ['ap-northeast-1', 'us-east-1'] }
|
21
|
+
its(:host_line) { should == 'host lines' }
|
22
|
+
it { expect(result.reject.call(123)).to eq(123) }
|
23
|
+
its(:path) { should == 'path' }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with aws_keys' do
|
27
|
+
let(:dsl_str) do
|
6
28
|
<<-END
|
7
29
|
aws_keys(
|
8
30
|
key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' },
|
@@ -13,18 +35,40 @@ host_line 'host lines'
|
|
13
35
|
reject {|instance| instance }
|
14
36
|
path 'path'
|
15
37
|
END
|
38
|
+
end
|
39
|
+
|
40
|
+
subject(:result) { Ec2ssh::Dsl::Parser.parse dsl_str }
|
41
|
+
|
42
|
+
its(:profiles) { should be_nil }
|
43
|
+
its(:aws_keys) do
|
44
|
+
should == {
|
45
|
+
key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' },
|
46
|
+
key2: { access_key_id: 'ACCESS_KEY2', secret_access_key: 'SECRET2' }
|
47
|
+
}
|
48
|
+
end
|
49
|
+
its(:regions) { should == ['ap-northeast-1', 'us-east-1'] }
|
50
|
+
its(:host_line) { should == 'host lines' }
|
51
|
+
it { expect(result.reject.call(123)).to eq(123) }
|
52
|
+
its(:path) { should == 'path' }
|
16
53
|
end
|
17
54
|
|
18
|
-
|
55
|
+
context 'with profiles and aws_keys both' do
|
56
|
+
let(:dsl_str) do
|
57
|
+
<<-END
|
58
|
+
aws_keys(
|
59
|
+
key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' },
|
60
|
+
key2: { access_key_id: 'ACCESS_KEY2', secret_access_key: 'SECRET2' }
|
61
|
+
)
|
62
|
+
profiles 'default', 'myprofile'
|
63
|
+
regions 'ap-northeast-1', 'us-east-1'
|
64
|
+
host_line 'host lines'
|
65
|
+
reject {|instance| instance }
|
66
|
+
path 'path'
|
67
|
+
END
|
68
|
+
end
|
19
69
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
key2: { access_key_id: 'ACCESS_KEY2', secret_access_key: 'SECRET2' }
|
24
|
-
}
|
70
|
+
it do
|
71
|
+
expect { Ec2ssh::Dsl::Parser.parse dsl_str }.to raise_error Ec2ssh::DotfileValidationError
|
72
|
+
end
|
25
73
|
end
|
26
|
-
its(:regions) { should == ['ap-northeast-1', 'us-east-1'] }
|
27
|
-
its(:host_line) { should == 'host lines' }
|
28
|
-
it { expect(result.reject.call(123)).to eq(123) }
|
29
|
-
its(:path) { should == 'path' }
|
30
74
|
end
|
@@ -12,7 +12,7 @@ describe Ec2ssh::Ec2Instances do
|
|
12
12
|
}
|
13
13
|
|
14
14
|
let(:mock) do
|
15
|
-
described_class.new(
|
15
|
+
described_class.new(profiles='', regions=[region]).tap do |e|
|
16
16
|
allow(e).to receive(:ec2s) { ec2s }
|
17
17
|
allow(e).to receive(:regions) { [region] }
|
18
18
|
end
|
@@ -65,4 +65,4 @@ describe Ec2ssh::Ec2Instances do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
68
|
-
end
|
68
|
+
end
|
data/zsh/_ec2ssh
CHANGED
@@ -25,7 +25,7 @@ _ec2ssh-update() {
|
|
25
25
|
|
26
26
|
integer ret=1
|
27
27
|
_arguments -C -S \
|
28
|
-
'--aws-key:aws key name' \
|
28
|
+
'--aws-key:aws key name:__ec2ssh_aws_keys' \
|
29
29
|
'--dotfile:ec2ssh dotfile:_files' \
|
30
30
|
'--verbose' && return
|
31
31
|
return $ret
|
@@ -48,6 +48,37 @@ __ec2ssh_noarg_cmd() {
|
|
48
48
|
return $ret
|
49
49
|
}
|
50
50
|
|
51
|
+
_ec2ssh-help() {
|
52
|
+
local curcontext context state line
|
53
|
+
declare -A opt_args
|
54
|
+
|
55
|
+
integer ret=1
|
56
|
+
_arguments -C -S \
|
57
|
+
'(-): :->commands' && return
|
58
|
+
|
59
|
+
case $state in
|
60
|
+
(commands)
|
61
|
+
_ec2ssh_commands && ret=0
|
62
|
+
;;
|
63
|
+
esac
|
64
|
+
|
65
|
+
return $ret
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
__ec2ssh_aws_keys() {
|
70
|
+
local keys dotfile
|
71
|
+
|
72
|
+
if (( ind = ${words[(I)--dotfile]} )) && [ -f "${~words[ind+1]}" ]; then
|
73
|
+
dotfile=${~words[ind+1]}
|
74
|
+
else
|
75
|
+
dotfile="$HOME/.ec2ssh"
|
76
|
+
fi
|
77
|
+
|
78
|
+
keys=$(echo "$dotfile" | ruby -r ec2ssh/dsl -e 'puts Ec2ssh::Dsl::Parser.parse_file(STDIN.read.strip).aws_keys.keys' 2> /dev/null)
|
79
|
+
_values 'aws key name' $(echo $keys)
|
80
|
+
}
|
81
|
+
|
51
82
|
_ec2ssh() {
|
52
83
|
local curcontext context state line
|
53
84
|
declare -A opt_args
|
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: 3.0.
|
4
|
+
version: 3.1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Issei Naruta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -109,12 +109,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
requirements:
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
112
|
+
version: 2.0.0
|
113
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 1.3.1
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project: ec2ssh
|
120
120
|
rubygems_version: 2.4.5
|