liquid_feedback_frontend

diff env/ldap/get_hosts.lua @ 1071:58f48a8a202a

Imported and merged LDAP patch
author bsw
date Fri Jul 18 21:42:59 2014 +0200 (2014-07-18)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/env/ldap/get_hosts.lua	Fri Jul 18 21:42:59 2014 +0200
     1.3 @@ -0,0 +1,46 @@
     1.4 +-- generate a ready-to-use list of the configures LDAP servers
     1.5 +-- --------------------------------------------------------------------------
     1.6 +-- result is in order of preference, including a round robin style random
     1.7 +-- selection of the preference of hosts with the same preference
     1.8 +--
     1.9 +-- returns:
    1.10 +--   hostlist: flattened list of LDAP servers in order of preference
    1.11 +
    1.12 +function ldap.get_hosts()
    1.13 +  
    1.14 +  math.randomseed(os.time())
    1.15 +  
    1.16 +  local hostlist = {}
    1.17 +  
    1.18 +  -- iterate through all entries on base level
    1.19 +  for i, host in ipairs (config.ldap.hosts) do
    1.20 +    
    1.21 +    -- a single host entry
    1.22 +    if host.uri then
    1.23 +      hostlist[#hostlist+1] = host
    1.24 +      
    1.25 +    -- or a list of host entries
    1.26 +    else
    1.27 +      local subhostlist = {}
    1.28 +      
    1.29 +      -- sort list of host entries by random
    1.30 +      for j, subhost in ipairs(host) do
    1.31 +        subhost.priority = math.random()
    1.32 +        subhostlist[#subhostlist+1] = subhost
    1.33 +      end
    1.34 +      table.sort(subhostlist, function (a,b)
    1.35 +        return a.priority < b.priority
    1.36 +      end)
    1.37 +      
    1.38 +      -- and add them to the main list
    1.39 +      for i, subhost in ipairs(subhostlist) do
    1.40 +        hostlist[#hostlist+1] = subhost
    1.41 +      end
    1.42 +      
    1.43 +    end
    1.44 +    
    1.45 +  end
    1.46 +  
    1.47 +  return hostlist
    1.48 +  
    1.49 +end

Impressum / About Us