tugboat 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +520 -0
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +0 -6
  5. data/README.md +34 -2
  6. data/Rakefile +6 -1
  7. data/bin/tugboat +2 -2
  8. data/features/cassettes/config/Array_of_SSH_Keys_in_Config.yml +1 -1
  9. data/features/cassettes/config/Single_SSH_key_as_number_in_config.yml +1 -1
  10. data/features/step_definitions/steps.rb +1 -1
  11. data/features/support/env.rb +7 -3
  12. data/lib/tugboat.rb +2 -2
  13. data/lib/tugboat/cli.rb +394 -444
  14. data/lib/tugboat/config.rb +43 -61
  15. data/lib/tugboat/middleware.rb +33 -33
  16. data/lib/tugboat/middleware/add_key.rb +12 -13
  17. data/lib/tugboat/middleware/ask_for_credentials.rb +12 -13
  18. data/lib/tugboat/middleware/base.rb +25 -20
  19. data/lib/tugboat/middleware/check_configuration.rb +3 -6
  20. data/lib/tugboat/middleware/check_credentials.rb +0 -1
  21. data/lib/tugboat/middleware/check_droplet_active.rb +2 -4
  22. data/lib/tugboat/middleware/check_droplet_inactive.rb +2 -4
  23. data/lib/tugboat/middleware/config.rb +3 -5
  24. data/lib/tugboat/middleware/confirm_action.rb +4 -6
  25. data/lib/tugboat/middleware/create_droplet.rb +27 -44
  26. data/lib/tugboat/middleware/custom_logger.rb +52 -54
  27. data/lib/tugboat/middleware/destroy_droplet.rb +5 -6
  28. data/lib/tugboat/middleware/destroy_image.rb +5 -6
  29. data/lib/tugboat/middleware/find_droplet.rb +43 -47
  30. data/lib/tugboat/middleware/find_image.rb +23 -29
  31. data/lib/tugboat/middleware/halt_droplet.rb +9 -10
  32. data/lib/tugboat/middleware/info_droplet.rb +30 -33
  33. data/lib/tugboat/middleware/info_image.rb +1 -1
  34. data/lib/tugboat/middleware/inject_client.rb +8 -10
  35. data/lib/tugboat/middleware/inject_configuration.rb +1 -2
  36. data/lib/tugboat/middleware/list_droplets.rb +9 -10
  37. data/lib/tugboat/middleware/list_images.rb +9 -9
  38. data/lib/tugboat/middleware/list_regions.rb +1 -1
  39. data/lib/tugboat/middleware/list_sizes.rb +1 -1
  40. data/lib/tugboat/middleware/list_ssh_keys.rb +1 -3
  41. data/lib/tugboat/middleware/password_reset.rb +6 -7
  42. data/lib/tugboat/middleware/rebuild_droplet.rb +7 -7
  43. data/lib/tugboat/middleware/resize_droplet.rb +6 -7
  44. data/lib/tugboat/middleware/restart_droplet.rb +4 -11
  45. data/lib/tugboat/middleware/snapshot_droplet.rb +7 -8
  46. data/lib/tugboat/middleware/ssh_droplet.rb +30 -31
  47. data/lib/tugboat/middleware/start_droplet.rb +5 -5
  48. data/lib/tugboat/middleware/wait_for_state.rb +2 -3
  49. data/lib/tugboat/version.rb +1 -1
  50. data/spec/cli/add_key_spec.rb +25 -28
  51. data/spec/cli/authorize_cli_spec.rb +57 -60
  52. data/spec/cli/config_cli_spec.rb +8 -11
  53. data/spec/cli/create_cli_spec.rb +40 -46
  54. data/spec/cli/debug_cli_spec.rb +29 -29
  55. data/spec/cli/destroy_cli_spec.rb +58 -60
  56. data/spec/cli/destroy_image_cli_spec.rb +42 -45
  57. data/spec/cli/droplets_cli_spec.rb +62 -64
  58. data/spec/cli/env_variable_spec.rb +14 -15
  59. data/spec/cli/halt_cli_spec.rb +65 -69
  60. data/spec/cli/help_cli_spec.rb +8 -8
  61. data/spec/cli/images_cli_spec.rb +28 -30
  62. data/spec/cli/info_cli_spec.rb +144 -147
  63. data/spec/cli/info_image_cli_spec.rb +57 -60
  64. data/spec/cli/keys_cli_spec.rb +8 -10
  65. data/spec/cli/password_reset_cli_spec.rb +56 -56
  66. data/spec/cli/rebuild_cli_spec.rb +194 -198
  67. data/spec/cli/regions_cli_spec.rb +8 -8
  68. data/spec/cli/resize_cli_spec.rb +54 -56
  69. data/spec/cli/restart_cli_spec.rb +53 -57
  70. data/spec/cli/sizes_cli_spec.rb +7 -8
  71. data/spec/cli/snapshot_cli_spec.rb +50 -53
  72. data/spec/cli/ssh_cli_spec.rb +41 -42
  73. data/spec/cli/start_cli_spec.rb +48 -52
  74. data/spec/cli/verify_cli_spec.rb +22 -25
  75. data/spec/cli/version_cli_spec.rb +6 -8
  76. data/spec/cli/wait_cli_spec.rb +50 -52
  77. data/spec/config_spec.rb +56 -57
  78. data/spec/middleware/base_spec.rb +5 -6
  79. data/spec/middleware/check_configuration_spec.rb +5 -7
  80. data/spec/middleware/check_credentials_spec.rb +9 -10
  81. data/spec/middleware/check_droplet_active_spec.rb +5 -7
  82. data/spec/middleware/check_droplet_inactive_spec.rb +5 -7
  83. data/spec/middleware/find_droplet_spec.rb +4 -5
  84. data/spec/middleware/find_image_spec.rb +4 -5
  85. data/spec/middleware/inject_client_spec.rb +9 -12
  86. data/spec/middleware/inject_configuration_spec.rb +4 -7
  87. data/spec/middleware/ssh_droplet_spec.rb +70 -73
  88. data/spec/shared/environment.rb +18 -20
  89. data/spec/spec_helper.rb +4 -4
  90. data/tugboat.gemspec +10 -6
  91. metadata +88 -17
