tugboat 2.2.2 → 2.2.3
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 +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
@@ -3,10 +3,9 @@ module Tugboat
|
|
3
3
|
# Check if the droplet in the environment is active
|
4
4
|
class CheckDropletActive < Base
|
5
5
|
def call(env)
|
6
|
-
|
7
6
|
unless env['user_droplet_ssh_wait']
|
8
|
-
if env[
|
9
|
-
say
|
7
|
+
if env['droplet_status'] != 'active'
|
8
|
+
say 'Droplet must be on for this operation to be successful.', :red
|
10
9
|
exit 1
|
11
10
|
end
|
12
11
|
end
|
@@ -16,4 +15,3 @@ module Tugboat
|
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
19
|
-
|
@@ -3,9 +3,8 @@ module Tugboat
|
|
3
3
|
# Check if the droplet in the environment is inactive, or "off"
|
4
4
|
class CheckDropletInactive < Base
|
5
5
|
def call(env)
|
6
|
-
|
7
|
-
|
8
|
-
say "Droplet must be off for this operation to be successful.", :red
|
6
|
+
if env['droplet_status'] != 'off'
|
7
|
+
say 'Droplet must be off for this operation to be successful.', :red
|
9
8
|
exit 1
|
10
9
|
end
|
11
10
|
|
@@ -14,4 +13,3 @@ module Tugboat
|
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
@@ -3,16 +3,15 @@ module Tugboat
|
|
3
3
|
# Check if the droplet in the environment is inactive, or "off"
|
4
4
|
class Config < Base
|
5
5
|
def call(env)
|
6
|
-
|
7
6
|
config = Tugboat::Configuration.instance
|
8
7
|
|
9
8
|
keys_retracted = ''
|
10
9
|
|
11
|
-
config_data = config.data.to_yaml.
|
10
|
+
config_data = config.data.to_yaml.delete('"')
|
12
11
|
|
13
|
-
if env[
|
12
|
+
if env['user_hide_keys']
|
14
13
|
keys_retracted = '(Keys Redacted)'
|
15
|
-
config_data = config_data.gsub(
|
14
|
+
config_data = config_data.gsub(%r{(access_token: )([a-zA-Z0-9]+)}, '\1 [REDACTED]')
|
16
15
|
end
|
17
16
|
|
18
17
|
say "Current Config #{keys_retracted}\n", :green
|
@@ -25,4 +24,3 @@ module Tugboat
|
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
@@ -2,12 +2,11 @@ module Tugboat
|
|
2
2
|
module Middleware
|
3
3
|
class ConfirmAction < Base
|
4
4
|
def call(env)
|
5
|
+
unless env['user_confirm_action']
|
6
|
+
response = yes? 'Warning! Potentially destructive action. Please confirm [y/n]:'
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
if !response
|
10
|
-
say "Aborted due to user request.", :red
|
8
|
+
unless response
|
9
|
+
say 'Aborted due to user request.', :red
|
11
10
|
# Quit
|
12
11
|
exit 1
|
13
12
|
end
|
@@ -19,4 +18,3 @@ module Tugboat
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
22
|
-
|
@@ -4,65 +4,49 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
say "Queueing creation of droplet '#{env[
|
7
|
+
say "Queueing creation of droplet '#{env['create_droplet_name']}'...", nil, false
|
8
8
|
|
9
|
-
env[
|
10
|
-
droplet_region_slug = env["create_droplet_region_slug"] :
|
11
|
-
droplet_region_slug = env["config"].default_region
|
9
|
+
droplet_region_slug = env['create_droplet_region_slug'] ? env['create_droplet_region_slug'] : env['config'].default_region
|
12
10
|
|
13
|
-
env[
|
14
|
-
droplet_image_slug = env["create_droplet_image_slug"] :
|
15
|
-
droplet_image_slug = env["config"].default_image
|
11
|
+
droplet_image_slug = env['create_droplet_image_slug'] ? env['create_droplet_image_slug'] : env['config'].default_image
|
16
12
|
|
17
|
-
env[
|
18
|
-
droplet_size_slug = env["create_droplet_size_slug"] :
|
19
|
-
droplet_size_slug = env["config"].default_size
|
13
|
+
droplet_size_slug = env['create_droplet_size_slug'] ? env['create_droplet_size_slug'] : env['config'].default_size
|
20
14
|
|
21
|
-
env[
|
22
|
-
droplet_ssh_key_ids = env["create_droplet_ssh_key_ids"] :
|
23
|
-
droplet_ssh_key_ids = env["config"].default_ssh_key
|
15
|
+
droplet_ssh_key_ids = env['create_droplet_ssh_key_ids'] ? env['create_droplet_ssh_key_ids'] : env['config'].default_ssh_key
|
24
16
|
|
25
|
-
env[
|
26
|
-
droplet_private_networking = env["create_droplet_private_networking"] :
|
27
|
-
droplet_private_networking = env["config"].default_private_networking
|
17
|
+
droplet_private_networking = env['create_droplet_private_networking'] ? env['create_droplet_private_networking'] : env['config'].default_private_networking
|
28
18
|
|
29
|
-
env[
|
30
|
-
droplet_ip6 = env["create_droplet_ip6"] :
|
31
|
-
droplet_ip6 = env["config"].default_ip6
|
19
|
+
droplet_ip6 = env['create_droplet_ip6'] ? env['create_droplet_ip6'] : env['config'].default_ip6
|
32
20
|
|
33
|
-
env[
|
34
|
-
droplet_user_data = env["create_droplet_user_data"] :
|
35
|
-
droplet_user_data = env["config"].default_user_data
|
21
|
+
droplet_user_data = env['create_droplet_user_data'] ? env['create_droplet_user_data'] : env['config'].default_user_data
|
36
22
|
|
37
23
|
if droplet_user_data
|
38
|
-
|
24
|
+
if File.file?(droplet_user_data)
|
25
|
+
user_data_string = File.open(droplet_user_data, 'rb', &:read)
|
26
|
+
else
|
39
27
|
say "Could not find file: #{droplet_user_data}, check your user_data setting"
|
40
28
|
exit 1
|
41
|
-
else
|
42
|
-
user_data_string = File.open(droplet_user_data, 'rb') { |f| f.read }
|
43
29
|
end
|
44
30
|
end
|
45
31
|
|
46
|
-
env[
|
47
|
-
droplet_backups_enabled = env["create_droplet_backups_enabled"] :
|
48
|
-
droplet_backups_enabled = env["config"].default_backups_enabled
|
32
|
+
droplet_backups_enabled = env['create_droplet_backups_enabled'] ? env['create_droplet_backups_enabled'] : env['config'].default_backups_enabled
|
49
33
|
|
50
|
-
if droplet_ssh_key_ids.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
34
|
+
droplet_key_array = if droplet_ssh_key_ids.is_a?(Array)
|
35
|
+
droplet_ssh_key_ids
|
36
|
+
else
|
37
|
+
droplet_ssh_key_ids.to_s.split(',')
|
38
|
+
end
|
55
39
|
|
56
40
|
create_opts = {
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
41
|
+
name: env['create_droplet_name'],
|
42
|
+
size: droplet_size_slug,
|
43
|
+
image: droplet_image_slug.to_s,
|
44
|
+
region: droplet_region_slug,
|
45
|
+
ssh_keys: droplet_key_array,
|
46
|
+
private_networking: droplet_private_networking,
|
47
|
+
backups_enabled: droplet_backups_enabled,
|
48
|
+
ipv6: droplet_ip6,
|
49
|
+
user_data: user_data_string
|
66
50
|
}
|
67
51
|
|
68
52
|
response = ocean.droplet.create(create_opts)
|
@@ -72,11 +56,10 @@ module Tugboat
|
|
72
56
|
exit 1
|
73
57
|
end
|
74
58
|
|
75
|
-
say
|
59
|
+
say 'Droplet created!'
|
76
60
|
|
77
61
|
@app.call(env)
|
78
62
|
end
|
79
63
|
end
|
80
64
|
end
|
81
65
|
end
|
82
|
-
|
@@ -1,58 +1,57 @@
|
|
1
1
|
module Tugboat
|
2
2
|
class CustomLogger < Faraday::Middleware
|
3
|
-
|
4
|
-
|
3
|
+
extend Forwardable
|
4
|
+
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
6
|
+
def initialize(app, options = {})
|
7
|
+
@app = app
|
8
|
+
@logger = options.fetch(:logger) do
|
9
|
+
require 'logger'
|
10
|
+
::Logger.new($stdout)
|
12
11
|
end
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
14
|
+
def call(env)
|
15
|
+
start_time = Time.now
|
16
|
+
info { request_info(env) }
|
17
|
+
debug { request_debug(env) }
|
18
|
+
@app.call(env).on_complete do
|
19
|
+
end_time = Time.now
|
20
|
+
response_time = end_time - start_time
|
21
|
+
info { response_info(env, response_time) }
|
22
|
+
debug { response_debug(env) }
|
24
23
|
end
|
24
|
+
end
|
25
25
|
|
26
|
-
|
26
|
+
private
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
28
|
+
def filter(output)
|
29
|
+
if ENV['DEBUG'].to_i == 2
|
30
|
+
output = output.to_s.gsub(%r{Bearer [a-zA-Z0-9]*}, 'Bearer [TOKEN REDACTED]')
|
31
|
+
output = output.to_s.gsub(%r{_digitalocean2_session_v2=[a-zA-Z0-9%-]*}, '_digitalocean2_session_v2=[SESSION_COOKIE]')
|
32
|
+
else
|
33
|
+
output
|
35
34
|
end
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
def request_info(env)
|
38
|
+
format('Started %s request to: %s', env[:method].to_s.upcase, filter(env[:url]))
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def response_info(env, response_time)
|
42
|
+
format('Response from %s; Status: %d; Time: %.1fms', filter(env[:url]), env[:status], (response_time * 1_000.0))
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
def response_debug(env)
|
50
|
-
debug_message("Response", env[:response_headers], env[:body])
|
51
|
-
end
|
45
|
+
def request_debug(env)
|
46
|
+
debug_message('Request', env[:request_headers], env[:body])
|
47
|
+
end
|
52
48
|
|
53
|
-
|
49
|
+
def response_debug(env)
|
50
|
+
debug_message('Response', env[:response_headers], env[:body])
|
51
|
+
end
|
54
52
|
|
55
|
-
|
53
|
+
def debug_message(name, headers, body)
|
54
|
+
main_message = <<-MESSAGE.gsub(%r{^ +([^ ])}m, '\\1')
|
56
55
|
#{name} Headers:
|
57
56
|
----------------
|
58
57
|
#{format_headers(headers)}
|
@@ -60,20 +59,19 @@ module Tugboat
|
|
60
59
|
#{name} Body:
|
61
60
|
-------------
|
62
61
|
MESSAGE
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
def pretty_body(body)
|
67
|
-
body_json = JSON.parse(body)
|
68
|
-
JSON.pretty_generate(body_json)
|
69
|
-
rescue JSON::ParserError => e
|
70
|
-
body
|
71
|
-
end
|
62
|
+
main_message + pretty_body(body)
|
63
|
+
end
|
72
64
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
65
|
+
def pretty_body(body)
|
66
|
+
body_json = JSON.parse(body)
|
67
|
+
JSON.pretty_generate(body_json)
|
68
|
+
rescue JSON::ParserError
|
69
|
+
body
|
70
|
+
end
|
77
71
|
|
72
|
+
def format_headers(headers)
|
73
|
+
length = headers.map { |k, _v| k.to_s.size }.max
|
74
|
+
headers.map { |name, value| "#{name.to_s.ljust(length)} : #{filter(value)}" }.join("\n")
|
75
|
+
end
|
78
76
|
end
|
79
77
|
end
|
@@ -4,15 +4,15 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
say "Queuing destroy for #{env[
|
7
|
+
say "Queuing destroy for #{env['droplet_id']} #{env['droplet_name']}...", nil, false
|
8
8
|
|
9
|
-
response = ocean.droplet.destroy env[
|
9
|
+
response = ocean.droplet.destroy env['droplet_id']
|
10
10
|
|
11
|
-
|
11
|
+
if response.success?
|
12
|
+
say 'Deletion Successful!', :green
|
13
|
+
else
|
12
14
|
say "Failed to destroy Droplet: #{response.message}", :red
|
13
15
|
exit 1
|
14
|
-
else
|
15
|
-
say "Deletion Successful!", :green
|
16
16
|
end
|
17
17
|
|
18
18
|
@app.call(env)
|
@@ -20,4 +20,3 @@ module Tugboat
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
@@ -4,15 +4,15 @@ module Tugboat
|
|
4
4
|
def call(env)
|
5
5
|
ocean = env['barge']
|
6
6
|
|
7
|
-
say "Queuing destroy image for #{env[
|
7
|
+
say "Queuing destroy image for #{env['image_id']} #{env['image_name']}...", nil, false
|
8
8
|
|
9
|
-
response = ocean.image.destroy env[
|
9
|
+
response = ocean.image.destroy env['image_id']
|
10
10
|
|
11
|
-
|
11
|
+
if response.success?
|
12
|
+
say 'Image deletion successful!', :green
|
13
|
+
else
|
12
14
|
say "Failed to destroy image: #{response.message}", :red
|
13
15
|
exit 1
|
14
|
-
else
|
15
|
-
say 'Image deletion successful!', :green
|
16
16
|
end
|
17
17
|
|
18
18
|
@app.call(env)
|
@@ -20,4 +20,3 @@ module Tugboat
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
@@ -3,15 +3,15 @@ module Tugboat
|
|
3
3
|
# Check if the client has set-up configuration yet.
|
4
4
|
class FindDroplet < Base
|
5
5
|
def get_public_ip(networks)
|
6
|
-
get_ip_per_network_type networks,
|
6
|
+
get_ip_per_network_type networks, 'public'
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_private_ip(networks)
|
10
|
-
get_ip_per_network_type networks,
|
10
|
+
get_ip_per_network_type networks, 'private'
|
11
11
|
end
|
12
12
|
|
13
13
|
def get_ip_per_network_type(networks, type)
|
14
|
-
found_network = networks.
|
14
|
+
found_network = networks.find { |n| n.type == type }
|
15
15
|
found_network.ip_address if found_network
|
16
16
|
end
|
17
17
|
|
@@ -26,14 +26,14 @@ module Tugboat
|
|
26
26
|
# let the user know.
|
27
27
|
if !user_fuzzy_name && !user_droplet_name && !user_droplet_id
|
28
28
|
|
29
|
-
say
|
29
|
+
say 'Tugboat attempted to find a droplet with no arguments.', :red
|
30
30
|
say "Try running `tugboat #{env['tugboat_action']} dropletname`", :green
|
31
31
|
say "For more help run: `tugboat help #{env['tugboat_action']}`", :blue
|
32
32
|
exit 1
|
33
33
|
end
|
34
34
|
|
35
35
|
if porcelain && (!(user_droplet_name || user_droplet_id) || user_fuzzy_name)
|
36
|
-
say
|
36
|
+
say 'Tugboat expects an exact droplet ID or droplet name for porcelain mode.', :red
|
37
37
|
exit 1
|
38
38
|
end
|
39
39
|
|
@@ -45,8 +45,8 @@ module Tugboat
|
|
45
45
|
# Easy for us if they provide an id. Just set it to the droplet_id
|
46
46
|
if user_droplet_id
|
47
47
|
|
48
|
-
|
49
|
-
say
|
48
|
+
unless porcelain
|
49
|
+
say 'Droplet id provided. Finding Droplet...', nil, false
|
50
50
|
end
|
51
51
|
response = ocean.droplet.show user_droplet_id
|
52
52
|
|
@@ -55,34 +55,33 @@ module Tugboat
|
|
55
55
|
exit 1
|
56
56
|
end
|
57
57
|
|
58
|
-
env[
|
59
|
-
env[
|
60
|
-
env[
|
61
|
-
env[
|
62
|
-
env[
|
58
|
+
env['droplet_id'] = response.droplet.id
|
59
|
+
env['droplet_name'] = "(#{response.droplet.name})"
|
60
|
+
env['droplet_ip'] = get_public_ip response.droplet.networks.v4
|
61
|
+
env['droplet_ip_private'] = get_private_ip response.droplet.networks.v4
|
62
|
+
env['droplet_status'] = response.droplet.status
|
63
63
|
end
|
64
64
|
|
65
65
|
# If they provide a name, we need to get the ID for it.
|
66
66
|
# This requires a lookup.
|
67
|
-
if user_droplet_name && !env[
|
68
|
-
|
69
|
-
say
|
67
|
+
if user_droplet_name && !env['droplet_id']
|
68
|
+
unless porcelain
|
69
|
+
say 'Droplet name provided. Finding droplet ID...', nil, false
|
70
70
|
end
|
71
71
|
|
72
72
|
# Look for the droplet by an exact name match.
|
73
73
|
(get_droplet_list ocean).each do |d|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
74
|
+
next unless d.name == user_droplet_name
|
75
|
+
env['droplet_id'] = d.id
|
76
|
+
env['droplet_name'] = "(#{d.name})"
|
77
|
+
env['droplet_ip'] = get_public_ip d.networks.v4
|
78
|
+
env['droplet_ip_private'] = get_private_ip d.networks.v4
|
79
|
+
env['droplet_status'] = d.status
|
81
80
|
end
|
82
81
|
|
83
82
|
# If we coulnd't find it, tell the user and drop out of the
|
84
83
|
# sequence.
|
85
|
-
|
84
|
+
unless env['droplet_id']
|
86
85
|
say "error\nUnable to find a droplet named '#{user_droplet_name}'.", :red
|
87
86
|
exit 1
|
88
87
|
end
|
@@ -93,17 +92,15 @@ module Tugboat
|
|
93
92
|
# with a flag.
|
94
93
|
#
|
95
94
|
# This requires a lookup.
|
96
|
-
if user_fuzzy_name && !env[
|
97
|
-
say
|
95
|
+
if user_fuzzy_name && !env['droplet_id']
|
96
|
+
say 'Droplet fuzzy name provided. Finding droplet ID...', nil, false
|
98
97
|
|
99
98
|
found_droplets = []
|
100
99
|
choices = []
|
101
100
|
|
102
101
|
(get_droplet_list ocean).each do |d|
|
103
102
|
# Check to see if one of the droplet names have the fuzzy string.
|
104
|
-
if d.name.upcase.include? user_fuzzy_name.upcase
|
105
|
-
found_droplets << d
|
106
|
-
end
|
103
|
+
found_droplets << d if d.name.upcase.include? user_fuzzy_name.upcase
|
107
104
|
end
|
108
105
|
|
109
106
|
# Check to see if we have more then one droplet, and prompt
|
@@ -111,46 +108,46 @@ module Tugboat
|
|
111
108
|
if found_droplets.length == 1
|
112
109
|
droplet_return = found_droplets.first
|
113
110
|
|
114
|
-
env[
|
115
|
-
env[
|
111
|
+
env['droplet_id'] = droplet_return.id
|
112
|
+
env['droplet_name'] = "(#{droplet_return.name})"
|
116
113
|
if droplet_return.networks.v4.empty?
|
117
|
-
env[
|
118
|
-
env[
|
114
|
+
env['droplet_ip'] = '' # No Network Yet
|
115
|
+
env['droplet_ip_private'] = '' # No Network Yet
|
119
116
|
else
|
120
|
-
env[
|
121
|
-
env[
|
117
|
+
env['droplet_ip'] = get_public_ip droplet_return.networks.v4
|
118
|
+
env['droplet_ip_private'] = get_private_ip droplet_return.networks.v4
|
122
119
|
end
|
123
|
-
env[
|
120
|
+
env['droplet_status'] = droplet_return.status
|
124
121
|
elsif found_droplets.length > 1
|
125
122
|
# Did we run the multiple questionairre?
|
126
123
|
did_run_multiple = true
|
127
124
|
|
128
|
-
say
|
125
|
+
say 'Multiple droplets found.'
|
129
126
|
say
|
130
127
|
found_droplets.each_with_index do |d, i|
|
131
128
|
say "#{i}) #{d.name} (#{d.id})"
|
132
129
|
choices << i.to_s
|
133
130
|
end
|
134
131
|
say
|
135
|
-
choice = ask
|
136
|
-
env[
|
137
|
-
env[
|
138
|
-
env[
|
139
|
-
env[
|
140
|
-
env[
|
132
|
+
choice = ask 'Please choose a droplet:', limited_to: choices
|
133
|
+
env['droplet_id'] = found_droplets[choice.to_i].id
|
134
|
+
env['droplet_name'] = found_droplets[choice.to_i].name
|
135
|
+
env['droplet_ip'] = get_public_ip found_droplets[choice.to_i].networks.v4
|
136
|
+
env['droplet_ip_private'] = get_private_ip found_droplets[choice.to_i].networks.v4
|
137
|
+
env['droplet_status'] = found_droplets[choice.to_i].status
|
141
138
|
end
|
142
139
|
|
143
140
|
# If we coulnd't find it, tell the user and drop out of the
|
144
141
|
# sequence.
|
145
|
-
|
142
|
+
unless env['droplet_id']
|
146
143
|
say "error\nUnable to find a droplet named '#{user_fuzzy_name}'.", :red
|
147
144
|
exit 1
|
148
145
|
end
|
149
146
|
end
|
150
147
|
|
151
|
-
|
152
|
-
|
153
|
-
say "done#{CLEAR}, #{env[
|
148
|
+
unless did_run_multiple
|
149
|
+
unless porcelain
|
150
|
+
say "done#{CLEAR}, #{env['droplet_id']} #{env['droplet_name']}", :green
|
154
151
|
end
|
155
152
|
end
|
156
153
|
@app.call(env)
|
@@ -158,4 +155,3 @@ module Tugboat
|
|
158
155
|
end
|
159
156
|
end
|
160
157
|
end
|
161
|
-
|