opsicle 2.11.0 → 2.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1ad1bea72c477d7da8b1f4a433b43c2e9b2a046
4
- data.tar.gz: bcfa61ba70e1041e5a7b4284dd6f4a8199b679c1
3
+ metadata.gz: 8a75d1113150783a01d54f283183d80ebd130752
4
+ data.tar.gz: 235fca70e248b9d6f5a8a5e7981fdbac0f3253ce
5
5
  SHA512:
6
- metadata.gz: 6693a08f3cdecbbba71746f248a623e9611cbfaeaf6b3b79d011b5a1cef44981293fb3a484fea8d6155663e482f54e556dd014f9e67c07bfdc6c3f2876df2bcd
7
- data.tar.gz: 0a0ec60a2747b605b22dd49150c3bf204b247c23a83177ba2f72e575eb6fed11da9f192d75dbea163f7b9051e23ae2b4d3340bb4fc428b95091f77ed095886c4
6
+ metadata.gz: 009279aec4c5366d91e71cde98ee00cd90d3a9e643731a940cd555197deb9779df3acd1ec367ba0c03255eed9fecfd8d0fcef811cc463cc2a9b2505f5f4ac921
7
+ data.tar.gz: 769f9652489b563bdd867676e979c2855f4e9694d65c84c94ab4c2d59a5cc625bb9d3a60a5b9fadfedc2871568d01f513de013a3259a16442f3980b08c884773
@@ -54,11 +54,13 @@ module Opsicle
54
54
  bastion_hostname = client.config.opsworks_config[:bastion_hostname]
55
55
  Output.say "Connecting via bastion with hostname '#{bastion_hostname}'"
56
56
  bastion_hostname
57
- else
58
- false
59
57
  end
60
58
  end
61
59
 
60
+ def use_bastion?
61
+ !!(client.config.opsworks_config[:bastion_layer_id] || client.config.opsworks_config[:bastion_hostname])
62
+ end
63
+
62
64
  def ssh_ip(instance)
63
65
  if client.config.opsworks_config[:internal_ssh_only]
64
66
  Output.say "This stack requires a private connection, only using internal IPs."
@@ -71,8 +73,12 @@ module Opsicle
71
73
  def ssh_command(instance, options={})
72
74
  ssh_command = " \"#{options[:"ssh-cmd"].gsub(/'/){ %q(\') }}\"" if options[:"ssh-cmd"] #escape single quotes
73
75
  ssh_options = options[:"ssh-opts"] ? "#{options[:"ssh-opts"]} " : ""
74
- external_ip = bastion_ip || public_ips.sample
75
- if instance_ip = ssh_ip(instance)
76
+ external_ip = public_ips.sample
77
+ if use_bastion?
78
+ external_ip = bastion_ip
79
+ ssh_string = "#{ssh_username}@#{external_ip} ssh #{instance[:private_ip]}"
80
+ ssh_options.concat('-A -t ')
81
+ elsif instance_ip = ssh_ip(instance)
76
82
  ssh_string = "#{ssh_username}@#{instance_ip}"
77
83
  else
78
84
  ssh_string = "#{ssh_username}@#{external_ip} ssh #{instance[:private_ip]}"
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "2.11.0"
2
+ VERSION = "2.11.1"
3
3
  end
@@ -138,8 +138,34 @@ module Opsicle
138
138
  end
139
139
  end
140
140
  context "when bastion is not used" do
141
+ it "returns nil" do
142
+ allow(client).to receive(:api_call).with(:describe_instances, {stack_id: "1234"})
143
+ .and_return(instances: [{:hostname => "taco", :status => "online"},{:hostname => "bar", :status => "online"}])
144
+ expect(subject.bastion_ip).to eq(nil)
145
+ end
146
+ end
147
+ end
148
+
149
+ context "#use_bastion" do
150
+ context "when bastion config option is disabled and some instances have public IPs" do
141
151
  it "returns false" do
142
- expect(subject.bastion_ip).to eq(false)
152
+ allow(subject).to receive(:instances) {[
153
+ { hostname: "host1", elastic_ip: "123.123.123.123", public_ip: "123.345.567.789"},
154
+ { hostname: "host2", public_ip: "456.456.456.456" },
155
+ { hostname: "host2", private_ip: "789.789.789.789" },
156
+ ]}
157
+ expect(subject.use_bastion?).to eq(false)
158
+ end
159
+ end
160
+ context "when bastion config option is enabled and some instances have public IPs" do
161
+ let(:client) { double(config: double(opsworks_config: {stack_id: "1234", bastion_layer_id: "4321"})) }
162
+ it "returns false" do
163
+ allow(subject).to receive(:instances) {[
164
+ { hostname: "host1", elastic_ip: "123.123.123.123", public_ip: "123.345.567.789"},
165
+ { hostname: "host2", public_ip: "456.456.456.456" },
166
+ { hostname: "host2", private_ip: "789.789.789.789" },
167
+ ]}
168
+ expect(subject.use_bastion?).to eq(true)
143
169
  end
144
170
  end
145
171
  end
@@ -197,15 +223,16 @@ module Opsicle
197
223
  end
198
224
  context "when bastion_layer_id is enabled" do
199
225
  let(:client) { double(config: double(opsworks_config: {stack_id: "1234", bastion_layer_id: "4321"})) }
200
- it "creates the proper ssh_command for an instance with a private ip" do
201
- expect(client).to receive(:api_call).with(:describe_instances, {layer_id: "4321"})
226
+ it "creates the proper ssh_commands" do
227
+ allow(client).to receive(:api_call).with(:describe_instances, {layer_id: "4321"})
202
228
  .and_return(instances: [
203
229
  {:hostname => "taco", :status => "stopped", :public_ip => "123.123.123.123"},
204
230
  {:hostname => "bar", :status => "online", :public_ip => "213.213.213.213"}
205
231
  ])
232
+ expect(subject.ssh_command({private_ip: "789.789.789.789" } )).to eq("ssh -A -t mrderpyman2014@213.213.213.213 ssh 789.789.789.789")
206
233
  expect(subject.ssh_command({private_ip: "789.789.789.789" })).to eq("ssh -A -t mrderpyman2014@213.213.213.213 ssh 789.789.789.789")
207
234
  end
208
- it "properly adds ssh options to the ssh_command for an instance with a private ip" do
235
+ it "properly adds ssh options to the ssh_commands" do
209
236
  expect(client).to receive(:api_call).with(:describe_instances, {layer_id: "4321"})
210
237
  .and_return(instances: [
211
238
  {:hostname => "taco", :status => "stopped", :public_ip => "123.123.123.123"},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsicle
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Fleener
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-23 00:00:00.000000000 Z
12
+ date: 2018-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk