opsicle 2.4.1 → 2.5.0

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: 1f8bc9ead683ab1997fd4fb96b7f348c67dad1df
4
- data.tar.gz: f0f6bf0fdc3cd66f04db2dbaa64938393fd4b3db
3
+ metadata.gz: bfb0c5b2df559b5e304081b7873a6b2a1cb54056
4
+ data.tar.gz: 003e30c1669eaa33aca7fe4c98d9442099c30e4d
5
5
  SHA512:
6
- metadata.gz: a5ddb67d3098dd6007e5f80900397ffc014c2c9b61aba164c448078300aa2eaf0a64027d6418a51f957919dd022a0631d7c96994bcec67e2ad2026fceaff50ca
7
- data.tar.gz: eace20aaf2d5bbb4ecffd5e5680b40f886c80d309e9726eb4056416872bf0d1579a7bf5a650e4c29e0650fc66bcd36f96c588a4263694f08901f3bcdae3ad9a3
6
+ metadata.gz: d94244b39e85e12301faa568330dae5a22fb937397fd55acee3f57fa0843e220d3bad89c1b3f45e08805dda16e609efd9d38a7792078ef5b313189242ddbf14c
7
+ data.tar.gz: d46d043f5ef64d3f74580cb9645a6b733533dc49323922f16f51bdb8acd523e2711e63aef8ce4b47c71db5be0dd7edff72cccfd2d19e1573148b75791067746d
@@ -42,6 +42,23 @@ module Opsicle
42
42
  @user_profile.ssh_username
43
43
  end
44
44
 
45
+ def bastion_ip
46
+ if client.config.opsworks_config[:bastion_layer_id]
47
+ online_bastions = client.api_call(
48
+ :describe_instances, {layer_id: client.config.opsworks_config[:bastion_layer_id] }
49
+ )[:instances].select { |instance| instance[:status].to_s == 'online'}
50
+ bastion_ip = online_bastions.sample[:public_ip]
51
+ Output.say "Connecting via bastion with IP #{bastion_ip}"
52
+ bastion_ip
53
+ elsif client.config.opsworks_config[:bastion_hostname]
54
+ bastion_hostname = client.config.opsworks_config[:bastion_hostname]
55
+ Output.say "Connecting via bastion with hostname '#{bastion_hostname}'"
56
+ bastion_hostname
57
+ else
58
+ false
59
+ end
60
+ end
61
+
45
62
  def ssh_ip(instance)
46
63
  if client.config.opsworks_config[:internal_ssh_only]
47
64
  Output.say "This stack requires a private connection, only using internal IPs."
@@ -54,10 +71,11 @@ module Opsicle
54
71
  def ssh_command(instance, options={})
55
72
  ssh_command = " \"#{options[:"ssh-cmd"].gsub(/'/){ %q(\') }}\"" if options[:"ssh-cmd"] #escape single quotes
56
73
  ssh_options = options[:"ssh-opts"] ? "#{options[:"ssh-opts"]} " : ""
74
+ external_ip = bastion_ip || public_ips.sample
57
75
  if instance_ip = ssh_ip(instance)
58
76
  ssh_string = "#{ssh_username}@#{instance_ip}"
59
77
  else
60
- ssh_string = "#{ssh_username}@#{public_ips.sample} ssh #{instance[:private_ip]}"
78
+ ssh_string = "#{ssh_username}@#{external_ip} ssh #{instance[:private_ip]}"
61
79
  ssh_options.concat('-A -t ')
62
80
  end
63
81
 
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "2.4.1"
2
+ VERSION = "2.5.0"
3
3
  end
@@ -120,6 +120,30 @@ module Opsicle
120
120
  end
121
121
  end
122
122
 