@@ -9,25 +9,25 @@ module Tugboat
9
9
  attr_reader :data
10
10
  attr_reader :path
11
11
 
12
- FILE_NAME = '.tugboat'
13
- DEFAULT_SSH_KEY_PATH = '.ssh/id_rsa'
14
- DEFAULT_SSH_PORT = '22'
15
- DEFAULT_REGION = 'nyc2'
16
- DEFAULT_IMAGE = 'ubuntu-14-04-x64'
17
- DEFAULT_SIZE = '512mb'
18
- DEFAULT_SSH_KEY = ''
19
- DEFAULT_IP6 = 'false'
20
- DEFAULT_PRIVATE_NETWORKING = 'false'
21
- DEFAULT_BACKUPS_ENABLED = 'false'
12
+ FILE_NAME = '.tugboat'.freeze
13
+ DEFAULT_SSH_KEY_PATH = '.ssh/id_rsa'.freeze
14
+ DEFAULT_SSH_PORT = '22'.freeze
15
+ DEFAULT_REGION = 'nyc2'.freeze
16
+ DEFAULT_IMAGE = 'ubuntu-14-04-x64'.freeze
17
+ DEFAULT_SIZE = '512mb'.freeze
18
+ DEFAULT_SSH_KEY = ''.freeze
19
+ DEFAULT_IP6 = 'false'.freeze
20
+ DEFAULT_PRIVATE_NETWORKING = 'false'.freeze
21
+ DEFAULT_BACKUPS_ENABLED = 'false'.freeze
22
22
  DEFAULT_USER_DATA = nil
23
23
 
24
24
  # Load config file from current directory, if not exit load from user's home directory
25
25
  def initialize
