Permalink
Browse files

0.0.7: Added --voxel-api-username/password support, better handling w…

…hen auth info is not supplied
  • Loading branch information...
1 parent 94f420c commit 246185d16674665ed6f2034b33a44677882c24d2 @splaspood splaspood committed Oct 17, 2011
Showing with 43 additions and 8 deletions.
  1. +42 −7 lib/chef/knife/voxel_base.rb
  2. +1 −1 lib/knife-voxel/version.rb
View
49 lib/chef/knife/voxel_base.rb
@@ -21,18 +21,53 @@ def self.included(includer)
:long => "--voxel-api-secret SECRET",
:description => "Voxel hAPI Secret",
:proc => Proc.new { |secret| Chef::Config[:knife][:voxel_api_secret] = secret }
+
+ option :voxel_api_username,
+ :long => "--voxel-api-username USERNAME",
+ :description => "Voxel hAPI Username",
+ :proc => Proc.new { |username| Chef::Config[:knife][:voxel_api_username] = username }
+
+ option :voxel_api_password,
+ :long => "--voxel-api-password PASSWORD",
+ :description => "Voxel hAPI Password",
+ :proc => Proc.new { |password| Chef::Config[:knife][:voxel_api_password] = password }
+
+
end
end
def hapi
@hapi ||= begin
- hapi = HAPI.new(
- :useauthkey => true,
- :username => Chef::Config[:knife][:voxel_api_key],
- :password => Chef::Config[:knife][:voxel_api_secret],
- :default_format => :ruby,
- :debug => false
- )
+ if Chef::Config[:knife].has_key?(:voxel_api_username)
+ unless Chef::Config[:knife].has_key?(:voxel_api_password)
+ ui.error( "--voxel-api-password is required when using --voxel-api-username" )
+ exit 1
+ end
+
+ hapi = HAPI.new(
+ :useauthkey => false,
+ :username => Chef::Config[:knife][:voxel_api_username],
+ :password => Chef::Config[:knife][:voxel_api_password],
+ :default_format => :ruby,
+ :debug => false
+ )
+ elsif Chef::Config[:knife].has_key?(:voxel_api_key)
+ unless Chef::Config[:knife].has_key?(:voxel_api_secret)
+ ui.error( "--voxel-api-secret is required when using --voxel-api-key" )
+ exit 1
+ end
+
+ hapi = HAPI.new(
+ :useauthkey => true,
+ :username => Chef::Config[:knife][:voxel_api_key],
+ :password => Chef::Config[:knife][:voxel_api_secret],
+ :default_format => :ruby,
+ :debug => false
+ )
+ else
+ ui.error( "--voxel-api-key or --voxel-api-username must be specified" )
+ exit 1
+ end
end
end
end
View
2 lib/knife-voxel/version.rb
@@ -1,5 +1,5 @@
module Knife
module Voxel
- VERSION = "0.0.6"
+ VERSION = "0.0.7"
end
end

0 comments on commit 246185d

Please sign in to comment.