shreemaan-abhishek commented on code in PR #12040: URL: https://github.com/apache/apisix/pull/12040#discussion_r1998170219
########## apisix/admin/consumers.lua: ########## @@ -32,7 +34,50 @@ local function check_conf(username, conf, need_username, schema) if conf.plugins then ok, err = plugins.check_schema(conf.plugins, core.schema.TYPE_CONSUMER) if not ok then - return nil, {error_msg = "invalid plugins configuration: " .. err} + return nil, { + error_msg = "invalid plugins configuration: " .. err + } + end + + -- check duplicate key + for plugin_name, plugin_conf in pairs(conf.plugins or {}) do + local plugin_obj = plugin.get(plugin_name) + if not plugin_obj then + return nil, {error_msg = "unknown plugin " .. plugin_name} + end + + if plugin_obj.type == "auth" then + local decrypted_conf = core.table.deepcopy(plugin_conf) + plugin.decrypt_conf(plugin_name, decrypted_conf, core.schema.TYPE_CONSUMER) + + local plugin_key_map = { + ["key-auth"] = "key", + ["basic-auth"] = "username", + ["jwt-auth"] = "key", + ["hmac-auth"] = "key_id" + } + + local key_field = plugin_key_map[plugin_name] + + if key_field then + local key_value = decrypted_conf[key_field] + + if key_value then + local consumer, _, err = consumer + .find_consumer(plugin_name, key_field, key_value) + if err then + core.log.warn("failed to find consumer: ", err) + end + + if consumer and consumer.username ~= conf.username then Review Comment: got it. What about my first question? > Is it guaranteed that the returned consumer will have the field username in it? Different consumers have different key fields right? Take your own code snippet for example: -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org