aptible-cli 0.8.5 → 0.8.6

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: 7ca32684c92760fd049ba703618258b837950590
4
- data.tar.gz: b251f6a123c54002638a7ef0c5567de892f6cb62
3
+ metadata.gz: 710c981d4ee3393bbe00fb09cabb6a45e964aeb7
4
+ data.tar.gz: 2705459f3698db56a010edce891f49f832dc584c
5
5
  SHA512:
6
- metadata.gz: 28e54b39f91cb892b9ce5443321b9049290a302b9e38de9cd3b7162b3567499fa5c00abc5d860d31d8661190fdbc692b24ce0186af410b98a4922a0b62cdd70d
7
- data.tar.gz: 772bb6f34a8a07baee41f1682189dbfa6a31c422802649d74721f028c89cd060ae7cfe4c77f3bfd150c9cb90c04b3ddc52acb6bc52be31f71cf83eafb8b05acf
6
+ metadata.gz: 67a7478f09bdfcf92839064523ee231e8b84d8b7455a8e0826ab47a5fa1a09dcb7eaea968a7981694921738bf9733b23b90518a7697427a067b4db921e6440d7
7
+ data.tar.gz: dc845bf331a6644e89352af644eacd95b871b12fdc443feb49ca543594fd2868fb735b4be358ece0753ffe125b546ec08991b7ced562b72d8c1bc2e5dc860703
@@ -26,7 +26,37 @@ module Aptible
26
26
 
27
27
  ENV['ACCESS_TOKEN'] = fetch_token
28
28
  opts = ['-o', 'SendEnv=ACCESS_TOKEN']
29
- opts << '-tt' if options[:force_tty]
29
+
30
+ # SSH's default behavior is as follows:
31
+ #
32
+ # - If a TTY is forced, one is allocated.
33
+ # - If there is no command, then a TTY is allocated.
34
+ # - If no-TTY is forced, then none is allocated.
35
+ # - No TTY is allocated if stdin isn't a TTY.
36
+ #
37
+ # Unfortunately, in our case, this breaks, because we use a
38
+ # forced-command, so we don't *ever* send a command, which causes
39
+ # SSH to *always* allocate TTY, which causes a variety of
40
+ # problems, not least of which is that stdout and stderr end up
41
+ # merged.
42
+ #
43
+ # Now, it's pretty common for Aptible users to run commands in
44
+ # their container with the intention of using a TTY (by e.g.
45
+ # running `aptible ssh bash`), so we use a slightly different
46
+ # heuristic from SSH: we allocate TTY iif there's no input or
47
+ # output redirection going on.
48
+ #
49
+ # End users can always override this behavior with the
50
+ # --force-tty option.
51
+ tty_mode = if options[:force_tty]
52
+ '-tt'
53
+ elsif [STDIN, STDOUT].all?(&:tty?)
54
+ '-t'
55
+ else
56
+ '-T'
57
+ end
58
+ opts << tty_mode
59
+
30
60
  connect_to_ssh_portal(op, *opts)
31
61
  end
