Skip to content

Commit adac4bf

Browse files
authored
Merge branch 'master' into dev-apisix
2 parents 1f64187 + 1490d7a commit adac4bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1090
-103
lines changed

apisix/admin/consumer_group.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local core = require("apisix.core")
1818
local consumers = require("apisix.consumer").consumers
1919
local resource = require("apisix.admin.resource")
2020
local schema_plugin = require("apisix.admin.plugins").check_schema
21+
local plugins_encrypt_conf = require("apisix.admin.plugins").encrypt_conf
2122
local type = type
2223
local tostring = tostring
2324
local ipairs = ipairs
@@ -38,6 +39,11 @@ local function check_conf(id, conf, need_id, schema)
3839
end
3940

4041

42+
local function encrypt_conf(id, conf)
43+
plugins_encrypt_conf(conf.plugins)
44+
end
45+
46+
4147
local function delete_checker(id)
4248
local consumers, consumers_ver = consumers()
4349
if consumers_ver and consumers then
@@ -61,6 +67,7 @@ return resource.new({
6167
kind = "consumer group",
6268
schema = core.schema.consumer_group,
6369
checker = check_conf,
70+
encrypt_conf = encrypt_conf,
6471
unsupported_methods = {"post"},
6572
delete_checker = delete_checker
6673
})

apisix/admin/consumers.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
--
1717
local core = require("apisix.core")
1818
local plugins = require("apisix.admin.plugins")
19+
local plugins_encrypt_conf = require("apisix.admin.plugins").encrypt_conf
1920
local resource = require("apisix.admin.resource")
2021

2122

@@ -57,10 +58,16 @@ local function check_conf(username, conf, need_username, schema, opts)
5758
end
5859

5960

61+
local function encrypt_conf(id, conf)
62+
plugins_encrypt_conf(conf.plugins, core.schema.TYPE_CONSUMER)
63+
end
64+
65+
6066
return resource.new({
6167
name = "consumers",
6268
kind = "consumer",
6369
schema = core.schema.consumer,
6470
checker = check_conf,
71+
encrypt_conf = encrypt_conf,
6572
unsupported_methods = {"post", "patch"}
6673
})

apisix/admin/credentials.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local core = require("apisix.core")
1818
local plugins = require("apisix.admin.plugins")
1919
local plugin = require("apisix.plugin")
2020
local resource = require("apisix.admin.resource")
21+
local plugins_encrypt_conf = require("apisix.admin.plugins").encrypt_conf
2122
local pairs = pairs
2223

2324
local function check_conf(_id, conf, _need_id, schema)
@@ -46,6 +47,12 @@ local function check_conf(_id, conf, _need_id, schema)
4647
return true, nil
4748
end
4849

50+
51+
local function encrypt_conf(id, conf)
52+
plugins_encrypt_conf(conf.plugins, core.schema.TYPE_CONSUMER)
53+
end
54+
55+
4956
-- get_credential_etcd_key is used to splice the credential's etcd key (without prefix)
5057
-- from credential_id and sub_path.
5158
-- Parameter credential_id is from the uri or payload; sub_path is in the form of
@@ -69,6 +76,7 @@ return resource.new({
6976
kind = "credential",
7077
schema = core.schema.credential,
7178
checker = check_conf,
79+
encrypt_conf = encrypt_conf,
7280
get_resource_etcd_key = get_credential_etcd_key,
7381
unsupported_methods = {"post", "patch"}
7482
})

apisix/admin/global_rules.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
local core = require("apisix.core")
1818
local resource = require("apisix.admin.resource")
1919
local schema_plugin = require("apisix.admin.plugins").check_schema
20+
local plugins_encrypt_conf = require("apisix.admin.plugins").encrypt_conf
2021

2122

2223
local function check_conf(id, conf, need_id, schema)
@@ -34,10 +35,16 @@ local function check_conf(id, conf, need_id, schema)
3435
end
3536

3637

38+
local function encrypt_conf(id, conf)
39+
plugins_encrypt_conf(conf.plugins)
40+
end
41+
42+
3743
return resource.new({
3844
name = "global_rules",
3945
kind = "global rule",
4046
schema = core.schema.global_rule,
4147
checker = check_conf,
48+
encrypt_conf = encrypt_conf,
4249
unsupported_methods = {"post"}
4350
})

apisix/admin/plugin_config.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local core = require("apisix.core")
1818
local get_routes = require("apisix.router").http_routes
1919
local resource = require("apisix.admin.resource")
2020
local schema_plugin = require("apisix.admin.plugins").check_schema
21+
local plugins_encrypt_conf = require("apisix.admin.plugins").encrypt_conf
2122
local type = type
2223
local tostring = tostring
2324
local ipairs = ipairs
@@ -38,6 +39,11 @@ local function check_conf(id, conf, need_id, schema)
3839
end
3940

