Sha256: ffa4518f9102b916134e15506d9e415250633f11a584f57ca39eca4364080f61

Contents?: true

Size: 1.81 KB

Versions: 42

Compression:

Stored size: 1.81 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_credentials(args)
    if args.is_a? Hash
      copy = Array.new
      args.each do |key, value|
        copy.push(key.to_sym, self.symbolize_credentials(value))
      end
      Hash[*copy]
    else
      args
    end
  end

end

Version data entries

42 entries across 42 versions & 12 rubygems

Version Path
cifrado-0.2.1 vendor/fog/lib/fog/core/credentials.rb
cifrado-0.2.0 vendor/fog/lib/fog/core/credentials.rb
gapinc-fog-1.12.1.2.1 lib/fog/core/credentials.rb
gapinc-fog-1.14.0 lib/fog/core/credentials.rb
fog-maestrodev-1.14.0.20130806165225 lib/fog/core/credentials.rb
fog-1.14.0 lib/fog/core/credentials.rb
fog-1.13.0 lib/fog/core/credentials.rb
gapinc-fog-1.12.1.2 lib/fog/core/credentials.rb
gapinc-fog-1.12.1.1 lib/fog/core/credentials.rb
gapinc-fog-1.12.1a lib/fog/core/credentials.rb
gapinc-fog-1.12.1 lib/fog/core/credentials.rb
fog-1.12.1 lib/fog/core/credentials.rb
fog-1.12.0 lib/fog/core/credentials.rb
hpfog-0.0.20 lib/fog/core/credentials.rb
vagrant-shell-0.2.6 vendor/bundle/gems/fog-1.10.1/lib/fog/core/credentials.rb
vagrant-shell-0.2.5 vendor/bundle/gems/fog-1.10.1/lib/fog/core/credentials.rb
fog-nirvanix-1.8.2 lib/fog/core/credentials.rb
fog-1.11.1 lib/fog/core/credentials.rb
fog-1.11.0 lib/fog/core/credentials.rb
fog-nirvanix-1.8.1 lib/fog/core/credentials.rb