Class: Git::Lighttp::Htpasswd

Inherits:
Object
  • Object
show all
Defined in:
lib/git/lighttp.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(file) {|_self| ... } ⇒ Htpasswd

Returns a new instance of Htpasswd.

Yields:

  • (_self)

Yield Parameters:



173
174
175
176
177
# File 'lib/git/lighttp.rb', line 173

def initialize(file)
  require "webrick/httpauth/htpasswd"
  @handler = WEBrick::HTTPAuth::Htpasswd.new(file)
  yield self if block_given?
end

Instance Method Details

#authenticated?(username, password) ⇒ Boolean

Returns:

  • (Boolean)


188
189
190
191
192
# File 'lib/git/lighttp.rb', line 188

def authenticated?(username, password)
  self.find username do |crypted, salt|
    crypted && salt && crypted == password.crypt(salt)
  end
end

#create(username, password) ⇒ Object Also known as: update



194
195
196
# File 'lib/git/lighttp.rb', line 194

def create(username, password)
  @handler.set_passwd(nil, username, password)
end

#destroy(username) ⇒ Object



199
200
201
# File 'lib/git/lighttp.rb', line 199

def destroy(username)
  @handler.delete_passwd(nil, username)
end

#find(username) ⇒ Object

:yield: password, salt



179
180
181
182
183
184
185
186
# File 'lib/git/lighttp.rb', line 179

def find(username) #:yield: password, salt
  password = @handler.get_passwd(nil, username, false)
  if block_given?
    yield password ? [password, password[0,2]] : [nil, nil]
  else
    password
  end
end

#include?(username) ⇒ Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/git/lighttp.rb', line 203

def include?(username)
  users.include? username
end

#sizeObject



207
208
209
# File 'lib/git/lighttp.rb', line 207

def size
  users.size
end

#write!Object



211
212
213
# File 'lib/git/lighttp.rb', line 211

def write!
  @handler.flush
end