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



##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -0,0 +1,124 @@
+--
+-- 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 = -1901,
+    name = "openwhisk",
+    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() ~= "GET" then
+        local content_type = core.request.header(ctx, "Content-Type")
+        if not core.string.has_prefix(content_type, "application/json") then
+            core.log.error("only support json request body")
+            return 415
+        end
+    end
+
+    -- Please avoid transferring large amounts of data or uploading files, 
which can
+    -- cause your requested data to be discarded. Depends on 
`client_body_buffer_size`.
+    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
+    end
+
+    -- setting response headers
+    core.response.set_header(res.headers)

Review comment:
       Should we handle HTTP2 like the azure version?

##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -0,0 +1,124 @@
+--
+-- 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 = -1901,
+    name = "openwhisk",
+    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() ~= "GET" then
+        local content_type = core.request.header(ctx, "Content-Type")
+        if not core.string.has_prefix(content_type, "application/json") then
+            core.log.error("only support json request body")
+            return 415
+        end
+    end
+
+    -- Please avoid transferring large amounts of data or uploading files, 
which can

Review comment:
       The `core.request.get_body` will read data from file. This comment is 
incorrect. Please remove it.

##########
File path: docs/en/latest/plugins/openwhisk.md
##########
@@ -0,0 +1,107 @@
+---
+title: serverless

Review comment:
       Wrong title.

##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -0,0 +1,124 @@
+--
+-- 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 = -1901,
+    name = "openwhisk",
+    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() ~= "GET" then
+        local content_type = core.request.header(ctx, "Content-Type")
+        if not core.string.has_prefix(content_type, "application/json") then
+            core.log.error("only support json request body")
+            return 415
+        end

Review comment:
       We can only get the body after the valid check to avoid bypassing.

##########
File path: t/core/request.t
##########
@@ -437,3 +437,31 @@ c=z_z&v=x%20x
 nil
 --- error_log
 the post form is too large: request body in temp file not supported
+
+
+
+=== TEST 13: get_method
+--- config
+    location = /hello {
+        client_body_in_file_only clean;

Review comment:
       We don't need this directive, right?

##########
File path: docs/en/latest/plugins/openwhisk.md
##########
@@ -0,0 +1,107 @@
+---
+title: serverless
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Summary
+
+- [**Description**](#description)
+- [**Attributes**](#attributes)
+- [**Example**](#example)
+- [**Notice**](#Notice)
+
+## Description
+
+The `openwhisk` plugin is used to support integration with the [Apache 
OpenWhisk](https://openwhisk.apache.org) serverless platform and can be set up 
on a route in place of Upstream, which will take over the request and send it 
to the OpenWhisk API endpoint.
+
+Users can call the OpenWhisk action via APISIX, pass the request parameters 
via JSON and get the response content.
+
+## Attributes
+
+| Name | Type | Requirement | Default | Valid | Description |
+| -- | -- | -- | -- | -- | -- |
+| api_host | string | yes |   |   | OpenWhisk API host (eg. 
https://localhost:3233) |

Review comment:
       Can we use required/optional  like other plugins?

##########
File path: docs/en/latest/plugins/openwhisk.md
##########
@@ -0,0 +1,107 @@
+---
+title: serverless
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Summary
+
+- [**Description**](#description)
+- [**Attributes**](#attributes)
+- [**Example**](#example)
+- [**Notice**](#Notice)
+
+## Description
+
+The `openwhisk` plugin is used to support integration with the [Apache 
OpenWhisk](https://openwhisk.apache.org) serverless platform and can be set up 
on a route in place of Upstream, which will take over the request and send it 
to the OpenWhisk API endpoint.
+
+Users can call the OpenWhisk action via APISIX, pass the request parameters 
via JSON and get the response content.
+
+## Attributes
+
+| Name | Type | Requirement | Default | Valid | Description |
+| -- | -- | -- | -- | -- | -- |
+| api_host | string | yes |   |   | OpenWhisk API host (eg. 
https://localhost:3233) |
+| ssl_verify | bool | no | true |   | Whether to verify the certificate |
+| service_token | string | yes |   |   | OpenWhisk ServiceToken (The format is 
`xxx:xxx`,Passed through Basic Auth when calling the API) |
+| namespace | string | yes |   |   | OpenWhisk  Namespace (eg. guest) |
+| action | string | yes |   |   | OpenWhisk Action (eg. hello) |
+| result | bool | no | true |   | Whether to get Action metadata (default to 
execute function and get response; false to get Action metadata but not execute 
Action, including runtime, function body, restrictions, etc.) |
+| timeout | integer | no | 60000ms | [1, 60000]ms | OpenWhisk Action and HTTP 
call timeout. |

Review comment:
       The default/min value of timeout doesn't match the schema




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


Reply via email to