fix(lint): most lint errors resolved
diff --git a/scripts/lua/api_gateway_init.lua b/scripts/lua/api_gateway_init.lua
index 0fc0fbf..91b3421 100644
--- a/scripts/lua/api_gateway_init.lua
+++ b/scripts/lua/api_gateway_init.lua
@@ -24,18 +24,20 @@
 --- Loads a lua gracefully. If the module doesn't exist the exception is caught, logged and the execution continues
 -- @param module path to the module to be loaded
 --
-local function loadrequire(module)
-    ngx.log(ngx.DEBUG, "Loading module [" .. tostring(module) .. "]")
+local function loadrequire(mod)
+    ngx.log(ngx.DEBUG, "Loading module [" .. tostring(mod) .. "]")
     local function requiref(module)
         require(module)
     end
 
-    local res = pcall(requiref, module)
+    local res = pcall(requiref, mod)
     if not (res) then
-        ngx.log(ngx.WARN, "Could not load module [", module, "].")
+        ngx.log(ngx.WARN, "Could not load module [", mod, "].")
         return nil
     end
-    return require(module)
+    return require(mod)
 end
 
+_M.loadrequire = loadrequire
+
 ngx.apiGateway = _M
diff --git a/scripts/lua/lib/redis.lua b/scripts/lua/lib/redis.lua
index 5c4da83..0012281 100644
--- a/scripts/lua/lib/redis.lua
+++ b/scripts/lua/lib/redis.lua
@@ -25,7 +25,7 @@
 local lrucache
 local CACHE_SIZE
 local CACHE_TTL
-local c, err
+local c
 
 local REDIS_HOST = os.getenv("REDIS_HOST")
 local REDIS_PORT = os.getenv("REDIS_PORT")
@@ -41,9 +41,10 @@
   lrucache = require "resty.lrucache"
   CACHE_SIZE = tonumber(os.getenv('CACHE_SIZE'))
   CACHE_TTL = tonumber(os.getenv('CACHE_TTL'))
-  c, err = lrucache.new(CACHE_SIZE)
+  local err_c
+  c, err_c = lrucache.new(CACHE_SIZE)
   if not c then
-    return error("Failed to initialize LRU cache" .. (err or "unknown"))
+    return error("Failed to initialize LRU cache" .. (err_c or "unknown"))
   end
 end
 
@@ -84,9 +85,10 @@
   end
   -- Authenticate with Redis
   if password ~= nil and password ~= "" and red:get_reused_times() < 1 then
-    local res, err = red:auth(password)
+    local res, err_auth = red:auth(password)
     if not res then
-      request.err(500, utils.concatStrings({"Failed to authenticate: ", err}))
+      ngx.log(ngx.ERR, utils.concatStrings({"[redis] failed to authenticate: ", err_auth}))
+      request.err(500, "Internal server error")
     end
   end
   return red
@@ -98,7 +100,8 @@
   -- put it into the connection pool of size 100, with 10 seconds max idle time
   local ok, err = red:set_keepalive(10000, 100)
   if not ok then
-    request.err(500, utils.concatStrings({"Failed to set keepalive: ", err}))
+    ngx.log(ngx.ERR, utils.concatStrings({"Failed to set keepalive: ", err}))
+    request.err(500, "Internal server error")
   end
 end
 
@@ -146,7 +149,7 @@
 
 local function get(red, key)
   if CACHING_ENABLED then
-    local cached, stale = c:get(key)
+    local cached = c:get(key)
     if cached ~= nil then
       return cached
     else
@@ -167,7 +170,7 @@
 
 local function hget(red, key, id)
   if CACHING_ENABLED then
-    local cachedmap, stale = c:get(key)
+    local cachedmap = c:get(key)
     if cachedmap ~= nil then
       local cached = cachedmap:get(id)
       if cached ~= nil then
@@ -290,7 +293,7 @@
     local snapshotId = _M.getSnapshotId(red, apiObj.tenantId)
     -- Delete all resources for the existingAPI
     local basePath = existingAPI.basePath:sub(2)
