@@ -18,7 +18,7 @@ local pcall = pcall
1818local require = require
1919local core = require (" apisix.core" )
2020local resource = require (" apisix.admin.resource" )
21- local encrypt_conf = require (" apisix.plugin" ).encrypt_conf
21+ local plugin_encrypt_conf = require (" apisix.plugin" ).encrypt_conf
2222
2323local injected_mark = " injected metadata_schema"
2424
@@ -35,6 +35,17 @@ local function validate_plugin(name)
3535end
3636
3737
38+ local function inject_metadata_schema (plugin_object )
39+ if not plugin_object .metadata_schema then
40+ plugin_object .metadata_schema = {
41+ type = " object" ,
42+ [' $comment' ] = injected_mark ,
43+ properties = {},
44+ }
45+ end
46+ end
47+
48+
3849local function check_conf (plugin_name , conf )
3950 if not plugin_name then
4051 return nil , {error_msg = " missing plugin name" }
@@ -45,13 +56,8 @@ local function check_conf(plugin_name, conf)
4556 return nil , {error_msg = " invalid plugin name" }
4657 end
4758
48- if not plugin_object .metadata_schema then
49- plugin_object .metadata_schema = {
50- type = " object" ,
51- [' $comment' ] = injected_mark ,
52- properties = {},
53- }
54- end
59+ inject_metadata_schema (plugin_object )
60+
5561 local schema = plugin_object .metadata_schema
5662
5763 local ok , err
@@ -64,20 +70,41 @@ local function check_conf(plugin_name, conf)
6470 ok , err = plugin_object .check_schema (conf , core .schema .TYPE_METADATA )
6571 end
6672
67- encrypt_conf (plugin_name , conf , core .schema .TYPE_METADATA )
68-
6973 if not ok then
7074 return nil , {error_msg = " invalid configuration: " .. err }
7175 end
7276
7377 return plugin_name
7478end
7579
80+ local function encrypt_conf (plugin_name , conf )
81+ if not plugin_name then
82+ -- This situation shouldn't happen according to the execution order.
83+ core .log .info (" missing plugin name" )
84+ return
85+ end
86+
87+ local ok , plugin_object = validate_plugin (plugin_name )
88+ if not ok then
89+ -- This situation shouldn't happen according to the execution order.
90+ core .log .info (" invalid plugin name" )
91+ return
92+ end
93+
94+ inject_metadata_schema (plugin_object )
95+
96+ local schema = plugin_object .metadata_schema
97+ if schema [' $comment' ] ~= injected_mark and plugin_object .check_schema then
98+ plugin_encrypt_conf (plugin_name , conf , core .schema .TYPE_METADATA )
99+ end
100+ end
101+
76102
77103return resource .new ({
78104 name = " plugin_metadata" ,
79105 kind = " plugin_metadata" ,
80106 schema = core .schema .plugin_metadata ,
81107 checker = check_conf ,
108+ encrypt_conf = encrypt_conf ,
82109 unsupported_methods = {" post" , " patch" }
83110})
0 commit comments