bzp2010 commented on a change in pull request #6145:
URL: https://github.com/apache/apisix/pull/6145#discussion_r789309852



##########
File path: apisix/plugins/public-api.lua
##########
@@ -0,0 +1,58 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local core   = require("apisix.core")
+local router = require("apisix.router")
+
+local schema = {
+    type = "object",
+    properties = {
+        uri = {type = "string"},
+    },
+}
+
+
+local _M = {
+    version = 0.1,
+    priority = 501,
+    name = "public-api",
+    schema = schema,
+}
+
+
+function _M.check_schema(conf)
+    return core.schema.check(schema, conf)
+end
+
+
+function _M.access(conf, ctx)
+    local local_conf = core.config.local_conf()
+
+    -- overwrite the uri in the ctx when the user has set the target uri
+    ctx.var.uri = conf.uri and conf.uri or ctx.var.uri
+    local skip = local_conf and local_conf.apisix.global_rule_skip_internal_api

Review comment:
       
https://github.com/apache/apisix/blob/64c47df50c5607e9bf9921021391bb32c5f4d0b2/apisix/init.lua#L376-L445
 
   
   Hi, @spacewander.
   
   Based on this part of the code, we can presume to have such a situation.
   
   1. HTTP match, and `public-api` plugin is enabled.
   This will be controlled by the configuration file whether to enforce global 
rules for public API calls. After the match, the subsequent request processing 
flow will be completely taken over by the public API handler, bypassing the 
rest of the code execution in the access phase.
   2. HTTP not matched, public API route matched.
   This will also be controlled by the configuration file whether to enforce 
global rules or not. 
   3. Both HTTP and public APIs do not match
   It will force the global rule to run and return 404 Not Route.
   
   ----------
   
   Also, as you said in this issue 
https://github.com/apache/apisix/issues/6137#issuecomment-1016016565, we will 
adjust the public API to not be exposed by default, which will be done by 
completely removing the public API route match in the access phase. (Currently 
HTTP matching is performed followed by public API matching as a backup) In that 
case, the matching and processing of the public API will be done by the 
public-api plugin only, and if a match is made the global rules will be 
enforced according to the configuration.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to