aptible-api 0.9.15 → 0.9.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aptible/api/account.rb +2 -0
- data/lib/aptible/api/operation.rb +32 -14
- data/lib/aptible/api/resource.rb +1 -0
- data/lib/aptible/api/stack.rb +19 -0
- data/lib/aptible/api/version.rb +1 -1
- data/spec/aptible/api/operation_spec.rb +25 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e448a72c9df895660ae7688754e17d297a0b4741
|
4
|
+
data.tar.gz: 4c521134184f9330a16fb021f91905da45bef81e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae1439466c61b7c4c663c3b2969efdbe4383a35fa080cd9e074bbcc9cd95fe2ab9642430ae57c6d4435122b75a964ab0326ecfce6031838db3feb0fb8688045
|
7
|
+
data.tar.gz: cd65a940153c1fa2ad0bad6455ca7898002eab61e8ace10dc4deb33618efaf48426cd0355d5a565760d6a31d3d1f5d03bb2d8e8f822c552b09b92c7a2e740a8d
|
data/lib/aptible/api/account.rb
CHANGED
@@ -57,25 +57,43 @@ module Aptible
|
|
57
57
|
connection = create_ssh_portal_connection!(ssh_public_key: public_key)
|
58
58
|
certificate = connection.ssh_certificate_body
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
60
|
+
stack = account.stack
|
61
|
+
host = stack.ssh_portal_host
|
62
|
+
port = stack.ssh_portal_port
|
63
|
+
key = stack.ssh_host_rsa_public_key
|
64
|
+
|
65
|
+
with_temporary_known_hosts(host, port, key) do |known_hosts_file|
|
66
|
+
with_temporary_id(private_key, public_key, certificate) do |id_file|
|
67
|
+
cmd = [
|
68
|
+
'ssh',
|
69
|
+
"#{connection.ssh_user}@#{host}",
|
70
|
+
'-p', port.to_s,
|
71
|
+
'-i', id_file,
|
72
|
+
'-o', 'IdentitiesOnly=yes',
|
73
|
+
'-o', "UserKnownHostsFile=#{known_hosts_file}",
|
74
|
+
'-o', 'StrictHostKeyChecking=yes'
|
75
|
+
]
|
76
|
+
|
77
|
+
# If we aren't allowed to create a pty, then we shouldn't try to
|
78
|
+
# allocate once, or we'll get an awkward error.
|
79
|
+
cmd << '-T' unless connection.ssh_pty
|
80
|
+
|
81
|
+
yield cmd, connection
|
82
|
+
end
|
74
83
|
end
|
75
84
|
end
|
76
85
|
|
77
86
|
private
|
78
87
|
|
88
|
+
def with_temporary_known_hosts(host, port, key)
|
89
|
+
Dir.mktmpdir do |dir|
|
90
|
+
known_hosts_file = File.join(dir, 'known_hosts')
|
91
|
+
contents = "[#{host}]:#{port} #{key}\n"
|
92
|
+
File.open(known_hosts_file, 'w', 0o600) { |f| f.write(contents) }
|
93
|
+
yield known_hosts_file
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
79
97
|
def with_temporary_id(private_key, public_key, certificate)
|
80
98
|
# Most versions of OpenSSH don't support specifying the SSH certificate
|
81
99
|
# to use when connecting, so we create a temporary directory with the
|
data/lib/aptible/api/resource.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Aptible
|
2
|
+
module Api
|
3
|
+
class Stack < Resource
|
4
|
+
field :id
|
5
|
+
field :type
|
6
|
+
field :name
|
7
|
+
field :version
|
8
|
+
field :region
|
9
|
+
field :default, type: Aptible::Resource::Boolean
|
10
|
+
field :ssh_host_dsa_public_key
|
11
|
+
field :ssh_host_rsa_public_key
|
12
|
+
field :ssh_host_ecdsa_public_key
|
13
|
+
field :ssh_portal_host
|
14
|
+
field :ssh_portal_port
|
15
|
+
field :created_at, type: Time
|
16
|
+
field :updated_at, type: Time
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/aptible/api/version.rb
CHANGED
@@ -3,15 +3,22 @@ require 'spec_helper'
|
|
3
3
|
describe Aptible::Api::Operation do
|
4
4
|
describe '#with_ssh_cmd' do
|
5
5
|
shared_examples '#with_ssh_cmd examples' do
|
6
|
-
let(:
|
6
|
+
let(:stack) do
|
7
7
|
Aptible::Api::Account.new.tap do |account|
|
8
8
|
account.stub(
|
9
|
-
|
10
|
-
ssh_portal_port: 1022
|
9
|
+
ssh_portal_host: 'foo-bastion.com',
|
10
|
+
ssh_portal_port: 1022,
|
11
|
+
ssh_host_rsa_public_key: 'some rsa key'
|
11
12
|
)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
let(:account) do
|
17
|
+
Aptible::Api::Account.new.tap do |account|
|
18
|
+
account.stub(stack: stack)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
15
22
|
let(:ssh_portal_connection) do
|
16
23
|
Aptible::Api::SshPortalConnection.new.tap do |connection|
|
17
24
|
connection.stub(
|
@@ -55,6 +62,14 @@ describe Aptible::Api::Operation do
|
|
55
62
|
expect(File.read("#{id_file}.pub")).to eq('some public key')
|
56
63
|
expect(File.read("#{id_file}-cert.pub")).to eq('some certificate')
|
57
64
|
|
65
|
+
hosts_param = cmd.find { |p| p.start_with?('UserKnownHostsFile') }
|
66
|
+
expect(cmd[cmd.index(hosts_param) - 1]).to eq('-o')
|
67
|
+
expect(hosts_param).not_to be_nil
|
68
|
+
hosts_file = hosts_param.split('=')[1]
|
69
|
+
|
70
|
+
expect(File.read(hosts_file))
|
71
|
+
.to eq("[foo-bastion.com]:1022 some rsa key\n")
|
72
|
+
|
58
73
|
expect(File.readable?(id_file)).to be_truthy
|
59
74
|
expect(File.writable?(id_file)).to be_truthy
|
60
75
|
|
@@ -69,9 +84,13 @@ describe Aptible::Api::Operation do
|
|
69
84
|
expect(cmd).to include('-T')
|
70
85
|
end
|
71
86
|
|
72
|
-
|
73
|
-
|
74
|
-
|
87
|
+
[
|
88
|
+
'IdentitiesOnly=yes',
|
89
|
+
'StrictHostKeyChecking=yes'
|
90
|
+
].each do |option|
|
91
|
+
expect(cmd).to include(option)
|
92
|
+
expect(cmd[cmd.index(option) - 1]).to eq('-o')
|
93
|
+
end
|
75
94
|
|
76
95
|
has_yielded = true
|
77
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptible-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Macreery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aptible-resource
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/aptible/api/resource.rb
|
186
186
|
- lib/aptible/api/service.rb
|
187
187
|
- lib/aptible/api/ssh_portal_connection.rb
|
188
|
+
- lib/aptible/api/stack.rb
|
188
189
|
- lib/aptible/api/version.rb
|
189
190
|
- lib/aptible/api/vhost.rb
|
190
191
|
- spec/aptible/api/agent_spec.rb
|