Class HTAuth::DigestFile
In: lib/htauth/digest_file.rb
lib/htauth/digest_file.rb
Parent: HTAuth::File

Methods

Constants

ENTRY_KLASS = HTAuth::DigestEntry
ENTRY_KLASS = HTAuth::DigestEntry

Public Instance methods

add an new record. raises an error if the entry exists.

[Source]

    # File lib/htauth/digest_file.rb, line 40
40:     def add(username, realm, password)
41:       raise DigestFileError, "Unable to add already existing user #{username} in realm #{realm}" if has_entry?(username, realm)
42: 
43:       new_entry = DigestEntry.new(username, realm, password)
44:       new_index = @lines.size
45:       @lines << new_entry.to_s
46:       @entries[new_entry.key] = { 'entry' => new_entry, 'line_index' => new_index }
47:       dirty!
48:       return nil
49:     end

add an new record. raises an error if the entry exists.

[Source]

    # File lib/htauth/digest_file.rb, line 40
40:     def add(username, realm, password)
41:       raise DigestFileError, "Unable to add already existing user #{username} in realm #{realm}" if has_entry?(username, realm)
42: 
43:       new_entry = DigestEntry.new(username, realm, password)
44:       new_index = @lines.size
45:       @lines << new_entry.to_s
46:       @entries[new_entry.key] = { 'entry' => new_entry, 'line_index' => new_index }
47:       dirty!
48:       return nil
49:     end

add or update an entry as appropriate

[Source]

    # File lib/htauth/digest_file.rb, line 31
31:     def add_or_update(username, realm, password)
32:       if has_entry?(username, realm) then
33:         update(username, realm, password)
34:       else
35:         add(username, realm, password)
36:       end
37:     end

add or update an entry as appropriate

[Source]

    # File lib/htauth/digest_file.rb, line 31
31:     def add_or_update(username, realm, password)
32:       if has_entry?(username, realm) then
33:         update(username, realm, password)
34:       else
35:         add(username, realm, password)
36:       end
37:     end

remove an entry from the file

[Source]

    # File lib/htauth/digest_file.rb, line 19
19:     def delete(username, realm)
20:       if has_entry?(username, realm) then
21:         ir = internal_record(username, realm)
22:         line_index = ir['line_index']
23:         @entries.delete(ir['entry'].key)
24:         @lines[line_index] = nil
25:         dirty!
26:       end
27:       nil
28:     end

remove an entry from the file

[Source]

    # File lib/htauth/digest_file.rb, line 19
19:     def delete(username, realm)
20:       if has_entry?(username, realm) then
21:         ir = internal_record(username, realm)
22:         line_index = ir['line_index']
23:         @entries.delete(ir['entry'].key)
24:         @lines[line_index] = nil
25:         dirty!
26:       end
27:       nil
28:     end

[Source]

    # File lib/htauth/digest_file.rb, line 69
69:     def entry_klass
70:       ENTRY_KLASS
71:     end

[Source]

    # File lib/htauth/digest_file.rb, line 69
69:     def entry_klass
70:       ENTRY_KLASS
71:     end

fetches a copy of an entry from the file. Updateing the entry returned from fetch will NOT propogate back to the file.

[Source]

    # File lib/htauth/digest_file.rb, line 63
63:     def fetch(username, realm)
64:       return nil unless has_entry?(username, realm)
65:       ir = internal_record(username, realm)
66:       return ir['entry'].dup
67:     end

fetches a copy of an entry from the file. Updateing the entry returned from fetch will NOT propogate back to the file.

[Source]

    # File lib/htauth/digest_file.rb, line 63
63:     def fetch(username, realm)
64:       return nil unless has_entry?(username, realm)
65:       ir = internal_record(username, realm)
66:       return ir['entry'].dup
67:     end

does the entry the the specified username and realm exist in the file

[Source]

    # File lib/htauth/digest_file.rb, line 13
13:     def has_entry?(username, realm)
14:       test_entry = DigestEntry.new(username, realm)
15:       @entries.has_key?(test_entry.key)
16:     end

does the entry the the specified username and realm exist in the file

[Source]

    # File lib/htauth/digest_file.rb, line 13
13:     def has_entry?(username, realm)
14:       test_entry = DigestEntry.new(username, realm)
15:       @entries.has_key?(test_entry.key)
16:     end

update an already existing entry with a new password. raises an error if the entry does not exist

[Source]

    # File lib/htauth/digest_file.rb, line 52
52:     def update(username, realm, password)
53:       raise DigestFileError, "Unable to update non-existent user #{username} in realm #{realm}" unless has_entry?(username, realm)
54:       ir = internal_record(username, realm)
55:       ir['entry'].password = password
56:       @lines[ir['line_index']] = ir['entry'].to_s
57:       dirty!
58:       return nil
59:     end

update an already existing entry with a new password. raises an error if the entry does not exist

[Source]

    # File lib/htauth/digest_file.rb, line 52
52:     def update(username, realm, password)
53:       raise DigestFileError, "Unable to update non-existent user #{username} in realm #{realm}" unless has_entry?(username, realm)
54:       ir = internal_record(username, realm)
55:       ir['entry'].password = password
56:       @lines[ir['line_index']] = ir['entry'].to_s
57:       dirty!
58:       return nil
59:     end

[Validate]