Class: Pechkin::Auth::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/auth.rb

Overview

Utility class for altering htpasswd files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(htpasswd) ⇒ Manager

Returns a new instance of Manager.



6
7
8
# File 'lib/pechkin/auth.rb', line 6

def initialize(htpasswd)
  @htpasswd = htpasswd
end

Instance Attribute Details

#htpasswdObject (readonly)

Returns the value of attribute htpasswd.



5
6
7
# File 'lib/pechkin/auth.rb', line 5

def htpasswd
  @htpasswd
end

Instance Method Details

#add(user, password) ⇒ Object



10
11
12
13
14
15
# File 'lib/pechkin/auth.rb', line 10

def add(user, password)
  m = File.exist?(htpasswd) ? HTAuth::File::ALTER : HTAuth::File::CREATE
  HTAuth::PasswdFile.open(htpasswd, m) do |f|
    f.add_or_update(user, password, 'md5')
  end
end