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 +4 -4
- data/lib/opsicle/commands/ssh.rb +10 -4
- data/lib/opsicle/version.rb +1 -1
- data/spec/opsicle/commands/ssh_spec.rb +31 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a75d1113150783a01d54f283183d80ebd130752
|
4
|
+
data.tar.gz: 235fca70e248b9d6f5a8a5e7981fdbac0f3253ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 009279aec4c5366d91e71cde98ee00cd90d3a9e643731a940cd555197deb9779df3acd1ec367ba0c03255eed9fecfd8d0fcef811cc463cc2a9b2505f5f4ac921
|
7
|
+
data.tar.gz: 769f9652489b563bdd867676e979c2855f4e9694d65c84c94ab4c2d59a5cc625bb9d3a60a5b9fadfedc2871568d01f513de013a3259a16442f3980b08c884773
|
data/lib/opsicle/commands/ssh.rb
CHANGED
@@ -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 =
|
75
|
-
if
|
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]}"
|
data/lib/opsicle/version.rb
CHANGED
@@ -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
|
-
|
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
|
201
|
-
|
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
|
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.
|
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-
|
12
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|