Remove session-cookie-hash annotation
This commit is contained in:
parent
79c52cf094
commit
d3ac73be79
18 changed files with 22 additions and 189 deletions
|
|
@ -2,29 +2,20 @@ local balancer_resty = require("balancer.resty")
|
|||
local resty_chash = require("resty.chash")
|
||||
local util = require("util")
|
||||
local ck = require("resty.cookie")
|
||||
local math = require("math")
|
||||
|
||||
local _M = balancer_resty:new({ factory = resty_chash, name = "sticky" })
|
||||
local DEFAULT_COOKIE_NAME = "route"
|
||||
|
||||
local function get_digest_func(hash)
|
||||
local digest_func = util.md5_digest
|
||||
if hash == "sha1" then
|
||||
digest_func = util.sha1_digest
|
||||
end
|
||||
return digest_func
|
||||
end
|
||||
|
||||
function _M.cookie_name(self)
|
||||
return self.cookie_session_affinity.name or DEFAULT_COOKIE_NAME
|
||||
end
|
||||
|
||||
function _M.new(self, backend)
|
||||
local nodes = util.get_nodes(backend.endpoints)
|
||||
local digest_func = get_digest_func(backend["sessionAffinityConfig"]["cookieSessionAffinity"]["hash"])
|
||||
|
||||
local o = {
|
||||
instance = self.factory:new(nodes),
|
||||
digest_func = digest_func,
|
||||
traffic_shaping_policy = backend.trafficShapingPolicy,
|
||||
alternative_backends = backend.alternativeBackends,
|
||||
cookie_session_affinity = backend["sessionAffinityConfig"]["cookieSessionAffinity"]
|
||||
|
|
@ -34,15 +25,6 @@ function _M.new(self, backend)
|
|||
return o
|
||||
end
|
||||
|
||||
local function encrypted_endpoint_string(self, endpoint_string)
|
||||
local encrypted, err = self.digest_func(endpoint_string)
|
||||
if err ~= nil then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
|
||||
return encrypted
|
||||
end
|
||||
|
||||
local function set_cookie(self, value)
|
||||
local cookie, err = ck:new()
|
||||
if not cookie then
|
||||
|
|
@ -86,8 +68,7 @@ function _M.balance(self)
|
|||
|
||||
local key = cookie:get(self:cookie_name())
|
||||
if not key then
|
||||
local random_str = string.format("%s.%s", ngx.now(), ngx.worker.pid())
|
||||
key = encrypted_endpoint_string(self, random_str)
|
||||
key = string.format("%s.%s.%s", ngx.now(), ngx.worker.pid(), math.random(999999))
|
||||
|
||||
if self.cookie_session_affinity.locations then
|
||||
local locs = self.cookie_session_affinity.locations[ngx.var.host]
|
||||
|
|
@ -118,7 +99,6 @@ function _M.sync(self, backend)
|
|||
end
|
||||
|
||||
self.cookie_session_affinity = backend.sessionAffinityConfig.cookieSessionAffinity
|
||||
self.digest_func = get_digest_func(backend.sessionAffinityConfig.cookieSessionAffinity.hash)
|
||||
end
|
||||
|
||||
return _M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue