Class: Cucumber::Chef::Config

Inherits:
Object
  • Object
show all
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

Class Method Details

.aws_image_idObject

Raises:



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
  message = "Could not find a valid AMI image ID.  Please check your configuration."
  Cucumber::Chef.logger.fatal { message }
  raise ConfigError, message
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

.inspectObject



54
55
56
# File 'lib/cucumber/chef/config.rb', line 54

def self.inspect
  configuration.inspect
end

.loadObject



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

.testObject



84
85
86
87
88
# File 'lib/cucumber/chef/config.rb', line 84

def self.test
  self.load
  self[:mode] = :test
  self
end

.verifyObject



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_keysObject



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
    message = "Configuration incomplete, missing configuration keys: #{missing_keys.join(", ")}"
    Cucumber::Chef.logger.fatal { message }
    raise ConfigError, message
  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
    message = "Configuration incomplete, invalid configuration keys: #{invalid_keys.join(", ")}"
    Cucumber::Chef.logger.fatal { message }
    raise ConfigError, message
  end
end

.verify_provider_awsObject



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
  message = "Invalid AWS credentials.  Please check your configuration. #{err.inspect}"
  Cucumber::Chef.logger.fatal { message }
  raise ConfigError, message
end

.verify_provider_keysObject



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
    message = "Configuration incomplete, missing provider configuration keys: #{missing_keys.join(", ")}"
    Cucumber::Chef.logger.fatal { message }
    raise ConfigError, message
  end
end

.verify_provider_vagrantObject



146
147
148
# File 'lib/cucumber/chef/config.rb', line 146

def self.verify_provider_vagrant
  # NOOP
end