Skip to content

Commit

Permalink
Merge pull request #151 from pearkes/add_config_cli_method
Browse files Browse the repository at this point in the history
Add config cli method
  • Loading branch information
petems committed Jan 29, 2015
2 parents 239daf5 + 13c122f commit 13c940b
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage
doc/*
log/*
pkg/*
tmp/*
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
sudo: false
language: ruby
rvm:
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1.0
script:
- "bundle exec rake spec"
- "bundle exec rake features:run"
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in tugboat.gemspec
gemspec

group :development do
# Random order is not in the Aruba Cucumber yet...
gem 'cucumber', git: 'https://github.com/cucumber/cucumber.git', tag: 'v2.0.0.beta.2'
gem 'cucumber-core', git: 'https://github.com/cucumber/cucumber-core.git', tag: 'v1.0.0.beta.2'
end
10 changes: 8 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

require 'cucumber/rake/task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec

namespace :features do
Cucumber::Rake::Task.new(:run) do |t|
t.cucumber_opts = %w(--format pretty --order random)
end
end
Empty file.
9 changes: 9 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'aruba/cucumber'

Before do

end

After do

end
27 changes: 27 additions & 0 deletions features/vagrant-adam/config_current_directory.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: config
In order to easily load DigitalOcean config
As a user
I should be able to load tugboat config from a .tugboat in the current directory

Scenario:
Given a file named ".tugboat" with:
"""
---
authentication:
client_key: FOO
api_key: BAR
ssh:
ssh_user: janedoe
ssh_key_path: "/Users/janedoe/.ssh/id_rsa"
ssh_port: '22'
defaults:
region: '8'
image: '9801950'
size: '66'
ssh_key: ''
private_networking: 'false'
backups_enabled: 'false'
"""
When I run `tugboat config`
Then the exit status should not be 1
And the output should contain "ssh_user: janedoe"
15 changes: 15 additions & 0 deletions lib/tugboat/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ def authorize
})
end

desc "config", "Show your current config information"
long_desc "This shows the current information in the .tugboat config
being used by the app
"
method_option "hide",
:type => :boolean,
:default => true,
:aliases => "-h",
:desc => "Hide your API keys"
def config
Middleware.sequence_config.call({
"user_hide_keys" => options[:hide],
})
end

desc "verify", "Check your DigitalOcean credentials"
long_desc "This tests that your credentials created by the \`authorize\`
command that are stored in ~/.tugboat are correct and allow you to connect
Expand Down
6 changes: 5 additions & 1 deletion lib/tugboat/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ class Configuration
DEFAULT_PRIVATE_NETWORKING = 'false'
DEFAULT_BACKUPS_ENABLED = 'false'

# Load config file from current directory, if not exit load from user's home directory
def initialize
@path = ENV["TUGBOAT_CONFIG_PATH"] || File.join(File.expand_path("~"), FILE_NAME)
@path = File.join(File.expand_path("."), FILE_NAME)
unless File.exists?(@path)
@path = ( ENV["TUGBOAT_CONFIG_PATH"] || File.join(File.expand_path("~"), FILE_NAME) )
end
@data = self.load_config_file
end

Expand Down
8 changes: 8 additions & 0 deletions lib/tugboat/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Middleware
autoload :CheckCredentials, "tugboat/middleware/check_credentials"
autoload :CheckDropletActive, "tugboat/middleware/check_droplet_active"
autoload :CheckDropletInactive, "tugboat/middleware/check_droplet_inactive"
autoload :Config, "tugboat/middleware/config"
autoload :ConfirmAction, "tugboat/middleware/confirm_action"
autoload :CreateDroplet, "tugboat/middleware/create_droplet"
autoload :RebuildDroplet, "tugboat/middleware/rebuild_droplet"
Expand Down Expand Up @@ -267,6 +268,13 @@ def self.sequence_password_reset
end
end

# Returns current used config
def self.sequence_config
::Middleware::Builder.new do
use Config
end
end

# Wait for a droplet to enter a desired state
def self.sequence_wait
::Middleware::Builder.new do
Expand Down
29 changes: 29 additions & 0 deletions lib/tugboat/middleware/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Tugboat
module Middleware
# Check if the droplet in the environment is inactive, or "off"
class Config < Base
def call(env)

config = Tugboat::Configuration.instance

keys_retracted = ''

config_data = config.data.to_yaml

if env["user_hide_keys"]
keys_retracted = '(Keys Redacted)'
config_data = config_data.gsub(/(client_key: )([a-zA-Z0-9]+)/,'\1 [REDACTED]')
config_data = config_data.gsub(/(api_key: )([a-zA-Z0-9]+)/,'\1 [REDACTED]')
end

say "Current Config #{keys_retracted}", :green

say "Path: #{config.path}"
say config_data

@app.call(env)
end
end
end
end

1 change: 1 addition & 0 deletions tugboat.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "rspec-mocks", "~> 2.14.0"
gem.add_development_dependency "webmock", "~> 1.11.0"
gem.add_development_dependency "coveralls", "~> 0.6.7"
gem.add_development_dependency 'aruba', '~> 0.6.2'

end

0 comments on commit 13c940b

Please sign in to comment.