Skip to content

feat: faas plugin refactoring with url path forwarding#5616

Merged
spacewander merged 7 commits into
apache:masterfrom
bisakhmondal:faas-refactoring
Nov 29, 2021
Merged

feat: faas plugin refactoring with url path forwarding#5616
spacewander merged 7 commits into
apache:masterfrom
bisakhmondal:faas-refactoring

Conversation

@bisakhmondal

@bisakhmondal bisakhmondal commented Nov 25, 2021

Copy link
Copy Markdown
Member

What this PR does / why we need it:

This PR is based on the idea of creating a single generic upstream where each faas plugin implements an authorization schema and perform the header processing.

GOAL: Reduce the same code over multiple plugins (mainly faas)

How developers should write new (faas) plugins:

  1. They should define plugin-specific authorization schema & metadata schema(if required)
  2. Write a request_processor function on the plugin lua file that take `plugin conf, ngx context and the URL params (that contains headers, body, urlpath, query params etc. etc.)". The function can perform a series of operations including update/adding the necessary authorization headers, performing encoding/decoding (base64 or anything) on the body.
  3. And yes, that's it. (see the azure-functions Lua code for example)

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

if ctx.curr_req_matched and ctx.curr_req_matched["*"] then
local end_path = ctx.curr_req_matched["*"]

if path:sub(-1, -1) == "/" or end_path:sub(1, 1) == "/" then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using :byte would be better.
BTW, it is not a good idea to refactor & add feature in the same PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for byte you mean like this
if path:byte(-1, -1) == string.byte"/" or end_path:byte(1, 1) == string.byte"/" then

The PRs are interdependent and require one PR to be merged before another. Do you think I should split it up into 2 PRs?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like if path:byte(-1) == string.byte("/") or end_path:byte(1) == string.byte("/") then.

We can accept this one now.
Next time, please don't mix up refactor & new feature.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Thanks boss

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

local url_decoded = url.parse(conf.function_uri)
local path = url_decoded.path or "/"

if ctx.curr_req_matched and ctx.curr_req_matched["*"] then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use :ext instead of *

@bisakhmondal bisakhmondal Nov 26, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I was using ** that's why the extra arg was received through curr_req_matched["*"]. Updated

Comment thread t/plugin/azure-functions.t Outdated
"function_uri": "http://localhost:8765/api"
}
},
"uri": "/azure/**"

@spacewander spacewander Nov 26, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"uri": "/azure/**"
"uri": "/azure/*"

The wildcard match only uses one *.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


ngx.say(body)

local code, _, body = t("/azure/httptrigger", "GET")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add another test which contains multiple levels of paths, like /azure/http/trigger.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline the following cases have been covered
multiple levels of paths
multiple slashes in the paths
the wildcard matches an empty part, like /azure




=== TEST 11: check multilevel url path forwarding

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time, we can use a table drive test for those cases. See

local t = require("lib.test_admin").test

@spacewander
spacewander merged commit 8f0b066 into apache:master Nov 29, 2021
bd1dtn pushed a commit to bd1dtn/apisix that referenced this pull request Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants