-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: admin api no longer populates default values when writing #12603
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
Changes from all commits
3c5b7c0
28b3d6d
9377513
5cf530d
52c4b98
fdefa4e
31a0138
5d32f93
8c0891c
106e1f4
199cf44
cb2d8f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ local pcall = pcall | |
| local require = require | ||
| local core = require("apisix.core") | ||
| local resource = require("apisix.admin.resource") | ||
| local encrypt_conf = require("apisix.plugin").encrypt_conf | ||
| local plugin_encrypt_conf = require("apisix.plugin").encrypt_conf | ||
|
|
||
| local injected_mark = "injected metadata_schema" | ||
|
|
||
|
|
@@ -35,6 +35,17 @@ local function validate_plugin(name) | |
| end | ||
|
|
||
|
|
||
| local function inject_metadata_schema(plugin_object) | ||
| if not plugin_object.metadata_schema then | ||
| plugin_object.metadata_schema = { | ||
| type = "object", | ||
| ['$comment'] = injected_mark, | ||
| properties = {}, | ||
| } | ||
| end | ||
| end | ||
|
|
||
|
|
||
| local function check_conf(plugin_name, conf) | ||
| if not plugin_name then | ||
| return nil, {error_msg = "missing plugin name"} | ||
|
|
@@ -45,13 +56,8 @@ local function check_conf(plugin_name, conf) | |
| return nil, {error_msg = "invalid plugin name"} | ||
| end | ||
|
|
||
| if not plugin_object.metadata_schema then | ||
| plugin_object.metadata_schema = { | ||
| type = "object", | ||
| ['$comment'] = injected_mark, | ||
| properties = {}, | ||
| } | ||
| end | ||
| inject_metadata_schema(plugin_object) | ||
|
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. Although it is not introduced by your PR, it is strange to actively inject an empty schema and use ordinary schema or metadata_schema according to certain conditions for configuration verification for some non-plugin metadata. If a plugin does not indicate that it supports plugin metadata configuration by actively declaring metadata_schema, it should not be configured in this way. Specifically, if this happens, it may be more appropriate to reject this configuration directly. For example, key-auth does not have the meaning of plugin metadata configuration. 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. Let's wait for what others think. 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. agree with @bzp2010 , it's strange to inject a empty metadata schema for plugins that don't need plugin metadata, look like we need a refactor for this, I think we can deal with it in another PR. |
||
|
|
||
| local schema = plugin_object.metadata_schema | ||
|
|
||
| local ok, err | ||
|
|
@@ -64,20 +70,41 @@ local function check_conf(plugin_name, conf) | |
| ok, err = plugin_object.check_schema(conf, core.schema.TYPE_METADATA) | ||
| end | ||
|
|
||
| encrypt_conf(plugin_name, conf, core.schema.TYPE_METADATA) | ||
|
|
||
| if not ok then | ||
| return nil, {error_msg = "invalid configuration: " .. err} | ||
| end | ||
|
|
||
| return plugin_name | ||
| end | ||
|
|
||
| local function encrypt_conf(plugin_name, conf) | ||
| if not plugin_name then | ||
| -- This situation shouldn't happen according to the execution order. | ||
| core.log.info("missing plugin name") | ||
| return | ||
| end | ||
|
|
||
| local ok, plugin_object = validate_plugin(plugin_name) | ||
| if not ok then | ||
| -- This situation shouldn't happen according to the execution order. | ||
| core.log.info("invalid plugin name") | ||
| return | ||
| end | ||
|
|
||
| inject_metadata_schema(plugin_object) | ||
|
|
||
| local schema = plugin_object.metadata_schema | ||
| if schema['$comment'] ~= injected_mark and plugin_object.check_schema then | ||
| plugin_encrypt_conf(plugin_name, conf, core.schema.TYPE_METADATA) | ||
| end | ||
| end | ||
|
|
||
|
|
||
| return resource.new({ | ||
| name = "plugin_metadata", | ||
| kind = "plugin_metadata", | ||
| schema = core.schema.plugin_metadata, | ||
| checker = check_conf, | ||
| encrypt_conf = encrypt_conf, | ||
| unsupported_methods = {"post", "patch"} | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ local core = require("apisix.core") | |
| local utils = require("apisix.admin.utils") | ||
| local apisix_ssl = require("apisix.ssl") | ||
| local apisix_consumer = require("apisix.consumer") | ||
| local tbl_deepcopy = require("apisix.core.table").deepcopy | ||
| local setmetatable = setmetatable | ||
| local tostring = tostring | ||
| local ipairs = ipairs | ||
|
|
@@ -123,7 +124,12 @@ function _M:check_conf(id, conf, need_id, typ, allow_time) | |
| core.log.info("schema: ", core.json.delay_encode(self.schema)) | ||
| end | ||
|
|
||
| local ok, err = self.checker(id, conf, need_id, self.schema, {secret_type = typ}) | ||
| local conf_for_check = tbl_deepcopy(conf) | ||
| local ok, err = self.checker(id, conf_for_check, need_id, self.schema, {secret_type = typ}) | ||
|
Comment on lines
+127
to
+128
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. I'm wondering if it's necessary to keep a switch enabled by a specific querystring to retain the old behavior? For example, when 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. This is actually a question I've thought about. Let's wait for other people's comments. 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. I can't think of any issues that require specifying 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. In terms of debugging purposes only, this PR should not be blocked, and the default value can be confirmed through the version of apisix. |
||
|
|
||
| if self.encrypt_conf then | ||
| self.encrypt_conf(id, conf) | ||
| end | ||
|
|
||
| if not ok then | ||
| return ok, err | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -106,7 +106,7 @@ function _M.decrypt_params(decrypt_func, body, schema_type) | |||||
| -- metadata | ||||||
| if schema_type == core.schema.TYPE_METADATA then | ||||||
| local conf = body.node and body.node.value | ||||||
| decrypt_func(conf.name, conf, schema_type) | ||||||
|
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. There is an amazing problem here: In apisix/apisix/plugins/error-log-logger.lua Line 130 in 36b2b83
This is a property not marked in the document. The intention of its design cannot be seen from the original PR #2592. At the same time, it is also the only one that contains apisix/apisix/plugins/error-log-logger.lua Line 149 in 36b2b83
This causes this logic in the actual However, due to the cancellation of the default value padding, this logic no longer takes effect. Anyway, I think this is wrong. And it needs to be repaired in subsequent PRs. The reasons are as follows:
|
||||||
| decrypt_func(conf.id, conf, schema_type) | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,10 @@ local schema = { | |
| default = "abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789" | ||
| } | ||
| }, | ||
| default = {} | ||
| default = { | ||
| length = 16, | ||
| char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789" | ||
| } | ||
|
Comment on lines
+54
to
+57
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. The tests revealed that this is the only way to properly populate default values when The original one should be because it's filled again after writing |
||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
pls confirm it never failed
for me, I prefer
return plugins_encrypt_conf(conf.plugins)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.
It looks like they are the same?
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.
Regarding the calling method, it references the original
local schema_plugin = require(“apisix.admin.plugins”).check_schema. And in the current scenario, no issues have been detected.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.
In the current implementation, it will never fail:
https://github.com/apache/apisix/pull/12603/files#diff-00090cde519e7280adbc73e830b92089c4e62a22057c1b7577c77dc1456e72e5