123
+ context "#bastion_ip" do
124
+ let(:instance) { { hostname: "host1", elastic_ip: "123.123.123.123", public_ip: "123.345.567.789", private_ip: "10.10.10.10" } }
125
+ context "when bastion_layer_id is enabled" do
126
+ let(:client) { double(config: double(opsworks_config: {stack_id: "1234", bastion_layer_id: "4321"})) }
127
+ it "returns a Bastion IP" do
128
+ expect(client).to receive(:api_call).with(:describe_instances, {layer_id: "4321"})
129
+ .and_return(instances: [{:hostname => "taco", :status => "stopped", :public_ip => "123.123.123.123"},{:hostname => "bar", :status => "online", :public_ip => "213.213.213.213"}])
130
+ expect(Output).to receive(:say).with("Connecting via bastion with IP 213.213.213.213")
131
+ expect(subject.bastion_ip).to eq("213.213.213.213")
132
+ end
133
+ end
134
+ context "when bastion_hostname is enabled" do
135
+ let(:client) { double(config: double(opsworks_config: {stack_id: "1234", bastion_hostname: "sebastion"})) }
136
+ it "returns the hostname of the bastion host" do
137
+ expect(subject.bastion_ip).to eq("sebastion")
138
+ end
139
+ end
140
+ context "when bastion is not used" do
141
+ it "returns false" do
142
+ expect(subject.bastion_ip).to eq(false)
143
+ end
144
+ end
145
+ end
146
+
123
147
  context "#ssh_ip" do
124
148
  let(:instance) { { hostname: "host1", elastic_ip: "123.123.123.123", public_ip: "123.345.567.789", private_ip: "10.10.10.10" } }
125
149
  context "when internal_ssh_only is enabled" do
@@ -165,12 +189,42 @@ module Opsicle
165
189
  it "creates the proper ssh_command for an instance with a private ip" do
166
190
  expect(subject.ssh_command({private_ip: "789.789.789.789" })).to eq("ssh -A -t mrderpyman2014@123.123.123.123 ssh 789.789.789.789")
167
191
  end
168
- it "properly adds ssh options to the ssh_command for an isntance with a public ip" do
192
+ it "properly adds ssh options to the ssh_command for an instance with a public ip" do
169
193
  expect(subject.ssh_command({elastic_ip: "123.123.123.123" }, { :"ssh-opts" => "-c"})).to eq("ssh -c mrderpyman2014@123.123.123.123")
170
194
  end
171
- it "properly adds ssh options to the ssh_command for an isntance with a private ip" do
195
+ it "properly adds ssh options to the ssh_command for an instance with a private ip" do
172
196
  expect(subject.ssh_command({private_ip: "789.789.789.789"}, { :"ssh-opts" => "-c"} )).to eq("ssh -c -A -t mrderpyman2014@123.123.123.123 ssh 789.789.789.789")
173
197
  end
198
+ context "when bastion_layer_id is enabled" do
199
+ 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"})
202
+ .and_return(instances: [
203
+ {:hostname => "taco", :status => "stopped", :public_ip => "123.123.123.123"},
204
+ {:hostname => "bar", :status => "online", :public_ip => "213.213.213.213"}
205
+ ])
206
+ 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
+ end
208
+ it "properly adds ssh options to the ssh_command for an instance with a private ip" do
209
+ expect(client).to receive(:api_call).with(:describe_instances, {layer_id: "4321"})
210
+ .and_return(instances: [
211
+ {:hostname => "taco", :status => "stopped", :public_ip => "123.123.123.123"},
212
+ {:hostname => "bar", :status => "online", :public_ip => "213.213.213.213"}
213
+ ])
214
+ expect(subject.ssh_command({private_ip: "789.789.789.789"}, { :"ssh-opts" => "-c"} )).to eq("ssh -c -A -t mrderpyman2014@213.213.213.213 ssh 789.789.789.789")
215
+ end
216
+ end
217
+ context "when bastion_hostname is enabled" do
218
+ let(:client) { double(config: double(opsworks_config: {stack_id: "1234", bastion_hostname: "sebastion"})) }
219
+ it "creates the proper ssh_command for an instance with a private ip" do
220
+ expect(Output).to receive(:say).with("Connecting via bastion with hostname 'sebastion'")
221
+ expect(subject.ssh_command({private_ip: "789.789.789.789" })).to eq("ssh -A -t mrderpyman2014@sebastion ssh 789.789.789.789")
222
+ end
223
+ it "properly adds ssh options to the ssh_command for an instance with a private ip" do
224
+ expect(Output).to receive(:say).with("Connecting via bastion with hostname 'sebastion'")
225
+ expect(subject.ssh_command({private_ip: "789.789.789.789"}, { :"ssh-opts" => "-c"} )).to eq("ssh -c -A -t mrderpyman2014@sebastion ssh 789.789.789.789")
226
+ end
227
+ end
174
228
  end
175
229
 
176
230
  context "#instance_info" do
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.4.1
4
+ version: 2.5.0
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: 2017-04-24 00:00:00.000000000 Z
12
+ date: 2017-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk