module Gitlab::Configuration

def self.extended(base)

when this module is extended.
Sets all configuration options to their default values
def self.extended(base)
  base.reset
end

def configure

Convenience method to allow configuration options to be set in a block.
def configure
  yield self
end

def get_httparty_config(options)

Allows HTTParty config to be specified in ENV using YAML hash.
def get_httparty_config(options)
  return if options.nil?
  httparty = Gitlab::CLI::Helpers.yaml_load(options)
  raise ArgumentError, 'HTTParty config should be a Hash.' unless httparty.is_a? Hash
  Gitlab::CLI::Helpers.symbolize_keys httparty
end

def options

Creates a hash of options and their values.
def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

def reset

Resets all configuration options to the defaults.
def reset
  self.endpoint       = ENV['GITLAB_API_ENDPOINT'] || ENV['CI_API_V4_URL']
  self.private_token  = ENV['GITLAB_API_PRIVATE_TOKEN'] || ENV['GITLAB_API_AUTH_TOKEN']
  self.httparty       = get_httparty_config(ENV['GITLAB_API_HTTPARTY_OPTIONS'])
  self.sudo           = nil
  self.user_agent     = DEFAULT_USER_AGENT
end