26
- @path = File.join(File.expand_path("."), FILE_NAME)
27
- unless File.exists?(@path)
28
- @path = ( ENV["TUGBOAT_CONFIG_PATH"] || File.join(File.expand_path("~"), FILE_NAME) )
26
+ @path = File.join(File.expand_path('.'), FILE_NAME)
27
+ unless File.exist?(@path)
28
+ @path = (ENV['TUGBOAT_CONFIG_PATH'] || File.join(File.expand_path('~'), FILE_NAME))
29
29
  end
30
- @data = self.load_config_file
30
+ @data = load_config_file
31
31
  end
32
32
 
33
33
  # If we can't load the config file, self.data is nil, which we can
@@ -97,80 +97,62 @@ module Tugboat
97
97
 
98
98
  # Re-runs initialize
99
99
  def reset!
100
- self.send(:initialize)
100
+ send(:initialize)
101
101
  end
102
102
 
103
103
  # Re-loads the config
104
104
  def reload!
105
- @data = self.load_config_file
105
+ @data = load_config_file
106
106
  end
107
107
 
108
108
  # Writes a config file
109
109
  def create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled, ip6)
110
110
  # Default SSH Key path
111
- if ssh_key_path.empty?
112
- ssh_key_path = File.join("~", DEFAULT_SSH_KEY_PATH)
113
- end
111
+ ssh_key_path = File.join('~', DEFAULT_SSH_KEY_PATH) if ssh_key_path.empty?
114
112
 
115
- if ssh_user.empty?
116
- ssh_user = 'root'
117
- end
113
+ ssh_user = 'root' if ssh_user.empty?
118
114
 
119
- if ssh_port.empty?
120
- ssh_port = DEFAULT_SSH_PORT
121
- end
115
+ ssh_port = DEFAULT_SSH_PORT if ssh_port.empty?
122
116
 
123
- if region.empty?
124
- region = DEFAULT_REGION
125
- end
117
+ region = DEFAULT_REGION if region.empty?
126
118
 
127
- if image.empty?
128
- image = DEFAULT_IMAGE
129
- end
119
+ image = DEFAULT_IMAGE if image.empty?
130
120
 
131
- if size.empty?
132
- size = DEFAULT_SIZE
133
- end
121
+ size = DEFAULT_SIZE if size.empty?
134
122
 
135
- if ssh_key.empty?
136
- default_ssh_key = DEFAULT_SSH_KEY
137
- end
123
+ default_ssh_key = DEFAULT_SSH_KEY if ssh_key.empty?
138
124
 
139
125
  if private_networking.empty?
140
126
  private_networking = DEFAULT_PRIVATE_NETWORKING
141
127
  end
142
128
 
143
- if backups_enabled.empty?
144
- backups_enabled = DEFAULT_BACKUPS_ENABLED
145
- end
129
+ backups_enabled = DEFAULT_BACKUPS_ENABLED if backups_enabled.empty?
146
130
 
147
- if ip6.empty?
148
- ip6 = DEFAULT_IP6
149
- end
131
+ ip6 = DEFAULT_IP6 if ip6.empty?
150
132
 
151
133
  require 'yaml'
152
- File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |file|
134
+ File.open(@path, File::RDWR | File::TRUNC | File::CREAT, 0o600) do |file|
153
135
  data = {
154
- "authentication" => {
155
- "access_token" => access_token
156
- },
157
- "ssh" => {
158
- "ssh_user" => ssh_user,
159
- "ssh_key_path" => ssh_key_path ,
160
- "ssh_port" => ssh_port },
161
- "defaults" => {
162
- "region" => region,
163
- "image" => image,
164
- "size" => size,
165
- "ssh_key" => ssh_key,
166
- "private_networking" => private_networking,
167
- "backups_enabled" => backups_enabled,
168
- "ip6" => ip6,
169
- }
136
+ 'authentication' => {
137
+ 'access_token' => access_token
138
+ },
139
+ 'ssh' => {
140
+ 'ssh_user' => ssh_user,
141
+ 'ssh_key_path' => ssh_key_path,
142
+ 'ssh_port' => ssh_port
143
+ },
144
+ 'defaults' => {
145
+ 'region' => region,
146
+ 'image' => image,
147
+ 'size' => size,
148
+ 'ssh_key' => ssh_key,
149
+ 'private_networking' => private_networking,
150
+ 'backups_enabled' => backups_enabled,
151
+ 'ip6' => ip6
152
+ }
170
153
  }
