Sha256: cbc339ba0a94f85313e551cb6196260f93b20f91cdcb26de02a5f6783e2ebe9c
Contents?: true
Size: 1.36 KB
Versions: 10
Compression:
Stored size: 1.36 KB
Contents
module Flydata class Credentials include Helpers attr_reader :user, :password def initialize(user=nil, password=nil) read_credentials if user && password @user = user @password = password elsif !(@authenticated) @user = ENV['FLYDATA_LOGIN'] @password = ENV['FLYDATA_PASSWORD'] end end def authenticate! @authenticated = true write_credentials end def authenticated? @authenticated end def write_credentials dir = File.dirname(credentials_file) FileUtils.mkdir_p(dir) File.delete(credentials_file) if FileTest.exists?(credentials_file) File.open(credentials_file, 'w', 0400) do |out| out.puts @user out.puts encode(@password) end FileUtils.chmod(0700, dir) end def read_credentials if FileTest.exist?(credentials_file) File.open(credentials_file, 'r') do |f| @user = f.gets.chomp @password = decode(f.gets.chomp) @authenticated = true if @user and @password end end end private def credentials_file File.join(home_directory, '.flydata', 'credentials') end def encode(str) str.unpack('H*') # want to change more complecated? still useful for shoulder hacking. end def decode(str) [str].pack('H*') end end end
Version data entries
10 entries across 10 versions & 1 rubygems