Sha256: 1c6b29f1f16fe09b41712f8dd7bafc0774522b929df4eab522a5db031e5e6cf9

Contents?: true

Size: 1.93 KB

Versions: 42

Compression:

Stored size: 1.93 KB

Contents

require 'yaml'

module Fog
  require 'fog/core/deprecation'

  # Assign a new credential to use from configuration file
  #   @param [String, Symbol] new_credential name of new credential to use
  #   @ return [Symbol] name of the new credential
  def self.credential=(new_credential)
    @credentials = nil
    @credential = new_credential && new_credential.to_sym
  end

  # @return [String, Symbol] The credential to use in Fog
  def self.credential
    @credential ||= ( ENV["FOG_CREDENTIAL"] && ENV["FOG_CREDENTIAL"].to_sym ) || :default
  end

  # @return [String] The path for configuration_file
  def self.credentials_path
    @credential_path ||= begin
      path = ENV["FOG_RC"] || (ENV['HOME'] && File.directory?(ENV['HOME']) && '~/.fog')
      File.expand_path(path) if path
    rescue
      nil
    end
  end

  # @return [String] The new path for credentials file
  def self.credentials_path=(new_credentials_path)
    @credentials = nil
    @credential_path = new_credentials_path
  end

  # @return [Hash] The credentials pulled from the configuration file
  # @raise [LoadError] Configuration unavailable in configuration file
  def self.credentials
    @credentials  ||= begin
      if credentials_path && File.exists?(credentials_path)
        credentials = self.symbolize_credentials(YAML.load_file(credentials_path))
        (credentials && credentials[credential]) || Fog::Errors.missing_credentials
      else
        {}
      end
    end
  end

  # @return [Hash] The newly assigned credentials
  def self.credentials=(new_credentials)
    @credentials = new_credentials
  end

  def self.symbolize_credential?(key)
    ![:headers].include?(key)
  end

  def self.symbolize_credentials(args)
    if args.is_a? Hash
      copy = Array.new
      args.each do |key, value|
        obj = symbolize_credential?(key) ? self.symbolize_credentials(value) : value
        copy.push(key.to_sym, obj)
      end
      Hash[*copy]
    else
      args
    end
  end

end

Version data entries

42 entries across 42 versions & 3 rubygems

Version Path
fog-core-1.21.1 lib/fog/core/credentials.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/core/credentials.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/core/credentials.rb
fog-core-1.21.0 lib/fog/core/credentials.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/core/credentials.rb
fog-1.20.0 lib/fog/core/credentials.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/core/credentials.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/core/credentials.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/core/credentials.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/core/credentials.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/core/credentials.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/core/credentials.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/core/credentials.rb
fog-1.19.0 lib/fog/core/credentials.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/core/credentials.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/core/credentials.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/core/credentials.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/core/credentials.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/core/credentials.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/core/credentials.rb