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



##########
File path: apisix/plugins/opa/helper.lua
##########
@@ -45,16 +52,136 @@ local function build_http_request(conf, ctx)
 end
 
 
-function _M.build_opa_input(conf, ctx, subsystem)
-    local request = build_http_request(conf, ctx)
+local function _build_http_route(conf, ctx)
+    local route_id = ctx.route_id
+    local routes = get_routes()
+
+    for _, route in ipairs(routes) do
+        if route.value.id == route_id then
+            return core.table.deepcopy(route).value
+        end
+    end
+
+    return nil
+end
+
+
+local function build_http_route(conf, ctx, remove_upstream)
+    local route = _build_http_route(conf, ctx)
+
+    if remove_upstream and route and route.upstream then
+        route.upstream = nil
+    end
+
+    return route
+end
+
+
+local function _build_http_upstream(conf, ctx)
+    local route = build_http_route(conf, ctx, false)
+
+    if route then
+        if route.upstream then
+            return core.table.deepcopy(route.upstream)
+        else
+            local upstream_id = route.upstream_id
+            local upstreams = get_upstreams()
+
+            for _, upstream in ipairs(upstreams) do
+                if upstream.value.id == upstream_id then
+                    return core.table.deepcopy(upstream).value
+                end
+            end
+        end
+    end
+
+    return nil
+end
+
+
+local function build_http_upstream(conf, ctx)
+    local upstream = _build_http_upstream(conf, ctx)
+
+    if upstream and upstream.parent then
+        upstream.parent = nil
+    end
+
+    return upstream
+end
+
+
+local function _build_http_service(conf, ctx)
+    local service_id = ctx.service_id
+
+    -- possible that the route is not bind a service
+    if service_id then
+        local services = get_services()
 
+        for _, service in ipairs(services) do
+            if service.value.id == service_id then
+                return core.table.deepcopy(service).value
+            end
+        end
+    end
+
+    return nil
+end
+
+
+local function build_http_service(conf, ctx)
+    local service = _build_http_service(conf, ctx)
+
+    if service and service.upstream and service.upstream.parent then
+        service.upstream.parent = nil
+    end
+
+    return service
+end
+
+
+local function build_http_consumer(conf, ctx)
+    local consumer_name = ctx.consumer_name

Review comment:
       changed




-- 
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