Class: Chef::Knife::S3Base
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::S3Base
- Defined in:
- lib/chef/knife/s3_base.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
- #locate_config_value(key) ⇒ Object
- #msg_pair(label, value, color = :cyan) ⇒ Object
- #validate!(keys = [:aws_access_key_id, :aws_secret_access_key]) ⇒ Object
Class Method Details
.included(includer) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/chef/knife/s3_base.rb', line 22 def self.included(includer) includer.class_eval do deps do require 'fog' require 'readline' require 'chef/json_compat' end option :aws_access_key_id, :short => "-A ID", :long => "--aws-access-key-id KEY", :description => "AWS Access Key ID", :proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key } option :aws_secret_access_key, :short => "-K SECRET", :long => "--aws-secret-access-key SECRET", :description => "Your AWS API Secret Access Key", :proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key } option :region, :long => "--region REGION", :description => "Your AWS region", :default => "us-east-1", :proc => Proc.new { |key| Chef::Config[:knife][:region] = key } end end |
Instance Method Details
#connection ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/knife/s3_base.rb', line 51 def connection @connection ||= begin connection = Fog::Storage.new( :provider => 'AWS', :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id], :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key], :region => locate_config_value(:region) ) end end |
#locate_config_value(key) ⇒ Object
62 63 64 65 |
# File 'lib/chef/knife/s3_base.rb', line 62 def locate_config_value(key) key = key.to_sym Chef::Config[:knife][key] || config[key] end |
#msg_pair(label, value, color = :cyan) ⇒ Object
67 68 69 70 71 |
# File 'lib/chef/knife/s3_base.rb', line 67 def msg_pair(label, value, color=:cyan) if value && @value.to_s.empty? puts "#{ui.color(label, color)}: #{value}" end end |
#validate!(keys = [:aws_access_key_id, :aws_secret_access_key]) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chef/knife/s3_base.rb', line 73 def validate!(keys=[:aws_access_key_id, :aws_secret_access_key]) errors = [] keys.each do |k| pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize } if Chef::Config[:knife][k].nil? errors << "You did not provide a valid '#{pretty_key}' value." end end if errors.each{|e| ui.error(e)}.any? exit 1 end end |