-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: added serverless plugins. #86
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a9a1b04
feature: added serverless plugins.
moonming 8b34cf7
add
moonming c6e69f8
feature: added serverless plugins.
moonming b13d7f6
add
moonming c816b7c
add test cases.
moonming 5919f91
add doc.
moonming e955c86
local.
moonming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
return require("apisix.plugins.serverless")("serverless-post-function", -2000) |
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 @@ | ||
return require("apisix.plugins.serverless")("serverless-pre-function", 10000) |
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,97 @@ | ||
local ipairs = ipairs | ||
local pcall = pcall | ||
local loadstring = loadstring | ||
local require = require | ||
|
||
return function(plugin_name, priority) | ||
local core = require("apisix.core") | ||
|
||
local schema = { | ||
type = "object", | ||
properties = { | ||
phase = { | ||
type = "string", | ||
-- the default phase is access | ||
enum = {"rewrite", "access", "header_filer", "body_filter", | ||
"log", "balancer"} | ||
}, | ||
functions = { | ||
type = "array", | ||
items = {type = "string"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing check to |
||
minItems = 1 | ||
}, | ||
}, | ||
required = {"functions"} | ||
} | ||
|
||
local _M = { | ||
version = 0.1, | ||
priority = priority, | ||
name = plugin_name, | ||
} | ||
|
||
local function load_funcs(functions) | ||
local funcs = core.table.new(#functions, 0) | ||
|
||
local index = 1 | ||
for _, func_str in ipairs(functions) do | ||
local _, func = pcall(loadstring(func_str)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it maybe failed, we need to capture the error message. |
||
funcs[index] = func | ||
index = index + 1 | ||
end | ||
|
||
return funcs | ||
end | ||
|
||
local function call_funcs(phase, conf, ctx) | ||
if phase ~= conf.phase then | ||
return | ||
end | ||
|
||
local functions = core.lrucache.plugin_ctx(plugin_name, ctx, | ||
load_funcs, conf.functions) | ||
|
||
for _, func in ipairs(functions) do | ||
func() | ||
end | ||
end | ||
|
||
function _M.check_schema(conf) | ||
local ok, err = core.schema.check(schema, conf) | ||
if not ok then | ||
return false, err | ||
end | ||
|
||
if not conf.phase then | ||
conf.phase = 'access' | ||
end | ||
|
||
return true | ||
end | ||
|
||
function _M.rewrite(conf, ctx) | ||
call_funcs('rewrite', conf, ctx) | ||
end | ||
|
||
function _M.access(conf, ctx) | ||
call_funcs('access', conf, ctx) | ||
end | ||
|
||
function _M.balancer(conf, ctx) | ||
call_funcs('balancer', conf, ctx) | ||
end | ||
|
||
function _M.header_filer(conf, ctx) | ||
call_funcs('header_filer', conf, ctx) | ||
end | ||
|
||
function _M.body_filter(conf, ctx) | ||
call_funcs('body_filter', conf, ctx) | ||
end | ||
|
||
function _M.log(conf, ctx) | ||
call_funcs('log', conf, ctx) | ||
end | ||
|
||
return _M | ||
end |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this style, how about to use
new
method to create new instance?