feat: set cors allow origins by plugin metadata#6546
Merged
spacewander merged 8 commits intoMar 13, 2022
Merged
Conversation
Contributor
Author
|
I haven't edited any docs yet, would like some opinions on the feature and the implementation/tests before moving on |
spacewander
reviewed
Mar 9, 2022
| if not match_origins(req_origin, allow_origins) then | ||
| allow_origins = process_with_allow_origins_by_regex(conf, ctx, req_origin) | ||
| end | ||
| if not match_origins(req_origin, allow_origins) then |
Member
There was a problem hiding this comment.
Suggested change
| if not match_origins(req_origin, allow_origins) then | |
| if not allow_origins then |
| } | ||
| } | ||
| --- request | ||
| GET /t |
Member
There was a problem hiding this comment.
Let's use this script to simplify the duplicate fields:
#!/usr/bin/env python
# coding: utf-8
# Usage: ./simpify.py $test_filename
import sys
with open(sys.argv[1]) as f:
lines = [l.rstrip() for l in f.readlines()]
newlines = []
for i, l in enumerate(lines):
if ((l == "GET /t" and lines[i-1] == "--- request") or
(l == "[error]" and lines[i-1] == "--- no_error_log")):
newlines = newlines[:-1]
continue
newlines.append(l)
res = "\n".join(newlines)
# print(res)
with open(sys.argv[1], "w") as f:
f.write(res + '\n')
…etadata # Conflicts: # docs/en/latest/plugins/cors.md # docs/zh/latest/plugins/cors.md
spacewander
reviewed
Mar 10, 2022
| create_multiple_origin_cache, conf) | ||
|
|
||
| if not (cache_key and cache_version) then | ||
| cache_key, cache_version = core.lrucache.plugin_ctx_id(ctx) |
Member
There was a problem hiding this comment.
plugin_ctx_id only returns an ID?
spacewander
previously approved these changes
Mar 10, 2022
| local allow_origins = conf.allow_origins | ||
| local function process_with_allow_origins(allow_origins_conf, ctx, req_origin, | ||
| cache_key, cache_version) | ||
| local allow_origins = allow_origins_conf |
Member
There was a problem hiding this comment.
We don't need to declare allow_origins_conf as local allow_origins here, just change the allow_origins_conf -> allow_origins in parameter list is ok?
Contributor
Author
There was a problem hiding this comment.
yep, changed that
Co-authored-by: tzssangglass <[email protected]>
…y_plugin_metadata' into feature/set_cors_allow_origins_by_plugin_metadata
spacewander
approved these changes
Mar 11, 2022
tzssangglass
approved these changes
Mar 13, 2022
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does / why we need it:
Supports setting allow_origins by plugin metadata in the cors plugin. We usually have many routes sharing the same set of allowed origins, and it's really inconvenient when trying to update the allowed_origins sets (have to do it for all routes). Existing admin objects like services and plugin configs don't exactly solve this issue since the routes may have different configurations for other plugins but share the same allowe_origins.
Pre-submission checklist: