Skip to content

Commit dcd08a6

Browse files
committed
added support for lua-resty-http lib and updated Makefile to execute integration tests
1 parent 5d042ed commit dcd08a6

File tree

12 files changed

+138
-12
lines changed

12 files changed

+138
-12
lines changed

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ test-docker:
4444
cp -r ~/tmp/apiplatform/api-gateway-aws/target/ ./target
4545
rm -rf ~/tmp/apiplatform/api-gateway-aws
4646

47+
integration-test-docker:
48+
echo "running integration-tests with docker ..."
49+
mkdir -p $(BUILD_DIR)
50+
mkdir -p $(BUILD_DIR)/test-logs
51+
# cp -r test/resources/api-gateway $(BUILD_DIR)
52+
# sed -i '' 's/127\.0\.0\.1/redis\.docker/g' $(BUILD_DIR)/api-gateway/redis-upstream.conf
53+
rm -f $(BUILD_DIR)/test-logs/*
54+
mkdir -p ~/tmp/apiplatform/api-gateway-aws
55+
cp -r ./src ~/tmp/apiplatform/api-gateway-aws/
56+
cp -r ./test ~/tmp/apiplatform/api-gateway-aws/
57+
cp -r ./target ~/tmp/apiplatform/api-gateway-aws/
58+
TEST_NGINX_AWS_CLIENT_ID="${TEST_NGINX_AWS_CLIENT_ID}" TEST_NGINX_AWS_SECRET="${TEST_NGINX_AWS_SECRET}" TEST_NGINX_AWS_SECURITY_TOKEN="${TEST_NGINX_AWS_SECURITY_TOKEN}" docker-compose -f ./test/docker-compose-integration-tests.yml up
59+
cp -r ~/tmp/apiplatform/api-gateway-aws/target/ ./target
60+
rm -rf ~/tmp/apiplatform/api-gateway-aws
61+
4762
test:
4863
echo "updating git submodules ..."
4964
if [ ! -d "test/resources/test-nginx/lib" ]; then git submodule update --init --recursive; fi

src/lua/api-gateway/aws/AwsService.lua

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
--[[
2+
Copyright (c) 2016. Adobe Systems Incorporated. All rights reserved.
3+
4+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software distributed under the License is
11+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR RESPRESENTATIONS OF ANY KIND,
12+
either express or implied. See the License for the specific language governing permissions and
13+
limitations under the License.
14+
15+
]]
16+
117
--- Base Class for working with AWS Services.
218
-- It's responsible for making API Requests to most of the AWS Services
319
--
@@ -13,11 +29,13 @@ local setmetatable = setmetatable
1329
local error = error
1430
local debug_mode = ngx.config.debug
1531
local http = require"api-gateway.aws.httpclient.http"
32+
local http_resty = require"api-gateway.aws.httpclient.restyhttp"
1633
local AWSV4S = require"api-gateway.aws.AwsV4Signature"
1734
local IamCredentials = require"api-gateway.aws.AWSIAMCredentials"
1835
local cjson = require"cjson"
1936

2037
local http_client = http:new()
38+
local http_client_resty = http_resty:new()
2139
local iam_credentials
2240

2341
local function tableToString(table_ref)
@@ -98,7 +116,9 @@ function _M:debug(...)
98116
end
99117

100118
function _M:getHttpClient()
101-
return http_client
119+
-- return http_client -- the original http_client which will be deprecated and removed soon
120+
-- by default use the new http client that uses resty.http module
121+
return http_client_resty
102122
end
103123

104124
function _M:getAWSHost()
@@ -242,6 +262,7 @@ function _M:performAction(actionName, arguments, path, http_method, useSSL, time
242262

243263
local ok, code, headers, status, body = self:getHttpClient():request(self:getRequestObject({
244264
scheme = scheme,
265+
ssl_verify = false,
245266
port = port,
246267
timeout = timeout or 60000,
247268
url = request_path, -- "/"
@@ -261,9 +282,4 @@ function _M:performAction(actionName, arguments, path, http_method, useSSL, time
261282
return ok, code, headers, status, body
262283
end
263284

264-
return _M
265-
266-
267-
268-
269-
285+
return _M
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--[[
2+
Copyright (c) 2016. Adobe Systems Incorporated. All rights reserved.
3+
4+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software distributed under the License is
11+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR RESPRESENTATIONS OF ANY KIND,
12+
either express or implied. See the License for the specific language governing permissions and
13+
limitations under the License.
14+
15+
]]
16+
17+
--
18+
-- This modules is a wrapper for the lua-resty-http (https://github.com/pintsized/lua-resty-http) library
19+
-- exposing the "request" method to be compatible with the embedded http client (api-gateway.aws.httpclient.http)
20+
-- User: ddascal
21+
-- Date: 08/03/16
22+
--
23+
24+
local _M = {}
25+
local http = require "resty.http"
26+
27+
function _M:new(o)
28+
local o = o or {}
29+
setmetatable(o, self)
30+
self.__index = self
31+
return o
32+
end
33+
34+
function _M:request( req )
35+
local ok, code
36+
local httpc = http.new()
37+
httpc:set_timeout(req.timeout or 60000)
38+
39+
local res, err = httpc:request_uri(req.scheme .. "://" .. req.host .. ":" .. req.port, {
40+
path = req.url,
41+
method = req.method,
42+
body = req.body,
43+
headers = req.headers,
44+
ssl_verify = false
45+
})
46+
47+
if not res then
48+
ngx.log(ngx.ERR, "failed to make request: ", err)
49+
return false, err, nil, err, nil
50+
end
51+
52+
return ok, res.status, res.headers, res.status, res.body
53+
end
54+
55+
return _M
56+

src/lua/api-gateway/aws/lambda/LambdaService.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ function _M:listFunctions(marker, maxItems)
4545
end
4646

4747
-- API: http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html
48-
-- {
49-
-- "ShardCount": number,
50-
-- "StreamName": "string"
51-
-- }
48+
--
5249
function _M:invoke(functionName, payload, clientContext, invocationType, logType)
5350
assert(functionName ~= nil, "Please provide a valid functionName.")
5451
local invocationType = invocationType or "RequestResponse"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
gateway:
2+
image: cellos/apigateway:1.9.7.3
3+
volumes:
4+
- ~/tmp/apiplatform/api-gateway-aws/src/lua/api-gateway/aws:/usr/local/api-gateway/lualib/api-gateway/aws
5+
- ~/tmp/apiplatform/api-gateway-aws/test/perl:/tmp/perl
6+
- ~/tmp/apiplatform/api-gateway-aws/test/integration:/tmp/integration
7+
- ~/tmp/apiplatform/api-gateway-aws/target/:/t
8+
environment:
9+
- LOG_LEVEL=debug
10+
- TEST_NGINX_AWS_CLIENT_ID
11+
- TEST_NGINX_AWS_SECRET
12+
- TEST_NGINX_AWS_SECURITY_TOKEN
13+
- TEST_NGINX_PORT=1989
14+
entrypoint: ["prove", "-I", "/usr/local/test-nginx-0.24/lib", "-I", "/usr/local/test-nginx-0.24/inc", "-r", "/tmp/integration"]

test/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
gateway:
2-
image: adobeapiplatform/apigateway
2+
image: cellos/apigateway:1.9.7.3
33
volumes:
44
- ~/tmp/apiplatform/api-gateway-aws/src/lua/api-gateway/aws:/usr/local/api-gateway/lualib/api-gateway/aws
55
- ~/tmp/apiplatform/api-gateway-aws/test/perl:/tmp/perl

test/integration/kinesis.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ our $HttpConfig = <<_EOC_;
4848
require "resty.core"
4949
';
5050
resolver @nameservers;
51+
52+
client_body_temp_path /tmp/;
53+
proxy_temp_path /tmp/;
54+
fastcgi_temp_path /tmp/;
5155
_EOC_
5256
5357
#no_diff();

test/integration/kms.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ our $HttpConfig = <<_EOC_;
4545
require "resty.core"
4646
';
4747
resolver @nameservers;
48+
49+
client_body_temp_path /tmp/;
50+
proxy_temp_path /tmp/;
51+
fastcgi_temp_path /tmp/;
4852
_EOC_
4953
5054
#no_diff();

test/integration/lambda.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ our $HttpConfig = <<_EOC_;
4848
require "resty.core"
4949
';
5050
resolver @nameservers;
51+
52+
client_body_temp_path /tmp/;
53+
proxy_temp_path /tmp/;
54+
fastcgi_temp_path /tmp/;
5155
_EOC_
5256
5357
#no_diff();

test/integration/sns.t

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# vim:set ft= ts=4 sw=4 et fdm=marker:
22
use lib 'lib';
3+
use strict;
4+
use warnings;
35
use Test::Nginx::Socket::Lua;
46
use Cwd qw(cwd);
57

@@ -45,6 +47,10 @@ our $HttpConfig = <<_EOC_;
4547
require "resty.core"
4648
';
4749
resolver @nameservers;
50+
51+
client_body_temp_path /tmp/;
52+
proxy_temp_path /tmp/;
53+
fastcgi_temp_path /tmp/;
4854
_EOC_
4955

5056
#no_diff();
@@ -172,6 +178,8 @@ X-Test: test
172178
ngx.say("Message_ID:" .. tostring(messageId))
173179
';
174180
}
181+
182+
--- timeout: 70
175183
--- more_headers
176184
X-Test: test
177185
--- request

0 commit comments

Comments
 (0)