ec2ssh 3.1.0.rc1 → 5.0.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.
@@ -3,10 +3,13 @@ require 'ec2ssh/command/update'
3
3
  require 'ec2ssh/exceptions'
4
4
 
5
5
  describe Ec2ssh::Command::Update do
6
+ include FakeFS::SpecHelpers
7
+
6
8
  describe '#run' do
7
9
  let(:command) do
8
10
  described_class.new(cli).tap do |cmd|
9
11
  allow(cmd).to receive(:options).and_return(options)
12
+ allow(cmd.builder).to receive(:aws_keys) { aws_keys }
10
13
  allow(cmd.builder.ec2s).to receive(:instances) { instances }
11
14
  end
12
15
  end
@@ -16,10 +19,13 @@ describe Ec2ssh::Command::Update do
16
19
  let(:cli) do
17
20
  double(:cli, options: options, red: nil, yellow: nil, green: nil)
18
21
  end
22
+ let(:aws_keys) do
23
+ {'default' => {'us-west-1' => Aws::Credentials.new('access_key_id', 'secret_access_key')}}
24
+ end
19
25
  let(:instances) do
20
26
  [
21
- double('instance', tags: {'Name' => 'srv1'}, private_ip_address: '10.0.0.1'),
22
- double('instance', tags: {'Name' => 'srv2'}, private_ip_address: '10.0.0.2')
27
+ double('instance', private_ip_address: '10.0.0.1').tap {|m| allow(m).to receive(:tag).with('Name').and_return('srv1') },
28
+ double('instance', private_ip_address: '10.0.0.2').tap {|m| allow(m).to receive(:tag).with('Name').and_return('srv2') }
23
29
  ]
24
30
  end
25
31
 
@@ -32,11 +38,10 @@ describe Ec2ssh::Command::Update do
32
38
  let(:ssh_config_str) { '' }
33
39
  let(:dotfile_str) { <<-END }
34
40
  path '/dotfile'
35
- aws_keys(
36
- default: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' }
37
- )
41
+ profiles 'default'
42
+ regions 'us-west-1'
38
43
  host_line <<EOS
39
- Host <%= tags['Name'] %>
44
+ Host <%= tag('Name') %>
40
45
  HostName <%= private_ip_address %>
41
46
  EOS
42
47
  END
@@ -58,11 +63,10 @@ EOS
58
63
 
59
64
  let(:dotfile_str) { <<-END }
60
65
  path '/dotfile'
61
- aws_keys(
62
- default: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' }
63
- )
66
+ profiles 'default'
67
+ regions 'us-west-1'
64
68
  host_line <<EOS
65
- Host <%= tags['Name'] %>
69
+ Host <%= tag('Name') %>
66
70
  HostName <%= private_ip_address %>
67
71
  EOS
68
72
  END
@@ -27,10 +27,9 @@ END
27
27
  let(:dsl_str) do
28
28
  <<-END
29
29
  aws_keys(
30
- key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' },
31
- key2: { access_key_id: 'ACCESS_KEY2', secret_access_key: 'SECRET2' }
30
+ 'key1' => { 'ap-northeast-1' => Aws::Credentials.new('ACCESS_KEY1', 'SECRET1') },
31
+ 'key2' => { 'us-east-1' => Aws::Credentials.new('ACCESS_KEY2', 'SECRET2') }
32
32
  )
33
- regions 'ap-northeast-1', 'us-east-1'
34
33
  host_line 'host lines'
35
34
  reject {|instance| instance }
36
35
  path 'path'
@@ -40,13 +39,12 @@ END
40
39
  subject(:result) { Ec2ssh::Dsl::Parser.parse dsl_str }
41
40
 
42
41
  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