171
154
  file.write data.to_yaml
172
155
  end
173
156
  end
174
-
175
157
  end
176
158
  end
@@ -1,39 +1,39 @@
1
- require "middleware"
1
+ require 'middleware'
2
2
 
3
3
  module Tugboat
4
4
  module Middleware
5
- autoload :AddKey, "tugboat/middleware/add_key"
6
- autoload :AskForCredentials, "tugboat/middleware/ask_for_credentials"
7
- autoload :Base, "tugboat/middleware/base"
8
- autoload :CheckConfiguration, "tugboat/middleware/check_configuration"
9
- autoload :CheckCredentials, "tugboat/middleware/check_credentials"
10
- autoload :CheckDropletActive, "tugboat/middleware/check_droplet_active"
11
- autoload :CheckDropletInactive, "tugboat/middleware/check_droplet_inactive"
12
- autoload :Config, "tugboat/middleware/config"
13
- autoload :ConfirmAction, "tugboat/middleware/confirm_action"
14
- autoload :CreateDroplet, "tugboat/middleware/create_droplet"
15
- autoload :RebuildDroplet, "tugboat/middleware/rebuild_droplet"
16
- autoload :DestroyDroplet, "tugboat/middleware/destroy_droplet"
17
- autoload :DestroyImage, "tugboat/middleware/destroy_image"
18
- autoload :FindDroplet, "tugboat/middleware/find_droplet"
19
- autoload :FindImage, "tugboat/middleware/find_image"
20
- autoload :HaltDroplet, "tugboat/middleware/halt_droplet"
21
- autoload :InfoDroplet, "tugboat/middleware/info_droplet"
22
- autoload :InfoImage, "tugboat/middleware/info_image"
23
- autoload :InjectClient, "tugboat/middleware/inject_client"
24
- autoload :InjectConfiguration, "tugboat/middleware/inject_configuration"
25
- autoload :ListDroplets, "tugboat/middleware/list_droplets"
26
- autoload :ListImages, "tugboat/middleware/list_images"
27
- autoload :ListRegions, "tugboat/middleware/list_regions"
28
- autoload :ListSizes, "tugboat/middleware/list_sizes"
29
- autoload :ListSSHKeys, "tugboat/middleware/list_ssh_keys"
30
- autoload :PasswordReset, "tugboat/middleware/password_reset"
31
- autoload :ResizeDroplet, "tugboat/middleware/resize_droplet"
32
- autoload :RestartDroplet, "tugboat/middleware/restart_droplet"
33
- autoload :SnapshotDroplet, "tugboat/middleware/snapshot_droplet"
34
- autoload :SSHDroplet, "tugboat/middleware/ssh_droplet"
35
- autoload :StartDroplet, "tugboat/middleware/start_droplet"
36
- autoload :WaitForState, "tugboat/middleware/wait_for_state"
5
+ autoload :AddKey, 'tugboat/middleware/add_key'
6
+ autoload :AskForCredentials, 'tugboat/middleware/ask_for_credentials'
7
+ autoload :Base, 'tugboat/middleware/base'
8
+ autoload :CheckConfiguration, 'tugboat/middleware/check_configuration'
9
+ autoload :CheckCredentials, 'tugboat/middleware/check_credentials'
10
+ autoload :CheckDropletActive, 'tugboat/middleware/check_droplet_active'
11
+ autoload :CheckDropletInactive, 'tugboat/middleware/check_droplet_inactive'
12
+ autoload :Config, 'tugboat/middleware/config'
13
+ autoload :ConfirmAction, 'tugboat/middleware/confirm_action'
14
+ autoload :CreateDroplet, 'tugboat/middleware/create_droplet'
15
+ autoload :RebuildDroplet, 'tugboat/middleware/rebuild_droplet'
16
+ autoload :DestroyDroplet, 'tugboat/middleware/destroy_droplet'
17
+ autoload :DestroyImage, 'tugboat/middleware/destroy_image'
18
+ autoload :FindDroplet, 'tugboat/middleware/find_droplet'
19
+ autoload :FindImage, 'tugboat/middleware/find_image'
20
+ autoload :HaltDroplet, 'tugboat/middleware/halt_droplet'
21
+ autoload :InfoDroplet, 'tugboat/middleware/info_droplet'
22
+ autoload :InfoImage, 'tugboat/middleware/info_image'
23
+ autoload :InjectClient, 'tugboat/middleware/inject_client'
24
+ autoload :InjectConfiguration, 'tugboat/middleware/inject_configuration'
25
+ autoload :ListDroplets, 'tugboat/middleware/list_droplets'
26
+ autoload :ListImages, 'tugboat/middleware/list_images'
27
+ autoload :ListRegions, 'tugboat/middleware/list_regions'
28
+ autoload :ListSizes, 'tugboat/middleware/list_sizes'
29
+ autoload :ListSSHKeys, 'tugboat/middleware/list_ssh_keys'
30
+ autoload :PasswordReset, 'tugboat/middleware/password_reset'
31
+ autoload :ResizeDroplet, 'tugboat/middleware/resize_droplet'
32
+ autoload :RestartDroplet, 'tugboat/middleware/restart_droplet'
33
+ autoload :SnapshotDroplet, 'tugboat/middleware/snapshot_droplet'
34
+ autoload :SSHDroplet, 'tugboat/middleware/ssh_droplet'
35
+ autoload :StartDroplet, 'tugboat/middleware/start_droplet'
36
+ autoload :WaitForState, 'tugboat/middleware/wait_for_state'
37
37
 
