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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 427d803411f39f80c250748ed172af0f72308082
4
- data.tar.gz: 0378e1f19cfd75db31a2441967b46e72f3abbd15
3
+ metadata.gz: 0fed04d98aec0c6bc32e228fec63e1a7040d7f3e
4
+ data.tar.gz: 778787d2041ac64d967d03a6bfd07515038308fd
5
5
  SHA512:
6
- metadata.gz: f8e5de4f469dbbfc56f6061484932748b0e6387f72035b51d9a53ce453fa2b8ee4007ce06e253ef087073c61d05999991ac44c16959a86b84a35d384261e8556
7
- data.tar.gz: a77fffdc9fec166647df4372238a277600bed4a8dbc8c4fa3935311de0a2b8f3712441ac6ec3f0bd4386a04d0b491ad976ef63797ddcf18bc1caf95f893678d9
6
+ metadata.gz: fac818f9832e2c5f51c754ddad8c6004a16714bd651913062c35874c1be3282cfccf17740a480069355551e71149bc4181f3179c4dece7e6e404b93af21966f7
7
+ data.tar.gz: 81122aef18a18b74f062e6f2b16aab5f1c84f5c275b82192307c40176823171c1b08ba58e7ad3cbc0097d0d70300cb6a47f6390bc6a8e01a13348b2fbf1a2a33
@@ -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. Install ec2ssh
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
- ### 3. Execute `ec2ssh init`
33
+ ### 4. Execute `ec2ssh init`
19
34
 
20
35
  ```
21
36
  $ ec2ssh init
22
37
  ```
23
38
 
24
- ### 4. Edit `.ec2ssh`
39
+ ### 5. Edit `.ec2ssh`
25
40
 
26
41
  ```
27
42
  $ vi ~/.ec2ssh
28
43
  ---
29
- aws_keys(
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
- ### 5. Execute `ec2ssh update`
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
- ### 6. And you can ssh to your instances with your tagged name.
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
@@ -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"
@@ -1,17 +1,9 @@
1
- path '~/.ssh/config'
2
- aws_keys(
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
- host_lines <<END
5
+
6
+ host_line <<END
15
7
  Host <%= tags['Name'] %>
16
8
  HostName <%= private_ip_address %>
17
9
  END
@@ -13,7 +13,7 @@ module Ec2ssh
13
13
 
14
14
  def build_host_lines
15
15
  out = StringIO.new
16
- @container.aws_keys.each do |name, key|
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 @container.aws_keys, @container.regions
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
@@ -19,7 +19,6 @@ module Ec2ssh
19
19
  end
20
20
 
21
21
  desc 'update', 'Update ec2 hosts list in ssh_config'
22
- method_option :aws_key, banner: 'aws key name', default: 'default'
23
22
  def update
24
23
  check_dotfile_existence
25
24
  check_dotfile_version
@@ -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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Ec2ssh
2
- VERSION = '3.0.3'
2
+ VERSION = '3.1.0.rc1'
3
3
  end
@@ -2,7 +2,29 @@ require 'spec_helper'
2
2
  require 'ec2ssh/dsl'
3
3
 
4
4
  describe Ec2ssh::Dsl do
5
- let(:dsl_str) do
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
- subject(:result) { Ec2ssh::Dsl::Parser.parse dsl_str }
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
- its(:aws_keys) do
21
- should == {
22
- key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' },
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(aws_keys='', regions=[region]).tap do |e|
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
@@ -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.3
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-02-22 00:00:00.000000000 Z
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: '0'
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: '0'
117
+ version: 1.3.1
118
118
  requirements: []
119
119
  rubyforge_project: ec2ssh
120
120
  rubygems_version: 2.4.5