class RHC::Auth::TokenStore
Public Class Methods
new(dir)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 5 def initialize(dir) @dir = dir end
Public Instance Methods
clear()
click to toggle source
# File lib/rhc/auth/token_store.rb, line 17 def clear Dir[File.join(@dir, "token_*")]. each{ |f| File.delete(f) unless File.directory?(f) }. present? end
get(login, server)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 9 def get(login, server) self[key(login,server)] end
put(login, server, token)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 13 def put(login, server, token) self[key(login,server)] = token end
Private Instance Methods
[](key)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 40 def [](key) s = IO.read(path(key)).presence s = s.strip.gsub(/[\n\r\t]/,'') if s s rescue Errno::ENOENT nil end
[]=(key, value)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 32 def []=(key, value) file = path(key) FileUtils.mkdir_p File.dirname(file) File.open(file, 'w'){ |f| f.write(value) } File.chmod(0600, file) value end
filename(key)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 28 def filename(key) "token_#{Base64.encode64(Digest::MD5.digest(key)).gsub(/[^\w\@]/,'')}" end
key(login, server)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 48 def key(login, server) "#{login || ''}@#{server}" end
path(key)
click to toggle source
# File lib/rhc/auth/token_store.rb, line 24 def path(key) File.join(@dir, filename(key)) end