4041

42+
local function encrypt_conf(id, conf)
43+
plugins_encrypt_conf(conf.plugins)
44+
end
45+
46+
4147
local function delete_checker(id)
4248
local routes, routes_ver = get_routes()
4349
if routes_ver and routes then
@@ -61,6 +67,7 @@ return resource.new({
6167
kind = "plugin config",
6268
schema = core.schema.plugin_config,
6369
checker = check_conf,
70+
encrypt_conf = encrypt_conf,
6471
unsupported_methods = {"post"},
6572
delete_checker = delete_checker
6673
})

apisix/admin/plugin_metadata.lua

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local pcall = pcall
1818
local require = require
1919
local core = require("apisix.core")
2020
local 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

2323
local injected_mark = "injected metadata_schema"
2424

@@ -35,6 +35,17 @@ local function validate_plugin(name)
3535
end
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+
3849
local 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
7478
end
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

77103
return 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
})

apisix/admin/plugins.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ local _M = {}
3131

3232

3333
function _M.check_schema(plugins_conf, schema_type)
34-
local ok, err = check_schema(plugins_conf, schema_type, false)
35-
if ok then
34+
return check_schema(plugins_conf, schema_type, false)
35+
end
36+
37+
38+
function _M.encrypt_conf(plugins_conf, schema_type)
39+
if plugins_conf then
3640
for name, conf in pairs(plugins_conf) do
3741
encrypt_conf(name, conf, schema_type)
3842
end
3943
end
40-
return ok, err
4144
end
4245

4346

apisix/admin/resource.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ local core = require("apisix.core")
1818
local utils = require("apisix.admin.utils")
1919
local apisix_ssl = require("apisix.ssl")
2020
local apisix_consumer = require("apisix.consumer")
21+
local tbl_deepcopy = require("apisix.core.table").deepcopy
2122
local setmetatable = setmetatable
2223
local tostring = tostring
2324
local ipairs = ipairs
@@ -123,7 +124,12 @@ function _M:check_conf(id, conf, need_id, typ, allow_time)
123124
core.log.info("schema: ", core.json.delay_encode(self.schema))
124125
end
125126

126-
local ok, err = self.checker(id, conf, need_id, self.schema, {secret_type = typ})
127+
local conf_for_check = tbl_deepcopy(conf)
128+
local ok, err = self.checker(id, conf_for_check, need_id, self.schema, {secret_type = typ})
129+
130+
if self.encrypt_conf then
131+
self.encrypt_conf(id, conf)
132+
end
127133

128134
if not ok then
129135
return ok, err

apisix/admin/routes.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ local core = require("apisix.core")
1919
local apisix_upstream = require("apisix.upstream")
2020
local resource = require("apisix.admin.resource")
2121
local schema_plugin = require("apisix.admin.plugins").check_schema
22+
local plugins_encrypt_conf = require("apisix.admin.plugins").encrypt_conf
2223
local type = type
2324
local loadstring = loadstring
2425
local ipairs = ipairs
@@ -173,11 +174,18 @@ local function check_conf(id, conf, need_id, schema, opts)
173174
end
174175

175176

177+
local function encrypt_conf(id, conf)
178+
apisix_upstream.encrypt_conf(conf.upstream)
179+
plugins_encrypt_conf(conf.plugins)
180+
end
181+
182+
176183
return resource.new({
177184
name = "routes",
178185
kind = "route",
179186
schema = core.schema.route,
180187
checker = check_conf,
188+
encrypt_conf = encrypt_conf,
181189
list_filter_fields = {
182190
service_id = true,
183191
upstream_id = true,

apisix/admin/services.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ local get_stream_routes = require("apisix.router").stream_routes
2020
local apisix_upstream = require("apisix.upstream")
2121
local resource = require("apisix.admin.resource")
2222
local schema_plugin = require("apisix.admin.plugins").check_schema
23+
local plugins_encrypt_conf = require("apisix.admin.plugins").encrypt_conf
2324
local tostring = tostring
2425
local ipairs = ipairs
2526
local type = type
@@ -120,10 +121,17 @@ local function delete_checker(id)
120121
end
121122

122123

124+
local function encrypt_conf(id, conf)
125+
apisix_upstream.encrypt_conf(conf.upstream)
126+
plugins_encrypt_conf(conf.plugins)
127+
end
128+
129+
123130
return resource.new({
124131
name = "services",
125132
kind = "service",
126133
schema = core.schema.service,
127134
checker = check_conf,
128-
delete_checker = delete_checker
135+
encrypt_conf = encrypt_conf,
136+
delete_checker = delete_checker,
129137
})

0 commit comments

Comments
 (0)