lib/terraformer/credentials/aws.rb in terraform-exporter-0.0.2 vs lib/terraformer/credentials/aws.rb in terraform-exporter-0.0.3
- old
+ new
@@ -1,16 +1,32 @@
module Terraformer
module Credentials
+ class AwsMissingCredentals < RuntimeError
+ attr_reader :key
+
+ def initialize(key)
+ @key = key
+
+ super(message)
+ end
+
+ def message
+ "'#{key}' not passed. set it via CLI --#{key} or #{key.upcase} enviroment variable."
+ end
+ end
+
class Aws
+ KEYS = %w(aws_region aws_access_key_id aws_secret_access_key).freeze
+
def self.get_from_options(options)
- credentials = {}
- %w(aws_region aws_access_key_id aws_secret_access_key).each do |key|
+ KEYS.inject({}) do |credentials, key|
aws_key = key.sub("aws_", "").to_sym
credentials[aws_key] = options[key.to_sym].nil? ? options[key] : options[key.to_sym]
credentials[aws_key] = ENV[key.upcase] if credentials[aws_key].nil?
- end
+ raise AwsMissingCredentals.new(key) if credentials[aws_key].nil?
- credentials.reject{ |k, v| v.nil? }
+ credentials
+ end
end
end
end
end