lib/terraformer/credentials/datadog.rb in terraform-exporter-0.0.2 vs lib/terraformer/credentials/datadog.rb in terraform-exporter-0.0.3

- old
+ new

@@ -1,16 +1,32 @@ module Terraformer module Credentials + class DatadogMissingCredentals < RuntimeError + attr_reader :key + + def initialize(key) + @key = key + + super(message) + end + + def message + "'#{key}' not being passed. set it via CLI --#{key} or #{key.upcase} enviroment variable." + end + end + class Datadog + KEYS = %w(datadog_api_key datadog_app_key).freeze + def self.get_from_options(options) - credentials = {} - %w(datadog_api_key datadog_app_key).each do |key| + KEYS.inject({}) do |credentials, key| datadog_key = key.sub("datadog_", "").to_sym credentials[datadog_key] = options[key.to_sym].nil? ? options[key] : options[key.to_sym] credentials[datadog_key] = ENV[key.upcase] if credentials[datadog_key].nil? - end + raise DatadogMissingCredentals.new(key) if credentials[datadog_key].nil? - credentials.reject{ |k, v| v.nil? } + credentials + end end end end end