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 2022/08/22 09:16:48 UTC

[GitHub] [apisix] tzssangglass opened a new pull request, #7760: feat: add workflow plugin(mvp)

tzssangglass opened a new pull request, #7760:
URL: https://github.com/apache/apisix/pull/7760

   ### Description
   
   I want to combine the existing DSL to support more complex limiting scenarios, this PR is just the first step in providing workflow plugins to implement basic orchestration capabilities.
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   Fixes # (issue)
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


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


[GitHub] [apisix] spacewander commented on a diff in pull request #7760: feat: add workflow plugin(mvp)

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #7760:
URL: https://github.com/apache/apisix/pull/7760#discussion_r952431812


##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,132 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 1
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+
+local return_schema = {
+    type = "object",
+    properties = {
+        code = {
+            type = "integer",
+            minimum = 100,
+            maximum = 599
+        }
+    },
+    required = {"code"}
+}
+
+
+local function exit(conf)
+    local code = tonumber(conf.code)

Review Comment:
   Is tonumber necessary after the schema check?



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


[GitHub] [apisix] spacewander commented on a diff in pull request #7760: feat: add workflow plugin(mvp)

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #7760:
URL: https://github.com/apache/apisix/pull/7760#discussion_r952328163


##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2

Review Comment:
   ```suggestion
                               minItems = 1
   ```
   is enough? Maybe we will add action without args in the future.



##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    for _, rule in ipairs(conf.rules) do
+        local ok, err = expr.new(rule.case)
+        if not ok then
+            return false, "failed to validate the 'case' expression: " .. err
+        end
+
+        local actions = rule.actions
+        for _, action in ipairs(actions) do
+
+            if not support_action[action[1]] then
+                return false, "unsupported action: " .. action[1]
+            end
+
+            if action[1] == "return" then
+                if not action[2].code then
+                    return false, "bad actions, code is needed if action is return"
+                end
+
+                if type(action[2].code) ~= "number" then
+                    return false, "bad code, the required type of code is number"
+                end
+            end
+       end
+    end
+
+    return true
+end
+
+
+local function do_action(actions)
+    for _, action in ipairs(actions) do
+        if action[1] == "return" then
+            local code = tonumber(action[2].code)
+            return core.response.exit(code)

Review Comment:
   Better to return a status code and do the exiting outside the plugin. Therefore, we can enable features like custom error response. And other actions in the future will need this change too.



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


[GitHub] [apisix] soulbird commented on a diff in pull request #7760: feat: add workflow plugin(mvp)

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7760:
URL: https://github.com/apache/apisix/pull/7760#discussion_r952292189


##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    for _, rule in ipairs(conf.rules) do
+        local ok, err = expr.new(rule.case)
+        if not ok then
+            return false, "failed to validate the 'case' expression: " .. err
+        end
+
+        local actions = rule.actions
+        for _, action in ipairs(actions) do
+
+            if not support_action[action[1]] then
+                return false, "unsupported action: " .. action[1]
+            end
+
+            if action[1] == "return" then
+                if not action[2].code then
+                    return false, "bad actions, code is needed if action is return"
+                end
+
+                if type(action[2].code) ~= "number" then
+                    return false, "bad code, the required type of code is number"
+                end
+            end
+       end
+    end
+
+    return true
+end
+
+
+local function do_action(actions)
+    for _, action in ipairs(actions) do
+        if action[1] == "return" then
+            local code = tonumber(action[2].code)
+            return core.response.exit(code)

Review Comment:
   It's better to also include error messages instead of just code.



##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,

Review Comment:
   It is better to register a handler for each action.



##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    for _, rule in ipairs(conf.rules) do
+        local ok, err = expr.new(rule.case)
+        if not ok then
+            return false, "failed to validate the 'case' expression: " .. err
+        end
+
+        local actions = rule.actions
+        for _, action in ipairs(actions) do
+
+            if not support_action[action[1]] then
+                return false, "unsupported action: " .. action[1]
+            end
+
+            if action[1] == "return" then
+                if not action[2].code then
+                    return false, "bad actions, code is needed if action is return"
+                end
+
+                if type(action[2].code) ~= "number" then
+                    return false, "bad code, the required type of code is number"
+                end
+            end

Review Comment:
   It's better to add a separate schema validation function for each action, it will look more elegant.



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


[GitHub] [apisix] tzssangglass commented on a diff in pull request #7760: feat: add workflow plugin(mvp)

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #7760:
URL: https://github.com/apache/apisix/pull/7760#discussion_r952465268


