Class: Cucumber::Chef::Config
- Inherits:
-
Object
- Object
- Cucumber::Chef::Config
- Extended by:
- Mixlib::Config
- Defined in:
- lib/cucumber/chef/config.rb
Constant Summary collapse
- KEYS =
%w( mode provider ).map(&:to_sym)
- MODES =
%w( user test ).map(&:to_sym)
- PROVIDERS =
%w( aws vagrant ).map(&:to_sym)
- PROVIDER_AWS_KEYS =
%w( aws_access_key_id aws_secret_access_key region availability_zone aws_ssh_key_id identity_file ).map(&:to_sym)
Class Method Summary collapse
- .aws_image_id ⇒ Object
- .duplicate(input) ⇒ Object
- .inspect ⇒ Object
- .load ⇒ Object
- .test ⇒ Object
- .verify ⇒ Object
- .verify_keys ⇒ Object
- .verify_provider_aws ⇒ Object
- .verify_provider_keys ⇒ Object
- .verify_provider_vagrant ⇒ Object
Class Method Details
.aws_image_id ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/cucumber/chef/config.rb', line 138 def self.aws_image_id if self[:aws][:aws_image_id] return self[:aws][:aws_image_id] elsif (self[:aws][:ubuntu_release] && self[:aws][:region]) ami = Ubuntu.release(self[:aws][:ubuntu_release]).amis.find do |ami| ami.arch == (self[:aws][:aws_instance_arch] || "i386") && ami.root_store == (self[:aws][:aws_instance_disk_store] || "instance-store") && ami.region == self[:aws][:region] end return ami.name if ami end = "Could not find a valid AMI image ID. Please check your configuration." $logger.fatal { } raise ConfigError, end |
.duplicate(input) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/cucumber/chef/config.rb', line 44 def self.duplicate(input) output = Hash.new input.each do |key, value| output[key] = (value.is_a?(Hash) ? self.duplicate(input[key]) : value.to_s.dup) end output end |
.inspect ⇒ Object
38 39 40 |
# File 'lib/cucumber/chef/config.rb', line 38 def self.inspect configuration.inspect end |
.load ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cucumber/chef/config.rb', line 52 def self.load config_rb = Cucumber::Chef.locate(:file, ".cucumber-chef", "config.rb") $logger.info { "Attempting to load cucumber-chef configuration from '%s'." % config_rb } self.from_file(config_rb) self.verify $logger.info { "Successfully loaded cucumber-chef configuration from '%s'." % config_rb } log_dump = self.duplicate(self.configuration) log_dump[:aws].merge!(:aws_access_key_id => "[REDACTED]", :aws_secret_access_key => "[REDACTED]") $logger.debug { log_dump.inspect } self rescue Errno::ENOENT, UtilityError raise ConfigError, "Could not find your cucumber-chef configuration file; did you run 'cucumber-chef init'?" end |
.test ⇒ Object
68 69 70 71 72 |
# File 'lib/cucumber/chef/config.rb', line 68 def self.test self.load self[:mode] = :test self end |
.verify ⇒ Object
76 77 78 79 80 81 |
# File 'lib/cucumber/chef/config.rb', line 76 def self.verify self.verify_keys self.verify_provider_keys eval("self.verify_provider_#{self[:provider].to_s.downcase}") $logger.debug { "Configuration verified successfully" } end |
.verify_keys ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cucumber/chef/config.rb', line 85 def self.verify_keys $logger.debug { "Checking for missing configuration keys" } missing_keys = KEYS.select{ |key| !self[key.to_sym] } if missing_keys.count > 0 = "Configuration incomplete, missing configuration keys: #{missing_keys.join(", ")}" $logger.fatal { } raise ConfigError, end $logger.debug { "Checking for invalid configuration keys" } invalid_keys = KEYS.select{ |key| !eval("#{key.to_s.upcase}S").include?(self[key]) } if invalid_keys.count > 0 = "Configuration incomplete, invalid configuration keys: #{invalid_keys.join(", ")}" $logger.fatal { } raise ConfigError, end end |
.verify_provider_aws ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cucumber/chef/config.rb', line 117 def self.verify_provider_aws if self[:aws][:aws_access_key_id] && self[:aws][:aws_secret_access_key] compute = Fog::Compute.new(:provider => 'AWS', :aws_access_key_id => self[:aws][:aws_access_key_id], :aws_secret_access_key => self[:aws][:aws_secret_access_key]) compute.describe_availability_zones end rescue Fog::Service::Error => err = "Invalid AWS credentials. Please check your configuration." $logger.fatal { } raise ConfigError, end |
.verify_provider_keys ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/cucumber/chef/config.rb', line 105 def self.verify_provider_keys $logger.debug { "Checking for missing provider keys" } missing_keys = eval("PROVIDER_#{self[:provider].to_s.upcase}_KEYS").select{ |key| !self[self[:provider]].key?(key) } if missing_keys.count > 0 = "Configuration incomplete, missing provider configuration keys: #{missing_keys.join(", ")}" $logger.fatal { } raise ConfigError, end end |
.verify_provider_vagrant ⇒ Object
130 131 132 133 134 |
# File 'lib/cucumber/chef/config.rb', line 130 def self.verify_provider_vagrant = "Not yet implemented." $logger.fatal { } raise ConfigError, end |