You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2019/05/09 05:10:27 UTC

[incubator-openwhisk-apigateway] branch master updated: Add paging to getTenantAPIs (#335)

This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-apigateway.git


The following commit(s) were added to refs/heads/master by this push:
     new 1f46de9  Add paging to getTenantAPIs (#335)
1f46de9 is described below

commit 1f46de9d2f7a9420e48c533af7a4b1b6118aa130
Author: Lars Andersson <la...@users.noreply.github.com>
AuthorDate: Thu May 9 07:10:22 2019 +0200

    Add paging to getTenantAPIs (#335)
    
    * Fix for https://github.com/apache/incubator-openwhisk/issues/1692#issuecomment-463651323
---
 scripts/lua/management/lib/tenants.lua | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/scripts/lua/management/lib/tenants.lua b/scripts/lua/management/lib/tenants.lua
index fda5413..314da92 100644
--- a/scripts/lua/management/lib/tenants.lua
+++ b/scripts/lua/management/lib/tenants.lua
@@ -114,7 +114,39 @@ function _M.getTenantAPIs(dataStore, id, queryParams)
       end
     end
   end
-  return apiList
+  if ((queryParams['skip']  == nil and queryParams['limit'] == nil) or table.getn(apiList) == 0) then
+    return apiList
+  else
+    return applyPagingToAPIs(apiList, queryParams)
+  end
+end
+
+-- Apply paging on apis
+-- @param apis the list of apis
+-- @param queryparams object containing optional query parameters
+function applyPagingToAPIs(apiList, queryParams)
+  local skip  = queryParams['skip']  == nil and 1 or queryParams['skip']
+  local limit = queryParams['limit'] == nil and table.getn(apiList) or queryParams['limit']
+  if (tonumber(limit) < 1) then
+    return {}
+  end
+  if (tonumber(skip) <= 0) then
+    skip = 1
+  else
+    skip = skip + 1
+  end
+  if ((skip + limit - 1) > table.getn(apiList)) then
+    limit = table.getn(apiList)
+  else
+    limit = skip + limit - 1
+  end
+  local apis  = {}
+  local idx   = 0
+  for i = skip, limit do
+    apis[idx] = apiList[i]
+    idx = idx + 1
+  end
+  return apis
 end
 
 --- Filter apis based on query paramters