Class | HTAuth::DigestFile |
In: |
lib/htauth/digest_file.rb
|
Parent: | HTAuth::File |
ENTRY_KLASS | = | HTAuth::DigestEntry |
add an new record. raises an error if the entry exists.
# File lib/htauth/digest_file.rb, line 41 41: def add(username, realm, password) 42: raise DigestFileError, "Unable to add already existing user #{username} in realm #{realm}" if has_entry?(username, realm) 43: 44: new_entry = DigestEntry.new(username, realm, password) 45: new_index = @lines.size 46: @lines << new_entry.to_s 47: @entries[new_entry.key] = { 'entry' => new_entry, 'line_index' => new_index } 48: dirty! 49: return nil 50: end
remove an entry from the file
# File lib/htauth/digest_file.rb, line 20 20: def delete(username, realm) 21: if has_entry?(username, realm) then 22: ir = internal_record(username, realm) 23: line_index = ir['line_index'] 24: @entries.delete(ir['entry'].key) 25: @lines[line_index] = nil 26: dirty! 27: end 28: nil 29: end
fetches a copy of an entry from the file. Updateing the entry returned from fetch will NOT propogate back to the file.
# File lib/htauth/digest_file.rb, line 64 64: def fetch(username, realm) 65: return nil unless has_entry?(username, realm) 66: ir = internal_record(username, realm) 67: return ir['entry'].dup 68: end
does the entry the the specified username and realm exist in the file
# File lib/htauth/digest_file.rb, line 14 14: def has_entry?(username, realm) 15: test_entry = DigestEntry.new(username, realm) 16: @entries.has_key?(test_entry.key) 17: end
update an already existing entry with a new password. raises an error if the entry does not exist
# File lib/htauth/digest_file.rb, line 53 53: def update(username, realm, password) 54: raise DigestFileError, "Unable to update non-existent user #{username} in realm #{realm}" unless has_entry?(username, realm) 55: ir = internal_record(username, realm) 56: ir['entry'].password = password 57: @lines[ir['line_index']] = ir['entry'].to_s 58: dirty! 59: return nil 60: end