aptible-api 0.9.15 → 0.9.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9c6eb639f828bf55b97ce98c42466f95783b119
4
- data.tar.gz: 52664905bf0e652c6c19bd7df7dc5e254b1f0da1
3
+ metadata.gz: e448a72c9df895660ae7688754e17d297a0b4741
4
+ data.tar.gz: 4c521134184f9330a16fb021f91905da45bef81e
5
5
  SHA512:
6
- metadata.gz: 449f42a33175161bfed43ea14de05fb08ee2338860909b358f4f7098b5f029a08e19e47c0861b76152a1d6aa53ed37f685a39dfcc5aa56742cb00ca0f2e21727
7
- data.tar.gz: 214c2eb943a3ebf04e77cad57dd01cd2a210678aa3c46aa8ba99dd0198a95c2328ab108996e225e3717b669a9c7be0c2f9f5fa6db617da4422d32eee76d9adc4
6
+ metadata.gz: bae1439466c61b7c4c663c3b2969efdbe4383a35fa080cd9e074bbcc9cd95fe2ab9642430ae57c6d4435122b75a964ab0326ecfce6031838db3feb0fb8688045
7
+ data.tar.gz: cd65a940153c1fa2ad0bad6455ca7898002eab61e8ace10dc4deb33618efaf48426cd0355d5a565760d6a31d3d1f5d03bb2d8e8f822c552b09b92c7a2e740a8d
@@ -3,6 +3,8 @@ require 'aptible/auth'
3
3
  module Aptible
4
4
  module Api
5
5
  class Account < Resource
6
+ belongs_to :stack
7
+
6
8
  has_many :apps
7
9
  has_many :backups
8
10
  has_many :certificates
@@ -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
- with_temporary_id(private_key, public_key, certificate) do |id_file|
61
- cmd = [
62
- 'ssh',
63
- "#{connection.ssh_user}@#{account.bastion_host}",
64
- '-p', account.ssh_portal_port.to_s,
65
- '-i', id_file,
66
- '-o', 'IdentitiesOnly=yes'
67
- ]
68
-
69
- # If we aren't allowed to create a pty, then we shouldn't try to
70
- # allocate once, or we'll get an awkward error.
71
- cmd << '-T' unless connection.ssh_pty
72
-
73
- yield cmd, connection
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
@@ -31,3 +31,4 @@ require 'aptible/api/release'
31
31
  require 'aptible/api/service'
32
32
  require 'aptible/api/vhost'
33
33
  require 'aptible/api/ssh_portal_connection'
34
+ require 'aptible/api/stack'
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module Api
3
- VERSION = '0.9.15'.freeze
3
+ VERSION = '0.9.16'.freeze
4
4
  end
5
5
  end
@@ -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(:account) do
6
+ let(:stack) do
7
7
  Aptible::Api::Account.new.tap do |account|
8
8
  account.stub(
9
- bastion_host: 'foo-bastion.com',
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
- identities_only = 'IdentitiesOnly=yes'
73
- expect(cmd).to include(identities_only)
74
- expect(cmd[cmd.index(identities_only) - 1]).to eq('-o')
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.15
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: 2016-12-13 00:00:00.000000000 Z
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