-    for path, v in pairs(existingAPI.resources) do
+    for path in pairs(existingAPI.resources) do
       local gatewayPath = ngx.unescape_uri(utils.concatStrings({basePath, ngx.escape_uri(path)}))
       gatewayPath = gatewayPath:sub(1,1) == "/" and gatewayPath:sub(2) or gatewayPath
       local redisKey = utils.concatStrings({"resources:", existingAPI.tenantId, ":", gatewayPath})
@@ -346,10 +349,12 @@
   if snapshotId ~= nil then
     resource = utils.concatStrings({'snapshots:', snapshotId, ':', resource})
   end
-  local resource = hget(red, resource, "resources")
+
+  resource = hget(red, resource, "resources")
   if resource == ngx.null then
     return nil
   end
+
   resource = cjson.decode(resource)
   return resource.apiId
 end
@@ -485,17 +490,17 @@
   if snapshotId ~= nil then
     key = utils.concatStrings({'snapshots:', snapshotId, ':', key})
   end
-  local resourceObj, err = hget(red, key, field)
+  local resourceObj, err_hget = hget(red, key, field)
   if not resourceObj then
-    request.err(500, utils.concatStrings({"Failed to delete the resource: ", err}))
+    request.err(500, utils.concatStrings({"Failed to delete the resource: ", err_hget}))
   end
   if resourceObj == ngx.null then
     request.err(404, "Resource doesn't exist.")
   end
   -- Delete redis resource
-  local ok, err = del(red, key)
+  local ok, err_del = del(red, key)
   if not ok then
-    request.err(500, utils.concatStrings({"Failed to delete the resource: ", err}))
+    request.err(500, utils.concatStrings({"Failed to delete the resource: ", err_del}))
   else
     return ok
   end
@@ -596,16 +601,16 @@
   if snapshotId ~= nil then
     key = utils.concatStrings({'snapshots:', snapshotId, ':', key})
   end
-  local subscription, err = get(red, key)
+  local subscription, err_get = get(red, key)
   if not subscription then
-    request.err(500, utils.concatStrings({"Failed to delete the subscription key: ", err}))
+    request.err(500, utils.concatStrings({"Failed to delete the subscription key: ", err_get}))
   end
   if subscription == ngx.null then
     request.err(404, "Subscription doesn't exist.")
   end
-  local ok, err = del(red, key)
+  local ok, err_del = del(red, key)
   if not ok then
-    request.err(500, utils.concatStrings({"Failed to delete the subscription key: ", err}))
+    request.err(500, utils.concatStrings({"Failed to delete the subscription key: ", err_del}))
   end
 end
 
diff --git a/scripts/lua/lib/utils.lua b/scripts/lua/lib/utils.lua
index 4c58f83..a7a617f 100644
--- a/scripts/lua/lib/utils.lua
+++ b/scripts/lua/lib/utils.lua
@@ -26,7 +26,7 @@
 -- @return concatenated string
 function _Utils.concatStrings(list)
   local t = {}
