-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prototype of executor and context for sharing data
- Loading branch information
Showing
12 changed files
with
232 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local setmetatable = setmetatable | ||
|
||
local policy_chain = require('policy_chain') | ||
local linked_list = require('linked_list') | ||
|
||
local _M = { } | ||
|
||
local mt = { __index = _M } | ||
|
||
-- forward all policy methods to the policy chain | ||
for i=1, #(policy_chain.PHASES) do | ||
local phase_name = policy_chain.PHASES[i] | ||
|
||
_M[phase_name] = function(self, ...) | ||
return self.policy_chain[phase_name](self.policy_chain, self:context(), ...) | ||
end | ||
end | ||
|
||
function _M.new() | ||
local local_chain = policy_chain.build() | ||
|
||
local load_configuration = policy_chain.load('policy.load_configuration', local_chain) | ||
|
||
local global_chain = policy_chain.build({ load_configuration, local_chain }) | ||
|
||
return setmetatable({ policy_chain = global_chain }, mt) | ||
end | ||
|
||
function _M:context() | ||
local config = self.policy_chain:export() | ||
|
||
return linked_list.readwrite({}, config) | ||
end | ||
|
||
return _M.new() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local setmetatable = setmetatable | ||
|
||
local _M = { | ||
|
||
} | ||
|
||
local noop = function() end | ||
|
||
|
||
local empty_t = setmetatable({}, { __newindex = noop }) | ||
local __index = function(t,k) | ||
return t.current[k] or t.next[k] | ||
end | ||
|
||
local ro_mt = { | ||
__index = __index, | ||
__newindex = noop, | ||
} | ||
|
||
local rw_mt = { | ||
__index = __index, | ||
__newindex = function(t, k, v) | ||
t.current[k] = v | ||
end | ||
} | ||
|
||
local function linked_list(item, next, mt) | ||
return setmetatable({ | ||
current = item or empty_t, | ||
next = next or empty_t | ||
}, mt) | ||
end | ||
|
||
local function readonly_linked_list(item, next) | ||
return linked_list(item, next, ro_mt) | ||
end | ||
|
||
local function readwrite_linked_list(item, next) | ||
return linked_list(item, next, rw_mt) | ||
end | ||
|
||
_M.readonly = readonly_linked_list | ||
_M.readwrite = readwrite_linked_list | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local _M = {} | ||
|
||
local setmetatable = setmetatable | ||
local policy_chain = require('policy_chain') | ||
|
||
local noop = function() end | ||
|
||
function _M.new(name) | ||
local policy = { | ||
_NAME = name or 'policy', | ||
_VERSION = '0.0', | ||
} | ||
local mt = { __index = policy } | ||
|
||
function policy.new() | ||
return setmetatable({}, mt) | ||
end | ||
|
||
for i=1,#(policy_chain.PHASES) do | ||
policy[policy_chain.PHASES[i]] = noop | ||
end | ||
|
||
return policy, mt | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local setmetatable = setmetatable | ||
|
||
local _M, mt = require('policy').new() | ||
|
||
local configuration_loader = require('configuration_loader').new() | ||
local configuration_store = require('configuration_store') | ||
|
||
function _M.new() | ||
return setmetatable({ | ||
configuration = configuration_store.new(), | ||
}, mt) | ||
end | ||
|
||
function _M:export() | ||
return { | ||
configuration = self.configuration | ||
} | ||
end | ||
|
||
function _M:init() | ||
configuration_loader.init(self.configuration) | ||
end | ||
|
||
function _M:init_worker() | ||
configuration_loader.init_worker(self.configuration) | ||
end | ||
|
||
function _M:rewrite(context) | ||
context.host = context.host or ngx.var.host | ||
context.configuration = configuration_loader.rewrite(context.configuration, context.host) | ||
end | ||
|
||
return _M |
Oops, something went wrong.