32
62
 
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.8.5'.freeze
3
+ VERSION = '0.8.6'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aptible::CLI::Agent do
4
+ describe '#ssh' do
5
+ let(:app) { Fabricate(:app) }
6
+ let(:operation) { double('operation') }
7
+
8
+ context 'TTY control' do
9
+ before do
10
+ expect(subject).to receive(:ensure_app).and_return(app)
11
+ expect(subject).to receive(:fetch_token).and_return('some token')
12
+
13
+ expect(app).to receive(:create_operation!).with(
14
+ type: 'execute', command: '/bin/bash', status: 'succeeded'
15
+ ).and_return(operation)
16
+ end
17
+
18
+ it 'allocates a TTY if STDIN and STDOUT are TTYs' do
19
+ allow(STDIN).to receive(:tty?).and_return(true)
20
+ allow(STDOUT).to receive(:tty?).and_return(true)
21
+
22
+ expect(subject).to receive(:connect_to_ssh_portal).with(
23
+ operation, '-o', 'SendEnv=ACCESS_TOKEN', '-t'
24
+ )
25
+ subject.ssh
26
+ end
27
+
28
+ it 'allocates a TTY even if STDERR is redirected ' do
29
+ allow(STDIN).to receive(:tty?).and_return(true)
30
+ allow(STDOUT).to receive(:tty?).and_return(true)
31
+ allow(STDERR).to receive(:tty?).and_return(false)
32
+
33
+ expect(subject).to receive(:connect_to_ssh_portal).with(
34
+ operation, '-o', 'SendEnv=ACCESS_TOKEN', '-t'
35
+ )
36
+ subject.ssh
37
+ end
38
+
39
+ it 'does not allocate TTY if STDIN is redirected' do
40
+ allow(STDIN).to receive(:tty?).and_return(false)
41
+ allow(STDOUT).to receive(:tty?).and_return(true)
42
+
43
+ expect(subject).to receive(:connect_to_ssh_portal).with(
44
+ operation, '-o', 'SendEnv=ACCESS_TOKEN', '-T'
45
+ )
46
+ subject.ssh
47
+ end
48
+
49
+ it 'does not allocate TTY if STDOUT is redirected' do
50
+ allow(STDIN).to receive(:tty?).and_return(true)
51
+ allow(STDOUT).to receive(:tty?).and_return(false)
52
+
53
+ expect(subject).to receive(:connect_to_ssh_portal).with(
54
+ operation, '-o', 'SendEnv=ACCESS_TOKEN', '-T'
55
+ )
56
+ subject.ssh
57
+ end
58
+
59
+ it 'allocates a TTY if forced' do
60
+ subject.options = { force_tty: true }
61
+
62
+ allow(STDIN).to receive(:tty?).and_return(false)
63
+ allow(STDOUT).to receive(:tty?).and_return(false)
64
+
65
+ expect(subject).to receive(:connect_to_ssh_portal).with(
66
+ operation, '-o', 'SendEnv=ACCESS_TOKEN', '-tt'
67
+ )
68
+ subject.ssh
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'json'
3
+
4
+ raise 'Something went wrong!' if ENV['SSH_MOCK_FAIL_TUNNEL']
5
+
6
+ # Log arguments to SSH_MOCK_OUTFILE
7
+ File.open(ENV.fetch('SSH_MOCK_OUTFILE'), 'w') do |f|
8
+ f.write({
9
+ 'pid' => $PID,
10
+ 'argc' => ARGV.size,
11
+ 'argv' => ARGV,
12
+ 'env' => ENV.to_hash
13
+ }.to_json)
14
+ end
15
+
16
+ puts 'TUNNEL READY'
17
+
18
+ exit Integer(ENV.fetch('SSH_MOCK_EXITCODE', 0))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api
@@ -260,6 +260,7 @@ files:
260
260
  - spec/aptible/cli/subcommands/logs_spec.rb
261
261
  - spec/aptible/cli/subcommands/operation_spec.rb
262
262
  - spec/aptible/cli/subcommands/restart_spec.rb
263
+ - spec/aptible/cli/subcommands/ssh_spec.rb
263
264
  - spec/fabricators/account_fabricator.rb
264
265
  - spec/fabricators/app_fabricator.rb
265
266
  - spec/fabricators/backup_fabricator.rb
@@ -295,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
296
  version: '0'
296
297
  requirements: []
297
298
  rubyforge_project:
298
- rubygems_version: 2.6.4
299
+ rubygems_version: 2.4.5.1
299
300
  signing_key:
300
301
  specification_version: 4
301
302
  summary: Command-line interface for Aptible services
@@ -314,6 +315,7 @@ test_files:
314
315
  - spec/aptible/cli/subcommands/logs_spec.rb
315
316
  - spec/aptible/cli/subcommands/operation_spec.rb
316
317
  - spec/aptible/cli/subcommands/restart_spec.rb
318
+ - spec/aptible/cli/subcommands/ssh_spec.rb
317
319
  - spec/fabricators/account_fabricator.rb
318
320
  - spec/fabricators/app_fabricator.rb
319
321
  - spec/fabricators/backup_fabricator.rb
@@ -1 +0,0 @@
1
- ssh_mock.rb