-  for k,v in ipairs(list) do
+  for _, v in ipairs(list) do
     t[#t+1] = tostring(v)
   end
   return table.concat(t)
@@ -84,7 +84,7 @@
 -- @param table table to check
 -- @param element element to check in table
 function _Utils.tableContains(table, element)
-  for i, value in pairs(table) do
+  for _, value in pairs(table) do
     if value == element then
       return true
     end
@@ -96,7 +96,7 @@
 -- @param table table to check
 -- @param requiredFields list of required fields
 function _Utils.tableContainsAll(table, requiredFields)
-  for i, field in ipairs(requiredFields) do
+  for _, field in ipairs(requiredFields) do
     if not table[field] then
       return false, { statusCode = 400, message = _Utils.concatStrings({"\"", field, "\" missing from request body."}) }
     end
diff --git a/scripts/lua/management/lib/resources.lua b/scripts/lua/management/lib/resources.lua
index 2c323e8..3b8ed4b 100644
--- a/scripts/lua/management/lib/resources.lua
+++ b/scripts/lua/management/lib/resources.lua
@@ -19,7 +19,6 @@
 -- Management interface for resources for the gateway
 
 local utils = require "lib/utils"
-local cjson = require "cjson"
 local REDIS_FIELD = "resources"
 local _M = {}
 
diff --git a/scripts/lua/management/lib/subscriptions.lua b/scripts/lua/management/lib/subscriptions.lua
index 68add54..cad91e6 100644
--- a/scripts/lua/management/lib/subscriptions.lua
+++ b/scripts/lua/management/lib/subscriptions.lua
@@ -18,7 +18,6 @@
 --- @module subscriptions
 -- Management interface for subscriptions for the gateway
 
-local redis = require "lib/redis"
 local utils = require "lib/utils"
 
 local _M = {}
diff --git a/scripts/lua/management/lib/tenants.lua b/scripts/lua/management/lib/tenants.lua
index 4fb7a8a..e99d885 100644
--- a/scripts/lua/management/lib/tenants.lua
+++ b/scripts/lua/management/lib/tenants.lua
@@ -115,18 +115,18 @@
   else
     limit = skip + limit - 1
   end
-  local apis  = {}
+  local apis_obj  = {}
   local idx   = 0
   for i = skip, limit do
-    apis[idx] = apiList[i]
+    apis_obj[idx] = apiList[i]
     idx = idx + 1
   end
-  return apis
+  return apis_obj
 end
 
 --- Filter apis based on query paramters
 -- @param queryParams query parameters to filter apis
-local function filterTenantAPIs(id, apis, queryParams)
+local function filterTenantAPIs(id, apis_obj, queryParams)
   local basePath = queryParams['filter[where][basePath]']
   basePath = basePath == nil and queryParams['basePath'] or basePath
   local name = queryParams['filter[where][name]']
@@ -137,7 +137,7 @@
   end
   -- filter apis
   local apiList = {}
-  for k, v in pairs(apis) do
+  for k, v in pairs(apis_obj) do
     if k%2 == 0 then
       local api = cjson.decode(v)
       if api.tenantId == id and
@@ -156,14 +156,14 @@
 -- @param id tenant id
 -- @param queryParams object containing optional query parameters
 function _M.getTenantAPIs(dataStore, id, queryParams)
-  local apis = dataStore:getAllAPIs()
+  local apis_obj = dataStore:getAllAPIs()
   local apiList
   if next(queryParams) ~= nil then
-    apiList = filterTenantAPIs(id, apis, queryParams);
+    apiList = filterTenantAPIs(id, apis_obj, queryParams);
   end
   if apiList == nil then
     apiList = {}
-    for k, v in pairs(apis) do
+    for k, v in pairs(apis_obj) do
       if k%2 == 0 then
         local decoded = cjson.decode(v)
         if decoded.tenantId == id then
diff --git a/scripts/lua/management/lib/validation.lua b/scripts/lua/management/lib/validation.lua
index 8eef460..de61389 100644
--- a/scripts/lua/management/lib/validation.lua
+++ b/scripts/lua/management/lib/validation.lua
@@ -62,7 +62,7 @@
     end
     -- Check required fields
     local requiredFields = {"backendMethod", "backendUrl"}
-    for k, v in pairs(requiredFields) do
+    for _, v in pairs(requiredFields) do
       if verbObj[v] == nil then
         return false, { statusCode = 400, message = utils.concatStrings({"Missing field '", v, "' for '", verb, "' operation."}) }
       end
diff --git a/scripts/lua/management/routes/apis.lua b/scripts/lua/management/routes/apis.lua
index 45086c1..c22b68f 100644
--- a/scripts/lua/management/routes/apis.lua
+++ b/scripts/lua/management/routes/apis.lua
@@ -19,7 +19,6 @@
 -- Management interface for apis for the gateway
 
 local cjson = require "cjson"
-local dataStore = require "lib/dataStore"
 local utils = require "lib/utils"
 local request = require "lib/request"
 local apis = require "management/lib/apis"
@@ -27,10 +26,6 @@
 local swagger = require "management/lib/swagger"
 local validation = require "management/lib/validation"
 
-local REDIS_HOST = os.getenv("REDIS_HOST")
-local REDIS_PORT = os.getenv("REDIS_PORT")
-local REDIS_PASS = os.getenv("REDIS_PASS")
-
 local _M = {}
 
 --- Check for api id from uri and use existing API if it already exists in redis
diff --git a/scripts/lua/management/routes/subscriptions.lua b/scripts/lua/management/routes/subscriptions.lua
index 6d9406a..e7fdfb5 100644
--- a/scripts/lua/management/routes/subscriptions.lua
+++ b/scripts/lua/management/routes/subscriptions.lua
@@ -19,15 +19,10 @@
 -- Management interface for subscriptions for the gateway
 
 local cjson = require "cjson"
-local redis = require "lib/redis"
 local utils = require "lib/utils"
 local request = require "lib/request"
 local subscriptions = require "management/lib/subscriptions"
 
-local REDIS_HOST = os.getenv("REDIS_HOST")
-local REDIS_PORT = os.getenv("REDIS_PORT")
-local REDIS_PASS = os.getenv("REDIS_PASS")
-
 local _M = {}
 
 local function validateSubscriptionBody(dataStore)
diff --git a/scripts/lua/management/routes/tenants.lua b/scripts/lua/management/routes/tenants.lua
index 4b92bdd..b9d0c33 100644
--- a/scripts/lua/management/routes/tenants.lua
+++ b/scripts/lua/management/routes/tenants.lua
@@ -19,13 +19,9 @@
 -- Management interface for tenants for the gateway
 
 local cjson = require "cjson"
-local redis = require "lib/redis"
 local utils = require "lib/utils"
 local request = require "lib/request"
 local tenants = require "management/lib/tenants"
-local REDIS_HOST = os.getenv("REDIS_HOST")
-local REDIS_PORT = os.getenv("REDIS_PORT")
-local REDIS_PASS = os.getenv("REDIS_PASS")
 
 local _M = {};
 
diff --git a/scripts/lua/oauth/app-id.lua b/scripts/lua/oauth/app-id.lua
index b594def..09cab09 100644
--- a/scripts/lua/oauth/app-id.lua
+++ b/scripts/lua/oauth/app-id.lua
@@ -63,7 +63,7 @@
   for _, v in ipairs(keys) do
     key = v
   end
-  local result = cjose.validateJWS(token, cjson.encode(key))
+  result = cjose.validateJWS(token, cjson.encode(key))
   if not result then
     request.err(401, 'The token signature did not match any known JWK.')
     return nil
diff --git a/scripts/lua/oauth/facebook.lua b/scripts/lua/oauth/facebook.lua
index 08b1f5b..33ef37c 100644
--- a/scripts/lua/oauth/facebook.lua
+++ b/scripts/lua/oauth/facebook.lua
@@ -23,7 +23,6 @@
 
 local function exchangeOAuthToken(dataStore, token, facebookAppToken)
   local http = require 'resty.http'
-  local request = require "lib/request"
   local httpc = http.new()
 
   local request_options = {
diff --git a/scripts/lua/oauth/github.lua b/scripts/lua/oauth/github.lua
index 51addf1..f76032d 100644
--- a/scripts/lua/oauth/github.lua
+++ b/scripts/lua/oauth/github.lua
@@ -16,7 +16,6 @@
 --
 
 -- A Proxy for Github OAuth API
-local cjson = require "cjson"
 local http = require "resty.http"
 local request = require "lib/request"
 local cjson = require "cjson"
diff --git a/scripts/lua/oauth/google.lua b/scripts/lua/oauth/google.lua
index efdbf28..bdc7efc 100644
--- a/scripts/lua/oauth/google.lua
+++ b/scripts/lua/oauth/google.lua
@@ -20,7 +20,6 @@
 local http = require "resty.http"
 local request = require "lib/request"
 local utils = require "lib/utils"
-local redis = require "lib/redis"
 
 local _M = {}
 function _M.process (dataStore, token)
diff --git a/scripts/lua/oauth/mock.lua b/scripts/lua/oauth/mock.lua
index 3fc9b47..f59c873 100644
--- a/scripts/lua/oauth/mock.lua
+++ b/scripts/lua/oauth/mock.lua
@@ -19,7 +19,6 @@
 local cjson = require "cjson"
 local _M = {}
 function _M.process (red, token)
-  local result
   if token == "test" then
     local goodResult = [[
       {
diff --git a/scripts/lua/policies/mapping.lua b/scripts/lua/policies/mapping.lua
index 3ed6385..9b06fdc 100644
--- a/scripts/lua/policies/mapping.lua
+++ b/scripts/lua/policies/mapping.lua
@@ -144,7 +144,7 @@
 -- @param d The destination object that we will move all found parameters to.
 local function transformAllParams(s, d)
   if s == 'query' then
-    for k, v in pairs(query) do
+    for k in pairs(query) do
       local t = {}
       t.from = {}
       t.from.name = k
@@ -156,7 +156,7 @@
       removeParam(t)
     end
   elseif s == 'header' then
-    for k, v in pairs(headers) do
+    for k in pairs(headers) do
       local t = {}
       t.from = {}
       t.from.name = k
@@ -168,7 +168,7 @@
       removeParam(t)
     end
   elseif s == 'body' then
-    for k, v in pairs(body) do
+    for k in pairs(body) do
       local t = {}
       t.from = {}
       t.from.name = k
@@ -180,7 +180,7 @@
       removeParam(t)
     end
   elseif s == 'path' then
-    for k, v in pairs(path) do
+    for k in pairs(path) do
       local t = {}
       t.from = {}
       t.from.name = k
@@ -229,7 +229,7 @@
 -- @param map The mapping object that contains details about request tranformations
 local function processMap(map)
   getRequestParams()
-  for k, v in pairs(map) do
+  for _, v in pairs(map) do
     if v.action == "insert" then
       insertParam(v)
     elseif v.action == "remove" then
diff --git a/scripts/lua/routing.lua b/scripts/lua/routing.lua
index fec0a45..a6ada97 100644
--- a/scripts/lua/routing.lua
+++ b/scripts/lua/routing.lua
@@ -45,7 +45,7 @@
 
 local function setRequestLogs()
   local requestHeaders = ngx.req.get_headers()
-  for k, v in pairs(requestHeaders) do
+  for k in pairs(requestHeaders) do
     if k == 'authorization' or k == ngx.ctx.clientSecretName then
       requestHeaders[k] = '[redacted]'
     end
@@ -60,7 +60,7 @@
 -- @param obj List of policies containing a type and value field. This function reads the type field and routes it appropriately.
 -- @param apiKey optional subscription api key
 local function parsePolicies(dataStore, obj, apiKey)
-  for k, v in pairs (obj) do
+  for _, v in pairs (obj) do
     if v.type == 'reqMapping' then
       mapping.processMap(v.value)
     elseif v.type == 'rateLimit' then
@@ -94,7 +94,7 @@
     dataStore:setSnapshotId(tenantId)
   end
   local gatewayPath = ngx.var.gatewayPath
-  local i, j = ngx.var.request_uri:find("/api/([^/]+)")
+  local _ , j = ngx.var.request_uri:find("/api/([^/]+)")
   ngx.var.analyticsUri = ngx.var.request_uri:sub(j+1)
   if ngx.req.get_headers()["x-debug-mode"] == "true" then
     setRequestLogs()
@@ -222,7 +222,7 @@
   end
   -- Construct a table of redisKeys based on number of slashes in the path
   local keyTable = {}
-  for i, key in pairs(resourceKeys) do
+  for _, key in pairs(resourceKeys) do
     local _, count = string.gsub(key, "/", "")
     -- handle cases where resource path is "/"
     if count == 1 and string.sub(key, -1) == "/" then