38
38
  # Start the authorization flow.
39
39
  # This writes a ~/.tugboat file, which can be edited manually.
@@ -4,40 +4,40 @@ module Tugboat
4
4
  def call(env)
5
5
  ocean = env['barge']
6
6
 
7
- if env["add_key_pub_key"]
8
- pub_key_string = env["add_key_pub_key"]
7
+ if env['add_key_pub_key']
8
+ pub_key_string = env['add_key_pub_key']
9
9
  else
10
- if env["add_key_file_path"]
11
- pub_key_string = File.read(env["add_key_file_path"])
10
+ if env['add_key_file_path']
11
+ pub_key_string = File.read(env['add_key_file_path'])
12
12
  else
13
13
  possible_keys = Dir.glob("#{ENV['HOME']}/.ssh/*.pub")
14
14
 
15
15
  # Only show hinted keys if the user has any
16
- if possible_keys.size > 0
16
+ unless possible_keys.empty?
17
17
  say "Possible public key paths from #{ENV['HOME']}/.ssh:"
18
18
  say
19
19
  possible_keys.each do |key_file|
20
- say "#{key_file}"
20
+ say key_file.to_s
21
21
  end
22
22
  say
23
23
  end
24
24
 
25
- ssh_key_file = ask "Enter the path to your SSH key:"
26
- pub_key_string = File.read("#{ssh_key_file}")
25
+ ssh_key_file = ask 'Enter the path to your SSH key:'
26
+ pub_key_string = File.read(ssh_key_file.to_s)
27
27
  end
28
28
  end
29
29
 
30
- say "Queueing upload of SSH key '#{env["add_key_name"]}'...", nil, false
30
+ say "Queueing upload of SSH key '#{env['add_key_name']}'...", nil, false
31
31
 
32
- response = ocean.key.create :name => env["add_key_name"],
33
- :public_key => pub_key_string
32
+ response = ocean.key.create name: env['add_key_name'],
33
+ public_key: pub_key_string
34
34
 
35
35
  unless response.success?
36
36
  say "Failed to create key: #{response.message}", :red
37
37
  exit 1
38
38
  end
39
39
 
40
- say "SSH Key uploaded", :green
40
+ say 'SSH Key uploaded', :green
41
41
  say
42
42
  say "Name: #{response.ssh_key.name}"
