Execute lua file using pre-function

1)I have created a lua file which I wanted to execute before the plugin execution in Kong EE using pre-function.

  1. contains custom.lua file

local BasePlugin = require “kong.plugins.base_plugin”
local access = require “kong.plugins.request-transformer.access”

local RequestTransformerHandler = BasePlugin:extend()

function RequestTransformerHandler:new()
RequestTransformerHandler.super.new(self, “request-transformer”)
end

function RequestTransformerHandler:access(conf)
RequestTransformerHandler.super.access(self)
access.execute(conf)
end

local ACLHandler = BasePlugin:extend()

function ACLHandler:new()
ACLHandler.super.new(self, “acl”)
end

function ACLHandler:access(conf)
ACLHandler.super.access(self)
end
3)
execute - curl -i -X POST http://localhost:8001/services/custom1/plugins -F ‘name=pre-function’ -F ‘config.functions=@custom.lua’
4)
I am getting the below error
HTTP/1.1 100 Continue

HTTP/1.1 400 Bad Request
Date: Tue, 26 Mar 2019 14:43:40 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: http://10.120.9.142:8002
X-Kong-Admin-Request-ID: rrE4ykbI4xmG4Dt7B1FAjsld3EuED92i
Vary: Origin
Access-Control-Allow-Credentials: true
Server: kong/0.34-1-enterprise-edition

{“config”:"Error parsing pre-function #1: [string “local BasePlugin = require “kong.plugins.base…”]:6: ‘)’ expected near ‘’”}

Hi, this forum is primarily for the open source version of Kong. For Kong EE, we recommend you contact your sales representative or your Customer Success contact. That is because communication in this forum is not covered by any contract, and thus not subject to any SLA.

That said, your immediate problem seems to be a syntax error inside custom.lua. I don’t know exactly where this problem is, the code that you have pasted doesn’t look incorrect.

Also, I’m under the impression that you misunderstood the way custom.lua is supposed to work. You seem to have assumed it is able to “inject” lua code inside Kong, and thus redefine how some functions (in this case, from the RequestTransformer and ACLHandler plugin).

That’s not possible because plugin execution is sandboxed: your custom code just created several tables and attempted to insert functions on them, but it can not alter Kong’s own code.

I recommend you give a look at the example docs for the serverless functions plugin. You will see that the code that is expected is code that will act on the request - things like checking a header or returning immediately are permitted. Overriding other plugin’s code is not allowed.