Lambda Function in Request Transformer plugin in Kubernetes

Hi Kong Nation

I have installed and tested few plugins in our K8s clusters (jwt and basic auth)

Currently I am having difficulty understanding how to implement the lambda function we created as a templated in our KongPlugin in K8s. Below is the lambda function.

I have no idea how I can apply the function that replaces the header to the plugin… thats my problem

Authorization:$((function()
local body, err, mimetype = kong.request.get_body()
local value = headers.Authorization
local default_basic_auth = "Basic " .. encode_base64("user:password") 
if (body.grant_type == "password" or body.grant_type == "refresh_token") then
    return default_basic_auth
end
if body.grant_type == "client_credentials" then
    return "Basic " .. encode_base64(body.client_id .. ":" .. body.client_secret) 
end
return kong.response.exit(401, [[{"message":"Invalid Credentials"}]])
  end)())

And below is the KongPlugin I have in place for Request Transformer, I just copied the one in the Kong Documentation.

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: request-xformer
config: 
  remove:
    headers:
    - x-toremove
    - x-another-one
  remove:
    querystring:
    - qs-old-name:qs-new-name
    - qs2-old-name:qs2-new-name
  remove:
    body:
    - formparam-toremove
    - formparam-another-one
  replace:
    body:
    - body-param1:new-value-1
    - body-param2:new-value-2
  rename:
    headers:
    - header-old-name:header-new-name
    - another-old-name:another-new-name
  rename:
    querystring:
    - qs-old-name:qs-new-name
    - qs2-old-name:qs2-new-name
  rename:
    body:
    - param-old:param-new
    - param2-old:param2-new
  add:
    headers:
    - x-new-header:value
    - x-another-header:something
  add:
    querystring:
    - new-param:some_value
    - another-param:some_value
  add:
    body:
    - new-form-param:some_value
    - another-form-param:some_value
plugin: request-transformer

I chose to enable it in Ingress resource

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: request-xformer-echo
  annotations:
    kubernetes.io/ingress.class: kong
    konghq.com/plugins: request-xformer
spec:
  rules:
  - host: echo.example.com
    http:
      paths:
      - path: /bar
        backend:
          serviceName: echo
          servicePort: 80

Im quite new at this but im quite familiar with K8s. thanks in adv!