43
43
  say "ID: #{response.ssh_key.id}"
@@ -47,4 +47,3 @@ module Tugboat
47
47
  end
48
48
  end
49
49
  end
50
-
@@ -3,24 +3,24 @@ module Tugboat
3
3
  # Ask for user credentials from the command line, then write them out.
4
4
  class AskForCredentials < Base
5
5
  def call(env)
6
- say "Note: You can get your Access Token from https://cloud.digitalocean.com/settings/tokens/new", :yellow
6
+ say 'Note: You can get your Access Token from https://cloud.digitalocean.com/settings/tokens/new', :yellow
7
7
  say
8
- access_token = ask "Enter your access token:"
8
+ access_token = ask 'Enter your access token:'
9
9
  access_token.strip!
10
- ssh_key_path = ask "Enter your SSH key path (optional, defaults to ~/.ssh/id_rsa):"
11
- ssh_user = ask "Enter your SSH user (optional, defaults to root):"
12
- ssh_port = ask "Enter your SSH port number (optional, defaults to 22):"
10
+ ssh_key_path = ask 'Enter your SSH key path (optional, defaults to ~/.ssh/id_rsa):'
11
+ ssh_user = ask 'Enter your SSH user (optional, defaults to root):'
12
+ ssh_port = ask 'Enter your SSH port number (optional, defaults to 22):'
13
13
  say
14
14
  say "To retrieve region, image, size and key ID's, you can use the corresponding tugboat command, such as `tugboat images`."
15
- say "Defaults can be changed at any time in your ~/.tugboat configuration file."
15
+ say 'Defaults can be changed at any time in your ~/.tugboat configuration file.'
16
16
  say
17
- region = ask "Enter your default region (optional, defaults to nyc1):"
18
- image = ask "Enter your default image ID or image slug (optional, defaults to ubuntu-14-04-x64):"
19
- size = ask "Enter your default size (optional, defaults to 512mb)):"
17
+ region = ask 'Enter your default region (optional, defaults to nyc1):'
18
+ image = ask 'Enter your default image ID or image slug (optional, defaults to ubuntu-14-04-x64):'
19
+ size = ask 'Enter your default size (optional, defaults to 512mb)):'
20
20
  ssh_key = ask "Enter your default ssh key IDs (optional, defaults to none, array of IDs of ssh keys eg. ['1234']):"
21
- private_networking = ask "Enter your default for private networking (optional, defaults to false):"
22
- backups_enabled = ask "Enter your default for enabling backups (optional, defaults to false):"
23
- ip6 = ask "Enter your default for IPv6 (optional, defaults to false):"
21
+ private_networking = ask 'Enter your default for private networking (optional, defaults to false):'
22
+ backups_enabled = ask 'Enter your default for enabling backups (optional, defaults to false):'
23
+ ip6 = ask 'Enter your default for IPv6 (optional, defaults to false):'
24
24
 
25
25
  # Write the config file.
26
26
  env['config'].create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled, ip6)
@@ -31,4 +31,3 @@ module Tugboat
31
31
  end
32
32
  end
33
33
  end
34
-
@@ -3,10 +3,10 @@ module Tugboat
3
3
  # A base middleware class to initalize.
4
4
  class Base
5
5
  # Some colors for making things pretty.
6
- CLEAR = "\e[0m"
7
- RED = "\e[31m"
8
- GREEN = "\e[32m"
9
- YELLOW = "\e[33m"
6
+ CLEAR = "\e[0m".freeze
7
+ RED = "\e[31m".freeze
8
+ GREEN = "\e[32m".freeze
9
+ YELLOW = "\e[33m".freeze
10
10
 
11
11
  # We want access to all of the fun thor cli helper methods,
12
12
  # like say, yes?, ask, etc.
@@ -15,7 +15,7 @@ module Tugboat
15
15
  def initialize(app)
16
16
  @app = app
17
17
  # This resets the color to "clear" on the user's terminal.
18
- say "", :clear, false
18
+ say '', :clear, false
19
19
  end
20
20
 
21
21
  def check_response_success(task_string, response)
