tugboat 2.2.2 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +520 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +0 -6
- data/README.md +34 -2
- data/Rakefile +6 -1
- data/bin/tugboat +2 -2
- data/features/cassettes/config/Array_of_SSH_Keys_in_Config.yml +1 -1
- data/features/cassettes/config/Single_SSH_key_as_number_in_config.yml +1 -1
- data/features/step_definitions/steps.rb +1 -1
- data/features/support/env.rb +7 -3
- data/lib/tugboat.rb +2 -2
- data/lib/tugboat/cli.rb +394 -444
- data/lib/tugboat/config.rb +43 -61
- data/lib/tugboat/middleware.rb +33 -33
- data/lib/tugboat/middleware/add_key.rb +12 -13
- data/lib/tugboat/middleware/ask_for_credentials.rb +12 -13
- data/lib/tugboat/middleware/base.rb +25 -20
- data/lib/tugboat/middleware/check_configuration.rb +3 -6
- data/lib/tugboat/middleware/check_credentials.rb +0 -1
- data/lib/tugboat/middleware/check_droplet_active.rb +2 -4
- data/lib/tugboat/middleware/check_droplet_inactive.rb +2 -4
- data/lib/tugboat/middleware/config.rb +3 -5
- data/lib/tugboat/middleware/confirm_action.rb +4 -6
- data/lib/tugboat/middleware/create_droplet.rb +27 -44
- data/lib/tugboat/middleware/custom_logger.rb +52 -54
- data/lib/tugboat/middleware/destroy_droplet.rb +5 -6
- data/lib/tugboat/middleware/destroy_image.rb +5 -6
- data/lib/tugboat/middleware/find_droplet.rb +43 -47
- data/lib/tugboat/middleware/find_image.rb +23 -29
- data/lib/tugboat/middleware/halt_droplet.rb +9 -10
- data/lib/tugboat/middleware/info_droplet.rb +30 -33
- data/lib/tugboat/middleware/info_image.rb +1 -1
- data/lib/tugboat/middleware/inject_client.rb +8 -10
- data/lib/tugboat/middleware/inject_configuration.rb +1 -2
- data/lib/tugboat/middleware/list_droplets.rb +9 -10
- data/lib/tugboat/middleware/list_images.rb +9 -9
- data/lib/tugboat/middleware/list_regions.rb +1 -1
- data/lib/tugboat/middleware/list_sizes.rb +1 -1
- data/lib/tugboat/middleware/list_ssh_keys.rb +1 -3
- data/lib/tugboat/middleware/password_reset.rb +6 -7
- data/lib/tugboat/middleware/rebuild_droplet.rb +7 -7
- data/lib/tugboat/middleware/resize_droplet.rb +6 -7
- data/lib/tugboat/middleware/restart_droplet.rb +4 -11
- data/lib/tugboat/middleware/snapshot_droplet.rb +7 -8
- data/lib/tugboat/middleware/ssh_droplet.rb +30 -31
- data/lib/tugboat/middleware/start_droplet.rb +5 -5
- data/lib/tugboat/middleware/wait_for_state.rb +2 -3
- data/lib/tugboat/version.rb +1 -1
- data/spec/cli/add_key_spec.rb +25 -28
- data/spec/cli/authorize_cli_spec.rb +57 -60
- data/spec/cli/config_cli_spec.rb +8 -11
- data/spec/cli/create_cli_spec.rb +40 -46
- data/spec/cli/debug_cli_spec.rb +29 -29
- data/spec/cli/destroy_cli_spec.rb +58 -60
- data/spec/cli/destroy_image_cli_spec.rb +42 -45
- data/spec/cli/droplets_cli_spec.rb +62 -64
- data/spec/cli/env_variable_spec.rb +14 -15
- data/spec/cli/halt_cli_spec.rb +65 -69
- data/spec/cli/help_cli_spec.rb +8 -8
- data/spec/cli/images_cli_spec.rb +28 -30
- data/spec/cli/info_cli_spec.rb +144 -147
- data/spec/cli/info_image_cli_spec.rb +57 -60
- data/spec/cli/keys_cli_spec.rb +8 -10
- data/spec/cli/password_reset_cli_spec.rb +56 -56
- data/spec/cli/rebuild_cli_spec.rb +194 -198
- data/spec/cli/regions_cli_spec.rb +8 -8
- data/spec/cli/resize_cli_spec.rb +54 -56
- data/spec/cli/restart_cli_spec.rb +53 -57
- data/spec/cli/sizes_cli_spec.rb +7 -8
- data/spec/cli/snapshot_cli_spec.rb +50 -53
- data/spec/cli/ssh_cli_spec.rb +41 -42
- data/spec/cli/start_cli_spec.rb +48 -52
- data/spec/cli/verify_cli_spec.rb +22 -25
- data/spec/cli/version_cli_spec.rb +6 -8
- data/spec/cli/wait_cli_spec.rb +50 -52
- data/spec/config_spec.rb +56 -57
- data/spec/middleware/base_spec.rb +5 -6
- data/spec/middleware/check_configuration_spec.rb +5 -7
- data/spec/middleware/check_credentials_spec.rb +9 -10
- data/spec/middleware/check_droplet_active_spec.rb +5 -7
- data/spec/middleware/check_droplet_inactive_spec.rb +5 -7
- data/spec/middleware/find_droplet_spec.rb +4 -5
- data/spec/middleware/find_image_spec.rb +4 -5
- data/spec/middleware/inject_client_spec.rb +9 -12
- data/spec/middleware/inject_configuration_spec.rb +4 -7
- data/spec/middleware/ssh_droplet_spec.rb +70 -73
- data/spec/shared/environment.rb +18 -20
- data/spec/spec_helper.rb +4 -4
- data/tugboat.gemspec +10 -6
- metadata +88 -17
@@ -4,20 +4,20 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
say "Queuing rebuild for droplet #{env[
|
7
|
+
say "Queuing rebuild for droplet #{env['droplet_id']} #{env['droplet_name']} with image #{env['image_id']} #{env['image_name']}...", nil, false
|
8
8
|
|
9
|
-
response = ocean.droplet.rebuild env[
|
10
|
-
|
9
|
+
response = ocean.droplet.rebuild env['droplet_id'],
|
10
|
+
image: env['image_id']
|
11
11
|
|
12
|
-
|
12
|
+
if response.success?
|
13
|
+
say 'Rebuild complete', :green
|
14
|
+
else
|
13
15
|
say "Failed to rebuild Droplet: #{response.message}", :red
|
14
16
|
exit 1
|
15
|
-
else
|
16
|
-
say "Rebuild complete", :green
|
17
17
|
end
|
18
18
|
|
19
19
|
@app.call(env)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -4,16 +4,16 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
say "Queuing resize for #{env[
|
7
|
+
say "Queuing resize for #{env['droplet_id']} #{env['droplet_name']}...", nil, false
|
8
8
|
|
9
|
-
response = ocean.droplet.resize env[
|
10
|
-
|
9
|
+
response = ocean.droplet.resize env['droplet_id'],
|
10
|
+
size: env['user_droplet_size']
|
11
11
|
|
12
|
-
|
12
|
+
if response.success?
|
13
|
+
say 'Resize complete!', :green
|
14
|
+
else
|
13
15
|
say "Failed to resize Droplet: #{response.message}", :red
|
14
16
|
exit 1
|
15
|
-
else
|
16
|
-
say "Resize complete!", :green
|
17
17
|
end
|
18
18
|
|
19
19
|
@app.call(env)
|
@@ -21,4 +21,3 @@ module Tugboat
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
@@ -4,19 +4,13 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
response =
|
8
|
-
say "Queuing hard restart for #{env["droplet_id"]} #{env["droplet_name"]}...", nil, false
|
9
|
-
ocean.droplet.power_cycle env["droplet_id"]
|
10
|
-
else
|
11
|
-
say "Queuing restart for #{env["droplet_id"]} #{env["droplet_name"]}...", nil, false
|
12
|
-
ocean.droplet.reboot env["droplet_id"]
|
13
|
-
end
|
7
|
+
response = restart_droplet(env['user_droplet_hard'], ocean, env['droplet_id'], env['droplet_name'])
|
14
8
|
|
15
|
-
|
9
|
+
if response.success?
|
10
|
+
say 'Restart complete!', :green
|
11
|
+
else
|
16
12
|
say "Failed to restart Droplet: #{response.message}", :red
|
17
13
|
exit 1
|
18
|
-
else
|
19
|
-
say "Restart complete!", :green
|
20
14
|
end
|
21
15
|
|
22
16
|
@app.call(env)
|
@@ -24,4 +18,3 @@ module Tugboat
|
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
27
|
-
|
@@ -6,18 +6,18 @@ module Tugboat
|
|
6
6
|
# Right now, the digital ocean API doesn't return an error
|
7
7
|
# when your droplet is not powered off and you try to snapshot.
|
8
8
|
# This is a temporary measure to let the user know.
|
9
|
-
say
|
9
|
+
say 'Warning: Droplet must be in a powered off state for snapshot to be successful', :yellow
|
10
10
|
|
11
|
-
say "Queuing snapshot '#{env[
|
11
|
+
say "Queuing snapshot '#{env['user_snapshot_name']}' for #{env['droplet_id']} #{env['droplet_name']}...", nil, false
|
12
12
|
|
13
|
-
response = ocean.droplet.snapshot env[
|
14
|
-
|
13
|
+
response = ocean.droplet.snapshot env['droplet_id'],
|
14
|
+
name: env['user_snapshot_name']
|
15
15
|
|
16
|
-
|
16
|
+
if response.success?
|
17
|
+
say 'Snapshot successful!', :green
|
18
|
+
else
|
17
19
|
say "Failed to snapshot Droplet: #{response.message}", :red
|
18
20
|
exit 1
|
19
|
-
else
|
20
|
-
say "Snapshot successful!", :green
|
21
21
|
end
|
22
22
|
|
23
23
|
@app.call(env)
|
@@ -25,4 +25,3 @@ module Tugboat
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
@@ -2,47 +2,47 @@ module Tugboat
|
|
2
2
|
module Middleware
|
3
3
|
class SSHDroplet < Base
|
4
4
|
def call(env)
|
5
|
-
say "Executing SSH on Droplet #{env[
|
5
|
+
say "Executing SSH on Droplet #{env['droplet_name']}..."
|
6
6
|
|
7
7
|
options = [
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
'-o', 'LogLevel=ERROR',
|
9
|
+
'-o', 'StrictHostKeyChecking=no',
|
10
|
+
'-o', 'UserKnownHostsFile=/dev/null'
|
11
11
|
]
|
12
12
|
|
13
|
-
if env[
|
14
|
-
options.push(
|
13
|
+
if env['config'].ssh_key_path.nil? || env['config'].ssh_key_path.empty?
|
14
|
+
options.push('-o', 'IdentitiesOnly=no')
|
15
15
|
else
|
16
|
-
options.push(
|
17
|
-
options.push(
|
16
|
+
options.push('-o', 'IdentitiesOnly=yes')
|
17
|
+
options.push('-i', File.expand_path(env['config'].ssh_key_path.to_s))
|
18
18
|
end
|
19
19
|
|
20
|
-
if env[
|
21
|
-
options.push(
|
22
|
-
elsif env[
|
23
|
-
options.push(
|
20
|
+
if env['user_droplet_ssh_port']
|
21
|
+
options.push('-p', env['user_droplet_ssh_port'].to_s)
|
22
|
+
elsif env['config'].ssh_port
|
23
|
+
options.push('-p', env['config'].ssh_port.to_s)
|
24
24
|
else
|
25
|
-
options.push(
|
25
|
+
options.push('-p', '22')
|
26
26
|
end
|
27
27
|
|
28
|
-
if env[
|
29
|
-
options.concat env[
|
28
|
+
if env['user_droplet_ssh_opts']
|
29
|
+
options.concat env['user_droplet_ssh_opts'].split
|
30
30
|
end
|
31
31
|
|
32
|
-
ssh_user = env[
|
32
|
+
ssh_user = env['user_droplet_ssh_user'] || env['config'].ssh_user
|
33
33
|
|
34
|
-
host_ip = env[
|
34
|
+
host_ip = env['droplet_ip']
|
35
35
|
|
36
|
-
if env[
|
37
|
-
say
|
36
|
+
if env['user_droplet_use_private_ip'] && env['droplet_ip_private'].nil?
|
37
|
+
say 'You asked to ssh to the private IP, but no Private IP found!', :red
|
38
38
|
exit 1
|
39
39
|
end
|
40
40
|
|
41
|
-
if env[
|
42
|
-
say
|
43
|
-
if env[
|
44
|
-
say
|
45
|
-
host_ip = env[
|
41
|
+
if env['droplet_ip_private']
|
42
|
+
say 'This droplet has a private IP, checking if you asked to use the Private IP...'
|
43
|
+
if env['user_droplet_use_private_ip']
|
44
|
+
say 'You did! Using private IP for ssh...', :yellow
|
45
|
+
host_ip = env['droplet_ip_private']
|
46
46
|
else
|
47
47
|
say "You didn't! Using public IP for ssh...", :yellow
|
48
48
|
end
|
@@ -51,25 +51,24 @@ module Tugboat
|
|
51
51
|
host_string = "#{ssh_user}@#{host_ip}"
|
52
52
|
|
53
53
|
if env['user_droplet_ssh_wait']
|
54
|
-
say
|
55
|
-
wait_for_state(env[
|
54
|
+
say 'Wait flag given, waiting for droplet to become active'
|
55
|
+
wait_for_state(env['droplet_id'], 'active', env['barge'])
|
56
56
|
end
|
57
57
|
|
58
58
|
say "Attempting SSH: #{host_string}"
|
59
59
|
|
60
60
|
options << host_string
|
61
61
|
|
62
|
-
if env[
|
63
|
-
options.push(env[
|
62
|
+
if env['user_droplet_ssh_command']
|
63
|
+
options.push(env['user_droplet_ssh_command'])
|
64
64
|
end
|
65
65
|
|
66
|
-
say "SShing with options: #{options.join(
|
66
|
+
say "SShing with options: #{options.join(' ')}"
|
67
67
|
|
68
|
-
Kernel.exec(
|
68
|
+
Kernel.exec('ssh', *options)
|
69
69
|
|
70
70
|
@app.call(env)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
@@ -4,14 +4,14 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
say "Queuing start for #{env[
|
8
|
-
response = ocean.droplet.power_on env[
|
7
|
+
say "Queuing start for #{env['droplet_id']} #{env['droplet_name']}...", nil, false
|
8
|
+
response = ocean.droplet.power_on env['droplet_id']
|
9
9
|
|
10
|
-
|
10
|
+
if response.success?
|
11
|
+
say 'Start complete!', :green
|
12
|
+
else
|
11
13
|
say "Failed to start Droplet: #{response.message}", :red
|
12
14
|
exit 1
|
13
|
-
else
|
14
|
-
say "Start complete!", :green
|
15
15
|
end
|
16
16
|
|
17
17
|
@app.call(env)
|
@@ -4,13 +4,12 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
say "Waiting for droplet to become #{env[
|
7
|
+
say "Waiting for droplet to become #{env['user_droplet_desired_state']}.", nil, false
|
8
8
|
|
9
|
-
wait_for_state(env[
|
9
|
+
wait_for_state(env['droplet_id'], env['user_droplet_desired_state'], ocean)
|
10
10
|
|
11
11
|
@app.call(env)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
data/lib/tugboat/version.rb
CHANGED
data/spec/cli/add_key_spec.rb
CHANGED
@@ -2,29 +2,28 @@ require 'spec_helper'
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
describe Tugboat::CLI do
|
5
|
-
include_context
|
5
|
+
include_context 'spec'
|
6
6
|
|
7
|
-
let(:tmp_path) { project_path +
|
7
|
+
let(:tmp_path) { project_path + '/tmp/tugboat' }
|
8
8
|
let(:fake_home) { "#{project_path}/tmp" }
|
9
9
|
|
10
|
-
before
|
11
|
-
File.open(
|
10
|
+
before do
|
11
|
+
File.open('id_dsa.pub', 'w') { |f| f.write('ssh-dss A456= user@host') }
|
12
12
|
end
|
13
13
|
|
14
|
-
after
|
15
|
-
File.delete(
|
14
|
+
after do
|
15
|
+
File.delete('id_dsa.pub') if File.exist?('id_dsa.pub')
|
16
16
|
File.delete("#{fake_home}/.ssh/id_rsa.pub") if File.exist?("#{fake_home}/.ssh/id_rsa.pub")
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
20
|
-
it
|
19
|
+
describe 'add-key' do
|
20
|
+
it 'with a name and key string' do
|
21
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/account/keys').
|
22
|
+
with(body: '{"name":"macbook_pro","public_key":"ssh-dss A123= user@host"}').
|
23
|
+
to_return(status: 201, body: fixture('create_ssh_key'), headers: {})
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
to_return(:status => 201, :body => fixture('create_ssh_key'), :headers => {})
|
25
|
-
|
26
|
-
@cli.options = @cli.options.merge(:key => "#{ssh_public_key}")
|
27
|
-
@cli.add_key(ssh_key_name)
|
25
|
+
cli.options = cli.options.merge(key: ssh_public_key.to_s)
|
26
|
+
cli.add_key(ssh_key_name)
|
28
27
|
|
29
28
|
expect($stdout.string).to eq <<-eos
|
30
29
|
Queueing upload of SSH key 'macbook_pro'...SSH Key uploaded
|
@@ -33,31 +32,31 @@ Name: macbook_pro
|
|
33
32
|
ID: 3
|
34
33
|
eos
|
35
34
|
|
36
|
-
expect(a_request(:post,
|
35
|
+
expect(a_request(:post, 'https://api.digitalocean.com/v2/account/keys')).to have_been_made
|
37
36
|
end
|
38
37
|
|
39
|
-
before
|
38
|
+
before do
|
40
39
|
allow(ENV).to receive(:[]).with('HOME').and_return(fake_home)
|
41
40
|
allow(ENV).to receive(:[]).with('DEBUG').and_return(nil)
|
42
41
|
allow(ENV).to receive(:[]).with('DO_API_TOKEN').and_return(nil)
|
43
42
|
allow(ENV).to receive(:[]).with('http_proxy').and_return(nil)
|
44
43
|
|
45
44
|
FileUtils.mkdir_p "#{fake_home}/.ssh"
|
46
|
-
File.open("#{fake_home}/.ssh/id_rsa.pub", 'w') {|f| f.write(
|
45
|
+
File.open("#{fake_home}/.ssh/id_rsa.pub", 'w') { |f| f.write('ssh-dss A456= user@host') }
|
47
46
|
end
|
48
47
|
|
49
|
-
it
|
50
|
-
stub_request(:post,
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
it 'with name, prompts from file folder' do
|
49
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/account/keys').
|
50
|
+
with(body: '{"name":"macbook_pro","public_key":"ssh-dss A456= user@host"}',
|
51
|
+
headers: { 'Accept' => '*/*', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json' }).
|
52
|
+
to_return(status: 201, body: fixture('create_ssh_key_from_file'), headers: {})
|
54
53
|
|
55
54
|
expect($stdout).to receive(:print).exactly(4).times
|
56
|
-
expect($stdout).to receive(:print).with(
|
55
|
+
expect($stdout).to receive(:print).with('Enter the path to your SSH key: ')
|
57
56
|
expect($stdout).to receive(:print).with("Queueing upload of SSH key '#{ssh_key_name}'...")
|
58
57
|
expect($stdin).to receive(:gets).and_return("#{fake_home}/.ssh/id_rsa.pub")
|
59
58
|
|
60
|
-
|
59
|
+
cli.add_key(ssh_key_name)
|
61
60
|
|
62
61
|
expect($stdout.string).to eq <<-eos
|
63
62
|
Possible public key paths from #{fake_home}/.ssh:
|
@@ -71,11 +70,9 @@ ID: 5
|
|
71
70
|
eos
|
72
71
|
end
|
73
72
|
|
74
|
-
after
|
75
|
-
File.delete(
|
73
|
+
after do
|
74
|
+
File.delete('id_dsa.pub') if File.exist?('id_dsa.pub')
|
76
75
|
FileUtils.rm_rf("#{fake_home}/.ssh/") if File.exist?("#{fake_home}/.ssh/")
|
77
76
|
end
|
78
|
-
|
79
77
|
end
|
80
78
|
end
|
81
|
-
|
@@ -1,113 +1,110 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tugboat::CLI do
|
4
|
-
include_context
|
4
|
+
include_context 'spec'
|
5
5
|
|
6
|
-
let(:tmp_path)
|
6
|
+
let(:tmp_path) { project_path + '/tmp/tugboat' }
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe 'authorize' do
|
9
9
|
before do
|
10
|
-
|
11
10
|
end
|
12
11
|
|
13
|
-
it
|
14
|
-
stub_request(:get,
|
15
|
-
|
16
|
-
|
12
|
+
it 'asks the right questions and checks credentials' do
|
13
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
14
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
15
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
17
16
|
|
18
17
|
expect($stdout).to receive(:print).exactly(6).times
|
19
|
-
expect($stdout).to receive(:print).with(
|
18
|
+
expect($stdout).to receive(:print).with('Enter your access token: ')
|
20
19
|
expect($stdin).to receive(:gets).and_return(access_token)
|
21
|
-
expect($stdout).to receive(:print).with(
|
20
|
+
expect($stdout).to receive(:print).with('Enter your SSH key path (optional, defaults to ~/.ssh/id_rsa): ')
|
22
21
|
expect($stdin).to receive(:gets).and_return(ssh_key_path)
|
23
|
-
expect($stdout).to receive(:print).with(
|
22
|
+
expect($stdout).to receive(:print).with('Enter your SSH user (optional, defaults to root): ')
|
24
23
|
expect($stdin).to receive(:gets).and_return(ssh_user)
|
25
|
-
expect($stdout).to receive(:print).with(
|
24
|
+
expect($stdout).to receive(:print).with('Enter your SSH port number (optional, defaults to 22): ')
|
26
25
|
expect($stdin).to receive(:gets).and_return(ssh_port)
|
27
|
-
expect($stdout).to receive(:print).with(
|
26
|
+
expect($stdout).to receive(:print).with('Enter your default region (optional, defaults to nyc1): ')
|
28
27
|
expect($stdin).to receive(:gets).and_return(region)
|
29
|
-
expect($stdout).to receive(:print).with(
|
28
|
+
expect($stdout).to receive(:print).with('Enter your default image ID or image slug (optional, defaults to ubuntu-14-04-x64): ')
|
30
29
|
expect($stdin).to receive(:gets).and_return(image)
|
31
|
-
expect($stdout).to receive(:print).with(
|
30
|
+
expect($stdout).to receive(:print).with('Enter your default size (optional, defaults to 512mb)): ')
|
32
31
|
expect($stdin).to receive(:gets).and_return(size)
|
33
32
|
expect($stdout).to receive(:print).with("Enter your default ssh key IDs (optional, defaults to none, array of IDs of ssh keys eg. ['1234']): ")
|
34
33
|
expect($stdin).to receive(:gets).and_return(ssh_key_id)
|
35
|
-
expect($stdout).to receive(:print).with(
|
34
|
+
expect($stdout).to receive(:print).with('Enter your default for private networking (optional, defaults to false): ')
|
36
35
|
expect($stdin).to receive(:gets).and_return(private_networking)
|
37
|
-
expect($stdout).to receive(:print).with(
|
36
|
+
expect($stdout).to receive(:print).with('Enter your default for enabling backups (optional, defaults to false): ')
|
38
37
|
expect($stdin).to receive(:gets).and_return(backups_enabled)
|
39
|
-
expect($stdout).to receive(:print).with(
|
38
|
+
expect($stdout).to receive(:print).with('Enter your default for IPv6 (optional, defaults to false): ')
|
40
39
|
expect($stdin).to receive(:gets).and_return(ip6)
|
41
40
|
|
42
|
-
|
41
|
+
cli.authorize
|
43
42
|
|
44
|
-
expect($stdout.string).to include(
|
43
|
+
expect($stdout.string).to include('Note: You can get your Access Token from https://cloud.digitalocean.com/settings/tokens/new')
|
45
44
|
expect($stdout.string).to include("To retrieve region, image, size and key ID's, you can use the corresponding tugboat command, such as `tugboat images`.")
|
46
|
-
expect($stdout.string).to include(
|
45
|
+
expect($stdout.string).to include('Defaults can be changed at any time in your ~/.tugboat configuration file.')
|
47
46
|
|
48
47
|
config = YAML.load_file(tmp_path)
|
49
48
|
|
50
|
-
expect(config[
|
51
|
-
expect(config[
|
52
|
-
expect(config[
|
53
|
-
expect(config[
|
54
|
-
expect(config[
|
55
|
-
expect(config[
|
56
|
-
expect(config[
|
57
|
-
expect(config[
|
58
|
-
expect(config[
|
59
|
-
expect(config[
|
49
|
+
expect(config['defaults']['image']).to eq image
|
50
|
+
expect(config['defaults']['region']).to eq region
|
51
|
+
expect(config['defaults']['size']).to eq size
|
52
|
+
expect(config['ssh']['ssh_user']).to eq ssh_user
|
53
|
+
expect(config['ssh']['ssh_key_path']).to eq ssh_key_path
|
54
|
+
expect(config['ssh']['ssh_port']).to eq ssh_port
|
55
|
+
expect(config['defaults']['ssh_key']).to eq ssh_key_id
|
56
|
+
expect(config['defaults']['private_networking']).to eq private_networking
|
57
|
+
expect(config['defaults']['backups_enabled']).to eq backups_enabled
|
58
|
+
expect(config['defaults']['ip6']).to eq ip6
|
60
59
|
end
|
61
60
|
|
62
|
-
it
|
63
|
-
stub_request(:get,
|
64
|
-
|
65
|
-
|
61
|
+
it 'sets defaults if no input given' do
|
62
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
63
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => %r{Bearer}, 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
64
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
66
65
|
|
67
66
|
expect($stdout).to receive(:print).exactly(6).times
|
68
|
-
expect($stdout).to receive(:print).with(
|
67
|
+
expect($stdout).to receive(:print).with('Enter your access token: ')
|
69
68
|
expect($stdin).to receive(:gets).and_return('')
|
70
|
-
expect($stdout).to receive(:print).with(
|
69
|
+
expect($stdout).to receive(:print).with('Enter your SSH key path (optional, defaults to ~/.ssh/id_rsa): ')
|
71
70
|
expect($stdin).to receive(:gets).and_return('')
|
72
|
-
expect($stdout).to receive(:print).with(
|
71
|
+
expect($stdout).to receive(:print).with('Enter your SSH user (optional, defaults to root): ')
|
73
72
|
expect($stdin).to receive(:gets).and_return('')
|
74
|
-
expect($stdout).to receive(:print).with(
|
73
|
+
expect($stdout).to receive(:print).with('Enter your SSH port number (optional, defaults to 22): ')
|
75
74
|
expect($stdin).to receive(:gets).and_return('')
|
76
|
-
expect($stdout).to receive(:print).with(
|
75
|
+
expect($stdout).to receive(:print).with('Enter your default region (optional, defaults to nyc1): ')
|
77
76
|
expect($stdin).to receive(:gets).and_return('')
|
78
|
-
expect($stdout).to receive(:print).with(
|
77
|
+
expect($stdout).to receive(:print).with('Enter your default image ID or image slug (optional, defaults to ubuntu-14-04-x64): ')
|
79
78
|
expect($stdin).to receive(:gets).and_return('')
|
80
|
-
expect($stdout).to receive(:print).with(
|
79
|
+
expect($stdout).to receive(:print).with('Enter your default size (optional, defaults to 512mb)): ')
|
81
80
|
expect($stdin).to receive(:gets).and_return('')
|
82
81
|
expect($stdout).to receive(:print).with("Enter your default ssh key IDs (optional, defaults to none, array of IDs of ssh keys eg. ['1234']): ")
|
83
82
|
expect($stdin).to receive(:gets).and_return('')
|
84
|
-
expect($stdout).to receive(:print).with(
|
83
|
+
expect($stdout).to receive(:print).with('Enter your default for private networking (optional, defaults to false): ')
|
85
84
|
expect($stdin).to receive(:gets).and_return('')
|
86
|
-
expect($stdout).to receive(:print).with(
|
85
|
+
expect($stdout).to receive(:print).with('Enter your default for enabling backups (optional, defaults to false): ')
|
87
86
|
expect($stdin).to receive(:gets).and_return('')
|
88
|
-
expect($stdout).to receive(:print).with(
|
87
|
+
expect($stdout).to receive(:print).with('Enter your default for IPv6 (optional, defaults to false): ')
|
89
88
|
expect($stdin).to receive(:gets).and_return('')
|
90
89
|
|
91
|
-
|
90
|
+
cli.authorize
|
92
91
|
|
93
|
-
expect($stdout.string).to include(
|
92
|
+
expect($stdout.string).to include('Note: You can get your Access Token from https://cloud.digitalocean.com/settings/tokens/new')
|
94
93
|
expect($stdout.string).to include("To retrieve region, image, size and key ID's, you can use the corresponding tugboat command, such as `tugboat images`.")
|
95
|
-
expect($stdout.string).to include(
|
94
|
+
expect($stdout.string).to include('Defaults can be changed at any time in your ~/.tugboat configuration file.')
|
96
95
|
|
97
96
|
config = YAML.load_file(tmp_path)
|
98
97
|
|
99
|
-
expect(config[
|
100
|
-
expect(config[
|
101
|
-
expect(config[
|
102
|
-
expect(config[
|
103
|
-
expect(config[
|
104
|
-
expect(config[
|
105
|
-
expect(config[
|
106
|
-
expect(config[
|
107
|
-
expect(config[
|
108
|
-
expect(config[
|
98
|
+
expect(config['defaults']['image']).to eq 'ubuntu-14-04-x64'
|
99
|
+
expect(config['defaults']['region']).to eq 'nyc2'
|
100
|
+
expect(config['defaults']['size']).to eq '512mb'
|
101
|
+
expect(config['ssh']['ssh_user']).to eq 'root'
|
102
|
+
expect(config['ssh']['ssh_key_path']).to eq '~/.ssh/id_rsa'
|
103
|
+
expect(config['ssh']['ssh_port']).to eq '22'
|
104
|
+
expect(config['defaults']['ssh_key']).to eq ''
|
105
|
+
expect(config['defaults']['private_networking']).to eq 'false'
|
106
|
+
expect(config['defaults']['backups_enabled']).to eq 'false'
|
107
|
+
expect(config['defaults']['ip6']).to eq 'false'
|
109
108
|
end
|
110
109
|
end
|
111
|
-
|
112
110
|
end
|
113
|
-
|