You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/11/19 01:52:43 UTC

[GitHub] [apisix] spacewander commented on a change in pull request #5518: feat: add Apache OpenWhisk plugin

spacewander commented on a change in pull request #5518:
URL: https://github.com/apache/apisix/pull/5518#discussion_r752804236



##########
File path: t/plugin/openwhisk.t
##########
@@ -0,0 +1,209 @@
+#
+# 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();

Review comment:
       New test file should contain https://github.com/apache/apisix/blob/1018576e30477a9d1e70710386aac998a68acc68/t/wasm/route.t#L31 to reduce repeated fields.

##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -0,0 +1,121 @@
+--
+-- 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 http              = require("resty.http")
+local ngx_encode_base64 = ngx.encode_base64
+local tostring          = tostring
+
+local schema = {
+    type = "object",
+    properties = {
+        api_host = {type = "string"},
+        ssl_verify = {
+            type = "boolean",
+            default = true,
+        },
+        service_token = {type = "string"},
+        namespace = {type = "string"},
+        action = {type = "string"},
+        result = {
+            type = "boolean",
+            default = true,
+        },
+        timeout = {
+            type = "integer",
+            minimum = 1000,
+            maximum = 60000,
+            default = 3000,
+            description = "timeout in milliseconds",
+        },
+        keepalive = {type = "boolean", default = true},
+        keepalive_timeout = {type = "integer", minimum = 1000, default = 60000},
+        keepalive_pool = {type = "integer", minimum = 1, default = 5}
+    },
+    required = {"api_host", "service_token", "namespace", "action"}
+}
+
+
+local _M = {
+    version = 0.1,
+    priority = 601,
+    name = "openwhisk-serverless",
+    schema = schema,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    return true
+end
+
+
+function _M.access(conf, ctx)
+    if core.request.get_method() == "POST" then
+        if core.request.header(ctx, "Content-Type") ~= "application/json" then
+            core.log.error("only support json request body")
+            return 400, "only support json request body"
+        end
+    end
+
+    local params = {
+        method = "POST",
+        body = core.request.get_body(),
+        query = {
+            blocking = "true",
+            result = tostring(conf.result),
+            timeout = conf.timeout
+        },
+        headers = {
+            ["Authorization"] = "Basic " .. ngx_encode_base64(conf.service_token),
+            ["Content-Type"] = "application/json",
+        },
+        keepalive = conf.keepalive,
+        ssl_verify = conf.ssl_verify
+    }
+
+    if conf.keepalive then
+        params.keepalive_timeout = conf.keepalive_timeout
+        params.keepalive_pool = conf.keepalive_pool
+    end
+
+    -- OpenWhisk action endpoint
+    local endpoint = conf.api_host .. "/api/v1/namespaces/" .. conf.namespace ..
+        "/actions/" .. conf.action
+
+    local httpc = http.new()
+    httpc:set_timeout(conf.timeout)
+
+    local res, err = httpc:request_uri(endpoint, params)
+
+    if not res or err then
+        core.log.error("failed to process openwhisk action, err: ", err)
+        return 503, "failed to process openwhisk action, err: " .. err

Review comment:
       See https://github.com/apache/apisix/pull/5479#discussion_r750813656

##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -0,0 +1,121 @@
+--
+-- 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 http              = require("resty.http")
+local ngx_encode_base64 = ngx.encode_base64
+local tostring          = tostring
+
+local schema = {
+    type = "object",
+    properties = {
+        api_host = {type = "string"},
+        ssl_verify = {
+            type = "boolean",
+            default = true,
+        },
+        service_token = {type = "string"},
+        namespace = {type = "string"},
+        action = {type = "string"},
+        result = {
+            type = "boolean",
+            default = true,
+        },
+        timeout = {
+            type = "integer",
+            minimum = 1000,
+            maximum = 60000,

Review comment:
       Please use the same timeout setting in azure-functions.

##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -0,0 +1,121 @@
+--
+-- 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 http              = require("resty.http")
+local ngx_encode_base64 = ngx.encode_base64
+local tostring          = tostring
+
+local schema = {
+    type = "object",
+    properties = {
+        api_host = {type = "string"},
+        ssl_verify = {
+            type = "boolean",
+            default = true,
+        },
+        service_token = {type = "string"},
+        namespace = {type = "string"},
+        action = {type = "string"},
+        result = {
+            type = "boolean",
+            default = true,
+        },
+        timeout = {
+            type = "integer",
+            minimum = 1000,
+            maximum = 60000,
+            default = 3000,
+            description = "timeout in milliseconds",
+        },
+        keepalive = {type = "boolean", default = true},
+        keepalive_timeout = {type = "integer", minimum = 1000, default = 60000},
+        keepalive_pool = {type = "integer", minimum = 1, default = 5}
+    },
+    required = {"api_host", "service_token", "namespace", "action"}
+}
+
+
+local _M = {
+    version = 0.1,
+    priority = 601,
+    name = "openwhisk-serverless",
+    schema = schema,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    return true
+end
+
+
+function _M.access(conf, ctx)
+    if core.request.get_method() == "POST" then
+        if core.request.header(ctx, "Content-Type") ~= "application/json" then
+            core.log.error("only support json request body")
+            return 400, "only support json request body"
+        end
+    end
+
+    local params = {
+        method = "POST",
+        body = core.request.get_body(),

Review comment:
       See https://github.com/apache/apisix/pull/5479#discussion_r750883106

##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -0,0 +1,121 @@
+--
+-- 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 http              = require("resty.http")
+local ngx_encode_base64 = ngx.encode_base64
+local tostring          = tostring
+
+local schema = {
+    type = "object",
+    properties = {
+        api_host = {type = "string"},
+        ssl_verify = {
+            type = "boolean",
+            default = true,
+        },
+        service_token = {type = "string"},
+        namespace = {type = "string"},
+        action = {type = "string"},
+        result = {
+            type = "boolean",
+            default = true,
+        },
+        timeout = {
+            type = "integer",
+            minimum = 1000,
+            maximum = 60000,
+            default = 3000,
+            description = "timeout in milliseconds",
+        },
+        keepalive = {type = "boolean", default = true},
+        keepalive_timeout = {type = "integer", minimum = 1000, default = 60000},
+        keepalive_pool = {type = "integer", minimum = 1, default = 5}
+    },
+    required = {"api_host", "service_token", "namespace", "action"}
+}
+
+
+local _M = {
+    version = 0.1,
+    priority = 601,
+    name = "openwhisk-serverless",
+    schema = schema,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    return true
+end
+
+
+function _M.access(conf, ctx)
+    if core.request.get_method() == "POST" then
+        if core.request.header(ctx, "Content-Type") ~= "application/json" then

Review comment:
       Why check the Content-Type here?

##########
File path: conf/config-default.yaml
##########
@@ -338,6 +338,7 @@ plugins:                          # plugin list (sorted by priority)
   - traffic-split                  # priority: 966
   - redirect                       # priority: 900
   - response-rewrite               # priority: 899
+  - openwhisk                      # priority: 601

Review comment:
       Please use the similar priority like azure-functions




-- 
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-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org