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)
- PROVIDER_VAGRANT_KEYS =
%w(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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/cucumber/chef/config.rb', line 152 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." Cucumber::Chef.logger.fatal { } raise ConfigError, end |
.duplicate(input) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/cucumber/chef/config.rb', line 60 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
54 55 56 |
# File 'lib/cucumber/chef/config.rb', line 54 def self.inspect configuration.inspect end |
.load ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cucumber/chef/config.rb', line 68 def self.load config_rb = Cucumber::Chef.config_rb Cucumber::Chef.logger.debug { "Attempting to load cucumber-chef configuration from '%s'." % config_rb } self.from_file(config_rb) self.verify Cucumber::Chef.logger.debug { "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]") Cucumber::Chef.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
84 85 86 87 88 |
# File 'lib/cucumber/chef/config.rb', line 84 def self.test self.load self[:mode] = :test self end |
.verify ⇒ Object
92 93 94 95 96 97 |
# File 'lib/cucumber/chef/config.rb', line 92 def self.verify self.verify_keys self.verify_provider_keys eval("self.verify_provider_#{self[:provider].to_s.downcase}") Cucumber::Chef.logger.debug { "Configuration verified successfully" } end |
.verify_keys ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cucumber/chef/config.rb', line 101 def self.verify_keys Cucumber::Chef.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(", ")}" Cucumber::Chef.logger.fatal { } raise ConfigError, end Cucumber::Chef.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(", ")}" Cucumber::Chef.logger.fatal { } raise ConfigError, end end |
.verify_provider_aws ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cucumber/chef/config.rb', line 133 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. #{err.inspect}" Cucumber::Chef.logger.fatal { } raise ConfigError, end |
.verify_provider_keys ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/cucumber/chef/config.rb', line 121 def self.verify_provider_keys Cucumber::Chef.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(", ")}" Cucumber::Chef.logger.fatal { } raise ConfigError, end end |
.verify_provider_vagrant ⇒ Object
146 147 148 |
# File 'lib/cucumber/chef/config.rb', line 146 def self.verify_provider_vagrant # NOOP end |