require 'gitlab_config/version'
require 'gitlab_config/configuration'
require 'gitlab_config/aws/iam_role'

module GitlabConfig
  def self.load_configuration(options)
    if options.fetch(:source) == :s3 and options.has_key?(:iam_role)
      options = add_iam_configuration!(options)
    end

    yield Configuration.new(options).get_configuration
  end

  def self.add_iam_configuration!(options)
    key = options.fetch(:key, nil)
    secret = options.fetch(:secret, nil)

    if key.nil? && secret.nil?
      options[:iam] = IamRole.new(options.fetch(:iam_role))
    end
    options
  end
end