@@ -29,11 +29,11 @@ module Tugboat
29
29
  @app.call(env)
30
30
  end
31
31
 
32
- def verify_credentials(ocean, say_success=false)
32
+ def verify_credentials(ocean, say_success = false)
33
33
  begin
34
- response = ocean.droplet.all({:per_page =>'1', :page =>'1'})
34
+ response = ocean.droplet.all(per_page: '1', page: '1')
35
35
  rescue Faraday::ClientError => e
36
- say "Authentication with DigitalOcean failed at an early stage"
36
+ say 'Authentication with DigitalOcean failed at an early stage'
37
37
  say "Error was: #{e}"
38
38
  exit 1
39
39
  end
@@ -43,25 +43,25 @@ module Tugboat
43
43
  exit 1
44
44
  end
45
45
 
46
- say "Authentication with DigitalOcean was successful.", :green if say_success
46
+ say 'Authentication with DigitalOcean was successful.', :green if say_success
47
47
  end
48
48
 
49
- def wait_for_state(droplet_id, desired_state,ocean)
49
+ def wait_for_state(droplet_id, desired_state, ocean)
50
50
  start_time = Time.now
51
51
 
52
52
  response = ocean.droplet.show droplet_id
53
53
 
54
- say ".", nil, false
54
+ say '.', nil, false
55
55
 
56
- if !response.success?
56
+ unless response.success?
57
57
  say "Failed to get status of Droplet: #{response.message}", :red
58
58
  exit 1
59
59
  end
60
60
 
61
- while response.droplet.status != desired_state do
61
+ while response.droplet.status != desired_state
62
62
  sleep 2
63
63
  response = ocean.droplet.show droplet_id
64
- say ".", nil, false
64
+ say '.', nil, false
65
65
  end
66
66
 
67
67
  total_time = (Time.now - start_time).to_i
@@ -69,15 +69,22 @@ module Tugboat
69
69
  say "done#{CLEAR} (#{total_time}s)", :green
70
70
  end
71
71
 
72
+ def restart_droplet(hard_restart, ocean, droplet_id = '', droplet_name = '')
73
+ if hard_restart
74
+ say "Queuing hard restart for #{droplet_id} #{droplet_name}...", nil, false
75
+ ocean.droplet.power_cycle droplet_id
76
+ else
77
+ say "Queuing restart for #{droplet_id} #{droplet_name}...", nil, false
78
+ ocean.droplet.reboot droplet_id
79
+ end
80
+ end
81
+
72
82
  # Get all pages of droplets
73
83
  def get_droplet_list(ocean)
74
-
75
84
  verify_credentials(ocean)
76
85
 
77
86
  page = ocean.droplet.all(per_page: 200, page: 1)
78
- if not page.paginated?
79
- return page.droplets
80
- end
87
+ return page.droplets unless page.paginated?
81
88
 
82
89
  Enumerator.new do |enum|
83
90
  page.droplets.each { |drop| enum.yield drop }
@@ -88,7 +95,5 @@ module Tugboat
88
95
  end
89
96
  end
90
97
  end
91
-
92
98
  end
93
99
  end
94
-
@@ -3,22 +3,19 @@ module Tugboat
3
3
  # Check if the client has set-up configuration yet.
4
4
  class CheckConfiguration < Base
5
5
  def call(env)
6
- config = env["config"]
6
+ config = env['config']
7
7
 
8
8
  if !config || !config.data || !config.access_token
9
- say "You must run `tugboat authorize` in order to connect to DigitalOcean", :red
9
+ say 'You must run `tugboat authorize` in order to connect to DigitalOcean', :red
10
10
  exit 1
11
11
  end
12
12
 
13
13
  # If the user passes the global `-q/--quiet` flag, redirect
14
14
  # stdout
15
- if env["user_quiet"]
16
- $stdout = File.new('/dev/null', 'w')
17
- end
15
+ $stdout = File.new('/dev/null', 'w') if env['user_quiet']
18
16
 
19
17
  @app.call(env)
20
18
  end
21
19
  end
22
20
  end
23
21
  end
24
-