Module: NginxTail::RemoteUser

Defined in:
lib/ntail/remote_user.rb

Constant Summary collapse

UNKNOWN_REMOTE_USER =

to easily identify remote and authenticated users, for filtering and formatting purposes

 e.g. add all employees as authenticated remote users (from your webserver’s .htaccess file)

"-".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

 the ‘default’ nginx value for the $remote_user variable



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ntail/remote_user.rb', line 12

def self.included(base) # :nodoc:
  base.class_eval do

    @@authenticated_users = []

    # mainly (solely?) for testing purposes...
    def self.reset_authenticated_users
      while !@@authenticated_users.empty? ; @@authenticated_users.pop ; end
    end
    
    # mainly (solely?) for testing purposes...
    def self.authenticated_users
      @@authenticated_users.dup
    end
    
    def self.add_authenticated_user(authenticated_user)
      raise "Cannot add unkown remote user" if self.unknown_remote_user? authenticated_user
      (@@authenticated_users << authenticated_user).uniq!
    end

    def self.unknown_remote_user?(remote_user)
      remote_user == UNKNOWN_REMOTE_USER
    end

    def self.remote_user?(remote_user)
      !self.unknown_remote_user?(remote_user)
    end
    
    def self.authenticated_user?(remote_user)
      self.remote_user?(remote_user) && @@authenticated_users.include?(remote_user)
    end

    # this ensures the below module methods actually make sense...
    raise "Class #{base.name} should implement instance method 'remote_user'" unless base.instance_methods.include? 'remote_user'

  end
end

Instance Method Details

#authenticated_user?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/ntail/remote_user.rb', line 58

def authenticated_user?
  self.class.authenticated_user?(self.remote_user)
end

#remote_user?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ntail/remote_user.rb', line 54

def remote_user?
  self.class.remote_user?(self.remote_user)
end

#unknown_remote_user?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/ntail/remote_user.rb', line 50

def unknown_remote_user?
  self.class.unknown_remote_user?(self.remote_user)
end