##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,132 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 1
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+
+local return_schema = {
+    type = "object",
+    properties = {
+        code = {
+            type = "integer",
+            minimum = 100,
+            maximum = 599
+        }
+    },
+    required = {"code"}
+}
+
+
+local function exit(conf)
+    local code = tonumber(conf.code)

Review Comment:
   no need, fix it on next PR.



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


[GitHub] [apisix] tzssangglass commented on a diff in pull request #7760: feat: add workflow plugin(mvp)

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #7760:
URL: https://github.com/apache/apisix/pull/7760#discussion_r952407137


##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    for _, rule in ipairs(conf.rules) do
+        local ok, err = expr.new(rule.case)
+        if not ok then
+            return false, "failed to validate the 'case' expression: " .. err
+        end
+
+        local actions = rule.actions
+        for _, action in ipairs(actions) do
+
+            if not support_action[action[1]] then
+                return false, "unsupported action: " .. action[1]
+            end
+
+            if action[1] == "return" then
+                if not action[2].code then
+                    return false, "bad actions, code is needed if action is return"
+                end
+
+                if type(action[2].code) ~= "number" then
+                    return false, "bad code, the required type of code is number"
+                end
+            end

Review Comment:
   updated



##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    for _, rule in ipairs(conf.rules) do
+        local ok, err = expr.new(rule.case)
+        if not ok then
+            return false, "failed to validate the 'case' expression: " .. err
+        end
+
+        local actions = rule.actions
+        for _, action in ipairs(actions) do
+
+            if not support_action[action[1]] then
+                return false, "unsupported action: " .. action[1]
+            end
+
+            if action[1] == "return" then
+                if not action[2].code then
+                    return false, "bad actions, code is needed if action is return"
+                end
+
+                if type(action[2].code) ~= "number" then
+                    return false, "bad code, the required type of code is number"
+                end
+            end
+       end
+    end
+
+    return true
+end
+
+
+local function do_action(actions)
+    for _, action in ipairs(actions) do
+        if action[1] == "return" then
+            local code = tonumber(action[2].code)
+            return core.response.exit(code)

Review Comment:
   updated



##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2

Review Comment:
   updated



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


[GitHub] [apisix] tzssangglass commented on a diff in pull request #7760: feat: add workflow plugin(mvp)

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #7760:
URL: https://github.com/apache/apisix/pull/7760#discussion_r952406967


##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,

Review Comment:
   updated



##########
apisix/plugins/workflow.lua:
##########
@@ -0,0 +1,123 @@
+--
+-- 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 expr       = require("resty.expr.v1")
+local ipairs     = ipairs
+local tonumber   = tonumber
+local type       = type
+
+local schema = {
+    type = "object",
+    properties = {
+        rules = {
+            type = "array",
+            items = {
+                type = "object",
+                properties = {
+                    case = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                        },
+                        minItems = 1,
+                    },
+                    actions = {
+                        type = "array",
+                        items = {
+                            type = "array",
+                            minItems = 2
+                        }
+                    }
+                },
+                required = {"case", "actions"}
+            }
+        }
+    }
+}
+
+local plugin_name = "workflow"
+
+local _M = {
+    version = 0.1,
+    priority = 1006,
+    name = plugin_name,
+    schema = schema
+}
+
+local support_action = {
+    ["return"] = true,
+}
+
+
+function _M.check_schema(conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return false, err
+    end
+
+    for _, rule in ipairs(conf.rules) do
+        local ok, err = expr.new(rule.case)
+        if not ok then
+            return false, "failed to validate the 'case' expression: " .. err
+        end
+
+        local actions = rule.actions
+        for _, action in ipairs(actions) do
+
+            if not support_action[action[1]] then
+                return false, "unsupported action: " .. action[1]
+            end
+
+            if action[1] == "return" then
+                if not action[2].code then
+                    return false, "bad actions, code is needed if action is return"
+                end
+
+                if type(action[2].code) ~= "number" then
+                    return false, "bad code, the required type of code is number"
+                end
+            end
+       end
+    end
+
+    return true
+end
+
+
+local function do_action(actions)
+    for _, action in ipairs(actions) do
+        if action[1] == "return" then
+            local code = tonumber(action[2].code)
+            return core.response.exit(code)

Review Comment:
   updated



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


[GitHub] [apisix] spacewander merged pull request #7760: feat: add workflow plugin(mvp)

Posted by GitBox <gi...@apache.org>.
spacewander merged PR #7760:
URL: https://github.com/apache/apisix/pull/7760


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