Skip to content

Commit

Permalink
Merge 3fc4402 into a4432e3
Browse files Browse the repository at this point in the history
  • Loading branch information
petems committed Mar 2, 2017
2 parents a4432e3 + 3fc4402 commit b6fa6f3
Show file tree
Hide file tree
Showing 35 changed files with 267 additions and 260 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ pkg/*
tmp/*
# Added file to not force other to use it.
.overcommit.yml
.yardoc/
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -311,7 +311,7 @@ D, [2015-12-06T12:04:27.149334 #92772] DEBUG -- : Request Headers:
----------------
Authorization : Bearer [TOKEN REDACTED]
Content-Type : application/json
User-Agent : Faraday v0.11.0
User-Agent : Faraday v0.9.2

Request Body:
-------------
Expand Down
2 changes: 1 addition & 1 deletion features/cassettes/config/Array_of_SSH_Keys_in_Config.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/tugboat.rb
Expand Up @@ -2,6 +2,10 @@
require 'tugboat/config'
require 'tugboat/version'
require 'json'
require 'hashie'
require 'hashie/logger'

Hashie.logger = Logger.new(nil)

module Tugboat
end
4 changes: 3 additions & 1 deletion lib/tugboat/middleware/custom_logger.rb
@@ -1,5 +1,7 @@
require 'faraday'

module Tugboat
class CustomLogger < Faraday::Middleware
class CustomLogger < ::Faraday::Middleware
extend Forwardable
def_delegators :@logger, :debug, :info, :warn, :error, :fatal

Expand Down
3 changes: 3 additions & 0 deletions lib/tugboat/middleware/inject_client.rb
@@ -1,4 +1,5 @@
require 'barge'
require 'droplet_kit'
require File.expand_path('../custom_logger', __FILE__)

module Tugboat
Expand All @@ -11,8 +12,10 @@ def call(env)
@access_token = env['config'].access_token

env['barge'] = Barge::Client.new(access_token: @access_token)
env['droplet_kit'] = DropletKit::Client.new(access_token: @access_token)

env['barge'].faraday.use CustomLogger if ENV['DEBUG']
env['droplet_kit'].connection.use CustomLogger if ENV['DEBUG']

@app.call(env)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tugboat/middleware/list_regions.rb
Expand Up @@ -2,8 +2,8 @@ module Tugboat
module Middleware
class ListRegions < Base
def call(env)
ocean = env['barge']
regions = ocean.region.all.regions.sort_by(&:name)
ocean = env['droplet_kit']
regions = ocean.regions.all.sort_by(&:name)

say 'Regions:'
regions.each do |region|
Expand Down
4 changes: 2 additions & 2 deletions lib/tugboat/middleware/list_sizes.rb
Expand Up @@ -2,8 +2,8 @@ module Tugboat
module Middleware
class ListSizes < Base
def call(env)
ocean = env['barge']
sizes = ocean.size.all.sizes
ocean = env['droplet_kit']
sizes = ocean.sizes.all

say 'Sizes:'
sizes.each do |size|
Expand Down
4 changes: 2 additions & 2 deletions spec/cli/authorize_cli_spec.rb
Expand Up @@ -11,7 +11,7 @@

it 'asks the right questions and checks credentials' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

expect($stdout).to receive(:print).exactly(6).times
Expand Down Expand Up @@ -60,7 +60,7 @@

it 'sets defaults if no input given' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

expect($stdout).to receive(:print).exactly(6).times
Expand Down
10 changes: 5 additions & 5 deletions spec/cli/create_cli_spec.rb
Expand Up @@ -7,7 +7,7 @@
it 'with a name, uses defaults from configuration' do
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
with(body: '{"name":"foo","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":null}',
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('create_droplet'), headers: {})

cli.create(droplet_name)
Expand All @@ -20,7 +20,7 @@
it 'with args does not use defaults from configuration' do
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
with(body: '{"name":"example.com","size":"1gb","image":"ubuntu-12-04-x64","region":"nyc3","ssh_keys":["foo_bar_key"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":null}',
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('create_droplet'), headers: {})

cli.options = cli.options.merge(image: 'ubuntu-12-04-x64', size: '1gb', region: 'nyc3', keys: 'foo_bar_key')
Expand All @@ -34,7 +34,7 @@
it 'with ip6 enable args' do
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
with(body: '{"name":"example.com","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"true","user_data":null}',
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('create_droplet'), headers: {})

cli.options = cli.options.merge(ip6: 'true')
Expand All @@ -48,7 +48,7 @@
it 'with user data args' do
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
with(body: '{"name":"example.com","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":"#!/bin/bash\\n\\necho \\"Hello world\\""}',
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('create_droplet'), headers: {})

cli.options = cli.options.merge(user_data: project_path + '/spec/fixtures/user_data.sh')
Expand Down Expand Up @@ -98,7 +98,7 @@
it 'does not clobber named droplets that contain the word help' do
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
with(body: '{"name":"somethingblahblah--help","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":null}',
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('create_droplet'), headers: {})

cli.create('somethingblahblah--help')
Expand Down
8 changes: 4 additions & 4 deletions spec/cli/debug_cli_spec.rb
Expand Up @@ -14,11 +14,11 @@

it 'gives full faraday logs' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

cli.droplets
Expand All @@ -41,11 +41,11 @@

it 'gives full faraday logs with redacted API keys' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})
cli.droplets

Expand Down
26 changes: 13 additions & 13 deletions spec/cli/destroy_cli_spec.rb
Expand Up @@ -6,15 +6,15 @@
describe 'destroy' do
it 'destroys a droplet with a fuzzy name' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
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' }).
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.9.2' }).
to_return(status: 204, body: '', headers: {})

expect($stdin).to receive(:gets).and_return('y')
Expand All @@ -28,11 +28,11 @@

it 'destroys a droplet with an id' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?per_page=200').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplet'), headers: {})

stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
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' }).
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.9.2' }).
to_return(status: 204, body: '', headers: {})

expect($stdin).to receive(:gets).and_return('y')
Expand All @@ -47,15 +47,15 @@

it 'destroys a droplet with a name' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
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' }).
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.9.2' }).
to_return(status: 204, body: '', headers: {})

expect($stdin).to receive(:gets).and_return('y')
Expand All @@ -70,15 +70,15 @@

it 'destroys a droplet with confirm flag set' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
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' }).
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.9.2' }).
to_return(status: 204, body: '', headers: {})

cli.options = cli.options.merge(name: 'example.com', confirm: true)
Expand All @@ -92,11 +92,11 @@

it 'does not destroy a droplet if no is chosen' do
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
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' }).
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.9.2' }).
to_return(status: 200, body: fixture('show_droplets'), headers: {})

$stdin.should_receive(:gets).and_return('n')
Expand Down

0 comments on commit b6fa6f3

Please sign in to comment.