- }
42
+ it do
43
+ expect(result.aws_keys).to match(
44
+ 'key1' => { 'ap-northeast-1' => be_a(Aws::Credentials).and(have_attributes(access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1')) } ,
45
+ 'key2' => { 'us-east-1' => be_a(Aws::Credentials).and(have_attributes(access_key_id: 'ACCESS_KEY2', secret_access_key: 'SECRET2')) }
46
+ )
48
47
  end
49
- its(:regions) { should == ['ap-northeast-1', 'us-east-1'] }
50
48
  its(:host_line) { should == 'host lines' }
51
49
  it { expect(result.reject.call(123)).to eq(123) }
52
50
  its(:path) { should == 'path' }
@@ -56,8 +54,8 @@ END
56
54
  let(:dsl_str) do
57
55
  <<-END
58
56
  aws_keys(
59
- key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' },
60
- key2: { access_key_id: 'ACCESS_KEY2', secret_access_key: 'SECRET2' }
57
+ 'key1' => { 'ap-northeast-1' => Aws::Credentials.new('ACCESS_KEY1', 'SECRET1') },
58
+ 'key2' => { 'us-east-1' => Aws::Credentials.new('ACCESS_KEY2', 'SECRET2') }
61
59
  )
62
60
  profiles 'default', 'myprofile'
63
61
  regions 'ap-northeast-1', 'us-east-1'
@@ -71,4 +69,39 @@ END
71
69
  expect { Ec2ssh::Dsl::Parser.parse dsl_str }.to raise_error Ec2ssh::DotfileValidationError
72
70
  end
73
71
  end
72
+
73
+ context 'with old structure aws_keys' do
74
+ let(:dsl_str) do
75
+ <<-END
76
+ aws_keys(
77
+ key1: { access_key_id: 'ACCESS_KEY1', secret_access_key: 'SECRET1' },
78
+ key2: { access_key_id: 'ACCESS_KEY2', secret_access_key: 'SECRET2' }
79
+ )
80
+ regions 'ap-northeast-1', 'us-east-1'
81
+ host_line 'host lines'
82
+ reject {|instance| instance }
83
+ path 'path'
84
+ END
85
+ end
86
+
87
+ it { expect { Ec2ssh::Dsl::Parser.parse dsl_str }.to raise_error Ec2ssh::DotfileValidationError }
88
+ end
89
+
90
+ context 'with filters' do
91
+ let(:dsl_str) do
92
+ <<-END
93
+ regions 'ap-northeast-1', 'us-east-1'
94
+ filters [{
95
+ name: 'instance-state-name',
96
+ values: ['running', 'stopped']
97
+ }]
98
+ END
99
+ end
100
+
101
+ subject(:result) { Ec2ssh::Dsl::Parser.parse dsl_str }
102
+
103
+ it do
104
+ expect(result.filters).to eq([{name:'instance-state-name', values:['running', 'stopped']}])
105
+ end
106
+ end
74
107
  end
@@ -12,9 +12,11 @@ describe Ec2ssh::Ec2Instances do
12
12
  }
13
13
 
14
14
  let(:mock) do
15
- described_class.new(profiles='', regions=[region]).tap do |e|
15
+ described_class.new(
16
+ {key_name => {region => ''}},
17
+ [{ name: 'instance-state-name', values: ['running'] }]
18
+ ).tap do |e|
16
19
  allow(e).to receive(:ec2s) { ec2s }
17
- allow(e).to receive(:regions) { [region] }
18
20
  end
19
21
  end
20
22
 
@@ -37,9 +39,9 @@ describe Ec2ssh::Ec2Instances do
37
39
  context 'with non-empty names' do
38
40
  let(:mock_instances) {
39
41
  [
40
- double('instance', n: 1, tags: {'Name' => 'srvB' }),
41
- double('instance', n: 2, tags: {'Name' => 'srvA' }),
42
- double('instance', n: 3, tags: {'Name' => 'srvC' })
42
+ double('instance', n: 1, tags: [double('tag', key: 'Name', value: 'srvB')]),
43
+ double('instance', n: 2, tags: [double('tag', key: 'Name', value: 'srvA')]),
44
+ double('instance', n: 3, tags: [double('tag', key: 'Name', value: 'srvC')])
43
45
  ]
44
46
  }
45
47
 
@@ -52,9 +54,9 @@ describe Ec2ssh::Ec2Instances do
52
54
  context 'with names including empty one' do
53
55
  let(:mock_instances) {
54
56
  [
55
- double('instance', n: 1, tags: {'Name' => 'srvA'}),
56
- double('instance', n: 2, tags: {}),
57
- double('instance', n: 3, tags: {'Name' => 'srvC' })
57
+ double('instance', n: 1, tags: [double('tag', key: 'Name', value: 'srvA')]),
58
+ double('instance', n: 2, tags: []),
59
+ double('instance', n: 3, tags: [double('tag', key: 'Name', value: 'srvC')])
58
60
  ]
59
61
  }
60
62
 
@@ -63,6 +65,22 @@ describe Ec2ssh::Ec2Instances do
63
65
  expect(result.map {|ins| ins.n}).to match_array([2, 1, 3])
64
66
  end
65
67
  end
68
+ end
69
+
70
+ describe Ec2ssh::Ec2Instances::InstanceWrapper do
71
+ let(:mock_instance) {
72
+ double('instance', n: 1, tags: [double('tag', key: 'Name', value: 'srvA')])
73
+ }
74
+ let(:instance) { described_class.new(mock_instance) }
66
75
 
76
+ describe '#tag' do
77
+ it { expect(instance.tag('Name')).to eq 'srvA' }
78
+ end
79
+
80
+ describe '#tags' do
81
+ it { expect(instance.tags).to match_array(have_attributes(key: 'Name', value: 'srvA')) }
82
+ it { expect(instance.tags[0]).to have_attributes(key: 'Name', value: 'srvA') }
83
+ it { expect { instance.tags['Name'] }.to raise_error Ec2ssh::DotfileValidationError }
84
+ end
67
85
  end
68
86
  end
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
  require 'ec2ssh/ssh_config'
3
3
 
4
4
  describe Ec2ssh::SshConfig do
5
+ include FakeFS::SpecHelpers
6
+
5
7
  let(:path) { Pathname('/ssh_config') }
6
8
 
7
9
  subject(:ssh_config) do
@@ -34,6 +34,10 @@ RSpec.configure do |config|
34
34
  end
35
35
 
36
36
  alias :silence :capture
37
+ end
37
38
 
38
- config.include FakeFS::SpecHelpers
39
+ require 'vcr'
40
+ VCR.configure do |config|
41
+ config.cassette_library_dir = "fixtures/vcr_cassettes"
42
+ config.hook_into :webmock
39
43
  end
@@ -3,82 +3,40 @@
3
3
  # main completion function
4
4
  _ec2ssh-init() {
5
5
  local ret
6
- _call_function ret __ec2ssh_noarg_cmd
7
- return $ret
8
- }
9
-
10
- _ec2ssh-migrate() {
11
- local ret
12
- _call_function ret __ec2ssh_noarg_cmd
6
+ _call_function ret __ec2ssh_common_cmd
13
7
  return $ret
14
8
  }
15
9
 
16
10
  _ec2ssh-remove() {
17
11
  local ret
18
- _call_function ret __ec2ssh_noarg_cmd
12
+ _call_function ret __ec2ssh_common_cmd
19
13
  return $ret
20
14
  }
21
15
 
22
16
  _ec2ssh-update() {
23
- local curcontext context state line
24
- declare -A opt_args
25
-
26
- integer ret=1
27
- _arguments -C -S \
28
- '--aws-key:aws key name:__ec2ssh_aws_keys' \
29
- '--dotfile:ec2ssh dotfile:_files' \
30
- '--verbose' && return
17
+ local ret
18
+ _call_function ret __ec2ssh_common_cmd
31
19
  return $ret
32
20
  }
33
21
 
34
22
  _ec2ssh-version() {
35
23
  local ret
36
- _call_function ret __ec2ssh_noarg_cmd
24
+ _call_function ret __ec2ssh_common_cmd
37
25
  return $ret
38
26
  }
39
27
 
40
- __ec2ssh_noarg_cmd() {
28
+ __ec2ssh_common_cmd() {
41
29
  local curcontext context state line
42
30
  declare -A opt_args
43
31
 
44
32
  integer ret=1
45
33
  _arguments -C -S \
34
+ '--path:ssh_config file:_files' \
46
35
  '--dotfile:ec2ssh dotfile:_files' \
47
36
  '--verbose' && return
48
37
  return $ret
49
38
  }
50
39
 
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
-
82
40
  _ec2ssh() {
83
41
  local curcontext context state line
84
42
  declare -A opt_args
@@ -86,6 +44,7 @@ _ec2ssh() {
86
44
  integer ret=1
87
45
 
88
46
  _arguments -C -S \
47
+ '--path:ssh_config file:_files' \
89
48
  '--dotfile:ec2ssh dotfile:_files' \
90
49
  '--verbose' \
91
50
  '(-): :->commands' \
@@ -111,7 +70,6 @@ _ec2ssh_commands() {
111
70
  _values 'command' \
112
71
  'help[Describe available commands or one specific command]' \
113
72
  'init[Add ec2ssh mark to ssh_config]' \
114
- 'migrate[Migrate dotfile from old versions]' \
115
73
  'remove[Remove ec2ssh mark from ssh_config]' \
116
74
  'update[Update ec2 hosts list in ssh_config]' \
117
75
  'version[Show version]'
metadata CHANGED
@@ -1,57 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.rc1
4
+ version: 5.0.0
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-08-08 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.14'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.14'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: highline
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: '1.6'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.0'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">="
39
48
  - !ruby/object:Gem::Version
40
49
  version: '1.6'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: aws-sdk-core
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3'
41
67
  - !ruby/object:Gem::Dependency
42
- name: aws-sdk
68
+ name: aws-sdk-ec2
43
69
  requirement: !ruby/object:Gem::Requirement
44
70
  requirements:
45
71
  - - "~>"
46
72
  - !ruby/object:Gem::Version
47
- version: '1.8'
73
+ version: '1'
48
74
  type: :runtime
49
75
  prerelease: false
50
76
  version_requirements: !ruby/object:Gem::Requirement
51
77
  requirements:
52
78
  - - "~>"
53
79
  - !ruby/object:Gem::Version
54
- version: '1.8'
80
+ version: '1'
55
81
  description: ec2ssh is a ssh_config manager for AWS EC2
56
82
  email:
57
83
  - mimitako@gmail.com
@@ -73,33 +99,32 @@ files:
73
99
  - bin/ec2ssh
74
100
  - ec2ssh.gemspec
75
101
  - example/example.ec2ssh
102
+ - fixtures/vcr_cassettes/ec2-instances.yml
76
103
  - lib/ec2ssh.rb
77
104
  - lib/ec2ssh/builder.rb
78
105
  - lib/ec2ssh/cli.rb
79
106
  - lib/ec2ssh/command.rb
80
107
  - lib/ec2ssh/command/init.rb
81
- - lib/ec2ssh/command/migrate.rb
82
108
  - lib/ec2ssh/command/remove.rb
83
109
  - lib/ec2ssh/command/update.rb
84
110
  - lib/ec2ssh/dsl.rb
85
111
  - lib/ec2ssh/ec2_instances.rb
86
112
  - lib/ec2ssh/exceptions.rb
87
- - lib/ec2ssh/migrator.rb
88
113
  - lib/ec2ssh/ssh_config.rb
89
114
  - lib/ec2ssh/version.rb
115
+ - spec/aws_sdk_compatibility_spec.rb
90
116
  - spec/lib/ec2ssh/builder_spec.rb
91
117
  - spec/lib/ec2ssh/command/init_spec.rb
92
- - spec/lib/ec2ssh/command/migrate_spec.rb
93
118
  - spec/lib/ec2ssh/command/remove_spec.rb
94
119
  - spec/lib/ec2ssh/command/update_spec.rb
95
120
  - spec/lib/ec2ssh/dsl_spec.rb
96
121
  - spec/lib/ec2ssh/ec2_instances_spec.rb
97
- - spec/lib/ec2ssh/migrator_spec.rb
98
122
  - spec/lib/ec2ssh/ssh_config_spec.rb
99
123
  - spec/spec_helper.rb
100
124
  - zsh/_ec2ssh
101
125
  homepage: http://github.com/mirakui/ec2ssh
102
- licenses: []
126
+ licenses:
127
+ - MIT
103
128
  metadata: {}
104
129
  post_install_message:
105
130
  rdoc_options: []
@@ -109,26 +134,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
134
  requirements:
110
135
  - - ">="
111
136
  - !ruby/object:Gem::Version
112
- version: 2.0.0
137
+ version: 2.4.0
113
138
  required_rubygems_version: !ruby/object:Gem::Requirement
114
139
  requirements:
115
- - - ">"
140
+ - - ">="
116
141
  - !ruby/object:Gem::Version
117
- version: 1.3.1
142
+ version: '0'
118
143
  requirements: []
119
- rubyforge_project: ec2ssh
120
- rubygems_version: 2.4.5
144
+ rubygems_version: 3.1.2
121
145
  signing_key:
122
146
  specification_version: 4
123
147
  summary: A ssh_config manager for AWS EC2
124
148
  test_files:
149
+ - spec/aws_sdk_compatibility_spec.rb
125
150
  - spec/lib/ec2ssh/builder_spec.rb
126
151
  - spec/lib/ec2ssh/command/init_spec.rb
127
- - spec/lib/ec2ssh/command/migrate_spec.rb
128
152
  - spec/lib/ec2ssh/command/remove_spec.rb
129
153
  - spec/lib/ec2ssh/command/update_spec.rb
130
154
  - spec/lib/ec2ssh/dsl_spec.rb
131
155
  - spec/lib/ec2ssh/ec2_instances_spec.rb
132
- - spec/lib/ec2ssh/migrator_spec.rb
133
156
  - spec/lib/ec2ssh/ssh_config_spec.rb
134
157
  - spec/spec_helper.rb