Sha256: df02d7cead4ca1d9c83d7fb0747f3063a3ff94ca51601962cf70cab0669f9f1b

Contents?: true

Size: 832 Bytes

Versions: 2

Compression:

Stored size: 832 Bytes

Contents

module ClusterFuck

  class CredentialGrabber
    FOG_PATH = "~/.fog"
    CF_PATH = "~/.cluster-fuck"

    def self.find
      new.find
    end

    def find
      from_cluster_fuck_file || from_fog_file
    end

    def from_fog_file
      if exists?(File.expand_path(FOG_PATH))
        fog_credentials = YAML.load_file(File.expand_path(FOG_PATH))
        {
            access_key_id: fog_credentials[:default][:aws_access_key_id],
            secret_access_key: fog_credentials[:default][:aws_secret_access_key],
        }
      end
    rescue ArgumentError #when there is no HOME, File.expand_path above raises ArgumentError
      nil
    end

    def from_cluster_fuck_file
      if exists?(CF_PATH)
        YAML.load_file(CF_PATH)
      end
    end

  private
    def exists?(path)
      File.exist?(path)
    end

  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cluster-fuck-0.1.4.3 lib/cluster-fuck/credential_grabber.rb
cluster-fuck-0.1.4.2 lib/cluster-fuck/credential_grabber.rb