spacewander commented on a change in pull request #5874: URL: https://github.com/apache/apisix/pull/5874#discussion_r774928668
########## File path: ci/pod/opa/debug.rego ########## @@ -0,0 +1,20 @@ +# +# 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. +# +package debug Review comment: Use the name `echo` would be better? ########## File path: apisix/plugins/opa/helper.lua ########## @@ -45,16 +48,68 @@ 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, remove_upstream) + local route = core.table.clone(ctx.matched_route).value + + if remove_upstream and route and route.upstream then + route.upstream = nil + end + + return route +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 service = core.table.clone(get_service(service_id)).value + + if service then + if service.upstream and service.upstream.parent then Review comment: Why not remove upstream of service? ########## File path: t/plugin/opa2.t ########## @@ -0,0 +1,206 @@ +# +# 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. +# +use t::APISIX 'no_plan'; + +repeat_each(1); +no_long_string(); +no_root_location(); + +add_block_preprocessor(sub { + my ($block) = @_; + + if ((!defined $block->error_log) && (!defined $block->no_error_log)) { + $block->set_value("no_error_log", "[error]"); + } + + if (!defined $block->request) { + $block->set_value("request", "GET /t"); + } +}); + +run_tests(); + +__DATA__ + +=== TEST 1: setup all-in-one test +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/upstreams/u1', + ngx.HTTP_PUT, + [[{ + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }]] + ) + + if code >= 300 then + ngx.status = code + return + end + ngx.say(body) + + local code, body = t('/apisix/admin/consumers', + ngx.HTTP_PUT, + [[{ + "username": "test", + "plugins": { + "key-auth": { + "disable": false, + "key": "test-key" + } + } + }]] + ) + + if code >= 300 then + ngx.status = code Review comment: We can't write to ngx.status after generating output (like ngx.say). This will cause an error. -- 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]
